Skip to content

Commit 0041426

Browse files
committed
itest+lntest: return the error from SendCoinsAssertErr
Also rename the send all coins test for clarity.
1 parent 0184846 commit 0041426

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

itest/list_on_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ var allTestCases = []*lntest.TestCase{
4646
TestFunc: testDataLossProtection,
4747
},
4848
{
49-
Name: "sweep coins",
50-
TestFunc: testSweepAllCoins,
49+
Name: "send all coins",
50+
TestFunc: testSendAllCoins,
5151
},
5252
{
5353
Name: "disconnecting target peer",

itest/lnd_misc_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,9 @@ func testAbandonChannel(ht *lntest.HarnessTest) {
758758
ht.ForceCloseChannel(bob, chanPoint)
759759
}
760760

761-
// testSweepAllCoins tests that we're able to properly sweep all coins from the
761+
// testSendAllCoins tests that we're able to properly sweep all coins from the
762762
// wallet into a single target address at the specified fee rate.
763-
func testSweepAllCoins(ht *lntest.HarnessTest) {
763+
func testSendAllCoins(ht *lntest.HarnessTest) {
764764
// First, we'll make a new node, Ainz who'll we'll use to test wallet
765765
// sweeping.
766766
//
@@ -777,20 +777,22 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
777777
sendCoinsLabel := "send all coins"
778778

779779
// Ensure that we can't send coins to our own Pubkey.
780-
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
780+
err := ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
781781
Addr: ainz.RPC.GetInfo().IdentityPubkey,
782782
SendAll: true,
783783
Label: sendCoinsLabel,
784784
TargetConf: 6,
785785
})
786+
require.ErrorContains(ht, err, "cannot send coins to pubkeys")
786787

787788
// Ensure that we can't send coins to another user's Pubkey.
788-
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
789+
err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
789790
Addr: ht.Alice.RPC.GetInfo().IdentityPubkey,
790791
SendAll: true,
791792
Label: sendCoinsLabel,
792793
TargetConf: 6,
793794
})
795+
require.ErrorContains(ht, err, "cannot send coins to pubkey")
794796

795797
// With the two coins above mined, we'll now instruct Ainz to sweep all
796798
// the coins to an external address not under its control. We will first
@@ -800,20 +802,23 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
800802
// same network as the user.
801803

802804
// Send coins to a testnet3 address.
803-
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
805+
err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
804806
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
805807
SendAll: true,
806808
Label: sendCoinsLabel,
807809
TargetConf: 6,
808810
})
811+
require.ErrorContains(ht, err, "not valid for this network")
809812

810813
// Send coins to a mainnet address.
811-
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
814+
err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
812815
Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3",
813816
SendAll: true,
814817
Label: sendCoinsLabel,
815818
TargetConf: 6,
816819
})
820+
// TODO(yy): should instead return "not valid for this network".
821+
require.ErrorContains(ht, err, "unknown address type")
817822

818823
// TODO(yy): we still allow default values to be used when neither conf
819824
// target or fee rate is set in 0.18.0. When future release forbidden
@@ -883,7 +888,7 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
883888
// label our transaction with an empty label, and check that we fail as
884889
// expected.
885890
sweepHash := sweepTx.TxHash()
886-
err := ainz.RPC.LabelTransactionAssertErr(
891+
err = ainz.RPC.LabelTransactionAssertErr(
887892
&walletrpc.LabelTransactionRequest{
888893
Txid: sweepHash[:],
889894
Label: "",
@@ -929,13 +934,14 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
929934

930935
// If we try again, but this time specifying an amount, then the call
931936
// should fail.
932-
ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
937+
err = ainz.RPC.SendCoinsAssertErr(&lnrpc.SendCoinsRequest{
933938
Addr: ht.NewMinerAddress().String(),
934939
Amount: 10000,
935940
SendAll: true,
936941
Label: sendCoinsLabel,
937942
TargetConf: 6,
938943
})
944+
require.ErrorContains(ht, err, "amount set while SendAll is active")
939945

940946
// With all the edge cases tested, we'll now test the happy paths of
941947
// change output types.

lntest/rpc/lnd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,14 @@ func (h *HarnessRPC) SendCoins(
378378

379379
// SendCoinsAssertErr sends a given amount of money to the specified address
380380
// from the passed node and asserts an error has returned.
381-
func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) {
381+
func (h *HarnessRPC) SendCoinsAssertErr(req *lnrpc.SendCoinsRequest) error {
382382
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
383383
defer cancel()
384384

385385
_, err := h.LN.SendCoins(ctxt, req)
386386
require.Error(h, err, "node %s didn't not return an error", h.Name)
387+
388+
return err
387389
}
388390

389391
// GetTransactions makes a RPC call to GetTransactions and asserts.

0 commit comments

Comments
 (0)