1
1
const assert = require ( 'assert' ) ;
2
2
const util = require ( './../util/util.js' ) ;
3
-
4
- const client = require ( 'ganache-cli' ) ;
5
3
const Coverage = require ( './../../lib/coverage' ) ;
6
4
const Api = require ( './../../lib/api' )
7
5
8
6
describe ( 'ternary conditionals' , ( ) => {
9
7
let coverage ;
10
8
let api ;
11
9
12
- before ( async ( ) => {
13
- api = new Api ( { silent : true } ) ;
14
- await api . ganache ( client ) ;
15
- } )
10
+ before ( async ( ) => api = new Api ( { silent : true } ) ) ;
16
11
beforeEach ( ( ) => coverage = new Coverage ( ) ) ;
17
12
after ( async ( ) => await api . finish ( ) ) ;
18
13
19
- async function setupAndRun ( solidityFile ) {
20
- const contract = await util . bootstrapCoverage ( solidityFile , api ) ;
14
+ async function setupAndRun ( solidityFile , provider ) {
15
+ const contract = await util . bootstrapCoverage ( solidityFile , api , provider ) ;
21
16
coverage . addContract ( contract . instrumented , util . filePath ) ;
22
- await contract . instance . a ( ) ;
17
+ await contract . instance . a ( contract . gas ) ;
23
18
return coverage . generate ( contract . data , util . pathPrefix ) ;
24
19
}
25
20
26
21
it ( 'should cover a conditional that reaches the consequent (same-line)' , async function ( ) {
27
- const mapping = await setupAndRun ( 'conditional/sameline-consequent' ) ;
22
+ const mapping = await setupAndRun ( 'conditional/sameline-consequent' , this . provider ) ;
28
23
29
24
assert . deepEqual ( mapping [ util . filePath ] . l , {
30
25
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -41,7 +36,7 @@ describe('ternary conditionals', () => {
41
36
} ) ;
42
37
43
38
it ( 'should cover an unbracketed conditional that reaches the consequent (same-line)' , async function ( ) {
44
- const mapping = await setupAndRun ( 'conditional/unbracketed-condition' ) ;
39
+ const mapping = await setupAndRun ( 'conditional/unbracketed-condition' , this . provider ) ;
45
40
46
41
assert . deepEqual ( mapping [ util . filePath ] . l , {
47
42
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -58,7 +53,7 @@ describe('ternary conditionals', () => {
58
53
} ) ;
59
54
60
55
it ( 'should cover a multi-part conditional (&&) that reaches the consequent' , async function ( ) {
61
- const mapping = await setupAndRun ( 'conditional/and-condition' ) ;
56
+ const mapping = await setupAndRun ( 'conditional/and-condition' , this . provider ) ;
62
57
63
58
assert . deepEqual ( mapping [ util . filePath ] . l , {
64
59
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -75,7 +70,7 @@ describe('ternary conditionals', () => {
75
70
} ) ;
76
71
77
72
it ( 'should cover a multi-part conditional (||) that reaches the consequent' , async function ( ) {
78
- const mapping = await setupAndRun ( 'conditional/or-condition' ) ;
73
+ const mapping = await setupAndRun ( 'conditional/or-condition' , this . provider ) ;
79
74
80
75
assert . deepEqual ( mapping [ util . filePath ] . l , {
81
76
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -92,7 +87,7 @@ describe('ternary conditionals', () => {
92
87
} ) ;
93
88
94
89
it ( 'should cover a multi-part unbracketed conditional (||) that reaches the consequent' , async function ( ) {
95
- const mapping = await setupAndRun ( 'conditional/unbracketed-or-condition' ) ;
90
+ const mapping = await setupAndRun ( 'conditional/unbracketed-or-condition' , this . provider ) ;
96
91
97
92
assert . deepEqual ( mapping [ util . filePath ] . l , {
98
93
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -109,7 +104,7 @@ describe('ternary conditionals', () => {
109
104
} ) ;
110
105
111
106
it ( 'should cover an always-false multi-part unbracketed conditional (||)' , async function ( ) {
112
- const mapping = await setupAndRun ( 'conditional/or-always-false-condition' ) ;
107
+ const mapping = await setupAndRun ( 'conditional/or-always-false-condition' , this . provider ) ;
113
108
114
109
assert . deepEqual ( mapping [ util . filePath ] . l , {
115
110
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -126,7 +121,7 @@ describe('ternary conditionals', () => {
126
121
} ) ;
127
122
128
123
it ( 'should cover a conditional that reaches the alternate (same-line)' , async function ( ) {
129
- const mapping = await setupAndRun ( 'conditional/sameline-alternate' ) ;
124
+ const mapping = await setupAndRun ( 'conditional/sameline-alternate' , this . provider ) ;
130
125
131
126
assert . deepEqual ( mapping [ util . filePath ] . l , {
132
127
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -143,7 +138,7 @@ describe('ternary conditionals', () => {
143
138
} ) ;
144
139
145
140
it ( 'should cover a conditional that reaches the consequent (multi-line)' , async function ( ) {
146
- const mapping = await setupAndRun ( 'conditional/multiline-consequent' ) ;
141
+ const mapping = await setupAndRun ( 'conditional/multiline-consequent' , this . provider ) ;
147
142
148
143
assert . deepEqual ( mapping [ util . filePath ] . l , {
149
144
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -160,7 +155,7 @@ describe('ternary conditionals', () => {
160
155
} ) ;
161
156
162
157
it ( 'should cover a conditional that reaches the alternate (multi-line)' , async function ( ) {
163
- const mapping = await setupAndRun ( 'conditional/multiline-alternate' ) ;
158
+ const mapping = await setupAndRun ( 'conditional/multiline-alternate' , this . provider ) ;
164
159
165
160
assert . deepEqual ( mapping [ util . filePath ] . l , {
166
161
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -178,7 +173,7 @@ describe('ternary conditionals', () => {
178
173
179
174
// Runs bool z = (x) ? false : true;
180
175
it ( 'should cover a definition assignment by conditional that reaches the alternate' , async function ( ) {
181
- const mapping = await setupAndRun ( 'conditional/declarative-exp-assignment-alternate' ) ;
176
+ const mapping = await setupAndRun ( 'conditional/declarative-exp-assignment-alternate' , this . provider ) ;
182
177
183
178
assert . deepEqual ( mapping [ util . filePath ] . l , {
184
179
5 : 1 , 6 : 1 , 7 : 1 ,
@@ -196,7 +191,7 @@ describe('ternary conditionals', () => {
196
191
197
192
// Runs z = (x) ? false : true;
198
193
it ( 'should cover an identifier assignment by conditional that reaches the alternate' , async function ( ) {
199
- const mapping = await setupAndRun ( 'conditional/identifier-assignment-alternate' ) ;
194
+ const mapping = await setupAndRun ( 'conditional/identifier-assignment-alternate' , this . provider ) ;
200
195
201
196
assert . deepEqual ( mapping [ util . filePath ] . l , {
202
197
5 : 1 , 6 : 1 , 7 : 1 , 8 : 1 ,
@@ -213,7 +208,7 @@ describe('ternary conditionals', () => {
213
208
} ) ;
214
209
215
210
it ( 'should cover an assignment to a member expression (reaches the alternate)' , async function ( ) {
216
- const mapping = await setupAndRun ( 'conditional/mapping-assignment' ) ;
211
+ const mapping = await setupAndRun ( 'conditional/mapping-assignment' , this . provider ) ;
217
212
218
213
assert . deepEqual ( mapping [ util . filePath ] . l , {
219
214
11 : 1 , 12 : 1 ,
0 commit comments