@@ -984,3 +984,48 @@ func TestSweepBatcherComposite(t *testing.T) {
984984 require .True (t , batcherStore .AssertSweepStored (sweepReq5 .SwapHash ))
985985 require .True (t , batcherStore .AssertSweepStored (sweepReq6 .SwapHash ))
986986}
987+
988+ // makeTestTx creates a test transaction with a single output of the given
989+ // value.
990+ func makeTestTx (value int64 ) * wire.MsgTx {
991+ tx := wire .NewMsgTx (wire .TxVersion )
992+ tx .AddTxOut (wire .NewTxOut (value , nil ))
993+ return tx
994+ }
995+
996+ // TestGetFeePortionForSweep tests that the fee portion for a sweep is correctly
997+ // calculated.
998+ func TestGetFeePortionForSweep (t * testing.T ) {
999+ tests := []struct {
1000+ name string
1001+ spendTxValue int64
1002+ numSweeps int
1003+ totalSweptAmt btcutil.Amount
1004+ expectedFeePortion btcutil.Amount
1005+ expectedRoundingDiff btcutil.Amount
1006+ }{
1007+ {
1008+ "Even Split" ,
1009+ 100 , 5 , 200 , 20 , 0 ,
1010+ },
1011+ {
1012+ "Single Sweep" ,
1013+ 100 , 1 , 200 , 100 , 0 ,
1014+ },
1015+ {
1016+ "With Rounding Diff" ,
1017+ 200 , 4 , 350 , 37 , 2 ,
1018+ },
1019+ }
1020+
1021+ for _ , tt := range tests {
1022+ t .Run (tt .name , func (t * testing.T ) {
1023+ spendTx := makeTestTx (tt .spendTxValue )
1024+ feePortion , roundingDiff := getFeePortionForSweep (
1025+ spendTx , tt .numSweeps , tt .totalSweptAmt ,
1026+ )
1027+ require .Equal (t , tt .expectedFeePortion , feePortion )
1028+ require .Equal (t , tt .expectedRoundingDiff , roundingDiff )
1029+ })
1030+ }
1031+ }
0 commit comments