forked from OpenZeppelin/openzeppelin-test-helpers
/
configure.js
55 lines (40 loc) · 1.18 KB
/
configure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* global web3 */
const { setWeb3 } = require('./src/configure-web3');
let loadedConfig;
function configure (config) {
if (!config) {
// if there already is a loaded config keep it
if (!loadedConfig) {
defaultConfigure();
loadedConfig = 'default';
}
} else {
if (loadedConfig) {
let errorMessage = 'Cannot configure openzeppelin-test-helpers a second time.';
if (loadedConfig === 'default') {
errorMessage += `
A configuration has been loaded by default. Make sure to do custom configuration before importing the library.
require('openzeppelin-test-helpers/configure')({ web3: ... });
const { expectEvent } = require('openzeppelin-test-helpers');
`;
}
throw new Error(errorMessage);
}
customConfigure(config);
loadedConfig = 'custom';
}
};
function defaultConfigure () {
if (typeof web3 === 'undefined') {
throw new Error(`Cannot find a global Web3 instance. Please configure one manually:
require('openzeppelin-test-helpers/configure')({ web3: ... });
`
);
}
// use global web3
setWeb3(web3);
}
function customConfigure (config) {
setWeb3(config.web3);
}
module.exports = configure;