Skip to content

Commit ef1a176

Browse files
committed
Add basic e2e test for snapshot
1 parent 27e3c4e commit ef1a176

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/src/e2e/snapshot.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2018-2019 Kodebox, Inc.
2+
// This file is part of CodeChain.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
import { expect } from "chai";
18+
import * as fs from "fs";
19+
import "mocha";
20+
import * as path from "path";
21+
22+
import { aliceAddress } from "../helper/constants";
23+
import CodeChain from "../helper/spawn";
24+
25+
const SNAPSHOT_PATH = `${__dirname}/../../../snapshot/`;
26+
27+
describe("Snapshot", async function() {
28+
let node: CodeChain;
29+
before(async function() {
30+
node = new CodeChain({
31+
argv: ["--snapshot-path", SNAPSHOT_PATH]
32+
});
33+
await node.start();
34+
});
35+
36+
it("can make a snapshot when it is requsted with devel rpc", async function() {
37+
const pay = await node.sendPayTx({
38+
quantity: 100,
39+
recipient: aliceAddress
40+
});
41+
42+
const blockHash = (await node.sdk.rpc.chain.getTransaction(pay.hash()))!
43+
.blockHash!;
44+
await node.sdk.rpc.sendRpcRequest("devel_snapshot", [
45+
blockHash.toJSON()
46+
]);
47+
// Wait for 1 secs
48+
await new Promise(resolve => setTimeout(resolve, 1000));
49+
50+
const stateRoot = (await node.sdk.rpc.chain.getBlock(blockHash))!
51+
.stateRoot;
52+
expect(
53+
path.join(SNAPSHOT_PATH, blockHash.toString(), stateRoot.toString())
54+
).to.satisfies(fs.existsSync);
55+
});
56+
57+
afterEach(function() {
58+
if (this.currentTest!.state === "failed") {
59+
node.keepLogs();
60+
}
61+
});
62+
63+
after(async function() {
64+
await node.clean();
65+
});
66+
});

0 commit comments

Comments
 (0)