From 97de9c6012b44202f2736e7368696064f0006f73 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Tue, 26 Nov 2019 23:43:00 -0800 Subject: [PATCH] Add builder-ethers test to CI (#441) * Let plugins manage which client is used * Use requested network name --- dist/buidler.plugin.js | 15 +++++--------- dist/plugin-assets/buidler.utils.js | 20 ++++++++++-------- dist/truffle.plugin.js | 3 ++- lib/api.js | 9 ++++---- scripts/run-buidler.sh | 32 ++++++++++++++++++++++++++++- scripts/run-moloch.sh | 1 + test/units/buidler/flags.js | 13 +++++++----- test/units/buidler/standard.js | 19 +++++++++++++++++ 8 files changed, 82 insertions(+), 30 deletions(-) diff --git a/dist/buidler.plugin.js b/dist/buidler.plugin.js index 8c005da..dfdd0dc 100644 --- a/dist/buidler.plugin.js +++ b/dist/buidler.plugin.js @@ -46,14 +46,10 @@ function plugin() { // ============== // Server launch // ============== - const network = buidlerUtils.setupNetwork( - env, - api, - args, - ui - ); - - const address = await api.ganache(ganache); + const network = buidlerUtils.setupNetwork(env, api, ui); + + const client = api.client || ganache; + const address = await api.ganache(client); const web3 = new Web3(address); const accounts = await web3.eth.getAccounts(); const nodeInfo = await web3.eth.getNodeInfo(); @@ -68,9 +64,8 @@ function plugin() { pkg.version ]); - // Network Info ui.report('network', [ - api.defaultNetworkName, + env.network.name, api.port ]); diff --git a/dist/plugin-assets/buidler.utils.js b/dist/plugin-assets/buidler.utils.js index 05de70d..f4044a1 100644 --- a/dist/plugin-assets/buidler.utils.js +++ b/dist/plugin-assets/buidler.utils.js @@ -16,7 +16,7 @@ const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/c * @param {BuidlerConfig} config * @return {BuidlerConfig} updated config */ -function normalizeConfig(config, args){ +function normalizeConfig(config, args={}){ config.workingDir = config.paths.root; config.contractsDir = config.paths.sources; config.testDir = config.paths.tests; @@ -27,11 +27,15 @@ function normalizeConfig(config, args){ return config; } -function setupNetwork(env, api, taskArgs, ui){ +function setupNetwork(env, api, ui){ let networkConfig = {}; - if (taskArgs.network){ - networkConfig = env.config.networks[taskArgs.network]; + let networkName = (env.buidlerArguments.network !== 'buidlerevm') + ? env.buidlerArguments.network + : api.defaultNetworkName; + + if (networkName !== api.defaultNetworkName){ + networkConfig = env.config.networks[networkName]; const configPort = networkConfig.url.split(':')[2]; @@ -48,13 +52,13 @@ function setupNetwork(env, api, taskArgs, ui){ networkConfig.gas = api.gasLimit; networkConfig.gasPrice = api.gasPrice; - const provider = createProvider(api.defaultNetworkName, networkConfig); + const provider = createProvider(networkName, networkConfig); - env.config.networks[api.defaultNetworkName] = networkConfig; - env.config.defaultNetwork = api.defaultNetworkName; + env.config.networks[networkName] = networkConfig; + env.config.defaultNetwork = networkName; env.network = { - name: api.defaultNetworkName, + name: networkName, config: networkConfig, provider: provider, } diff --git a/dist/truffle.plugin.js b/dist/truffle.plugin.js index 57445cd..dce3c9d 100644 --- a/dist/truffle.plugin.js +++ b/dist/truffle.plugin.js @@ -36,7 +36,8 @@ async function plugin(config){ truffleUtils.setNetwork(config, api); // Server launch - const address = await api.ganache(truffle.ganache); + const client = api.client || truffle.ganache; + const address = await api.ganache(client); const web3 = new Web3(address); const accounts = await web3.eth.getAccounts(); diff --git a/lib/api.js b/lib/api.js index 0d710e1..6084c72 100644 --- a/lib/api.js +++ b/lib/api.js @@ -39,10 +39,9 @@ class API { this.onIstanbulComplete = config.onIstanbulComplete || this.defaultHook; this.server = null; - this.provider = null; this.defaultPort = 8555; - this.defaultNetworkName = 'soliditycoverage'; this.client = config.client; + this.defaultNetworkName = 'soliditycoverage'; this.port = config.port || this.defaultPort; this.host = config.host || "127.0.0.1"; this.providerOptions = config.providerOptions || {}; @@ -224,9 +223,9 @@ class API { async attachToVM(client){ const self = this; - // Prefer client from options - if(!this.client) this.client = client; - this.server = this.client.server(this.providerOptions); + // Fallback to client from options + if(!client) client = this.client; + this.server = client.server(this.providerOptions); this.assertHasBlockchain(this.server.provider); await this.vmIsResolved(this.server.provider); diff --git a/scripts/run-buidler.sh b/scripts/run-buidler.sh index bc7dd3f..104d047 100755 --- a/scripts/run-buidler.sh +++ b/scripts/run-buidler.sh @@ -21,6 +21,12 @@ fi echo "PR_PATH >>>>> $PR_PATH" +echo "" +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "Simple buidler/buidler-trufflev5 " +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "" + # Install buidler e2e test git clone https://github.com/sc-forks/buidler-e2e.git cd buidler-e2e @@ -28,10 +34,34 @@ npm install # Install and run solidity-coverage @ PR npm install --save-dev $PR_PATH +cat package.json + +npx buidler coverage + +# Test that coverage/ was generated +if [ ! -d "coverage" ]; then + echo "ERROR: no coverage folder was created for buidler-trufflev5." + exit 1 +fi + +echo "" +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "Simple buidler/buidler-ethers " +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "" +cd .. +git clone https://github.com/sc-forks/example-buidler-ethers.git +cd example-buidler-ethers +npm install + +# Install and run solidity-coverage @ PR +npm install --save-dev $PR_PATH +cat package.json + npx buidler coverage # Test that coverage/ was generated if [ ! -d "coverage" ]; then - echo "ERROR: no coverage folder was created." + echo "ERROR: no coverage folder was created for buidler-ethers." exit 1 fi diff --git a/scripts/run-moloch.sh b/scripts/run-moloch.sh index 4c1191e..e3fc981 100755 --- a/scripts/run-moloch.sh +++ b/scripts/run-moloch.sh @@ -28,6 +28,7 @@ npm install npm uninstall --save-dev solidity-coverage # Install and run solidity-coverage @ PR +# Should run on network 'localhost' npm install --save-dev $PR_PATH npm run coverage diff --git a/test/units/buidler/flags.js b/test/units/buidler/flags.js index 8e45158..5cf7e31 100644 --- a/test/units/buidler/flags.js +++ b/test/units/buidler/flags.js @@ -53,16 +53,14 @@ describe('Buidler Plugin: command line options', function() { }); it('--network (declared port mismatches)', async function(){ - const taskArgs = { - network: 'development' // 8545 - } - solcoverConfig.port = 8222; mock.install('Simple', 'simple.js', solcoverConfig); mock.buidlerSetupEnv(this); - await this.env.run("coverage", taskArgs); + this.env.buidlerArguments.network = "development"; + + await this.env.run("coverage"); assert( mock.loggerOutput.val.includes("The 'port' values"), @@ -74,6 +72,11 @@ describe('Buidler Plugin: command line options', function() { `Should have used default coverage port 8545: ${mock.loggerOutput.val}` ); + assert( + mock.loggerOutput.val.includes("development"), + `Should have used specified network name: ${mock.loggerOutput.val}` + ); + const expected = [{ file: mock.pathToContract(buidlerConfig, 'Simple.sol'), pct: 100 diff --git a/test/units/buidler/standard.js b/test/units/buidler/standard.js index 527cca1..36a7abf 100644 --- a/test/units/buidler/standard.js +++ b/test/units/buidler/standard.js @@ -51,6 +51,25 @@ describe('Buidler Plugin: standard use cases', function() { ); }); + it('default network ("buidlerevm")', async function(){ + mock.install('Simple', 'simple.js', solcoverConfig); + mock.buidlerSetupEnv(this); + + this.env.buidlerArguments.network = "buidlerevm" + + await this.env.run("coverage"); + + assert( + mock.loggerOutput.val.includes("8555"), + `Should have used default coverage port 8555: ${mock.loggerOutput.val}` + ); + + assert( + mock.loggerOutput.val.includes("soliditycoverage"), + `Should have used specified network name: ${mock.loggerOutput.val}` + ); + }); + it('with relative path solidity imports', async function() { mock.installFullProject('import-paths'); mock.buidlerSetupEnv(this);