feat(@embark/test-runner): make evmMethod globally available + docs

This commit is contained in:
Jonathan Rainville 2020-02-18 15:21:25 -05:00 committed by Eric Mastro
parent 3b753e856c
commit 67581ce482
2 changed files with 26 additions and 1 deletions

View File

@ -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);
}
);

View File

@ -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<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.