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.
189 lines
7.0 KiB
189 lines
7.0 KiB
8 years ago
|
/* eslint-env node, mocha */
|
||
|
|
||
5 years ago
|
/*const solc = require('solc');
|
||
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 path = require('path');
|
||
|
const vm = require('./util/vm');
|
||
|
const assert = require('assert');
|
||
8 years ago
|
|
||
8 years ago
|
describe('generic statements', () => {
|
||
7 years ago
|
const filePath = path.resolve('./test.sol');
|
||
8 years ago
|
const pathPrefix = './';
|
||
|
|
||
7 years ago
|
it('should compile function defined in a struct', () => {
|
||
|
const contract = util.getCode('statements/fn-struct.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
5 years ago
|
util.report(output.errors);
|
||
|
})
|
||
|
|
||
|
it('should compile when using the type keyword', () => {
|
||
|
const contract = util.getCode('statements/type-keyword.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
7 years ago
|
util.report(output.errors);
|
||
|
})
|
||
|
|
||
8 years ago
|
it('should compile after instrumenting a single statement (first line of function)', () => {
|
||
|
const contract = util.getCode('statements/single.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
8 years ago
|
util.report(output.errors);
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
it('should compile after instrumenting multiple statements', () => {
|
||
|
const contract = util.getCode('statements/multiple.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
8 years ago
|
util.report(output.errors);
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
it('should compile after instrumenting a statement that is a function argument (single line)', () => {
|
||
|
const contract = util.getCode('statements/fn-argument.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
8 years ago
|
util.report(output.errors);
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
8 years ago
|
it('should compile after instrumenting a statement that is a function argument (multi-line)', () => {
|
||
|
const contract = util.getCode('statements/fn-argument-multiline.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
8 years ago
|
util.report(output.errors);
|
||
8 years ago
|
});
|
||
8 years ago
|
|
||
|
it('should compile after instrumenting an empty-contract-body', () => {
|
||
|
const contract = util.getCode('statements/empty-contract-ala-melonport.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
8 years ago
|
util.report(output.errors);
|
||
|
});
|
||
|
|
||
7 years ago
|
it('should NOT pass tests if the contract has a compilation error', () => {
|
||
|
const contract = util.getCode('statements/compilation-error.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
7 years ago
|
try {
|
||
|
util.report(output.errors);
|
||
|
assert.fail('WRONG'); // We shouldn't hit this.
|
||
|
} catch (err) {
|
||
7 years ago
|
(err.actual === 'WRONG') ? assert(false) : assert(true);
|
||
|
}
|
||
7 years ago
|
});
|
||
|
|
||
7 years ago
|
it('should compile after instrumenting an emit statement after an un-enclosed if statement', () => {
|
||
|
const contract = util.getCode('statements/emit-instrument.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
6 years ago
|
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
|
||
7 years ago
|
util.report(output.errors);
|
||
|
});
|
||
|
|
||
|
it('should cover an emitted event statement', done => {
|
||
|
const contract = util.getCode('statements/emit-coverage.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
6 years ago
|
vm.execute(info.contract, 'a', [0]).then(events => {
|
||
7 years ago
|
const mapping = coverage.generate(events, pathPrefix);
|
||
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
6: 1
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
|
|
||
8 years ago
|
it('should cover a statement following a close brace', done => {
|
||
8 years ago
|
const contract = util.getCode('statements/post-close-brace.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
vm.execute(info.contract, 'a', [1]).then(events => {
|
||
|
const mapping = coverage.generate(events, pathPrefix);
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
5: 1, 6: 0, 8: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {
|
||
|
1: [0, 1],
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 0, 3: 1,
|
||
|
});
|
||
|
assert.deepEqual(mapping[filePath].f, {
|
||
|
1: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
8 years ago
|
|
||
8 years ago
|
it('should cover a library statement and an invoked library method', done => {
|
||
8 years ago
|
const contract = util.getCode('statements/library.sol');
|
||
8 years ago
|
const info = getInstrumentedVersion(contract, filePath);
|
||
8 years ago
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
vm.execute(info.contract, 'not', []).then(events => {
|
||
|
const mapping = coverage.generate(events, pathPrefix);
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].l, {
|
||
|
9: 1, 10: 1, 19: 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, 2: 1,
|
||
|
});
|
||
8 years ago
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
8 years ago
|
|
||
|
it('should cover a tuple statement', done => {
|
||
|
const contract = util.getCode('statements/tuple.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, {
|
||
6 years ago
|
6: 1, 10: 1, 11: 1
|
||
8 years ago
|
});
|
||
|
assert.deepEqual(mapping[filePath].b, {});
|
||
7 years ago
|
assert.deepEqual(mapping[filePath].s, {
|
||
|
1: 1, 2: 1, 3: 1,
|
||
8 years ago
|
});
|
||
8 years ago
|
assert.deepEqual(mapping[filePath].f, {
|
||
7 years ago
|
1: 1, 2: 1,
|
||
8 years ago
|
});
|
||
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
8 years ago
|
|
||
|
it('should cover an empty bodied contract statement', done => {
|
||
|
const contract = util.getCode('statements/empty-contract-body.sol');
|
||
|
const info = getInstrumentedVersion(contract, filePath);
|
||
|
const coverage = new CoverageMap();
|
||
|
coverage.addContract(info, filePath);
|
||
|
|
||
|
vm.execute(info.contract, null, []).then(events => {
|
||
|
const mapping = coverage.generate(events, pathPrefix);
|
||
|
assert.deepEqual(mapping[filePath].l, {});
|
||
|
assert.deepEqual(mapping[filePath].b, {});
|
||
|
assert.deepEqual(mapping[filePath].s, {});
|
||
|
assert.deepEqual(mapping[filePath].f, {});
|
||
|
done();
|
||
|
}).catch(done);
|
||
|
});
|
||
5 years ago
|
});*/
|