itest: add label check to sweep coins test

Add a label to our sweep all coins itest and check that it is correctly
set.
This commit is contained in:
carla 2020-05-18 14:13:24 +02:00
parent e8ca306f12
commit d021eae392
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91

@ -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)