Skip to content

Commit 97a0b59

Browse files
committedDec 9, 2019
Add snapshot restore test for solo
1 parent 246eca5 commit 97a0b59

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
 

‎test/src/e2e/snapshot.test.ts

+54
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,60 @@ describe("Snapshot", async function() {
5454
).to.satisfies(fs.existsSync);
5555
});
5656

57+
it("can restore from snapshot", async function() {
58+
for (let i = 0; i < 10; i++) {
59+
const tx = await node.sendPayTx({
60+
quantity: 100,
61+
recipient: aliceAddress
62+
});
63+
await node.waitForTx(tx.hash());
64+
}
65+
66+
const pay = await node.sendPayTx({
67+
quantity: 100,
68+
recipient: aliceAddress
69+
});
70+
71+
const blockHash = (await node.sdk.rpc.chain.getTransaction(pay.hash()))!
72+
.blockHash!;
73+
74+
const block = (await node.sdk.rpc.chain.getBlock(blockHash))!;
75+
await node.sdk.rpc.sendRpcRequest("devel_snapshot", [
76+
blockHash.toJSON()
77+
]);
78+
// Wait for 1 secs
79+
await new Promise(resolve => setTimeout(resolve, 1000));
80+
81+
const newNode = new CodeChain({
82+
argv: [
83+
"--snapshot-hash",
84+
block.hash.toString(),
85+
"--snapshot-number",
86+
block.number.toString()
87+
]
88+
});
89+
90+
try {
91+
await newNode.start();
92+
await newNode.connect(node);
93+
await newNode.waitBlockNumber(block.number);
94+
await node.sdk.rpc.devel.stopSealing();
95+
// New node creates block
96+
const newPay = await newNode.sendPayTx({
97+
quantity: 100,
98+
recipient: aliceAddress
99+
});
100+
await newNode.waitForTx(newPay.hash());
101+
await node.sdk.rpc.devel.startSealing();
102+
await node.waitForTx(newPay.hash());
103+
} catch (e) {
104+
newNode.keepLogs();
105+
throw e;
106+
} finally {
107+
await newNode.clean();
108+
}
109+
});
110+
57111
afterEach(function() {
58112
if (this.currentTest!.state === "failed") {
59113
node.keepLogs();

0 commit comments

Comments
 (0)