Skip to content

Commit 97de9c6

Browse files
authored
Add builder-ethers test to CI (#441)
* Let plugins manage which client is used * Use requested network name
1 parent 4f73e15 commit 97de9c6

File tree

8 files changed

+82
-30
lines changed

8 files changed

+82
-30
lines changed

dist/buidler.plugin.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,10 @@ function plugin() {
4646
// ==============
4747
// Server launch
4848
// ==============
49-
const network = buidlerUtils.setupNetwork(
50-
env,
51-
api,
52-
args,
53-
ui
54-
);
55-
56-
const address = await api.ganache(ganache);
49+
const network = buidlerUtils.setupNetwork(env, api, ui);
50+
51+
const client = api.client || ganache;
52+
const address = await api.ganache(client);
5753
const web3 = new Web3(address);
5854
const accounts = await web3.eth.getAccounts();
5955
const nodeInfo = await web3.eth.getNodeInfo();
@@ -68,9 +64,8 @@ function plugin() {
6864
pkg.version
6965
]);
7066

71-
// Network Info
7267
ui.report('network', [
73-
api.defaultNetworkName,
68+
env.network.name,
7469
api.port
7570
]);
7671

dist/plugin-assets/buidler.utils.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/c
1616
* @param {BuidlerConfig} config
1717
* @return {BuidlerConfig} updated config
1818
*/
19-
function normalizeConfig(config, args){
19+
function normalizeConfig(config, args={}){
2020
config.workingDir = config.paths.root;
2121
config.contractsDir = config.paths.sources;
2222
config.testDir = config.paths.tests;
@@ -27,11 +27,15 @@ function normalizeConfig(config, args){
2727
return config;
2828
}
2929

30-
function setupNetwork(env, api, taskArgs, ui){
30+
function setupNetwork(env, api, ui){
3131
let networkConfig = {};
3232

33-
if (taskArgs.network){
34-
networkConfig = env.config.networks[taskArgs.network];
33+
let networkName = (env.buidlerArguments.network !== 'buidlerevm')
34+
? env.buidlerArguments.network
35+
: api.defaultNetworkName;
36+
37+
if (networkName !== api.defaultNetworkName){
38+
networkConfig = env.config.networks[networkName];
3539

3640
const configPort = networkConfig.url.split(':')[2];
3741

@@ -48,13 +52,13 @@ function setupNetwork(env, api, taskArgs, ui){
4852
networkConfig.gas = api.gasLimit;
4953
networkConfig.gasPrice = api.gasPrice;
5054

51-
const provider = createProvider(api.defaultNetworkName, networkConfig);
55+
const provider = createProvider(networkName, networkConfig);
5256

53-
env.config.networks[api.defaultNetworkName] = networkConfig;
54-
env.config.defaultNetwork = api.defaultNetworkName;
57+
env.config.networks[networkName] = networkConfig;
58+
env.config.defaultNetwork = networkName;
5559

5660
env.network = {
57-
name: api.defaultNetworkName,
61+
name: networkName,
5862
config: networkConfig,
5963
provider: provider,
6064
}

dist/truffle.plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ async function plugin(config){
3636
truffleUtils.setNetwork(config, api);
3737

3838
// Server launch
39-
const address = await api.ganache(truffle.ganache);
39+
const client = api.client || truffle.ganache;
40+
const address = await api.ganache(client);
4041

4142
const web3 = new Web3(address);
4243
const accounts = await web3.eth.getAccounts();

lib/api.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ class API {
3939
this.onIstanbulComplete = config.onIstanbulComplete || this.defaultHook;
4040

4141
this.server = null;
42-
this.provider = null;
4342
this.defaultPort = 8555;
44-
this.defaultNetworkName = 'soliditycoverage';
4543
this.client = config.client;
44+
this.defaultNetworkName = 'soliditycoverage';
4645
this.port = config.port || this.defaultPort;
4746
this.host = config.host || "127.0.0.1";
4847
this.providerOptions = config.providerOptions || {};
@@ -224,9 +223,9 @@ class API {
224223
async attachToVM(client){
225224
const self = this;
226225

227-
// Prefer client from options
228-
if(!this.client) this.client = client;
229-
this.server = this.client.server(this.providerOptions);
226+
// Fallback to client from options
227+
if(!client) client = this.client;
228+
this.server = client.server(this.providerOptions);
230229

231230
this.assertHasBlockchain(this.server.provider);
232231
await this.vmIsResolved(this.server.provider);

scripts/run-buidler.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,47 @@ fi
2121

2222
echo "PR_PATH >>>>> $PR_PATH"
2323

24+
echo ""
25+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
26+
echo "Simple buidler/buidler-trufflev5 "
27+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
28+
echo ""
29+
2430
# Install buidler e2e test
2531
git clone https://github.com/sc-forks/buidler-e2e.git
2632
cd buidler-e2e
2733
npm install
2834

2935
# Install and run solidity-coverage @ PR
3036
npm install --save-dev $PR_PATH
37+
cat package.json
38+
39+
npx buidler coverage
40+
41+
# Test that coverage/ was generated
42+
if [ ! -d "coverage" ]; then
43+
echo "ERROR: no coverage folder was created for buidler-trufflev5."
44+
exit 1
45+
fi
46+
47+
echo ""
48+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
49+
echo "Simple buidler/buidler-ethers "
50+
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
51+
echo ""
52+
cd ..
53+
git clone https://github.com/sc-forks/example-buidler-ethers.git
54+
cd example-buidler-ethers
55+
npm install
56+
57+
# Install and run solidity-coverage @ PR
58+
npm install --save-dev $PR_PATH
59+
cat package.json
60+
3161
npx buidler coverage
3262

3363
# Test that coverage/ was generated
3464
if [ ! -d "coverage" ]; then
35-
echo "ERROR: no coverage folder was created."
65+
echo "ERROR: no coverage folder was created for buidler-ethers."
3666
exit 1
3767
fi

scripts/run-moloch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ npm install
2828
npm uninstall --save-dev solidity-coverage
2929

3030
# Install and run solidity-coverage @ PR
31+
# Should run on network 'localhost'
3132
npm install --save-dev $PR_PATH
3233
npm run coverage
3334

test/units/buidler/flags.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ describe('Buidler Plugin: command line options', function() {
5353
});
5454

5555
it('--network (declared port mismatches)', async function(){
56-
const taskArgs = {
57-
network: 'development' // 8545
58-
}
59-
6056
solcoverConfig.port = 8222;
6157

6258
mock.install('Simple', 'simple.js', solcoverConfig);
6359
mock.buidlerSetupEnv(this);
6460

65-
await this.env.run("coverage", taskArgs);
61+
this.env.buidlerArguments.network = "development";
62+
63+
await this.env.run("coverage");
6664

6765
assert(
6866
mock.loggerOutput.val.includes("The 'port' values"),
@@ -74,6 +72,11 @@ describe('Buidler Plugin: command line options', function() {
7472
`Should have used default coverage port 8545: ${mock.loggerOutput.val}`
7573
);
7674

75+
assert(
76+
mock.loggerOutput.val.includes("development"),
77+
`Should have used specified network name: ${mock.loggerOutput.val}`
78+
);
79+
7780
const expected = [{
7881
file: mock.pathToContract(buidlerConfig, 'Simple.sol'),
7982
pct: 100

test/units/buidler/standard.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,25 @@ describe('Buidler Plugin: standard use cases', function() {
5151
);
5252
});
5353

54+
it('default network ("buidlerevm")', async function(){
55+
mock.install('Simple', 'simple.js', solcoverConfig);
56+
mock.buidlerSetupEnv(this);
57+
58+
this.env.buidlerArguments.network = "buidlerevm"
59+
60+
await this.env.run("coverage");
61+
62+
assert(
63+
mock.loggerOutput.val.includes("8555"),
64+
`Should have used default coverage port 8555: ${mock.loggerOutput.val}`
65+
);
66+
67+
assert(
68+
mock.loggerOutput.val.includes("soliditycoverage"),
69+
`Should have used specified network name: ${mock.loggerOutput.val}`
70+
);
71+
});
72+
5473
it('with relative path solidity imports', async function() {
5574
mock.installFullProject('import-paths');
5675
mock.buidlerSetupEnv(this);

0 commit comments

Comments
 (0)