Configuration
The Test Helpers require some light configuration to properly connect to your testing environment.
Where possible, this will be done automatically, but some scenarios require manual settings. This is achieved by calling the configure
function:
// Apply configuration
require('@openzeppelin/test-helpers/configure')({ ... });
// Import the helpers
const { expectRevert } = require('@openzeppelin/test-helpers');
The configuration must be applied on all test files, before importing the helpers.
provider
In a Truffle environment, the web3 provider will be pulled from Truffle’s global web3
instance. Otherwise, this value defaults to http://localhost:8545
.
You can override this behavior and configure your own via the provider
key:
require('@openzeppelin/test-helpers/configure')({
provider: 'http://localhost:8080',
});
singletons
The singletons
helper returns contract objects, and these have multiple settings that can be configured:
-
abstraction
: the underlying contract abstraction type,'web3'
forweb3-eth-contract
and'truffle'
for@truffle/contract
instances. Defaults to'web3'
unless a Truffle environment is detected. -
defaultGas
: how much gas to allocate when a transaction’sgas
field is not specified. Defaults to 200k. -
defaultSender
: the sender address to use when a transaction’sfrom
field is not specified. No default.
While automatic detection and defaults should cover most use cases, all values can be manually supplied:
require('@openzeppelin/test-helpers/configure')({
singletons: {
abstraction: 'web3',
defaultGas: 6e6,
defaultSender: '0x5a0b5...',
},
});