diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-13 11:17:18 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-13 11:17:18 +0800 |
commit | c4ee2d73865a1444c079b9e2836b7630a0adf03e (patch) | |
tree | b9c7794e7022fb189675d914f5fe58dcabd67dec /test/utils/rpc.ts | |
parent | a74ec0effa818a86233fe64cb0dad2c61bbb4bb6 (diff) | |
download | dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.gz dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.bz2 dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.lz dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.xz dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.zst dexon-sol-tools-c4ee2d73865a1444c079b9e2836b7630a0adf03e.zip |
Switch over to Lerna + Yarn Workspaces setup for a mono-repo approach
Diffstat (limited to 'test/utils/rpc.ts')
-rw-r--r-- | test/utils/rpc.ts | 57 |
1 files changed, 0 insertions, 57 deletions
diff --git a/test/utils/rpc.ts b/test/utils/rpc.ts deleted file mode 100644 index 299e72e79..000000000 --- a/test/utils/rpc.ts +++ /dev/null @@ -1,57 +0,0 @@ -import * as ethUtil from 'ethereumjs-util'; -import * as request from 'request-promise-native'; -import {constants} from './constants'; - -export class RPC { - private host: string; - private port: number; - private id: number; - constructor() { - this.host = constants.RPC_HOST; - this.port = constants.RPC_PORT; - this.id = 0; - } - public async takeSnapshotAsync(): Promise<number> { - const method = 'evm_snapshot'; - const params: any[] = []; - const payload = this.toPayload(method, params); - const snapshotIdHex = await this.sendAsync(payload); - const snapshotId = ethUtil.bufferToInt(ethUtil.toBuffer(snapshotIdHex)); - return snapshotId; - } - public async revertSnapshotAsync(snapshotId: number): Promise<boolean> { - const method = 'evm_revert'; - const params = [snapshotId]; - const payload = this.toPayload(method, params); - const didRevert = await this.sendAsync(payload); - return didRevert; - } - public async mineBlockAsync(): Promise<void> { - const method = 'evm_mine'; - const params: any[] = []; - const payload = this.toPayload(method, params); - await this.sendAsync(payload); - } - private toPayload(method: string, params: any[] = []): string { - const payload = JSON.stringify({ - id: this.id, - method, - params, - }); - this.id += 1; - return payload; - } - private async sendAsync(payload: string): Promise<any> { - const opts = { - method: 'POST', - uri: `http://${this.host}:${this.port}`, - body: payload, - headers: { - 'content-type': 'application/json', - }, - }; - const bodyString = await request(opts); - const body = JSON.parse(bodyString); - return body.result; - } -} |