1
1
const assert = require ( 'assert' ) ;
2
2
const util = require ( './../util/util.js' ) ;
3
3
4
- const ganache = require ( 'ganache-core-sc ' ) ;
4
+ const client = require ( 'ganache-cli ' ) ;
5
5
const Coverage = require ( './../../lib/coverage' ) ;
6
+ const Api = require ( './../../lib/api' )
6
7
7
8
describe ( 'logical OR branches' , ( ) => {
8
9
let coverage ;
9
- let provider ;
10
- let collector ;
10
+ let api ;
11
11
12
- before ( async ( ) => ( { provider, collector } = await util . initializeProvider ( ganache ) ) ) ;
12
+ before ( async ( ) => {
13
+ api = new Api ( { silent : true } ) ;
14
+ await api . ganache ( client ) ;
15
+ } )
13
16
beforeEach ( ( ) => coverage = new Coverage ( ) ) ;
14
- after ( ( done ) => provider . close ( done ) ) ;
17
+ after ( async ( ) => await api . finish ( ) ) ;
15
18
16
19
// if (x == 1 || x == 2) { } else ...
17
20
it ( 'should cover an if statement with a simple OR condition (single branch)' , async function ( ) {
18
- const contract = await util . bootstrapCoverage ( 'or/if-or' , provider , collector ) ;
21
+ const contract = await util . bootstrapCoverage ( 'or/if-or' , api ) ;
19
22
coverage . addContract ( contract . instrumented , util . filePath ) ;
20
23
await contract . instance . a ( 1 ) ;
21
24
const mapping = coverage . generate ( contract . data , util . pathPrefix ) ;
@@ -36,7 +39,7 @@ describe('logical OR branches', () => {
36
39
37
40
// if (x == 1 || x == 2) { } else ...
38
41
it ( 'should cover an if statement with a simple OR condition (both branches)' , async function ( ) {
39
- const contract = await util . bootstrapCoverage ( 'or/if-or' , provider , collector ) ;
42
+ const contract = await util . bootstrapCoverage ( 'or/if-or' , api ) ;
40
43
coverage . addContract ( contract . instrumented , util . filePath ) ;
41
44
await contract . instance . a ( 1 ) ;
42
45
await contract . instance . a ( 2 ) ;
@@ -59,7 +62,7 @@ describe('logical OR branches', () => {
59
62
60
63
// require(x == 1 || x == 2)
61
64
it ( 'should cover a require statement with a simple OR condition (single branch)' , async function ( ) {
62
- const contract = await util . bootstrapCoverage ( 'or/require-or' , provider , collector ) ;
65
+ const contract = await util . bootstrapCoverage ( 'or/require-or' , api ) ;
63
66
coverage . addContract ( contract . instrumented , util . filePath ) ;
64
67
await contract . instance . a ( 1 ) ;
65
68
@@ -85,7 +88,7 @@ describe('logical OR branches', () => {
85
88
// x == 3
86
89
// )
87
90
it ( 'should cover a require statement with multiline OR condition (two branches)' , async function ( ) {
88
- const contract = await util . bootstrapCoverage ( 'or/require-multiline-or' , provider , collector ) ;
91
+ const contract = await util . bootstrapCoverage ( 'or/require-multiline-or' , api ) ;
89
92
coverage . addContract ( contract . instrumented , util . filePath ) ;
90
93
await contract . instance . a ( 1 ) ;
91
94
await contract . instance . a ( 3 ) ;
@@ -108,7 +111,7 @@ describe('logical OR branches', () => {
108
111
109
112
// require(x == 1 || x == 2)
110
113
it ( 'should cover a require statement with a simple OR condition (both branches)' , async function ( ) {
111
- const contract = await util . bootstrapCoverage ( 'or/require-or' , provider , collector ) ;
114
+ const contract = await util . bootstrapCoverage ( 'or/require-or' , api ) ;
112
115
coverage . addContract ( contract . instrumented , util . filePath ) ;
113
116
await contract . instance . a ( 1 ) ;
114
117
await contract . instance . a ( 2 ) ;
@@ -131,7 +134,7 @@ describe('logical OR branches', () => {
131
134
132
135
// while( (x == 1 || x == 2) && counter < 2 ){
133
136
it ( 'should cover a while statement with a simple OR condition (single branch)' , async function ( ) {
134
- const contract = await util . bootstrapCoverage ( 'or/while-or' , provider , collector ) ;
137
+ const contract = await util . bootstrapCoverage ( 'or/while-or' , api ) ;
135
138
coverage . addContract ( contract . instrumented , util . filePath ) ;
136
139
await contract . instance . a ( 1 ) ;
137
140
@@ -153,7 +156,7 @@ describe('logical OR branches', () => {
153
156
154
157
// while( (x == 1 || x == 2) && counter < 2 ){
155
158
it ( 'should cover a while statement with a simple OR condition (both branches)' , async function ( ) {
156
- const contract = await util . bootstrapCoverage ( 'or/while-or' , provider , collector ) ;
159
+ const contract = await util . bootstrapCoverage ( 'or/while-or' , api ) ;
157
160
coverage . addContract ( contract . instrumented , util . filePath ) ;
158
161
await contract . instance . a ( 1 ) ;
159
162
await contract . instance . a ( 2 ) ;
@@ -176,7 +179,7 @@ describe('logical OR branches', () => {
176
179
177
180
// return (x == 1 && true) || (x == 2 && true);
178
181
it ( 'should cover a return statement with ANDED OR conditions (single branch)' , async function ( ) {
179
- const contract = await util . bootstrapCoverage ( 'or/return-or' , provider , collector ) ;
182
+ const contract = await util . bootstrapCoverage ( 'or/return-or' , api ) ;
180
183
coverage . addContract ( contract . instrumented , util . filePath ) ;
181
184
await contract . instance . a ( 1 ) ;
182
185
@@ -198,7 +201,7 @@ describe('logical OR branches', () => {
198
201
199
202
// return (x == 1 && true) || (x == 2 && true);
200
203
it ( 'should cover a return statement with ANDED OR conditions (both branches)' , async function ( ) {
201
- const contract = await util . bootstrapCoverage ( 'or/return-or' , provider , collector ) ;
204
+ const contract = await util . bootstrapCoverage ( 'or/return-or' , api ) ;
202
205
coverage . addContract ( contract . instrumented , util . filePath ) ;
203
206
await contract . instance . a ( 1 ) ;
204
207
await contract . instance . a ( 2 ) ;
@@ -221,7 +224,7 @@ describe('logical OR branches', () => {
221
224
222
225
//if (x == 1 && true || x == 2) {
223
226
it ( 'should cover an if statement with OR and AND conditions (single branch)' , async function ( ) {
224
- const contract = await util . bootstrapCoverage ( 'or/and-or' , provider , collector ) ;
227
+ const contract = await util . bootstrapCoverage ( 'or/and-or' , api ) ;
225
228
coverage . addContract ( contract . instrumented , util . filePath ) ;
226
229
await contract . instance . a ( 1 ) ;
227
230
@@ -243,7 +246,7 @@ describe('logical OR branches', () => {
243
246
244
247
//if (x == 1 && true || x == 2) {
245
248
it ( 'should cover an if statement with OR and AND conditions (both branches)' , async function ( ) {
246
- const contract = await util . bootstrapCoverage ( 'or/and-or' , provider , collector ) ;
249
+ const contract = await util . bootstrapCoverage ( 'or/and-or' , api ) ;
247
250
coverage . addContract ( contract . instrumented , util . filePath ) ;
248
251
await contract . instance . a ( 1 ) ;
249
252
await contract . instance . a ( 2 ) ;
@@ -266,7 +269,7 @@ describe('logical OR branches', () => {
266
269
267
270
// if ((x == 1) && (x == 2 || true)) {
268
271
it ( 'should cover an if statement with bracked ANDED OR conditions (rightmost sub-branch)' , async function ( ) {
269
- const contract = await util . bootstrapCoverage ( 'or/and-or-brackets' , provider , collector ) ;
272
+ const contract = await util . bootstrapCoverage ( 'or/and-or-brackets' , api ) ;
270
273
coverage . addContract ( contract . instrumented , util . filePath ) ;
271
274
await contract . instance . a ( 1 ) ;
272
275
@@ -288,7 +291,7 @@ describe('logical OR branches', () => {
288
291
289
292
// if ((x == 1) || (x == 2 || true)) {
290
293
it ( 'should cover an if statement with multiple (bracketed) OR conditions (branch 1)' , async function ( ) {
291
- const contract = await util . bootstrapCoverage ( 'or/multi-or' , provider , collector ) ;
294
+ const contract = await util . bootstrapCoverage ( 'or/multi-or' , api ) ;
292
295
coverage . addContract ( contract . instrumented , util . filePath ) ;
293
296
await contract . instance . a ( 1 ) ;
294
297
@@ -310,7 +313,7 @@ describe('logical OR branches', () => {
310
313
311
314
// if ((x == 1) || (x == 2 || true)) {
312
315
it ( 'should cover an if statement with multiple (bracketed) OR conditions (branch 2)' , async function ( ) {
313
- const contract = await util . bootstrapCoverage ( 'or/multi-or' , provider , collector ) ;
316
+ const contract = await util . bootstrapCoverage ( 'or/multi-or' , api ) ;
314
317
coverage . addContract ( contract . instrumented , util . filePath ) ;
315
318
await contract . instance . a ( 2 ) ;
316
319
@@ -332,7 +335,7 @@ describe('logical OR branches', () => {
332
335
333
336
// if ((x == 1) || (x == 2 || true)) {
334
337
it ( 'should cover an if statement with multiple (bracketed) OR conditions (branch 3)' , async function ( ) {
335
- const contract = await util . bootstrapCoverage ( 'or/multi-or' , provider , collector ) ;
338
+ const contract = await util . bootstrapCoverage ( 'or/multi-or' , api ) ;
336
339
coverage . addContract ( contract . instrumented , util . filePath ) ;
337
340
await contract . instance . a ( 3 ) ;
338
341
@@ -353,7 +356,7 @@ describe('logical OR branches', () => {
353
356
} ) ;
354
357
355
358
it ( 'should cover the bzx example' , async function ( ) {
356
- const contract = await util . bootstrapCoverage ( 'or/bzx-or' , provider , collector ) ;
359
+ const contract = await util . bootstrapCoverage ( 'or/bzx-or' , api ) ;
357
360
coverage . addContract ( contract . instrumented , util . filePath ) ;
358
361
await contract . instance . a ( 3 ) ;
359
362
0 commit comments