From d021eae39275ef4c0ec51f559ca819fb5ceab93b Mon Sep 17 00:00:00 2001 From: carla Date: Mon, 18 May 2020 14:13:24 +0200 Subject: [PATCH] itest: add label check to sweep coins test Add a label to our sweep all coins itest and check that it is correctly set. --- lntest/itest/lnd_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lntest/itest/lnd_test.go b/lntest/itest/lnd_test.go index ef7d0a32..6b7d401b 100644 --- a/lntest/itest/lnd_test.go +++ b/lntest/itest/lnd_test.go @@ -12486,9 +12486,13 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) { t.Fatalf("unable to get node info: %v", err) } + // Create a label that we will used to label the transaction with. + sendCoinsLabel := "send all coins" + sweepReq := &lnrpc.SendCoinsRequest{ Addr: info.IdentityPubkey, SendAll: true, + Label: sendCoinsLabel, } _, err = ainz.SendCoins(ctxt, sweepReq) if err == nil { @@ -12504,6 +12508,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) { sweepReq = &lnrpc.SendCoinsRequest{ Addr: info.IdentityPubkey, SendAll: true, + Label: sendCoinsLabel, } _, err = ainz.SendCoins(ctxt, sweepReq) if err == nil { @@ -12522,6 +12527,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) { sweepReq = &lnrpc.SendCoinsRequest{ Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg", SendAll: true, + Label: sendCoinsLabel, } _, err = ainz.SendCoins(ctxt, sweepReq) if err == nil { @@ -12533,6 +12539,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) { sweepReq = &lnrpc.SendCoinsRequest{ Addr: "1MPaXKp5HhsLNjVSqaL7fChE3TVyrTMRT3", SendAll: true, + Label: sendCoinsLabel, } _, err = ainz.SendCoins(ctxt, sweepReq) if err == nil { @@ -12548,6 +12555,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) { sweepReq = &lnrpc.SendCoinsRequest{ Addr: minerAddr.String(), SendAll: true, + Label: sendCoinsLabel, } ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) _, err = ainz.SendCoins(ctxt, sweepReq) @@ -12566,6 +12574,24 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) { t.Fatalf("expected 2 inputs instead have %v", len(sweepTx.TxIn)) } + // List all transactions relevant to our wallet, and find the sweep tx + // so that we can check the correct label has been set. + ctxt, _ = context.WithTimeout(ctxb, defaultTimeout) + txResp, err := ainz.GetTransactions(ctxt, &lnrpc.GetTransactionsRequest{}) + if err != nil { + t.Fatalf("could not get transactions: %v", err) + } + + sweepTxStr := sweepTx.TxHash().String() + for _, txn := range txResp.Transactions { + if txn.TxHash == sweepTxStr { + if txn.Label != sendCoinsLabel { + t.Fatalf("expected label: %v, got: %v", + sendCoinsLabel, txn.Label) + } + } + } + // Finally, Ainz should now have no coins at all within his wallet. balReq := &lnrpc.WalletBalanceRequest{} resp, err := ainz.WalletBalance(ctxt, balReq)