parent
20d357971a
commit
66fa5ea7a5
@ -1,181 +1,146 @@ |
|||||||
/* eslint-env node, mocha */ |
|
||||||
|
|
||||||
/*const solc = require('solc'); |
|
||||||
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js'); |
|
||||||
const util = require('./util/util.js'); |
|
||||||
const CoverageMap = require('./../lib/coverageMap'); |
|
||||||
const path = require('path'); |
|
||||||
const vm = require('./util/vm'); |
|
||||||
const assert = require('assert'); |
const assert = require('assert'); |
||||||
|
const util = require('./../util/util.js'); |
||||||
|
|
||||||
|
const ganache = require('ganache-core'); |
||||||
|
const Coverage = require('./../../lib/coverage'); |
||||||
|
|
||||||
describe('generic statements', () => { |
describe('generic statements', () => { |
||||||
const filePath = path.resolve('./test.sol'); |
let coverage; |
||||||
const pathPrefix = './'; |
let provider; |
||||||
|
let collector; |
||||||
|
|
||||||
|
before(async () => ({ provider, collector } = await util.initializeProvider(ganache))); |
||||||
|
beforeEach(() => coverage = new Coverage()); |
||||||
|
after((done) => provider.close(done)); |
||||||
|
|
||||||
it('should compile function defined in a struct', () => { |
it('should compile function defined in a struct', () => { |
||||||
const contract = util.getCode('statements/fn-struct.sol'); |
const info = util.instrumentAndCompile('statements/fn-struct'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}) |
}) |
||||||
|
|
||||||
it('should compile after instrumenting a single statement (first line of function)', () => { |
it('should instrument a single statement (first line of function)', () => { |
||||||
const contract = util.getCode('statements/single.sol'); |
const info = util.instrumentAndCompile('statements/single'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should compile after instrumenting multiple statements', () => { |
it('should instrument multiple statements', () => { |
||||||
const contract = util.getCode('statements/multiple.sol'); |
const info = util.instrumentAndCompile('statements/multiple'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should compile after instrumenting a statement that is a function argument (single line)', () => { |
it('should instrument a statement that is a function argument (single line)', () => { |
||||||
const contract = util.getCode('statements/fn-argument.sol'); |
const info = util.instrumentAndCompile('statements/fn-argument'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should compile after instrumenting a statement that is a function argument (multi-line)', () => { |
it('should instrument a statement that is a function argument (multi-line)', () => { |
||||||
const contract = util.getCode('statements/fn-argument-multiline.sol'); |
const info = util.instrumentAndCompile('statements/fn-argument-multiline'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should compile after instrumenting an empty-contract-body', () => { |
it('should instrument an empty-contract-body', () => { |
||||||
const contract = util.getCode('statements/empty-contract-ala-melonport.sol'); |
const info = util.instrumentAndCompile('statements/empty-contract-ala-melonport'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should NOT pass tests if the contract has a compilation error', () => { |
it('should NOT pass tests if the contract has a compilation error', () => { |
||||||
const contract = util.getCode('statements/compilation-error.sol'); |
const info = util.instrumentAndCompile('../errors/compilation-error'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
|
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
try { |
try { |
||||||
util.report(output.errors); |
util.report(output.errors); |
||||||
assert.fail('WRONG'); // We shouldn't hit this.
|
assert.fail('failure'); // We shouldn't hit this.
|
||||||
} catch (err) { |
} catch (err) { |
||||||
(err.actual === 'WRONG') ? assert(false) : assert(true); |
(err.actual === 'failure') ? assert(false) : assert(true); |
||||||
} |
} |
||||||
}); |
}); |
||||||
|
|
||||||
it('should compile after instrumenting an emit statement after an un-enclosed if statement', () => { |
it('should instrument an emit statement after an un-enclosed if statement', () => { |
||||||
const contract = util.getCode('statements/emit-instrument.sol'); |
const info = util.instrumentAndCompile('statements/emit-instrument'); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
util.report(info.solcOutput.errors); |
||||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
|
||||||
util.report(output.errors); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover an emitted event statement', done => { |
it('should cover an emitted event statement', async function() { |
||||||
const contract = util.getCode('statements/emit-coverage.sol'); |
const contract = await util.bootstrapCoverage('statements/emit-coverage', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
await contract.instance.a(0); |
||||||
coverage.addContract(info, filePath); |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
vm.execute(info.contract, 'a', [0]).then(events => { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
|
||||||
6: 1 |
6: 1 |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
1: 1 |
1: 1 |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, |
1: 1, |
||||||
}); |
}); |
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover a statement following a close brace', done => { |
it('should cover a statement following a close brace', async function() { |
||||||
const contract = util.getCode('statements/post-close-brace.sol'); |
const contract = await util.bootstrapCoverage('statements/post-close-brace', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
await contract.instance.a(1); |
||||||
coverage.addContract(info, filePath); |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
vm.execute(info.contract, 'a', [1]).then(events => { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
|
||||||
5: 1, 6: 0, 8: 1, |
5: 1, 6: 0, 8: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].b, { |
assert.deepEqual(mapping[util.filePath].b, { |
||||||
1: [0, 1], |
1: [0, 1], |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
1: 1, 2: 0, 3: 1, |
1: 1, 2: 0, 3: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, |
1: 1, |
||||||
}); |
}); |
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover a library statement and an invoked library method', done => { |
it('should cover a library statement and an invoked library method', async function() { |
||||||
const contract = util.getCode('statements/library.sol'); |
const contract = await util.bootstrapCoverage('statements/library', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
await contract.instance.not(); |
||||||
coverage.addContract(info, filePath); |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
vm.execute(info.contract, 'not', []).then(events => { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
|
||||||
9: 1, 10: 1, 19: 1, |
9: 1, 10: 1, 19: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
1: 1, 2: 1, 3: 1, |
1: 1, 2: 1, 3: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, 2: 1, |
1: 1, 2: 1, |
||||||
}); |
}); |
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover a tuple statement', done => { |
it('should cover a tuple statement', async function() { |
||||||
const contract = util.getCode('statements/tuple.sol'); |
const contract = await util.bootstrapCoverage('statements/tuple', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
await contract.instance.a(); |
||||||
coverage.addContract(info, filePath); |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
vm.execute(info.contract, 'a', []).then(events => { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
|
||||||
6: 1, 10: 1, 11: 1 |
6: 1, 10: 1, 11: 1 |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
1: 1, 2: 1, 3: 1, |
1: 1, 2: 1, 3: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, 2: 1, |
1: 1, 2: 1, |
||||||
}); |
}); |
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover an empty bodied contract statement', done => { |
it('should cover an empty bodied contract statement', async function() { |
||||||
const contract = util.getCode('statements/empty-contract-body.sol'); |
const contract = await util.bootstrapCoverage('statements/empty-contract-body', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
coverage.addContract(info, filePath); |
|
||||||
|
|
||||||
vm.execute(info.contract, null, []).then(events => { |
assert.deepEqual(mapping[util.filePath].l, {}); |
||||||
const mapping = coverage.generate(events, pathPrefix); |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
assert.deepEqual(mapping[filePath].l, {}); |
assert.deepEqual(mapping[util.filePath].s, {}); |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
assert.deepEqual(mapping[util.filePath].f, {}); |
||||||
assert.deepEqual(mapping[filePath].s, {}); |
|
||||||
assert.deepEqual(mapping[filePath].f, {}); |
|
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
});*/ |
}); |
||||||
|
Loading…
Reference in new issue