Skip to content

Commit 19f1990

Browse files
authored
Remove ganache-core-sc dev dependency (#554)
* Use api.ganache in unit tests
1 parent f1d4001 commit 19f1990

File tree

10 files changed

+175
-1917
lines changed

10 files changed

+175
-1917
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ step_install_nvm: &step_install_nvm
2020
jobs:
2121
unit-test:
2222
docker:
23-
- image: circleci/node:10
23+
- image: circleci/node:12
2424
steps:
2525
- checkout
2626
- run:

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"@truffle/contract": "^4.0.36",
5151
"buidler-gas-reporter": "^0.1.3",
5252
"decache": "^4.5.1",
53-
"ganache-core-sc": "^2.7.0-sc.0",
5453
"mocha": "5.2.0",
5554
"nyc": "^14.1.1",
5655
"solc": "^0.5.10",

test/units/assert.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
const assert = require('assert');
22
const util = require('./../util/util.js');
33

4-
const ganache = require('ganache-core-sc');
4+
const client = require('ganache-cli');
55
const Coverage = require('./../../lib/coverage');
6+
const Api = require('./../../lib/api')
67

78
describe('asserts and requires', () => {
89
let coverage;
9-
let provider;
10-
let collector;
10+
let api;
1111

12-
before(() => ({ provider, collector } = util.initializeProvider(ganache)));
12+
before(async () => {
13+
api = new Api({silent: true});
14+
await api.ganache(client);
15+
})
1316
beforeEach(() => coverage = new Coverage());
14-
after((done) => provider.close(done));
17+
after(async() => await api.finish());
1518

1619
it('should cover assert statements as `if` statements when they pass', async function() {
17-
const contract = await util.bootstrapCoverage('assert/Assert', provider, collector);
20+
const contract = await util.bootstrapCoverage('assert/Assert', api);
1821
coverage.addContract(contract.instrumented, util.filePath);
1922
await contract.instance.a(true);
2023
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -36,7 +39,7 @@ describe('asserts and requires', () => {
3639
// NB: Truffle replays failing txs as .calls to obtain the revert reason from the return
3740
// data. Hence the 2X measurements.
3841
it('should cover assert statements as `if` statements when they fail', async function() {
39-
const contract = await util.bootstrapCoverage('assert/Assert', provider, collector);
42+
const contract = await util.bootstrapCoverage('assert/Assert', api);
4043
coverage.addContract(contract.instrumented, util.filePath);
4144

4245
try { await contract.instance.a(false) } catch(err) { /* Invalid opcode */ }
@@ -57,7 +60,7 @@ describe('asserts and requires', () => {
5760
});
5861

5962
it('should cover multi-line require stmts as `if` statements when they pass', async function() {
60-
const contract = await util.bootstrapCoverage('assert/RequireMultiline', provider, collector);
63+
const contract = await util.bootstrapCoverage('assert/RequireMultiline', api);
6164
coverage.addContract(contract.instrumented, util.filePath);
6265
await contract.instance.a(true, true, true);
6366
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -79,7 +82,7 @@ describe('asserts and requires', () => {
7982
// NB: Truffle replays failing txs as .calls to obtain the revert reason from the return
8083
// data. Hence the 2X measurements.
8184
it('should cover multi-line require stmts as `if` statements when they fail', async function() {
82-
const contract = await util.bootstrapCoverage('assert/RequireMultiline', provider, collector);
85+
const contract = await util.bootstrapCoverage('assert/RequireMultiline', api);
8386
coverage.addContract(contract.instrumented, util.filePath);
8487

8588
try { await contract.instance.a(true, true, false) } catch(err) { /* Revert */ }

test/units/function.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
const assert = require('assert');
22
const util = require('./../util/util.js');
33

4-
const ganache = require('ganache-core-sc');
4+
const client = require('ganache-cli');
55
const Coverage = require('./../../lib/coverage');
6+
const Api = require('./../../lib/api')
67

78
describe('function declarations', () => {
89
let coverage;
9-
let provider;
10-
let collector;
10+
let api;
1111

12-
before(async () => ({ provider, collector } = await util.initializeProvider(ganache)));
12+
before(async () => {
13+
api = new Api({silent: true});
14+
await api.ganache(client);
15+
})
1316
beforeEach(() => coverage = new Coverage());
14-
after((done) => provider.close(done));
17+
after(async() => await api.finish());
1518

1619
it('should compile after instrumenting an ordinary function declaration', () => {
1720
const info = util.instrumentAndCompile('function/function');
@@ -54,7 +57,7 @@ describe('function declarations', () => {
5457
});
5558

5659
it('should cover a simple invoked function call', async function() {
57-
const contract = await util.bootstrapCoverage('function/function-call', provider, collector);
60+
const contract = await util.bootstrapCoverage('function/function-call', api);
5861
coverage.addContract(contract.instrumented, util.filePath);
5962
await contract.instance.a();
6063
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -73,7 +76,7 @@ describe('function declarations', () => {
7376
});
7477

7578
it('should cover a modifier used on a function', async function() {
76-
const contract = await util.bootstrapCoverage('function/modifier', provider, collector);
79+
const contract = await util.bootstrapCoverage('function/modifier', api);
7780
coverage.addContract(contract.instrumented, util.filePath);
7881
await contract.instance.a(0);
7982
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -92,7 +95,7 @@ describe('function declarations', () => {
9295
});
9396

9497
it('should cover a constructor that uses the `constructor` keyword', async function() {
95-
const contract = await util.bootstrapCoverage('function/constructor-keyword', provider, collector);
98+
const contract = await util.bootstrapCoverage('function/constructor-keyword', api);
9699
coverage.addContract(contract.instrumented, util.filePath);
97100
await contract.instance.a();
98101
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -115,7 +118,7 @@ describe('function declarations', () => {
115118
//
116119
// NB: 2x values are result of Truffle replaying failing txs to get reason string...
117120
it('should cover a constructor --> method call chain', async function() {
118-
const contract = await util.bootstrapCoverage('function/chainable', provider, collector);
121+
const contract = await util.bootstrapCoverage('function/chainable', api);
119122
coverage.addContract(contract.instrumented, util.filePath);
120123

121124
try { await contract.instance.a() } catch(err){}
@@ -140,7 +143,7 @@ describe('function declarations', () => {
140143
//
141144
// NB: 2x values are result of Truffle replaying failing txs to get reason string...
142145
it('should cover a constructor --> method --> value call chain', async function() {
143-
const contract = await util.bootstrapCoverage('function/chainable-value', provider, collector);
146+
const contract = await util.bootstrapCoverage('function/chainable-value', api);
144147
coverage.addContract(contract.instrumented, util.filePath);
145148

146149
try { await contract.instance.a() } catch(err){}

test/units/if.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
const assert = require('assert');
22
const util = require('./../util/util.js');
33

4-
const ganache = require('ganache-core-sc');
4+
const client = require('ganache-cli');
55
const Coverage = require('./../../lib/coverage');
6+
const Api = require('./../../lib/api')
67

78
describe('if, else, and else if statements', () => {
89
let coverage;
9-
let provider;
10-
let collector;
10+
let api;
1111

12-
before(async () => ({ provider, collector } = await util.initializeProvider(ganache)));
12+
before(async () => {
13+
api = new Api({silent: true});
14+
await api.ganache(client);
15+
})
1316
beforeEach(() => coverage = new Coverage());
14-
after((done) => provider.close(done));
17+
after(async() => await api.finish());
1518

1619
it('should compile after instrumenting unbracketed if-elses', () => {
1720
const info = util.instrumentAndCompile('if/if-else-no-brackets');
@@ -24,7 +27,7 @@ describe('if, else, and else if statements', () => {
2427
});
2528

2629
it('should cover an if statement with a bracketed consequent', async function() {
27-
const contract = await util.bootstrapCoverage('if/if-with-brackets', provider, collector);
30+
const contract = await util.bootstrapCoverage('if/if-with-brackets', api);
2831
coverage.addContract(contract.instrumented, util.filePath);
2932
await contract.instance.a(1);
3033
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -45,7 +48,7 @@ describe('if, else, and else if statements', () => {
4548

4649
// Runs: a(1) => if (x == 1) x = 2;
4750
it('should cover an unbracketed if consequent (single line)', async function(){
48-
const contract = await util.bootstrapCoverage('if/if-no-brackets', provider, collector);
51+
const contract = await util.bootstrapCoverage('if/if-no-brackets', api);
4952
coverage.addContract(contract.instrumented, util.filePath);
5053
await contract.instance.a(1);
5154
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -66,7 +69,7 @@ describe('if, else, and else if statements', () => {
6669

6770
// Runs: a(1) => if (x == 1){\n x = 3; }
6871
it('should cover an if statement with multiline bracketed consequent', async function() {
69-
const contract = await util.bootstrapCoverage('if/if-with-brackets-multiline',provider,collector);
72+
const contract = await util.bootstrapCoverage('if/if-with-brackets-multiline',api);
7073

7174
coverage.addContract(contract.instrumented, util.filePath);
7275
await contract.instance.a(1);
@@ -89,7 +92,7 @@ describe('if, else, and else if statements', () => {
8992

9093
// Runs: a(1) => if (x == 1)\n x = 3;
9194
it('should cover an unbracketed if consequent (multi-line)', async function() {
92-
const contract = await util.bootstrapCoverage('if/if-no-brackets-multiline',provider,collector);
95+
const contract = await util.bootstrapCoverage('if/if-no-brackets-multiline',api);
9396

9497
coverage.addContract(contract.instrumented, util.filePath);
9598
await contract.instance.a(1);
@@ -111,7 +114,7 @@ describe('if, else, and else if statements', () => {
111114

112115
// Runs: a(2) => if (x == 1) { x = 3; }
113116
it('should cover a simple if statement with a failing condition', async function() {
114-
const contract = await util.bootstrapCoverage('if/if-with-brackets',provider,collector);
117+
const contract = await util.bootstrapCoverage('if/if-with-brackets',api);
115118

116119
coverage.addContract(contract.instrumented, util.filePath);
117120
await contract.instance.a(2);
@@ -133,7 +136,7 @@ describe('if, else, and else if statements', () => {
133136

134137
// Runs: a(2) => if (x == 1){\n throw;\n }else{\n x = 5; \n}
135138
it('should cover an if statement with a bracketed alternate', async function() {
136-
const contract = await util.bootstrapCoverage('if/else-with-brackets',provider,collector);
139+
const contract = await util.bootstrapCoverage('if/else-with-brackets',api);
137140

138141
coverage.addContract(contract.instrumented, util.filePath);
139142
await contract.instance.a(2);
@@ -154,7 +157,7 @@ describe('if, else, and else if statements', () => {
154157
});
155158

156159
it('should cover an if statement with an unbracketed alternate', async function() {
157-
const contract = await util.bootstrapCoverage('if/else-without-brackets',provider,collector);
160+
const contract = await util.bootstrapCoverage('if/else-without-brackets',api);
158161

159162
coverage.addContract(contract.instrumented, util.filePath);
160163
await contract.instance.a(2);
@@ -176,7 +179,7 @@ describe('if, else, and else if statements', () => {
176179
});
177180

178181
it('should cover an else if statement with an unbracketed alternate', async function() {
179-
const contract = await util.bootstrapCoverage('if/else-if-without-brackets',provider,collector);
182+
const contract = await util.bootstrapCoverage('if/else-if-without-brackets',api);
180183

181184
coverage.addContract(contract.instrumented, util.filePath);
182185
await contract.instance.a(2);
@@ -197,7 +200,7 @@ describe('if, else, and else if statements', () => {
197200
});
198201

199202
it('should cover nested if statements with missing else statements', async function() {
200-
const contract = await util.bootstrapCoverage('if/nested-if-missing-else',provider,collector);
203+
const contract = await util.bootstrapCoverage('if/nested-if-missing-else',api);
201204

202205
coverage.addContract(contract.instrumented, util.filePath);
203206
await contract.instance.a(2,3,3);
@@ -219,7 +222,7 @@ describe('if, else, and else if statements', () => {
219222
});
220223

221224
it('should cover if-elseif-else statements that are at the same depth as each other', async function() {
222-
const contract = await util.bootstrapCoverage('if/if-elseif-else',provider,collector);
225+
const contract = await util.bootstrapCoverage('if/if-elseif-else',api);
223226

224227
coverage.addContract(contract.instrumented, util.filePath);
225228
await contract.instance.a(2,3,3);

test/units/loops.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
const assert = require('assert');
22
const util = require('./../util/util.js');
33

4-
const ganache = require('ganache-core-sc');
4+
const client = require('ganache-cli');
55
const Coverage = require('./../../lib/coverage');
6+
const Api = require('./../../lib/api')
67

78
describe('for and while statements', () => {
89
let coverage;
9-
let provider;
10-
let collector;
10+
let api;
1111

12-
before(async () => ({ provider, collector } = await util.initializeProvider(ganache)));
12+
before(async () => {
13+
api = new Api({silent: true});
14+
await api.ganache(client);
15+
})
1316
beforeEach(() => coverage = new Coverage());
14-
after((done) => provider.close(done));
17+
after(async() => await api.finish());
1518

1619
// Runs: a() => for(var x = 1; x < 10; x++){\n sha3(x);\n }
1720
it('should cover a for statement with a bracketed body (multiline)', async function() {
18-
const contract = await util.bootstrapCoverage('loops/for-with-brackets', provider, collector);
21+
const contract = await util.bootstrapCoverage('loops/for-with-brackets', api);
1922
coverage.addContract(contract.instrumented, util.filePath);
2023
await contract.instance.a();
2124
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -34,7 +37,7 @@ describe('for and while statements', () => {
3437

3538
// Runs: a() => for(var x = 1; x < 10; x++)\n sha3(x);\n
3639
it('should cover a for statement with an unbracketed body', async function() {
37-
const contract = await util.bootstrapCoverage('loops/for-no-brackets', provider, collector);
40+
const contract = await util.bootstrapCoverage('loops/for-no-brackets', api);
3841
coverage.addContract(contract.instrumented, util.filePath);
3942
await contract.instance.a();
4043
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -53,7 +56,7 @@ describe('for and while statements', () => {
5356

5457
// Runs: a() => var t = true;\n while(t){\n t = false;\n }
5558
it('should cover a while statement with an bracketed body (multiline)', async function() {
56-
const contract = await util.bootstrapCoverage('loops/while-with-brackets', provider, collector);
59+
const contract = await util.bootstrapCoverage('loops/while-with-brackets', api);
5760
coverage.addContract(contract.instrumented, util.filePath);
5861
await contract.instance.a();
5962
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -72,7 +75,7 @@ describe('for and while statements', () => {
7275

7376
// Runs: a() => var t = true;\n while(t)\n t = false;\n
7477
it('should cover a while statement with an unbracketed body (multiline)', async function() {
75-
const contract = await util.bootstrapCoverage('loops/while-no-brackets', provider, collector);
78+
const contract = await util.bootstrapCoverage('loops/while-no-brackets', api);
7679
coverage.addContract(contract.instrumented, util.filePath);
7780
await contract.instance.a();
7881
const mapping = coverage.generate(contract.data, util.pathPrefix);

test/units/statements.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
const assert = require('assert');
22
const util = require('./../util/util.js');
33

4-
const ganache = require('ganache-core-sc');
4+
const client = require('ganache-cli');
55
const Coverage = require('./../../lib/coverage');
6+
const Api = require('./../../lib/api')
67

78
describe('generic statements', () => {
89
let coverage;
9-
let provider;
10-
let collector;
10+
let api;
1111

12-
before(async () => ({ provider, collector } = await util.initializeProvider(ganache)));
12+
before(async () => {
13+
api = new Api({silent: true});
14+
await api.ganache(client);
15+
})
1316
beforeEach(() => coverage = new Coverage());
14-
after((done) => provider.close(done));
17+
after(async() => await api.finish());
1518

1619
it('should compile function defined in a struct', () => {
1720
const info = util.instrumentAndCompile('statements/fn-struct');
@@ -79,7 +82,7 @@ describe('generic statements', () => {
7982
});
8083

8184
it('should cover an emitted event statement', async function() {
82-
const contract = await util.bootstrapCoverage('statements/emit-coverage', provider, collector);
85+
const contract = await util.bootstrapCoverage('statements/emit-coverage', api);
8386
coverage.addContract(contract.instrumented, util.filePath);
8487
await contract.instance.a(0);
8588
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -97,7 +100,7 @@ describe('generic statements', () => {
97100
});
98101

99102
it('should cover a statement following a close brace', async function() {
100-
const contract = await util.bootstrapCoverage('statements/post-close-brace', provider, collector);
103+
const contract = await util.bootstrapCoverage('statements/post-close-brace', api);
101104
coverage.addContract(contract.instrumented, util.filePath);
102105
await contract.instance.a(1);
103106
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -117,7 +120,7 @@ describe('generic statements', () => {
117120
});
118121

119122
it('should cover a library statement and an invoked library method', async function() {
120-
const contract = await util.bootstrapCoverage('statements/library', provider, collector);
123+
const contract = await util.bootstrapCoverage('statements/library', api);
121124
coverage.addContract(contract.instrumented, util.filePath);
122125
await contract.instance.not();
123126
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -135,7 +138,7 @@ describe('generic statements', () => {
135138
});
136139

137140
it('should cover a tuple statement', async function() {
138-
const contract = await util.bootstrapCoverage('statements/tuple', provider, collector);
141+
const contract = await util.bootstrapCoverage('statements/tuple', api);
139142
coverage.addContract(contract.instrumented, util.filePath);
140143
await contract.instance.a();
141144
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -153,7 +156,7 @@ describe('generic statements', () => {
153156
});
154157

155158
it.skip('should cover a unary statement', async function(){
156-
const contract = await util.bootstrapCoverage('statements/unary', provider, collector);
159+
const contract = await util.bootstrapCoverage('statements/unary', api);
157160
coverage.addContract(contract.instrumented, util.filePath);
158161
await contract.instance.a();
159162
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -162,7 +165,7 @@ describe('generic statements', () => {
162165
})
163166

164167
it('should cover an empty bodied contract statement', async function() {
165-
const contract = await util.bootstrapCoverage('statements/empty-contract-body', provider, collector);
168+
const contract = await util.bootstrapCoverage('statements/empty-contract-body', api);
166169
coverage.addContract(contract.instrumented, util.filePath);
167170
const mapping = coverage.generate(contract.data, util.pathPrefix);
168171

0 commit comments

Comments
 (0)