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