diff --git a/packages/stack/test-runner/src/lib/index.js b/packages/stack/test-runner/src/lib/index.js index 7dbd410ed6..b4b05536e9 100644 --- a/packages/stack/test-runner/src/lib/index.js +++ b/packages/stack/test-runner/src/lib/index.js @@ -177,6 +177,8 @@ class TestRunner { } }; + global.evmMethod = this.evmMethod.bind(this); + global.getEvmVersion = async () => { return this.evmMethod('web3_clientVersion'); }; @@ -382,6 +384,9 @@ class TestRunner { if (error) { return reject(error); } + if (res.error) { + return reject(new Error(res.error)); + } resolve(res.result); } ); diff --git a/site/source/docs/contracts_testing.md b/site/source/docs/contracts_testing.md index f019905bd0..5c83eaf564 100644 --- a/site/source/docs/contracts_testing.md +++ b/site/source/docs/contracts_testing.md @@ -293,7 +293,7 @@ This function lets you increase the time of the EVM. It is useful in the case wh await increaseTime(amount); ``` -`amount`: [Number] Number of seconds to increase +- `amount`: [Number] Number of seconds to increase ```javascript it("should have expired after increasing time", async function () { @@ -325,6 +325,26 @@ await getEvmVersion(); Returns a string, eg: `EthereumJS TestRPC/v2.9.2/ethereum-js` +### evmMethod + +If there are EVM methods that are not supported by the web3 library you use, Embark exposes the global function `evmMethod` that lets you call the RPC method directly. + +#### Syntax +`evmMethod(rpcMethodName, parameters)` + + - `rpcMethodName`: [string] Name of the RPC method to call. + - `parameters`: [Array] Optional array of parameters, as specified by the RPC method API. + +#### Usage +For example, let's say you are using `web3.js` in your tests, but would like to call the `eth_signTypedData` RPC method. Because `web3.js` does not support this method, it won't be possible to use `web3.js` for this call. Instead, we can call the `eth_signTypedData` RPC method in our tests using the global `evmMethod` function: + +```javascript + const signature = await evmMethod("eth_signTypedData", [ + accounts[0], + data +]); +``` + ## Code coverage Embark allows you to generate a coverage report for your Solidity Smart Contracts by passing the `--coverage` option on the `embark test` command.