Skip to content

Commit b9952fb

Browse files
committed
itest+lntest: add tests for sat/kw option
Add new itests for openchannel, sendcoins and sendmany. Fix the test "rbf coop close" that was broken by a safety check added to prevent very high fees. Change the test "runWalletImportAccountScenario" to start using SatPerVbyte field instead of the deprecated fiels SatPerByte.
1 parent 4ed48bb commit b9952fb

File tree

8 files changed

+338
-15
lines changed

8 files changed

+338
-15
lines changed

itest/list_on_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,18 @@ var allTestCases = []*lntest.TestCase{
615615
Name: "route blinding dummy hops",
616616
TestFunc: testBlindedRouteDummyHops,
617617
},
618+
{
619+
Name: "openchannel feerate",
620+
TestFunc: testOpenChannelFeerate,
621+
},
622+
{
623+
Name: "sendcoins feerate",
624+
TestFunc: testSendCoinsFeerate,
625+
},
626+
{
627+
Name: "sendmany feerate",
628+
TestFunc: testSendManyFeerate,
629+
},
618630
{
619631
Name: "removetx",
620632
TestFunc: testRemoveTx,

itest/lnd_coop_close_rbf_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func testCoopCloseRbf(ht *lntest.HarnessTest) {
1919
// enough coins to make a 50/50 channel.
2020
cfgs := [][]string{rbfCoopFlags, rbfCoopFlags}
2121
params := lntest.OpenChannelParams{
22-
Amt: btcutil.Amount(1000000),
23-
PushAmt: btcutil.Amount(1000000 / 2),
22+
Amt: btcutil.Amount(100000),
23+
PushAmt: btcutil.Amount(100000 / 2),
2424
}
2525
chanPoints, nodes := ht.CreateSimpleNetwork(cfgs, params)
2626
alice, bob := nodes[0], nodes[1]
@@ -92,8 +92,9 @@ func testCoopCloseRbf(ht *lntest.HarnessTest) {
9292
_, err = ht.ReceiveCloseChannelUpdate(bobCloseStream)
9393
require.NoError(ht, err)
9494

95-
// We'll now attempt a fee update that we can't actually pay for. This
96-
// will actually show up as an error to the remote party.
95+
// We'll now attempt a fee update greater than DefaultMaxFeeRate. It
96+
// will be capped at DefaultMaxFeeRate, but we still can't afford it.
97+
// This will result in an error shown to the remote party.
9798
aliceRejectedFeeRate = 100_000
9899
_, _ = ht.CloseChannelAssertPending(
99100
alice, chanPoint, false,

itest/lnd_onchain_test.go

Lines changed: 135 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
}

itest/lnd_open_channel_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,3 +1039,66 @@ func testFundingManagerFundingTimeout(ht *lntest.HarnessTest) {
10391039
// Cleanup the mempool by mining blocks.
10401040
ht.MineBlocksAndAssertNumTxes(6, 1)
10411041
}
1042+
1043+
// testOpenChannelFeerate tests that we can open a channel with a specified
1044+
// feerate either in sat_per_vbyte or in sat_per_kweight.
1045+
func testOpenChannelFeerate(ht *lntest.HarnessTest) {
1046+
alice, bob := ht.NewNode("Alice", nil), ht.NewNode("Bob", nil)
1047+
1048+
// Ensure Alice is connected to Bob.
1049+
ht.EnsureConnected(alice, bob)
1050+
1051+
// Send Alice enough coins to be able to call OpenChannel.
1052+
ht.FundCoins(btcutil.SatoshiPerBitcoin, alice)
1053+
1054+
chanAmt := funding.MaxBtcFundingAmount / 3
1055+
1056+
// First we test opening a channel by specifying the feerate in
1057+
// sat_per_kweight
1058+
params := lntest.OpenChannelParams{
1059+
Amt: chanAmt,
1060+
SatPerKWeight: 500,
1061+
}
1062+
1063+
// Create a channel Alice->Bob.
1064+
chanPoint := ht.OpenChannel(alice, bob, params)
1065+
defer ht.CloseChannel(alice, chanPoint)
1066+
1067+
// Calculate the feerate of the funding transaction.
1068+
fundingTxID := ht.GetChanPointFundingTxid(chanPoint)
1069+
rawTx := ht.Miner().GetRawTransaction(fundingTxID)
1070+
feerate := ht.CalculateFeeRateSatPerKWeight(rawTx.MsgTx())
1071+
1072+
// Allow some deviation because weight estimates during tx generation
1073+
// are estimates (ECDSA signature size estimate).
1074+
require.InEpsilon(ht, int64(params.SatPerKWeight), feerate, 0.01)
1075+
1076+
// Now we open another channel with the feerate sat_per_vbyte
1077+
params = lntest.OpenChannelParams{
1078+
Amt: chanAmt,
1079+
SatPerVByte: 100,
1080+
}
1081+
1082+
// Create a channel Alice->Bob.
1083+
chanPoint = ht.OpenChannel(alice, bob, params)
1084+
defer ht.CloseChannel(alice, chanPoint)
1085+
1086+
// Calculate the feerate of the funding transaction.
1087+
fundingTxID = ht.GetChanPointFundingTxid(chanPoint)
1088+
rawTx = ht.Miner().GetRawTransaction(fundingTxID)
1089+
feerate = ht.CalculateFeeRateSatPerVByte(rawTx.MsgTx())
1090+
1091+
// Allow some deviation because weight estimates during tx generation
1092+
// are estimates (ECDSA signature size estimate).
1093+
require.InEpsilon(ht, int64(params.SatPerVByte), feerate, 0.01)
1094+
1095+
// Test when specififying both feerate options we should fail.
1096+
params = lntest.OpenChannelParams{
1097+
Amt: chanAmt,
1098+
SatPerVByte: 2,
1099+
SatPerKWeight: 500,
1100+
}
1101+
1102+
ht.OpenChannelAssertErr(alice, bob, params, fmt.Errorf("either "+
1103+
"SatPerKWeight or SatPerVByte should be set, but not both"))
1104+
}

itest/lnd_wallet_import_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ func runWalletImportAccountScenario(ht *lntest.HarnessTest,
566566
// balance updates accordingly.
567567
alice := ht.NewNodeWithCoins("Alice", nil)
568568
req := &lnrpc.SendCoinsRequest{
569-
Addr: externalAddr,
570-
Amount: utxoAmt,
571-
SatPerByte: 1,
569+
Addr: externalAddr,
570+
Amount: utxoAmt,
571+
SatPerVbyte: 1,
572572
}
573573
alice.RPC.SendCoins(req)
574574

@@ -599,9 +599,9 @@ func runWalletImportAccountScenario(ht *lntest.HarnessTest,
599599
// Send coins to Carol's address and confirm them, making sure the
600600
// balance updates accordingly.
601601
req = &lnrpc.SendCoinsRequest{
602-
Addr: externalAddr,
603-
Amount: utxoAmt,
604-
SatPerByte: 1,
602+
Addr: externalAddr,
603+
Amount: utxoAmt,
604+
SatPerVbyte: 1,
605605
}
606606
alice.RPC.SendCoins(req)
607607

@@ -739,9 +739,9 @@ func testWalletImportPubKeyScenario(ht *lntest.HarnessTest,
739739
// Send coins to Carol's address and confirm them, making sure
740740
// the balance updates accordingly.
741741
req := &lnrpc.SendCoinsRequest{
742-
Addr: carolAddrResp.Address,
743-
Amount: utxoAmt,
744-
SatPerByte: 1,
742+
Addr: carolAddrResp.Address,
743+
Amount: utxoAmt,
744+
SatPerVbyte: 1,
745745
}
746746
alice.RPC.SendCoins(req)
747747

0 commit comments

Comments
 (0)