parent
b558f21f8c
commit
687e6642fe
@ -1,109 +1,101 @@ |
|||||||
/* eslint-env node, mocha */ |
|
||||||
|
|
||||||
/*const path = require('path'); |
|
||||||
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js'); |
|
||||||
const util = require('./util/util.js'); |
|
||||||
const CoverageMap = require('./../lib/coverageMap'); |
|
||||||
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'); |
||||||
|
const DataCollector = require('./../../lib/collector'); |
||||||
|
const nodeUtil = require('util'); |
||||||
|
|
||||||
describe('asserts and requires', () => { |
describe('asserts and requires', () => { |
||||||
const filePath = path.resolve('./test.sol'); |
let coverage; |
||||||
const pathPrefix = './'; |
let provider; |
||||||
|
let collector; |
||||||
|
|
||||||
it('should cover assert statements as if they are if statements when they pass', done => { |
before(async () => ({ provider, collector } = await util.initializeProvider(ganache))); |
||||||
const contract = util.getCode('assert/Assert.sol'); |
beforeEach(() => coverage = new Coverage()); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
after((done) => provider.close(done)); |
||||||
const coverage = new CoverageMap(); |
|
||||||
coverage.addContract(info, filePath); |
|
||||||
|
|
||||||
vm.execute(info.contract, 'a', [true]).then(events => { |
it('should cover assert statements as `if` statements when they pass', async function() { |
||||||
const mapping = coverage.generate(events, pathPrefix); |
const contract = await util.bootstrapCoverage('assert/Assert', provider, collector); |
||||||
assert.deepEqual(mapping[filePath].l, { |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
|
await contract.instance.a(true); |
||||||
|
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
|
assert.deepEqual(mapping[util.filePath].l, { |
||||||
5: 1, |
5: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].b, { |
assert.deepEqual(mapping[util.filePath].b, { |
||||||
1: [1, 0], |
1: [1, 0], |
||||||
}); |
}); |
||||||
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 assert statements as if they are if statements when they fail', done => { |
it('should cover assert statements as `if` statements when they fail', async function() { |
||||||
const contract = util.getCode('assert/Assert.sol'); |
const contract = await util.bootstrapCoverage('assert/Assert', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
|
||||||
coverage.addContract(info, filePath); |
try { await contract.instance.a(false) } catch(err) { /* Invalid opcode */ } |
||||||
|
|
||||||
vm.execute(info.contract, 'a', [false]).then(events => { |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
5: 1, |
5: 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, |
1: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, |
1: 1, |
||||||
}); |
}); |
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover multi-line require statements as if they are if statements when they pass', done => { |
it('should cover multi-line require stmts as `if` statements when they pass', async function() { |
||||||
const contract = util.getCode('assert/RequireMultiline.sol'); |
const contract = await util.bootstrapCoverage('assert/RequireMultiline', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
await contract.instance.a(true, true, true); |
||||||
coverage.addContract(info, filePath); |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
vm.execute(info.contract, 'a', [true, true, true]).then(events => { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
|
||||||
5: 1, |
5: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].b, { |
assert.deepEqual(mapping[util.filePath].b, { |
||||||
1: [1, 0], |
1: [1, 0], |
||||||
}); |
}); |
||||||
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 multi-line require statements as if they are if statements when they fail', done => { |
it('should cover multi-line require stmts as `if` statements when they fail', async function() { |
||||||
const contract = util.getCode('assert/RequireMultiline.sol'); |
const contract = await util.bootstrapCoverage('assert/RequireMultiline', provider, collector); |
||||||
const info = getInstrumentedVersion(contract, filePath); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
const coverage = new CoverageMap(); |
|
||||||
coverage.addContract(info, filePath); |
try { await contract.instance.a(true, true, false) } catch(err) { /* Revert */ } |
||||||
|
|
||||||
vm.execute(info.contract, 'a', [true, true, false]).then(events => { |
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
const mapping = coverage.generate(events, pathPrefix); |
|
||||||
assert.deepEqual(mapping[filePath].l, { |
assert.deepEqual(mapping[util.filePath].l, { |
||||||
5: 1, |
5: 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, |
1: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, |
1: 1, |
||||||
}); |
}); |
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
});*/ |
}); |
||||||
|
Loading…
Reference in new issue