@@ -1954,6 +1954,96 @@ 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+ sendResp , sendEvents = sendAssetsToAddr (t , bob , aliceAddr )
2037+
2038+ ConfirmAndAssertOutboundTransfer (
2039+ t .t , t .lndHarness .Miner ().Client , bob , sendResp ,
2040+ genInfo .AssetId ,
2041+ []uint64 {rpcAsset .Amount - sendAmount * 2 , sendAmount }, 1 , 2 ,
2042+ )
2043+ AssertNonInteractiveRecvComplete (t .t , alice , 2 )
2044+ AssertSendEventsComplete (t .t , aliceAddr .ScriptKey , sendEvents )
2045+ }
2046+
19572047// addProofTestVectorFromFile adds a proof test vector by extracting it from the
19582048// proof file found at the given asset ID and script key.
19592049func addProofTestVectorFromFile (t * testing.T , testName string ,
0 commit comments