Skip to content

Commit 96739f9

Browse files
foriequal0remagpie
authored andcommitted
Add basic e2e test for snapshot
1 parent 9c1911a commit 96739f9

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

test/src/e2e/snapshot.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
fs.existsSync(
54+
path.join(
55+
SNAPSHOT_PATH,
56+
blockHash.toString(),
57+
stateRoot.toString()
58+
)
59+
)
60+
);
61+
});
62+
63+
afterEach(function() {
64+
if (this.currentTest!.state === "failed") {
65+
node.keepLogs();
66+
}
67+
});
68+
69+
after(async function() {
70+
await node.clean();
71+
});
72+
});

0 commit comments

Comments
 (0)