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.
186 lines
5.8 KiB
186 lines
5.8 KiB
8 years ago
|
/* eslint-env node, mocha */
|
||
|
|
||
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');
|
||
|
|
||
7 years ago
|
describe.skip('conditional statements', () => {
|
||
7 years ago
|
const filePath = path.resolve('./test.sol');
|
||
8 years ago
|
const pathPrefix = './';
|
||
|
|
||
8 years ago
|
it('should cover a conditional that reaches the consequent (same-line)', done => {
|
||
8 years ago
|
const contract = util.getCode('conditional/sameline-consequent.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
8 years ago
|
|
||
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,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [1, 0],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('should cover a conditional that reaches the alternate (same-line)', done => {
|
||
8 years ago
|
const contract = util.getCode('conditional/sameline-alternate.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
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,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [0, 1],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('should cover a conditional that reaches the consequent (multi-line)', done => {
|
||
8 years ago
|
const contract = util.getCode('conditional/multiline-consequent.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
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,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [1, 0],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('should cover a conditional that reaches the alternate (multi-line)', done => {
|
||
8 years ago
|
const contract = util.getCode('conditional/multiline-alternate.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
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,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [0, 1],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('should cover a DeclarativeExpression assignment by conditional that reaches the alternate', done => {
|
||
8 years ago
|
const contract = util.getCode('conditional/declarative-exp-assignment-alternate.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
// Runs bool z = (x) ? false : true;
|
||
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,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [0, 1],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('should cover an Identifier assignment by conditional that reaches the alternate', done => {
|
||
8 years ago
|
const contract = util.getCode('conditional/identifier-assignment-alternate.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
// Runs z = (x) ? false : true;
|
||
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: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [0, 1],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1, 4: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
8 years ago
|
});
|
||
|
|
||
|
it('should cover an assignment to a member expression (reaches the alternate)', done => {
|
||
|
const contract = util.getCode('conditional/mapping-assignment.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
vm.execute(info.contract, 'a', []).then(events => {
|
||
|
const mapping = coverage.generate(events, pathPrefix);
|
||
|
assert.deepEqual(mapping[filePath].l, {
|
||
7 years ago
|
11: 1, 12: 1,
|
||
8 years ago
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [0, 1],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
7 years ago
|
1: 1, 2: 1,
|
||
8 years ago
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
|
done();
|
||
|
}).catch(done);
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
});
|
||
5 years ago
|
*/
|