forked from OpenZeppelin/openzeppelin-test-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.js
45 lines (36 loc) · 1.14 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
const { setWeb3Provider } = require('./src/config/web3');
const { setSingletonsConfig } = require('./src/config/singletons');
const { deprecate } = require('util');
const setEnvironment = deprecate((environment) => setSingletonsConfig({ abstraction: environment }),
'The \'environment\' configuration option is deprecated, use \'singletons.abstraction\' instead.'
);
let configLoaded = false;
function configure (config) {
if (!config) {
// If there is a config already loaded keep it
if (!configLoaded) {
defaultConfigure();
configLoaded = true;
}
} else {
customConfigure(config);
configLoaded = true;
}
};
function defaultConfigure () {
setWeb3Provider.default();
setSingletonsConfig.default();
}
function customConfigure (config) {
defaultConfigure();
if ('provider' in config) {
// The provider may be either an URL to an HTTP endpoint, or a complete provider object
setWeb3Provider(config.provider);
}
if ('singletons' in config) {
setSingletonsConfig(config.singletons);
} else if ('environment' in config) {
setEnvironment(config.environment);
}
}
module.exports = configure;