@@ -153,7 +153,7 @@ func testChainKitSendOutputsAnchorReserve(ht *lntest.HarnessTest) {
153153 // Charlie opens an anchor channel and keeps twice the amount of the
154154 // anchor reserve in her wallet.
155155 chanAmt := fundingAmount - 2 * btcutil .Amount (reserve .RequiredReserve )
156- ht .OpenChannel (charlie , bob , lntest.OpenChannelParams {
156+ outpoint := ht .OpenChannel (charlie , bob , lntest.OpenChannelParams {
157157 Amt : chanAmt ,
158158 CommitmentType : lnrpc .CommitmentType_ANCHORS ,
159159 SatPerVByte : 1 ,
@@ -208,6 +208,9 @@ func testChainKitSendOutputsAnchorReserve(ht *lntest.HarnessTest) {
208208 // This second transaction should be published correctly.
209209 charlie .RPC .SendOutputs (req )
210210 ht .MineBlocksAndAssertNumTxes (1 , 1 )
211+
212+ // Clean up our test setup.
213+ ht .CloseChannel (charlie , outpoint )
211214}
212215
213216// testAnchorReservedValue tests that we won't allow sending transactions when
@@ -898,3 +901,134 @@ func testListSweeps(ht *lntest.HarnessTest) {
898901 }
899902 ht .AssertNumSweeps (alice , req4 , 0 )
900903}
904+
905+ // testSendCoinsFeerate tests that we can create transaction with a specified
906+ // feerate in either sats_per_vbyte and sats_per_kweight.
907+ func testSendCoinsFeerate (ht * lntest.HarnessTest ) {
908+ alice := ht .NewNode ("Alice" , nil )
909+ // Send Alice enough coins to be able to call SendCoins.
910+ ht .FundCoins (btcutil .SatoshiPerBitcoin , alice )
911+ minerAddr := ht .Miner ().NewMinerAddress ()
912+
913+ sweepReq := & lnrpc.SendCoinsRequest {
914+ Addr : minerAddr .String (),
915+ SatPerVbyte : 2 ,
916+ Amount : 10001 ,
917+ }
918+ _ = alice .RPC .SendCoins (sweepReq )
919+
920+ // We'll mine a block which should include the sweep transaction we
921+ // generated above.
922+ block := ht .MineBlocksAndAssertNumTxes (1 , 1 )[0 ]
923+ sweepTx := block .Transactions [1 ].TxHash ()
924+
925+ // Calculate the feerate of the funding transaction in sat_per_vbyte.
926+ rawTx := ht .Miner ().GetRawTransaction (sweepTx )
927+ feerate := ht .CalculateFeeRateSatPerVByte (rawTx .MsgTx ())
928+
929+ // Allow some deviation because weight estimates during tx generation
930+ // are estimates (ECDSA signature size estimate).
931+ require .InEpsilon (ht , int64 (sweepReq .SatPerVbyte ), feerate , 0.01 )
932+
933+ // Send coins with a defined feerate in sat_per_kw.
934+ sweepReq = & lnrpc.SendCoinsRequest {
935+ Addr : minerAddr .String (),
936+ SatPerKw : 5000 ,
937+ Amount : 10002 ,
938+ }
939+ _ = alice .RPC .SendCoins (sweepReq )
940+
941+ // We'll mine a block which should include the sweep transaction we
942+ // generated above.
943+ block = ht .MineBlocksAndAssertNumTxes (1 , 1 )[0 ]
944+ sweepTx = block .Transactions [1 ].TxHash ()
945+
946+ // Calculate the feerate of the funding transaction in sat_per_kw.
947+ rawTx = ht .Miner ().GetRawTransaction (sweepTx )
948+ feerate = ht .CalculateFeeRateSatPerKWeight (rawTx .MsgTx ())
949+
950+ // Allow some deviation because weight estimates during tx generation
951+ // are estimates (ECDSA signature size estimate).
952+ require .InEpsilon (ht , int64 (sweepReq .SatPerKw ), feerate , 0.01 )
953+
954+ // Try sending coins with both feerate options sat_per_kw and
955+ // sat_per_vbyte specified.
956+ sweepReq = & lnrpc.SendCoinsRequest {
957+ Addr : minerAddr .String (),
958+ SatPerKw : 500 ,
959+ SatPerVbyte : 2 ,
960+ SendAll : true ,
961+ }
962+
963+ // This should fail because only one feerate option makes sense.
964+ err := alice .RPC .SendCoinsAssertErr (sweepReq )
965+ require .Error (ht , err , "either SatPerKW or SatPerVByte should " +
966+ "be set, but not both" )
967+ }
968+
969+ // testSendManyFeerate tests that we can create transaction with many outputs
970+ // with a specified feerate in either sats_per_vbyte and sats_per_kweight.
971+ func testSendManyFeerate (ht * lntest.HarnessTest ) {
972+ alice := ht .NewNode ("Alice" , nil )
973+ // Send Alice enough coins to be able to call SendCoins.
974+ ht .FundCoins (btcutil .SatoshiPerBitcoin , alice )
975+ addr1 := ht .Miner ().NewMinerAddress ().String ()
976+ addr2 := ht .Miner ().NewMinerAddress ().String ()
977+
978+ addrAmtMap := map [string ]int64 {
979+ addr1 : 50000 ,
980+ addr2 : 50000 ,
981+ }
982+
983+ // We create the transaction specifying the feerate in sats_per_vbyte.
984+ sendManyReq := & lnrpc.SendManyRequest {
985+ AddrToAmount : addrAmtMap ,
986+ SatPerVbyte : 2 ,
987+ }
988+ _ = alice .RPC .SendMany (sendManyReq )
989+
990+ // We'll mine a block which should include the sweep transaction we
991+ // generated above.
992+ block := ht .MineBlocksAndAssertNumTxes (1 , 1 )[0 ]
993+ sweepTx := block .Transactions [1 ].TxHash ()
994+
995+ // Calculate the feerate of the funding transaction in sat_per_vbyte.
996+ rawTx := ht .Miner ().GetRawTransaction (sweepTx )
997+ feerate := ht .CalculateFeeRateSatPerVByte (rawTx .MsgTx ())
998+
999+ // Allow some deviation because weight estimates during tx generation
1000+ // are estimates (ECDSA signature size estimate).
1001+ require .InEpsilon (ht , int64 (sendManyReq .SatPerVbyte ), feerate , 0.01 )
1002+
1003+ // We create the transaction specifying the feerate in
1004+ // sats_per_kweight.
1005+ sendManyReq = & lnrpc.SendManyRequest {
1006+ AddrToAmount : addrAmtMap ,
1007+ SatPerKw : 2000 ,
1008+ }
1009+ _ = alice .RPC .SendMany (sendManyReq )
1010+
1011+ // We'll mine a block which should include the sweep transaction we
1012+ // generated above.
1013+ block = ht .MineBlocksAndAssertNumTxes (1 , 1 )[0 ]
1014+ sweepTx = block .Transactions [1 ].TxHash ()
1015+
1016+ // Calculate the feerate of the funding transaction in sats_per_kweight.
1017+ rawTx = ht .Miner ().GetRawTransaction (sweepTx )
1018+ feerate = ht .CalculateFeeRateSatPerKWeight (rawTx .MsgTx ())
1019+
1020+ // Allow some deviation because weight estimates during tx generation
1021+ // are estimates (ECDSA signature size estimate).
1022+ require .InEpsilon (ht , int64 (sendManyReq .SatPerKw ), feerate , 0.01 )
1023+
1024+ // Try sending coins with both feerate options sat_per_kw and
1025+ // sat_per_vbyte specified.
1026+ sendManyReq = & lnrpc.SendManyRequest {
1027+ AddrToAmount : addrAmtMap ,
1028+ SatPerKw : 2000 ,
1029+ SatPerVbyte : 3 ,
1030+ }
1031+
1032+ // This should fail because only one feerate option makes sense.
1033+ alice .RPC .SendManyAssertErr (sendManyReq )
1034+ }
0 commit comments