11const assert = require ( 'assert' ) ;
22const util = require ( './../util/util.js' ) ;
33
4- const ganache = require ( 'ganache-core-sc ' ) ;
4+ const client = require ( 'ganache-cli ' ) ;
55const Coverage = require ( './../../lib/coverage' ) ;
6+ const Api = require ( './../../lib/api' )
67
78describe ( '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 ) ;
0 commit comments