How to use openzeppelin-test-helpers in Embark tests

I am using the openzeppelin-test-helpers – more specifically, I am interested in the time.increase function – in my test file in an Embark project. If I do the regular

const { time } = require('openzeppelin-test-helpers');

the use of time will fail with

  1) SimpleStorage
       get storage value after timewarp:
     TypeError: Cannot read property 'send' of null
      at Object.increase (node_modules/openzeppelin-test-helpers/src/time.js:30:40)
      at Context.<anonymous> (test/simple_storage_spec.js:41:16)

I eventually got it working by calling the configure method in the callback of the Embark config function.

let helpers;

  contracts: {
    "SimpleStorage": {
      args: [100]
}, (_err, web3_accounts) => {
  require('openzeppelin-test-helpers/configure')({ web3: web3 });
  helpers = require('openzeppelin-test-helpers');

contract("SimpleStorage", function () { ... }

Question is: is this the recommended way to go? Has anyone encountered this before? It feels… ugly.


Welcome to the forum @semuelle!

For now, yes. We haven’t optimized for use with Embark yet, though we would love to! The fact that the web3 instance is only available in a callback makes it kind of hard.

One obvious thing that needs to be improved is the fact that configure needs to be called before any of the helpers are imported. This is the reason why you had to do the ugly global mutable helpers variable.

The reason we made it so is that when the helpers are imported, if configure wasn’t called beforehand the library will default to using a global web3 instance and once the web3 instance is set it cannot be changed. It’s difficult to fix that correctly but there are a few options.

Would love to hear your thoughts on what else could be improved for use with Embark.

Also, we’d love to know a bit about about you and what you’re working on in Introduce yourself here! :slight_smile:

1 Like