aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-14 21:16:08 +0800
committerFabio Berger <me@fabioberger.com>2018-03-14 21:16:08 +0800
commit009b70f5b218a1ccb154034936256308131b7d9c (patch)
treecd9642a8d3323c9e80da54ac4e8fc40ade9f9020 /packages/web3-wrapper
parentf7c1e10b5ac112866ee55e7fededdb37c890d30f (diff)
parent3f3e8be004818ddaa1921b3dff12bdd46052278b (diff)
downloaddexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.tar
dexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.tar.gz
dexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.tar.bz2
dexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.tar.lz
dexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.tar.xz
dexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.tar.zst
dexon-sol-tools-009b70f5b218a1ccb154034936256308131b7d9c.zip
Merge branch 'development' into convertScriptsToTs
* development: (71 commits) Transform input data before encoding for callAsync and getABIEncodedTransactionData Update coverage badge to show development coverage Configure post build hook Notify coveralls after all tasks have finished Address feedback Revert "Report all coverage reports together" Separate published packages and typescript typings on README Report all coverage reports together Add other statement types Properly and consistently parse ENV vars Add forgotten file Start using solidity-parser-antlr Fix the default always overriding to address Submit a TD PR Add an explanatory comment for making ranges unique Fix a typo in handling env variables Introduce TESTRPC_FIRST_ADDRESS Make BlockchainLifecycle accept only web3Wrapper Fix comments Fix deployer CHANGELOG ... # Conflicts: # README.md # packages/deployer/package.json # packages/subproviders/src/globals.d.ts # yarn.lock
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r--packages/web3-wrapper/CHANGELOG.md4
-rw-r--r--packages/web3-wrapper/src/index.ts18
2 files changed, 20 insertions, 2 deletions
diff --git a/packages/web3-wrapper/CHANGELOG.md b/packages/web3-wrapper/CHANGELOG.md
index 6dabc7eb4..2b2fc7540 100644
--- a/packages/web3-wrapper/CHANGELOG.md
+++ b/packages/web3-wrapper/CHANGELOG.md
@@ -1,7 +1,9 @@
# CHANGELOG
-## v0.2.1 _TBD_
+## v0.3.0 _TBD, 2018_
+ * Add `web3Wrapper.takeSnapshotAsync`, `web3Wrapper.revertSnapshotAsync`, `web3Wrapper.mineBlockAsync`, `web3Wrapper.increaseTimeAsync` (#426)
+ * Add `web3Wrapper.isZeroExWeb3Wrapper` for runtime instanceOf checks (#426)
* Add a `getProvider` method (#444)
## v0.2.0 _March 4, 2018_
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index e14eb2914..02d5e4f7b 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -4,6 +4,8 @@ import * as _ from 'lodash';
import * as Web3 from 'web3';
export class Web3Wrapper {
+ // This is here purely to reliably distinguish it from other objects in runtime (like BigNumber.isBigNumber)
+ public isZeroExWeb3Wrapper = true;
private _web3: Web3;
private _defaults: Partial<TxData>;
private _jsonRpcRequestId: number;
@@ -92,6 +94,20 @@ export class Web3Wrapper {
const normalizedAddresses = _.map(addresses, address => address.toLowerCase());
return normalizedAddresses;
}
+ public async takeSnapshotAsync(): Promise<number> {
+ const snapshotId = Number(await this._sendRawPayloadAsync<string>({ method: 'evm_snapshot', params: [] }));
+ return snapshotId;
+ }
+ public async revertSnapshotAsync(snapshotId: number): Promise<boolean> {
+ const didRevert = await this._sendRawPayloadAsync<boolean>({ method: 'evm_revert', params: [snapshotId] });
+ return didRevert;
+ }
+ public async mineBlockAsync(): Promise<void> {
+ await this._sendRawPayloadAsync<string>({ method: 'evm_mine', params: [] });
+ }
+ public async increaseTimeAsync(timeDelta: number): Promise<void> {
+ await this._sendRawPayloadAsync<string>({ method: 'evm_increaseTime', params: [timeDelta] });
+ }
public async getLogsAsync(filter: Web3.FilterObject): Promise<Web3.LogEntry[]> {
let fromBlock = filter.fromBlock;
if (_.isNumber(fromBlock)) {
@@ -132,7 +148,7 @@ export class Web3Wrapper {
const txHash = await promisify<string>(this._web3.eth.sendTransaction)(txData);
return txHash;
}
- private async _sendRawPayloadAsync<A>(payload: Web3.JSONRPCRequestPayload): Promise<A> {
+ private async _sendRawPayloadAsync<A>(payload: Partial<Web3.JSONRPCRequestPayload>): Promise<A> {
const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider);
const response = await promisify<Web3.JSONRPCResponsePayload>(sendAsync)(payload);
const result = response.result;