From afa871a96cedae02a16a4bb4eaa772e83f0d9f57 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Sun, 15 Dec 2019 11:23:33 -0800 Subject: [PATCH 1/5] Add E2E Mosaic test --- .travis.yml | 6 +++- package.json | 1 + scripts/ci.sh | 5 ++++ scripts/e2e.mosaic.sh | 56 ++++++++++++++++++++++++++++++++++++ scripts/e2e.npm.publish.sh | 1 - scripts/e2e.truffle.sh | 3 ++ scripts/js/resolutions.js | 59 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 129 insertions(+), 2 deletions(-) create mode 100755 scripts/e2e.mosaic.sh create mode 100755 scripts/js/resolutions.js diff --git a/.travis.yml b/.travis.yml index 3e0f671b778..7c104d1270a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,8 @@ matrix: env: TEST=unit_and_e2e_clients - node_js: 10 env: TEST=e2e_truffle + - node_js: 10 + env: TEST=e2e_mosaic - node_js: 10 env: TEST=e2e_browsers addons: @@ -26,6 +28,8 @@ matrix: allow_failures: - node_js: 10 env: TEST=e2e_truffle + - node_js: 10 + env: TEST=e2e_mosaic addons: apt: @@ -45,7 +49,7 @@ before_install: - export DISPLAY=:99.0 - export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true install: - - if [ $TEST != "e2e_truffle" ]; then + - if [[ $TEST != "e2e_truffle" ]] && [[ $TEST != "e2e_mosaic" ]]; then npm install; fi script: diff --git a/package.json b/package.json index c2a284a3422..b570969283a 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "test:e2e:browsers": "npm run build; npm run test:e2e:chrome; npm run test:e2e:firefox", "test:e2e:publish": "./scripts/e2e.npm.publish.sh", "test:e2e:truffle": "./scripts/e2e.truffle.sh", + "test:e2e:mosaic": "./scripts/e2e.mosaic.sh", "ci": "./scripts/ci.sh", "coveralls": "./scripts/coveralls.sh" }, diff --git a/scripts/ci.sh b/scripts/ci.sh index a1d5e11994a..584ee6431b1 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -39,4 +39,9 @@ elif [ "$TEST" = "e2e_truffle" ]; then npm run test:e2e:publish npm run test:e2e:truffle +elif [ "$TEST" = "e2e_mosaic" ]; then + + npm run test:e2e:publish + npm run test:e2e:mosaic + fi diff --git a/scripts/e2e.mosaic.sh b/scripts/e2e.mosaic.sh new file mode 100755 index 00000000000..26d84019428 --- /dev/null +++ b/scripts/e2e.mosaic.sh @@ -0,0 +1,56 @@ +# ------------------------------------------------------------------------------------------- +# Run mosaicdao/mosaic-1 fork (w/ buidler truffle5 plugin) using a candidate +# branch of web3 which has been published to a proxy npm registry in `e2e.npm.publish.sh` +# +# This test's purpose is to watch web3 execute a long, complex test suite +# It uses buidler-adapted fork of mosaicdao because that tool is simpler and +# more modular than Truffle and lets us resolve arbitrary versions of web3 more easily. +# -------------------------------------------------------------------------------------------- + +# Exit immediately on error +set -o errexit + +# To mimic `npm install web3` correctly, this test does not install Web3's dev deps. +# However, we need the npm package `semver` to coerce yarn resolutions correctly. +# It must be installed as a dev dep or Node complains. We also need web3's package.json +# to resolve the current version + patch increment. So some file renaming is necessary here... +cp package.json original.package.json +rm package.json +rm package-lock.json +npm init --yes +npm install --save-dev semver + +# Install mosaic and set yarn resolutions to virtually published patch version +git clone https://github.com/cgewecke/mosaic-1.git +scripts/js/resolutions.js mosaic-1 +cd mosaic-1 + +# Install via registry and verify +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "Installing updated web3 via virtual registry " +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + +git submodule update --init --recursive +yarn --registry http://localhost:4873 + +yarn add web3@e2e --registry http://localhost:4873 + +yarn list web3 +yarn list web3-utils +yarn list web3-core +yarn list web3-core-promievent + +cat ./package.json + +# Test +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +echo "Running mosaicdao/mosaic-1 unit tests. " +echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + +# Launch ganache +./tools/run_ganache_cli.sh /dev/null 2>&1 & +sleep 10 + +# Compile and test +npx buidler compile +npm test diff --git a/scripts/e2e.npm.publish.sh b/scripts/e2e.npm.publish.sh index b71595f3ad5..884004ccbf2 100755 --- a/scripts/e2e.npm.publish.sh +++ b/scripts/e2e.npm.publish.sh @@ -23,7 +23,6 @@ fi # what it needs here. npm install -g verdaccio@4.3.4 npm install -g npm-auth-to-token@1.0.0 -npm install -g geth-dev-assistant@0.1.3 npm install -g lerna@3.18.3 # Launch npm proxy registry diff --git a/scripts/e2e.truffle.sh b/scripts/e2e.truffle.sh index 984931ab117..1a1b6fa2771 100755 --- a/scripts/e2e.truffle.sh +++ b/scripts/e2e.truffle.sh @@ -8,6 +8,9 @@ # Exit immediately on error set -o errexit +# Install test specific dependencies +npm install -g geth-dev-assistant@0.1.3 + # Launch geth npm run geth diff --git a/scripts/js/resolutions.js b/scripts/js/resolutions.js new file mode 100755 index 00000000000..b6134829c16 --- /dev/null +++ b/scripts/js/resolutions.js @@ -0,0 +1,59 @@ +#!/usr/bin/env node + +/** + * This script is a helper for running a buidler based e2e unit test target and is + * used in combination with the npm virtual publishing script. + * + * It discovers the current web3 package version, gets its patch increment + * (also the value of the virtually published version) and attaches a yarn resolutions field + * to the target's package.json to coerce any Web3 packages up to the patch when target is + * installed. + * + * USAGE: resolutions.js + * EXAMPLE: node scripts/js/resolutions.js mosaic-1 + * + */ +const fs = require('fs'); +const path = require('path'); + +const semver = require('semver'); +const web3PackagePath = path.join(process.cwd(), 'original.package.json'); +const targetPackagePath = path.join(process.cwd(), process.argv[2], 'package.json'); + +const web3Package = require(web3PackagePath); +const targetPackage = require(targetPackagePath); + +const patch = semver.inc(web3Package.version, 'patch'); + +targetPackage.resolutions = { + "@nomiclabs/**/web3": `${patch}`, + "@nomiclabs/**/web3-bzz": `${patch}`, + "@nomiclabs/**/web3-core-helpers": `${patch}`, + "@nomiclabs/**/web3-core-method": `${patch}`, + "@nomiclabs/**/web3-core-promievent": `${patch}`, + "@nomiclabs/**/web3-core-requestmanager": `${patch}`, + "@nomiclabs/**/web3-core-subscriptions": `${patch}`, + "@nomiclabs/**/web3-core": `${patch}`, + "@nomiclabs/**/web3-eth-abi": `${patch}`, + "@nomiclabs/**/web3-eth-accounts": `${patch}`, + "@nomiclabs/**/web3-eth-contract": `${patch}`, + "@nomiclabs/**/web3-eth-ens": `${patch}`, + "@nomiclabs/**/web3-eth-iban": `${patch}`, + "@nomiclabs/**/web3-eth-personal": `${patch}`, + "@nomiclabs/**/web3-eth": `${patch}`, + "@nomiclabs/**/web3-net": `${patch}`, + "@nomiclabs/**/web3-providers-http": `${patch}`, + "@nomiclabs/**/web3-providers-ipc": `${patch}`, + "@nomiclabs/**/web3-providers-ws": `${patch}`, + "@nomiclabs/**/web3-shh": `${patch}`, + "@nomiclabs/**/web3-utils": `${patch}` +} + +console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); +console.log(`Yarn will resolve Web3 packages in "${process.argv[2]}"" to...`); +console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + +console.log(JSON.stringify(targetPackage.resolutions, null, ' ')); + +fs.writeFileSync(targetPackagePath, JSON.stringify(targetPackage, null, ' ')); + From 65b4e76ed72b6c5ef5904bef28c317c2ebd75be2 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Sun, 15 Dec 2019 13:46:10 -0800 Subject: [PATCH 2/5] Prove the virtually published version is used --- packages/web3-core-requestmanager/src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/web3-core-requestmanager/src/index.js b/packages/web3-core-requestmanager/src/index.js index 4bff56b5ea3..4ccc260e11c 100644 --- a/packages/web3-core-requestmanager/src/index.js +++ b/packages/web3-core-requestmanager/src/index.js @@ -144,6 +144,7 @@ RequestManager.prototype.send = function (data, callback) { return callback(errors.InvalidResponse(result)); } + console.log('In published web3 @ requestManager.send'); callback(null, result.result); }); }; From 2cf33394a30dbc1e16a4cf859a286e80840ce679 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Sun, 15 Dec 2019 14:03:23 -0800 Subject: [PATCH 3/5] Prove test is using virtually published version --- packages/web3-core-requestmanager/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/web3-core-requestmanager/src/index.js b/packages/web3-core-requestmanager/src/index.js index 4ccc260e11c..df1b5df51ff 100644 --- a/packages/web3-core-requestmanager/src/index.js +++ b/packages/web3-core-requestmanager/src/index.js @@ -65,6 +65,7 @@ RequestManager.providers = { */ RequestManager.prototype.setProvider = function (p, net) { var _this = this; + console.log('Using published Web3 @ RequestManager.setProvider') // autodetect provider if(p && typeof p === 'string' && this.providers) { @@ -144,7 +145,6 @@ RequestManager.prototype.send = function (data, callback) { return callback(errors.InvalidResponse(result)); } - console.log('In published web3 @ requestManager.send'); callback(null, result.result); }); }; From 84a646cdc72f125b36c0d6ddb787b64ab7fa37b5 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Sun, 15 Dec 2019 14:18:42 -0800 Subject: [PATCH 4/5] Remove log line --- packages/web3-core-requestmanager/src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/web3-core-requestmanager/src/index.js b/packages/web3-core-requestmanager/src/index.js index df1b5df51ff..4bff56b5ea3 100644 --- a/packages/web3-core-requestmanager/src/index.js +++ b/packages/web3-core-requestmanager/src/index.js @@ -65,7 +65,6 @@ RequestManager.providers = { */ RequestManager.prototype.setProvider = function (p, net) { var _this = this; - console.log('Using published Web3 @ RequestManager.setProvider') // autodetect provider if(p && typeof p === 'string' && this.providers) { From 54f6eebc4ee07b23b3220d180b4ef3bf5135f2f5 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Sun, 15 Dec 2019 14:53:05 -0800 Subject: [PATCH 5/5] Increase timeout for contract.js unit test --- test/contract.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/contract.js b/test/contract.js index b727ee937b8..7c2d43ec53f 100644 --- a/test/contract.js +++ b/test/contract.js @@ -3219,7 +3219,7 @@ describe('typical usage', function() { // done(); // }); - }).timeout(6000); + }).timeout(10000); // TODO add error check });