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 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', () => { |
||||
const filePath = path.resolve('./test.sol'); |
||||
const pathPrefix = './'; |
||||
let coverage; |
||||
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 => { |
||||
const contract = util.getCode('loops/for-with-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 }
|
||||
it('should cover a for statement with a bracketed body (multiline)', async function() { |
||||
const contract = await util.bootstrapCoverage('loops/for-with-brackets', provider, collector); |
||||
coverage.addContract(contract.instrumented, util.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 }
|
||||
vm.execute(info.contract, 'a', []).then(events => { |
||||
const mapping = coverage.generate(events, pathPrefix); |
||||
assert.deepEqual(mapping[filePath].l, { |
||||
5: 1, 6: 10, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].b, {}); |
||||
assert.deepEqual(mapping[filePath].s, { |
||||
1: 1, 2: 10, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].f, { |
||||
1: 1, |
||||
}); |
||||
done(); |
||||
}).catch(done); |
||||
assert.deepEqual(mapping[util.filePath].l, { |
||||
5: 1, 6: 10, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].b, {}); |
||||
assert.deepEqual(mapping[util.filePath].s, { |
||||
1: 1, 2: 10, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].f, { |
||||
1: 1, |
||||
}); |
||||
}); |
||||
|
||||
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
|
||||
it('should cover a for statement with an unbracketed body', async function() { |
||||
const contract = await util.bootstrapCoverage('loops/for-no-brackets', provider, collector); |
||||
coverage.addContract(contract.instrumented, util.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
|
||||
vm.execute(info.contract, 'a', []).then(events => { |
||||
const mapping = coverage.generate(events, pathPrefix); |
||||
assert.deepEqual(mapping[filePath].l, { |
||||
5: 1, 6: 10, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].b, {}); |
||||
assert.deepEqual(mapping[filePath].s, { |
||||
1: 1, 2: 10, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].f, { |
||||
1: 1, |
||||
}); |
||||
done(); |
||||
}).catch(done); |
||||
assert.deepEqual(mapping[util.filePath].l, { |
||||
5: 1, 6: 10, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].b, {}); |
||||
assert.deepEqual(mapping[util.filePath].s, { |
||||
1: 1, 2: 10, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].f, { |
||||
1: 1, |
||||
}); |
||||
}); |
||||
|
||||
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 }
|
||||
it('should cover a while statement with an bracketed body (multiline)', async function() { |
||||
const contract = await util.bootstrapCoverage('loops/while-with-brackets', provider, collector); |
||||
coverage.addContract(contract.instrumented, util.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 }
|
||||
vm.execute(info.contract, 'a', []).then(events => { |
||||
const mapping = coverage.generate(events, pathPrefix); |
||||
assert.deepEqual(mapping[filePath].l, { |
||||
5: 1, 6: 1, 7: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].b, {}); |
||||
assert.deepEqual(mapping[filePath].s, { |
||||
1: 1, 2: 1, 3: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].f, { |
||||
1: 1, |
||||
}); |
||||
done(); |
||||
}).catch(done); |
||||
assert.deepEqual(mapping[util.filePath].l, { |
||||
5: 1, 6: 1, 7: 1, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].b, {}); |
||||
assert.deepEqual(mapping[util.filePath].s, { |
||||
1: 1, 2: 1, 3: 1, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].f, { |
||||
1: 1, |
||||
}); |
||||
}); |
||||
|
||||
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
|
||||
it('should cover a while statement with an unbracketed body (multiline)', async function() { |
||||
const contract = await util.bootstrapCoverage('loops/while-no-brackets', provider, collector); |
||||
coverage.addContract(contract.instrumented, util.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
|
||||
vm.execute(info.contract, 'a', []).then(events => { |
||||
const mapping = coverage.generate(events, pathPrefix); |
||||
assert.deepEqual(mapping[filePath].l, { |
||||
5: 1, 6: 1, 7: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].b, {}); |
||||
assert.deepEqual(mapping[filePath].s, { |
||||
1: 1, 2: 1, 3: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].f, { |
||||
1: 1, |
||||
}); |
||||
done(); |
||||
}).catch(done); |
||||
assert.deepEqual(mapping[util.filePath].l, { |
||||
5: 1, 6: 1, 7: 1, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].b, {}); |
||||
assert.deepEqual(mapping[util.filePath].s, { |
||||
1: 1, 2: 1, 3: 1, |
||||
}); |
||||
assert.deepEqual(mapping[util.filePath].f, { |
||||
1: 1, |
||||
}); |
||||
}); |
||||
});*/ |
||||
}); |
||||
|
Loading…
Reference in new issue