From 8236b0169655bab71ddcfde71120caf3d9159fba Mon Sep 17 00:00:00 2001 From: SeongChan Lee Date: Thu, 21 Nov 2019 21:11:21 +0900 Subject: [PATCH] Add snapshot restore test for solo --- test/src/e2e/snapshot.test.ts | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/src/e2e/snapshot.test.ts b/test/src/e2e/snapshot.test.ts index d0b81f614d..195cf00c8a 100644 --- a/test/src/e2e/snapshot.test.ts +++ b/test/src/e2e/snapshot.test.ts @@ -54,6 +54,60 @@ describe("Snapshot", async function() { ).to.satisfies(fs.existsSync); }); + it("can restore from snapshot", async function() { + for (let i = 0; i < 10; i++) { + const tx = await node.sendPayTx({ + quantity: 100, + recipient: aliceAddress + }); + await node.waitForTx(tx.hash()); + } + + const pay = await node.sendPayTx({ + quantity: 100, + recipient: aliceAddress + }); + + const blockHash = (await node.sdk.rpc.chain.getTransaction(pay.hash()))! + .blockHash!; + + const block = (await node.sdk.rpc.chain.getBlock(blockHash))!; + await node.sdk.rpc.sendRpcRequest("devel_snapshot", [ + blockHash.toJSON() + ]); + // Wait for 1 secs + await new Promise(resolve => setTimeout(resolve, 1000)); + + const newNode = new CodeChain({ + argv: [ + "--snapshot-hash", + block.hash.toString(), + "--snapshot-number", + block.number.toString() + ] + }); + + try { + await newNode.start(); + await newNode.connect(node); + await newNode.waitBlockNumber(block.number); + await node.sdk.rpc.devel.stopSealing(); + // New node creates block + const newPay = await newNode.sendPayTx({ + quantity: 100, + recipient: aliceAddress + }); + await newNode.waitForTx(newPay.hash()); + await node.sdk.rpc.devel.startSealing(); + await node.waitForTx(newPay.hash()); + } catch (e) { + newNode.keepLogs(); + throw e; + } finally { + await newNode.clean(); + } + }); + afterEach(function() { if (this.currentTest!.state === "failed") { node.keepLogs();