Skip to content

Commit 67581ce

Browse files
jrainvilleemizzle
authored andcommitted
feat(@embark/test-runner): make evmMethod globally available + docs
1 parent 3b753e8 commit 67581ce

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

packages/stack/test-runner/src/lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ class TestRunner {
177177
}
178178
};
179179

180+
global.evmMethod = this.evmMethod.bind(this);
181+
180182
global.getEvmVersion = async () => {
181183
return this.evmMethod('web3_clientVersion');
182184
};
@@ -382,6 +384,9 @@ class TestRunner {
382384
if (error) {
383385
return reject(error);
384386
}
387+
if (res.error) {
388+
return reject(new Error(res.error));
389+
}
385390
resolve(res.result);
386391
}
387392
);

site/source/docs/contracts_testing.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ This function lets you increase the time of the EVM. It is useful in the case wh
293293
await increaseTime(amount);
294294
```
295295

296-
`amount`: [Number] Number of seconds to increase
296+
- `amount`: [Number] Number of seconds to increase
297297

298298
```javascript
299299
it("should have expired after increasing time", async function () {
@@ -325,6 +325,26 @@ await getEvmVersion();
325325

326326
Returns a string, eg: `EthereumJS TestRPC/v2.9.2/ethereum-js`
327327

328+
### evmMethod
329+
330+
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.
331+
332+
#### Syntax
333+
`evmMethod(rpcMethodName, parameters)`
334+
335+
- `rpcMethodName`: [string] Name of the RPC method to call.
336+
- `parameters`: [Array<any>] Optional array of parameters, as specified by the RPC method API.
337+
338+
#### Usage
339+
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:
340+
341+
```javascript
342+
const signature = await evmMethod("eth_signTypedData", [
343+
accounts[0],
344+
data
345+
]);
346+
```
347+
328348
## Code coverage
329349

330350
Embark allows you to generate a coverage report for your Solidity Smart Contracts by passing the `--coverage` option on the `embark test` command.

0 commit comments

Comments
 (0)