You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.5 KiB
104 lines
3.5 KiB
5 years ago
|
/*const path = require('path');
|
||
8 years ago
|
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js');
|
||
8 years ago
|
const util = require('./util/util.js');
|
||
8 years ago
|
const CoverageMap = require('./../lib/coverageMap');
|
||
8 years ago
|
const vm = require('./util/vm');
|
||
|
const assert = require('assert');
|
||
|
|
||
8 years ago
|
describe('for and while statements', () => {
|
||
7 years ago
|
const filePath = path.resolve('./test.sol');
|
||
8 years ago
|
const pathPrefix = './';
|
||
|
|
||
8 years ago
|
it('should cover a for statement with a bracketed body (multiline)', done => {
|
||
8 years ago
|
const contract = util.getCode('loops/for-with-brackets.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
// Runs: a() => for(var x = 1; x < 10; x++){\n sha3(x);\n }
|
||
8 years ago
|
vm.execute(info.contract, 'a', []).then(events => {
|
||
8 years ago
|
const mapping = coverage.generate(events, pathPrefix);
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
5: 1, 6: 10,
|
||
|
});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].b, {});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 10,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
8 years ago
|
}).catch(done);
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
it('should cover a for statement with an unbracketed body', done => {
|
||
8 years ago
|
const contract = util.getCode('loops/for-no-brackets.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
8 years ago
|
// Runs: a() => for(var x = 1; x < 10; x++)\n sha3(x);\n
|
||
8 years ago
|
vm.execute(info.contract, 'a', []).then(events => {
|
||
8 years ago
|
const mapping = coverage.generate(events, pathPrefix);
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
5: 1, 6: 10,
|
||
|
});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].b, {});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 10,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
8 years ago
|
}).catch(done);
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
it('should cover a while statement with an bracketed body (multiline)', done => {
|
||
8 years ago
|
const contract = util.getCode('loops/while-with-brackets.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
// Runs: a() => var t = true;\n while(t){\n t = false;\n }
|
||
8 years ago
|
vm.execute(info.contract, 'a', []).then(events => {
|
||
8 years ago
|
const mapping = coverage.generate(events, pathPrefix);
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
5: 1, 6: 1, 7: 1,
|
||
|
});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].b, {});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
8 years ago
|
}).catch(done);
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
it('should cover a while statement with an unbracketed body (multiline)', done => {
|
||
8 years ago
|
const contract = util.getCode('loops/while-no-brackets.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
8 years ago
|
// Runs: a() => var t = true;\n while(t)\n t = false;\n
|
||
8 years ago
|
vm.execute(info.contract, 'a', []).then(events => {
|
||
8 years ago
|
const mapping = coverage.generate(events, pathPrefix);
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
5: 1, 6: 1, 7: 1,
|
||
|
});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].b, {});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
8 years ago
|
}).catch(done);
|
||
8 years ago
|
});
|
||
5 years ago
|
});*/
|