parent
6caefc0687
commit
03f585f1dd
@ -1,103 +1,92 @@ |
|||||||
/*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'); |
||||||
|
|
||||||
describe('for and while statements', () => { |
describe('for and while 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 cover a for statement with a bracketed body (multiline)', done => { |
// Runs: a() => for(var x = 1; x < 10; x++){\n sha3(x);\n }
|
||||||
const contract = util.getCode('loops/for-with-brackets.sol'); |
it('should cover a for statement with a bracketed body (multiline)', async function() { |
||||||
const info = getInstrumentedVersion(contract, filePath); |
const contract = await util.bootstrapCoverage('loops/for-with-brackets', provider, collector); |
||||||
const coverage = new CoverageMap(); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
coverage.addContract(info, filePath); |
await contract.instance.a(); |
||||||
|
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
// Runs: a() => for(var x = 1; x < 10; x++){\n sha3(x);\n }
|
assert.deepEqual(mapping[util.filePath].l, { |
||||||
vm.execute(info.contract, 'a', []).then(events => { |
5: 1, 6: 10, |
||||||
const mapping = coverage.generate(events, pathPrefix); |
}); |
||||||
assert.deepEqual(mapping[filePath].l, { |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
5: 1, 6: 10, |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
}); |
1: 1, 2: 10, |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, 2: 10, |
1: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
|
||||||
1: 1, |
|
||||||
}); |
|
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover a for statement with an unbracketed body', done => { |
// Runs: a() => for(var x = 1; x < 10; x++)\n sha3(x);\n
|
||||||
const contract = util.getCode('loops/for-no-brackets.sol'); |
it('should cover a for statement with an unbracketed body', async function() { |
||||||
const info = getInstrumentedVersion(contract, filePath); |
const contract = await util.bootstrapCoverage('loops/for-no-brackets', provider, collector); |
||||||
const coverage = new CoverageMap(); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
coverage.addContract(info, filePath); |
await contract.instance.a(); |
||||||
|
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
// Runs: a() => for(var x = 1; x < 10; x++)\n sha3(x);\n
|
assert.deepEqual(mapping[util.filePath].l, { |
||||||
vm.execute(info.contract, 'a', []).then(events => { |
5: 1, 6: 10, |
||||||
const mapping = coverage.generate(events, pathPrefix); |
}); |
||||||
assert.deepEqual(mapping[filePath].l, { |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
5: 1, 6: 10, |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
}); |
1: 1, 2: 10, |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, 2: 10, |
1: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
|
||||||
1: 1, |
|
||||||
}); |
|
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover a while statement with an bracketed body (multiline)', done => { |
// Runs: a() => var t = true;\n while(t){\n t = false;\n }
|
||||||
const contract = util.getCode('loops/while-with-brackets.sol'); |
it('should cover a while statement with an bracketed body (multiline)', async function() { |
||||||
const info = getInstrumentedVersion(contract, filePath); |
const contract = await util.bootstrapCoverage('loops/while-with-brackets', provider, collector); |
||||||
const coverage = new CoverageMap(); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
coverage.addContract(info, filePath); |
await contract.instance.a(); |
||||||
|
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
// Runs: a() => var t = true;\n while(t){\n t = false;\n }
|
assert.deepEqual(mapping[util.filePath].l, { |
||||||
vm.execute(info.contract, 'a', []).then(events => { |
5: 1, 6: 1, 7: 1, |
||||||
const mapping = coverage.generate(events, pathPrefix); |
}); |
||||||
assert.deepEqual(mapping[filePath].l, { |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
5: 1, 6: 1, 7: 1, |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
}); |
1: 1, 2: 1, 3: 1, |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, 2: 1, 3: 1, |
1: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
|
||||||
1: 1, |
|
||||||
}); |
|
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
|
|
||||||
it('should cover a while statement with an unbracketed body (multiline)', done => { |
// Runs: a() => var t = true;\n while(t)\n t = false;\n
|
||||||
const contract = util.getCode('loops/while-no-brackets.sol'); |
it('should cover a while statement with an unbracketed body (multiline)', async function() { |
||||||
const info = getInstrumentedVersion(contract, filePath); |
const contract = await util.bootstrapCoverage('loops/while-no-brackets', provider, collector); |
||||||
const coverage = new CoverageMap(); |
coverage.addContract(contract.instrumented, util.filePath); |
||||||
coverage.addContract(info, filePath); |
await contract.instance.a(); |
||||||
|
const mapping = coverage.generate(contract.data, util.pathPrefix); |
||||||
|
|
||||||
// Runs: a() => var t = true;\n while(t)\n t = false;\n
|
assert.deepEqual(mapping[util.filePath].l, { |
||||||
vm.execute(info.contract, 'a', []).then(events => { |
5: 1, 6: 1, 7: 1, |
||||||
const mapping = coverage.generate(events, pathPrefix); |
}); |
||||||
assert.deepEqual(mapping[filePath].l, { |
assert.deepEqual(mapping[util.filePath].b, {}); |
||||||
5: 1, 6: 1, 7: 1, |
assert.deepEqual(mapping[util.filePath].s, { |
||||||
}); |
1: 1, 2: 1, 3: 1, |
||||||
assert.deepEqual(mapping[filePath].b, {}); |
}); |
||||||
assert.deepEqual(mapping[filePath].s, { |
assert.deepEqual(mapping[util.filePath].f, { |
||||||
1: 1, 2: 1, 3: 1, |
1: 1, |
||||||
}); |
}); |
||||||
assert.deepEqual(mapping[filePath].f, { |
|
||||||
1: 1, |
|
||||||
}); |
|
||||||
done(); |
|
||||||
}).catch(done); |
|
||||||
}); |
}); |
||||||
});*/ |
}); |
||||||
|
Loading…
Reference in new issue