Skip to content

Commit

Permalink
feat(@embark/test-runner): make evmMethod globally available + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville authored and emizzle committed Mar 5, 2020
1 parent 3b753e8 commit 67581ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/stack/test-runner/src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ class TestRunner {
}
};

global.evmMethod = this.evmMethod.bind(this);

global.getEvmVersion = async () => {
return this.evmMethod('web3_clientVersion');
};
Expand Down Expand Up @@ -382,6 +384,9 @@ class TestRunner {
if (error) {
return reject(error);
}
if (res.error) {
return reject(new Error(res.error));
}
resolve(res.result);
}
);
Expand Down
22 changes: 21 additions & 1 deletion site/source/docs/contracts_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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<any>] 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.
Expand Down

0 comments on commit 67581ce

Please sign in to comment.