-
Notifications
You must be signed in to change notification settings - Fork 269
/
statements.js
178 lines (151 loc) · 6.42 KB
/
statements.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
const assert = require('assert');
const util = require('./../util/util.js');
const Coverage = require('./../../lib/coverage');
const Api = require('./../../lib/api')
describe('generic statements', () => {
let coverage;
let api;
before(async () => api = new Api({silent: true}))
beforeEach(() => coverage = new Coverage());
after(async() => await api.finish());
it('should compile function defined in a struct', () => {
const info = util.instrumentAndCompile('statements/fn-struct');
util.report(info.solcOutput.errors);
})
it('should compile when using the type keyword', () => {
const info = util.instrumentAndCompile('statements/type-keyword');
util.report(info.solcOutput.errors);
})
it('should compile base contract contructors with string args containing "{"', ()=> {
const info = util.instrumentAndCompile('statements/interpolation');
util.report(info.solcOutput.errors);
})
it('should instrument a single statement (first line of function)', () => {
const info = util.instrumentAndCompile('statements/single');
util.report(info.solcOutput.errors);
});
it('should instrument multiple statements', () => {
const info = util.instrumentAndCompile('statements/multiple');
util.report(info.solcOutput.errors);
});
it('should instrument a statement that is a function argument (single line)', () => {
const info = util.instrumentAndCompile('statements/fn-argument');
util.report(info.solcOutput.errors);
});
it('should instrument a statement that is a function argument (multi-line)', () => {
const info = util.instrumentAndCompile('statements/fn-argument-multiline');
util.report(info.solcOutput.errors);
});
it('should instrument an empty-contract-body', () => {
const info = util.instrumentAndCompile('statements/empty-contract-ala-melonport');
util.report(info.solcOutput.errors);
});
// FAILING WITH 0.8.x ... unskip when viaIR work is done
it.skip('should instrument without triggering stack-too-deep', () => {
const info = util.instrumentAndCompile('statements/stack-too-deep');
util.report(info.solcOutput.errors);
});
it('should instrument an interface contract', () => {
const info = util.instrumentAndCompile('statements/interface');
util.report(info.solcOutput.errors);
})
it('should instrument a multi-contract file with diamond inheritance (#769)', () => {
const info = util.instrumentAndCompile('statements/multi-contract-diamond');
util.report(info.solcOutput.errors);
});
it('should NOT pass tests if the contract has a compilation error', () => {
const info = util.instrumentAndCompile('app/SimpleError');
try {
util.report(output.errors);
assert.fail('failure'); // We shouldn't hit this.
} catch (err) {
(err.actual === 'failure') ? assert(false) : assert(true);
}
});
it('should instrument an emit statement after an un-enclosed if statement', () => {
const info = util.instrumentAndCompile('statements/emit-instrument');
util.report(info.solcOutput.errors);
});
it('should cover an emitted event statement', async function() {
const contract = await util.bootstrapCoverage('statements/emit-coverage', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(0, contract.gas);
const mapping = coverage.generate(contract.data, util.pathPrefix);
assert.deepEqual(mapping[util.filePath].l, {
6: 1
});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {
1: 1
});
assert.deepEqual(mapping[util.filePath].f, {
1: 1,
});
});
it('should cover a statement following a close brace', async function() {
const contract = await util.bootstrapCoverage('statements/post-close-brace', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1, contract.gas);
const mapping = coverage.generate(contract.data, util.pathPrefix);
assert.deepEqual(mapping[util.filePath].l, {
5: 1, 6: 0, 8: 1,
});
assert.deepEqual(mapping[util.filePath].b, {
1: [0, 1],
});
assert.deepEqual(mapping[util.filePath].s, {
1: 1,
});
assert.deepEqual(mapping[util.filePath].f, {
1: 1,
});
});
it('should cover a library statement and an invoked library method', async function() {
const contract = await util.bootstrapCoverage('statements/library', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.not(contract.gas);
const mapping = coverage.generate(contract.data, util.pathPrefix);
assert.deepEqual(mapping[util.filePath].l, {
11: 1, 12: 1, 21: 1,
});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 1,
});
assert.deepEqual(mapping[util.filePath].f, {
1: 1, 2: 1,
});
});
it('should cover a tuple statement', async function() {
const contract = await util.bootstrapCoverage('statements/tuple', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(contract.gas);
const mapping = coverage.generate(contract.data, util.pathPrefix);
assert.deepEqual(mapping[util.filePath].l, {
6: 1, 10: 1, 11: 1
});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 1,
});
assert.deepEqual(mapping[util.filePath].f, {
1: 1, 2: 1,
});
});
it.skip('should cover a unary statement', async function(){
const contract = await util.bootstrapCoverage('statements/unary', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(contract.gas);
const mapping = coverage.generate(contract.data, util.pathPrefix);
// TODO: obtain both statements in unary.sol
})
it('should cover an empty bodied contract statement', async function() {
const contract = await util.bootstrapCoverage('statements/empty-contract-body', api, this.provider);
coverage.addContract(contract.instrumented, util.filePath);
const mapping = coverage.generate(contract.data, util.pathPrefix);
assert.deepEqual(mapping[util.filePath].l, {});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {});
assert.deepEqual(mapping[util.filePath].f, {});
});
});