From d5feb5fc792c54bcf4a3a029ddc404e95a5df166 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 26 May 2017 18:01:54 +0200 Subject: rename BlockClean to BlockchainLifecycle and setupAsync to startAsync, restoreAsync to revertAsync --- test/utils/blockchain_lifecycle.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/utils/blockchain_lifecycle.ts (limited to 'test/utils/blockchain_lifecycle.ts') diff --git a/test/utils/blockchain_lifecycle.ts b/test/utils/blockchain_lifecycle.ts new file mode 100644 index 000000000..f7342b680 --- /dev/null +++ b/test/utils/blockchain_lifecycle.ts @@ -0,0 +1,19 @@ +import {RPC} from './rpc'; + +export class BlockchainLifecycle { + private rpc: RPC; + private snapshotId: number; + constructor() { + this.rpc = new RPC(); + } + // TODO: Check if running on TestRPC or on actual node, if actual node, re-deploy contracts instead + public async startAsync(): Promise { + this.snapshotId = await this.rpc.takeSnapshotAsync(); + } + public async revertAsync(): Promise { + const didRevert = await this.rpc.revertSnapshotAsync(this.snapshotId); + if (!didRevert) { + throw new Error(`Snapshot with id #${this.snapshotId} failed to revert`); + } + } +}; -- cgit v1.2.3 From 4c3c1d049b0d6dd147a56b3ce9e6ccc17686acf1 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 26 May 2017 18:08:50 +0200 Subject: improve comment --- test/utils/blockchain_lifecycle.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/utils/blockchain_lifecycle.ts') diff --git a/test/utils/blockchain_lifecycle.ts b/test/utils/blockchain_lifecycle.ts index f7342b680..68e169ac0 100644 --- a/test/utils/blockchain_lifecycle.ts +++ b/test/utils/blockchain_lifecycle.ts @@ -6,7 +6,8 @@ export class BlockchainLifecycle { constructor() { this.rpc = new RPC(); } - // TODO: Check if running on TestRPC or on actual node, if actual node, re-deploy contracts instead + // TODO: In order to run these tests on an actual node, we should check if we are running against + // TestRPC, if so, use snapshots, otherwise re-deploy contracts before every test public async startAsync(): Promise { this.snapshotId = await this.rpc.takeSnapshotAsync(); } -- cgit v1.2.3