Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuring custom web3 instance (#38)
* add web3-utils as a dependency * rename main file to index.js * add explicit web3 injection with global fallback * change installation procedure for integration tests * add integration test for using in migrations * emit better error message on migration integration test * add version check to web3 injection * allow multiple injection of the same instance * tweak migration integration test * fix linter errors * pin web3-utils to beta 37 * remove leftover comment * rename integration test * add truffle-migration test to travis * keep test directory * make inject-web3 a configuration step instead of alternative entry point * remove unnecessary npm install * move default configuration logic to configure.js * rename global-web3 to configure-web3 * add changelog entry * add note about configuration in README * fix linter errors * Revert "remove unnecessary npm install" This reverts commit a918899. * configure eslint globals correctly * fix some parentheses
- Loading branch information
Francisco Giordano
committed
May 10, 2019
1 parent
1b11b39
commit 401e0bd
Showing
34 changed files
with
1,217 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; |
File renamed without changes.
Oops, something went wrong.