itest+lntest: return the error from SendCoinsAssertErr

Also rename the send all coins test for clarity.
This commit is contained in:
yyforyongyu 2024-07-30 01:33:47 +08:00
parent 018484628a
commit 0041426e7e
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
3 changed files with 19 additions and 11 deletions

View file

@ -46,8 +46,8 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testDataLossProtection, TestFunc: testDataLossProtection,
}, },
{ {
Name: "sweep coins", Name: "send all coins",
TestFunc: testSweepAllCoins, TestFunc: testSendAllCoins,
}, },
{ {
Name: "disconnecting target peer", Name: "disconnecting target peer",

View file

@ -758,9 +758,9 @@ func testAbandonChannel(ht *lntest.HarnessTest) {
ht.ForceCloseChannel(bob, chanPoint) ht.ForceCloseChannel(bob, chanPoint)
} }
// testSweepAllCoins tests that we're able to properly sweep all coins from the // testSendAllCoins tests that we're able to properly sweep all coins from the
// wallet into a single target address at the specified fee rate. // wallet into a single target address at the specified fee rate.
func testSweepAllCoins(ht *lntest.HarnessTest) { func testSendAllCoins(ht *lntest.HarnessTest) {
// First, we'll make a new node, Ainz who'll we'll use to test wallet // First, we'll make a new node, Ainz who'll we'll use to test wallet
// sweeping. // sweeping.
// //
@ -777,20 +777,22 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
sendCoinsLabel := "send all coins" sendCoinsLabel := "send all coins"
// Ensure that we can't send coins to our own Pubkey. // Ensure that we can't send coins to our own Pubkey.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{ err := ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: ainz.RPC.GetInfo().IdentityPubkey, Addr: ainz.RPC.GetInfo().IdentityPubkey,
SendAll: true, SendAll: true,
Label: sendCoinsLabel, Label: sendCoinsLabel,
TargetConf: 6, TargetConf: 6,
}) })
require.ErrorContains(ht, err, "cannot send coins to pubkeys")
// Ensure that we can't send coins to another user's Pubkey. // Ensure that we can't send coins to another user's Pubkey.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{ err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: ht.Alice.RPC.GetInfo().IdentityPubkey, Addr: ht.Alice.RPC.GetInfo().IdentityPubkey,
SendAll: true, SendAll: true,
Label: sendCoinsLabel, Label: sendCoinsLabel,
TargetConf: 6, TargetConf: 6,
}) })
require.ErrorContains(ht, err, "cannot send coins to pubkey")
// With the two coins above mined, we'll now instruct Ainz to sweep all // With the two coins above mined, we'll now instruct Ainz to sweep all
// the coins to an external address not under its control. We will first // the coins to an external address not under its control. We will first
@ -800,20 +802,23 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
// same network as the user. // same network as the user.
// Send coins to a testnet3 address. // Send coins to a testnet3 address.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{ err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg", Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
SendAll: true, SendAll: true,
Label: sendCoinsLabel, Label: sendCoinsLabel,
TargetConf: 6, TargetConf: 6,
}) })
require.ErrorContains(ht, err, "not valid for this network")
// Send coins to a mainnet address. // Send coins to a mainnet address.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{ err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3", Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3",
SendAll: true, SendAll: true,
Label: sendCoinsLabel, Label: sendCoinsLabel,
TargetConf: 6, TargetConf: 6,
}) })
// TODO(yy): should instead return "not valid for this network".
require.ErrorContains(ht, err, "unknown address type")
// TODO(yy): we still allow default values to be used when neither conf // TODO(yy): we still allow default values to be used when neither conf
// target or fee rate is set in 0.18.0. When future release forbidden // target or fee rate is set in 0.18.0. When future release forbidden
@ -883,7 +888,7 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
// label our transaction with an empty label, and check that we fail as // label our transaction with an empty label, and check that we fail as
// expected. // expected.
sweepHash := sweepTx.TxHash() sweepHash := sweepTx.TxHash()
err := ainz.RPC.LabelTransactionAssertErr( err = ainz.RPC.LabelTransactionAssertErr(
&walletrpc.LabelTransactionRequest{ &walletrpc.LabelTransactionRequest{
Txid: sweepHash[:], Txid: sweepHash[:],
Label: "", Label: "",
@ -929,13 +934,14 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
// If we try again, but this time specifying an amount, then the call // If we try again, but this time specifying an amount, then the call
// should fail. // should fail.
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{ err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
Addr: ht.NewMinerAddress().String(), Addr: ht.NewMinerAddress().String(),
Amount: 10000, Amount: 10000,
SendAll: true, SendAll: true,
Label: sendCoinsLabel, Label: sendCoinsLabel,
TargetConf: 6, TargetConf: 6,
}) })
require.ErrorContains(ht, err, "amount set while SendAll is active")
// With all the edge cases tested, we'll now test the happy paths of // With all the edge cases tested, we'll now test the happy paths of
// change output types. // change output types.

View file

@ -378,12 +378,14 @@ func (h *HarnessRPC) SendCoins(
// SendCoinsAssertErr sends a given amount of money to the specified address // SendCoinsAssertErr sends a given amount of money to the specified address
// from the passed node and asserts an error has returned. // from the passed node and asserts an error has returned.
func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) { func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) error {
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel() defer cancel()
_, err := h.LN.SendCoins(ctxt, req) _, err := h.LN.SendCoins(ctxt, req)
require.Error(h, err, "node %s didn't not return an error", h.Name) require.Error(h, err, "node %s didn't not return an error", h.Name)
return err
} }
// GetTransactions makes a RPC call to GetTransactions and asserts. // GetTransactions makes a RPC call to GetTransactions and asserts.