Skip to content

Commit 3fd411b

Browse files
committed
itest: reproduce error with restored lnd node
Reproduces the error reported in #1208. We explicitly first reproduce the exact error with an itest. We'll then fix the problem and update the test in the following commits.
1 parent ef47d90 commit 3fd411b

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

itest/send_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,6 +1954,91 @@ func testSendNoCourierUniverseImport(t *harnessTest) {
19541954
AssertSendEventsComplete(t.t, receiveAddr.ScriptKey, sendEvents)
19551955
}
19561956

1957+
// testRestoreLndFromSeed tests that we can restore an LND node from a seed and
1958+
// then continue to interact with assets previously minted on the node.
1959+
func testRestoreLndFromSeed(t *harnessTest) {
1960+
// We create a new lnd node from a seed, so we can restore it with the
1961+
// same seed later.
1962+
password := []byte("somepassword")
1963+
seedLnd, mnemonic, _ := t.lndHarness.NewNodeWithSeed(
1964+
"seed-lnd", lndDefaultArgs, password, false,
1965+
)
1966+
t.lndHarness.FundCoins(btcutil.SatoshiPerBitcoin, seedLnd)
1967+
1968+
// We're going to restart Bob at some point, so we don't do a deferred
1969+
// shutdown here.
1970+
bob := setupTapdHarness(t.t, t, seedLnd, t.universeServer)
1971+
1972+
// We mint a batch of normal assets with enough units to allow us to
1973+
// send it around a few times.
1974+
rpcAssets := MintAssetsConfirmBatch(
1975+
t.t, t.lndHarness.Miner().Client, bob,
1976+
[]*mintrpc.MintAssetRequest{issuableAssets[0]},
1977+
)
1978+
1979+
var (
1980+
alice = t.tapd
1981+
ctxb = context.Background()
1982+
rpcAsset = rpcAssets[0]
1983+
genInfo = rpcAsset.AssetGenesis
1984+
)
1985+
1986+
// We send some of the minted assets to our default tapd node.
1987+
const sendAmount = 123
1988+
aliceAddr, err := alice.NewAddr(ctxb, &taprpc.NewAddrRequest{
1989+
AssetId: genInfo.AssetId,
1990+
Amt: sendAmount,
1991+
})
1992+
require.NoError(t.t, err)
1993+
1994+
AssertAddrCreated(t.t, alice, rpcAsset, aliceAddr)
1995+
1996+
sendResp, sendEvents := sendAssetsToAddr(t, bob, aliceAddr)
1997+
1998+
ConfirmAndAssertOutboundTransfer(
1999+
t.t, t.lndHarness.Miner().Client, bob, sendResp,
2000+
genInfo.AssetId,
2001+
[]uint64{rpcAsset.Amount - sendAmount, sendAmount}, 0, 1,
2002+
)
2003+
AssertNonInteractiveRecvComplete(t.t, alice, 1)
2004+
AssertSendEventsComplete(t.t, aliceAddr.ScriptKey, sendEvents)
2005+
2006+
// We now restore Bob's lnd node from the seed.
2007+
require.NoError(t.t, bob.stop(false))
2008+
require.NoError(t.t, seedLnd.Shutdown())
2009+
2010+
// Starting the node again should restore it to the same state as
2011+
// before. This takes a couple of seconds, so let's log that we're
2012+
// waiting for the node to start.
2013+
t.Logf("Restoring node from seed, this may take a few seconds...")
2014+
seedLnd = t.lndHarness.RestoreNodeWithSeed(
2015+
"lnd-seed-restored", lndDefaultArgs, password, mnemonic, "",
2016+
2500, nil,
2017+
)
2018+
require.NoError(t.t, updateConfigWithNode(bob.clientCfg, seedLnd))
2019+
2020+
require.NoError(t.t, bob.start(false))
2021+
2022+
// Let's make sure we properly clean up the node at the end of the test.
2023+
defer func() {
2024+
require.NoError(t.t, bob.stop(!*noDelete))
2025+
}()
2026+
2027+
// Send more assets after restoring the node.
2028+
aliceAddr, err = alice.NewAddr(ctxb, &taprpc.NewAddrRequest{
2029+
AssetId: genInfo.AssetId,
2030+
Amt: sendAmount,
2031+
})
2032+
require.NoError(t.t, err)
2033+
2034+
AssertAddrCreated(t.t, alice, rpcAsset, aliceAddr)
2035+
2036+
sendAsset(
2037+
t, bob, withReceiverAddresses(aliceAddr),
2038+
withError("invalid transfer asset witness"),
2039+
)
2040+
}
2041+
19572042
// addProofTestVectorFromFile adds a proof test vector by extracting it from the
19582043
// proof file found at the given asset ID and script key.
19592044
func addProofTestVectorFromFile(t *testing.T, testName string,

itest/test_list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ var testCases = []*testCase{
324324
name: "ownership verification",
325325
test: testOwnershipVerification,
326326
},
327+
{
328+
name: "asset signing after lnd restore from seed",
329+
test: testRestoreLndFromSeed,
330+
},
327331
}
328332

329333
var optionalTestCases = []*testCase{

0 commit comments

Comments
 (0)