Skip to content

Commit 2493e02

Browse files
Chinwendu20kaloudis
authored andcommitted
test importAccount scenario
1 parent 013ca40 commit 2493e02

14 files changed

+1166
-805
lines changed

itest/lnd_wallet_import_test.go

+62-18
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func psbtSendFromImportedAccount(ht *lntest.HarnessTest, srcNode, destNode,
208208
default:
209209
ht.Fatalf("unsupported addr type %v", accountAddrType)
210210
}
211-
changeUtxoAmt := confBalance - destAmt - expTxFee
211+
changeUtxoAmt := 100000000 - destAmt - expTxFee
212212

213213
// If the transaction was created from the default imported account,
214214
// then any change produced is moved to the default wallet account.
@@ -217,11 +217,11 @@ func psbtSendFromImportedAccount(ht *lntest.HarnessTest, srcNode, destNode,
217217
accountWithBalance = defaultAccount
218218
}
219219
ht.AssertWalletAccountBalance(
220-
srcNode, accountWithBalance, 0, changeUtxoAmt,
220+
srcNode, accountWithBalance, 8000, changeUtxoAmt,
221221
)
222222
ht.MineBlocksAndAssertNumTxes(1, 1)
223223
ht.AssertWalletAccountBalance(
224-
srcNode, accountWithBalance, changeUtxoAmt, 0,
224+
srcNode, accountWithBalance, changeUtxoAmt+8000, 0,
225225
)
226226

227227
// Finally, assert that the transaction has the expected change address
@@ -520,7 +520,11 @@ func testWalletImportAccountScenario(ht *lntest.HarnessTest,
520520
// NOTE: we won't use standby nodes here since the test will change
521521
// each of the node's wallet state.
522522
carol := ht.NewNode("carol", nil)
523-
dave := ht.NewNode("dave", nil)
523+
524+
dave, _, _ := ht.NewNodeWithSeed("dave",
525+
[]string{"--reset-wallet-transactions"},
526+
[]byte("bensonidahosa"),
527+
false)
524528

525529
runWalletImportAccountScenario(ht, addrType, carol, dave)
526530
}
@@ -538,11 +542,33 @@ func runWalletImportAccountScenario(ht *lntest.HarnessTest,
538542
require.Len(ht, listResp.Accounts, 1)
539543
carolAccount := listResp.Accounts[0]
540544

545+
// Generate an address for carol and send coins to it,
546+
// when we import carol's account into dave's,
547+
// we would generate this address in dave's node and test that we can
548+
// recover the funds that we sent to this address after a restart of
549+
// Dave's node.
550+
r := carol.RPC.NewAddress(&lnrpc.NewAddressRequest{
551+
Type: walletToLNAddrType(ht.T, addrType),
552+
})
553+
554+
ht.FundCoins(100000, ht.Alice)
555+
556+
req := &lnrpc.SendCoinsRequest{
557+
Addr: r.Address,
558+
Amount: 8000,
559+
SatPerByte: 1,
560+
}
561+
ht.Alice.RPC.SendCoins(req)
562+
ht.MineBlocks(6)
563+
564+
ht.AssertWalletAccountBalance(carol, defaultAccount, 8000, 0)
565+
541566
const importedAccount = "carol"
542567
importReq := &walletrpc.ImportAccountRequest{
543568
Name: importedAccount,
544569
ExtendedPublicKey: carolAccount.ExtendedPublicKey,
545570
AddressType: addrType,
571+
BirthdayHeight: 5,
546572
}
547573
dave.RPC.ImportAccount(importReq)
548574

@@ -574,25 +600,43 @@ func runWalletImportAccountScenario(ht *lntest.HarnessTest,
574600
err := dave.RPC.ImportAccountAssertErr(importReq)
575601
require.ErrorContains(ht, err, errAccountExists)
576602

603+
// externalAddr := newExternalAddr(
604+
// ht, dave, carol, importedAccount, addrType,
605+
// )
606+
577607
// We'll generate an address for Carol from Dave's node to receive some
578-
// funds.
579-
externalAddr := newExternalAddr(
580-
ht, dave, carol, importedAccount, addrType,
581-
)
608+
// funds. This account should be the same as the address that we
609+
// generated in carol's node.
610+
resp := dave.RPC.NewAddress(&lnrpc.NewAddressRequest{
611+
Type: walletToLNAddrType(ht.T, addrType),
612+
Account: importedAccount,
613+
})
614+
615+
externalAddr := resp.Address
616+
617+
require.Equal(ht, r.Address, externalAddr)
618+
619+
// We should only be able to recover the coins in this address after a
620+
// restart.
621+
ht.AssertWalletAccountBalance(dave, importedAccount, 0, 0)
622+
623+
ht.RestartNode(dave)
624+
625+
ht.AssertWalletAccountBalance(dave, importedAccount, 8000, 0)
582626

583627
// Send coins to Carol's address and confirm them, making sure the
584628
// balance updates accordingly.
585629
alice := ht.Alice
586-
req := &lnrpc.SendCoinsRequest{
630+
req = &lnrpc.SendCoinsRequest{
587631
Addr: externalAddr,
588632
Amount: utxoAmt,
589633
SatPerByte: 1,
590634
}
591635
alice.RPC.SendCoins(req)
592636

593-
ht.AssertWalletAccountBalance(dave, importedAccount, 0, utxoAmt)
637+
ht.AssertWalletAccountBalance(dave, importedAccount, 8000, utxoAmt)
594638
ht.MineBlocksAndAssertNumTxes(1, 1)
595-
ht.AssertWalletAccountBalance(dave, importedAccount, utxoAmt, 0)
639+
ht.AssertWalletAccountBalance(dave, importedAccount, utxoAmt+8000, 0)
596640

597641
// To ensure that Dave can use Carol's account as watch-only, we'll
598642
// construct a PSBT that sends funds to Alice, which we'll then hand
@@ -631,13 +675,13 @@ func runWalletImportAccountScenario(ht *lntest.HarnessTest,
631675
dave, importedAccount, confBalance+utxoAmt, 0,
632676
)
633677

634-
// Now that we have enough funds, it's time to fund the channel, make a
635-
// test payment, and close it. This contains several balance assertions
636-
// along the way.
637-
fundChanAndCloseFromImportedAccount(
638-
ht, dave, alice, carol, importedAccount, addrType, utxoAmt,
639-
int64(funding.MaxBtcFundingAmount),
640-
)
678+
// // Now that we have enough funds, it's time to fund the channel, make a
679+
// // test payment, and close it. This contains several balance assertions
680+
// // along the way.
681+
// fundChanAndCloseFromImportedAccount(
682+
// ht, dave, alice, carol, importedAccount, addrType, utxoAmt,
683+
// int64(funding.MaxBtcFundingAmount),
684+
// )
641685
}
642686

643687
// testWalletImportPubKey tests that an imported public keys can fund

0 commit comments

Comments
 (0)