Skip to content

Commit df1c7b3

Browse files
committed
Re-enable e2e zeppelin & metacoin (#396)
* Handle truffle.library require cases * Fix sanity-check paths
1 parent e75a631 commit df1c7b3

File tree

8 files changed

+90
-28
lines changed

8 files changed

+90
-28
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ workflows:
7474
build:
7575
jobs:
7676
- unit-test
77-
# TODO: re-enable
78-
#- e2e-zeppelin
79-
#- e2e-metacoin
77+
- e2e-zeppelin
78+
- e2e-metacoin
79+
# TODO: re-enable.
80+
# At the moment we're using forks so this is pointless
8081
#nightly:
8182
# triggers:
8283
# - schedule:
@@ -86,6 +87,5 @@ workflows:
8687
# only:
8788
# - master
8889
# jobs:
89-
# TODO: re-enable
9090
#- e2e-zeppelin
9191
#- e2e-colony

dist/truffle.plugin.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const dir = require('node-dir');
3434
const Web3 = require('web3');
3535
const util = require('util');
3636
const globby = require('globby');
37+
const globalModules = require('global-modules');
3738

3839
async function plugin(truffleConfig){
3940
let app;
@@ -59,7 +60,7 @@ async function plugin(truffleConfig){
5960
return app.ui.report('truffle-help')
6061
}
6162

62-
truffle = loadTruffleLibrary();
63+
truffle = loadTruffleLibrary(app);
6364

6465
} catch (err) {
6566
throw err;
@@ -152,13 +153,36 @@ function tests(truffle){
152153
}
153154

154155

155-
function loadTruffleLibrary(){
156-
try { return require("truffle") } catch(err) {};
157-
try { return require("./truffle.library")} catch(err) {};
156+
function loadTruffleLibrary(app){
157+
158+
// Case: from local node_modules
159+
try {
160+
const lib = require("truffle");
161+
app.ui.report('truffle-local');
162+
return lib;
163+
164+
} catch(err) {};
165+
166+
// Case: global
167+
try {
168+
const globalTruffle = path.join(globalModules, 'truffle');
169+
const lib = require(globalTruffle);
170+
app.ui.report('truffle-global');
171+
return lib;
172+
173+
} catch(err) {};
174+
175+
// Default: fallback
176+
try {
177+
178+
app.ui.report('truffle-warn');
179+
return require("./truffle.library")}
180+
181+
catch(err) {
182+
const msg = app.ui.generate('truffle-fail', [err]);
183+
throw new Error(msg);
184+
};
158185

159-
// TO DO: throw error? This point should never be reached.
160-
// Validate that truffle.ganache exists? Have checked that
161-
// a non-existent prop defaults to the ganache-core-sc fallback FWIW.
162186
}
163187

164188
/**

lib/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ class App {
261261
this.cleanUp("Couldn't find a 'contracts' folder to instrument.");
262262
}
263263

264-
if (shell.test('-e', path.join(this.cwd, this.contractsDir))){
264+
if (shell.test('-e', this.contractsDir)){
265265
shell.rm('-Rf', this.contractsDir);
266266
}
267267

268-
if (shell.test('-e', path.join(this.cwd, this.artifactsDir))){
268+
if (shell.test('-e', this.artifactsDir)){
269269
shell.rm('-Rf', this.artifactsDir);
270270
}
271271
}

lib/ui.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class UI {
2626
`${c.red('Check the provider option syntax in solidity-coverage docs.')}\n`+
2727
`:warning: ${c.red('Using ganache-core-sc (eq. core v2.7.0) instead.')}\n`,
2828

29+
'truffle-local': `\n${ct} ${c.grey('Using Truffle library from local node_modules.')}\n`,
30+
'truffle-global': `\n${ct} ${c.grey('Using Truffle library from global node_modules.')}\n`,
31+
32+
'truffle-warn': `:warning: ${c.red('Unable to require Truffle library locally or globally. ')} `+
33+
`${c.red('Expected to find installed Truffle >= v5.0.31 ...')}\n` +
34+
`:warning: ${c.red('Using fallback Truffle library instead (v5.0.31)')}\n`,
35+
2936
'truffle-help': `Usage: truffle run coverage [options]\n\n` +
3037
`Options:\n` +
3138
` --file: path (or glob) to subset of JS test files. (Quote your globs)\n` +
@@ -55,8 +62,14 @@ class UI {
5562
* @param {String[]} args info to inject into template
5663
* @return {String} message
5764
*/
58-
generate(kind, args){
65+
generate(kind, args=[]){
66+
const kinds = {
67+
'truffle-fail': `${c.red('Unable to load fail-safe Truffle library. Caught: ')} ${args[0]}\n` +
68+
`:x: ${c.red('Try installing Truffle >= v5.0.31 locally or globally.\n')}`,
69+
}
70+
5971

72+
return emoji.emojify(kinds[kind])
6073
}
6174
}
6275

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"chalk": "^2.4.2",
2525
"death": "^1.1.0",
2626
"ganache-core-sc": "2.7.0-sc.0",
27+
"global-modules": "^2.0.0",
2728
"globby": "^10.0.1",
2829
"istanbul": "^0.4.5",
2930
"node-dir": "^0.1.17",

scripts/run-metacoin.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# E2E CI: installs PR candidate on Truffle's MetaCoin and runs coverage
44
#
55

6+
set -o errexit
7+
68
# Get rid of any caches
79
sudo rm -rf node_modules
810
echo "NVM CURRENT >>>>>" && nvm current
@@ -23,9 +25,15 @@ npm install -g truffle
2325
mkdir metacoin
2426
cd metacoin
2527
truffle unbox metacoin --force
26-
rm test/TestMetacoin.sol
27-
npm init --yes
28+
rm truffle-config.js
29+
echo "module.exports={plugins:['solidity-coverage']}" > truffle-config.js
30+
cat truffle-config.js
31+
32+
# TODO: Remove this rm.
33+
# Unknown bug running truffle native solidity tests
34+
rm test/TestMetaCoin.sol
2835

2936
# Install and run solidity-coverage @ PR
37+
npm init --yes
3038
npm install --save-dev $PR_PATH
31-
npx solidity-coverage
39+
npx truffle run coverage

scripts/run-zeppelin.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# E2E CI: installs PR candidate on openzeppelin-solidity and runs coverage
44
#
55

6+
set -o errexit
7+
68
# Get rid of any caches
79
sudo rm -rf node_modules
810
echo "NVM CURRENT >>>>>" && nvm current
@@ -18,16 +20,14 @@ fi
1820

1921
echo "PR_PATH >>>>> $PR_PATH"
2022

21-
# Install Zeppelin
22-
git clone https://github.com/OpenZeppelin/openzeppelin-solidity.git
23-
cd openzeppelin-solidity
23+
# Install sc-forks Zeppelin fork (temporarily). It's setup to
24+
# consume the plugin and skips a small set of GSN tests that rely on
25+
# the client being stand-alone. (See OZ issue #1918 for discussion)
26+
git clone https://github.com/sc-forks/openzeppelin-contracts.git
27+
cd openzeppelin-contracts
2428

25-
# Update Zeppelin's script to use 0.6.x
26-
sed -i 's/if/# /g' scripts/coverage.sh
27-
sed -i 's/curl/# /g' scripts/coverage.sh
28-
sed -i 's/fi/# /g' scripts/coverage.sh
29-
sed -i 's/ganache-cli-coverage/testrpc-sc/g' scripts/test.sh
30-
sed -i 's/--emitFreeLogs true/ /g' scripts/test.sh
29+
echo ">>>>> checkout provider-benchmarks branch"
30+
git checkout provider-benchmarks
3131

3232
# Swap installed coverage for PR branch version
3333
echo ">>>>> npm install"
@@ -39,4 +39,5 @@ npm uninstall --save-dev solidity-coverage
3939
echo ">>>>> npm install --save-dev PR_PATH"
4040
npm install --save-dev "$PR_PATH"
4141

42-
npm run coverage
42+
# Track perf
43+
time npx truffle run coverage

yarn.lock

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3852,6 +3852,13 @@ global-modules@^1.0.0:
38523852
is-windows "^1.0.1"
38533853
resolve-dir "^1.0.0"
38543854

3855+
global-modules@^2.0.0:
3856+
version "2.0.0"
3857+
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-2.0.0.tgz#997605ad2345f27f51539bea26574421215c7780"
3858+
integrity sha512-NGbfmJBp9x8IxyJSd1P+otYK8vonoJactOogrVfFRIAEY1ukil8RSKDz2Yo7wh1oihl51l/r6W4epkeKJHqL8A==
3859+
dependencies:
3860+
global-prefix "^3.0.0"
3861+
38553862
global-prefix@^1.0.1:
38563863
version "1.0.2"
38573864
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-1.0.2.tgz#dbf743c6c14992593c655568cb66ed32c0122ebe"
@@ -3863,6 +3870,15 @@ global-prefix@^1.0.1:
38633870
is-windows "^1.0.1"
38643871
which "^1.2.14"
38653872

3873+
global-prefix@^3.0.0:
3874+
version "3.0.0"
3875+
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-3.0.0.tgz#fc85f73064df69f50421f47f883fe5b913ba9b97"
3876+
integrity sha512-awConJSVCHVGND6x3tmMaKcQvwXLhjdkmomy2W+Goaui8YPgYgXJZewhg3fWC+DlfqqQuWg8AwqjGTD2nAPVWg==
3877+
dependencies:
3878+
ini "^1.3.5"
3879+
kind-of "^6.0.2"
3880+
which "^1.3.1"
3881+
38663882
global@~4.3.0:
38673883
version "4.3.2"
38683884
resolved "https://registry.yarnpkg.com/global/-/global-4.3.2.tgz#e76989268a6c74c38908b1305b10fc0e394e9d0f"
@@ -9520,7 +9536,6 @@ [email protected], "websocket@github:web3-js/WebSocket-Node#polyfill/globalThis":
95209536
dependencies:
95219537
debug "^2.2.0"
95229538
es5-ext "^0.10.50"
9523-
gulp "^4.0.2"
95249539
nan "^2.14.0"
95259540
typedarray-to-buffer "^3.1.5"
95269541
yaeti "^0.0.6"

0 commit comments

Comments
 (0)