parent
ca19b64d76
commit
f1389eecda
@ -0,0 +1,63 @@ |
||||
/* 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'); |
||||
|
||||
describe('asserts and requires', () => { |
||||
const filePath = path.resolve('./test.sol'); |
||||
const pathPrefix = './'; |
||||
|
||||
before(() => process.env.NO_EVENTS_FILTER = true); |
||||
|
||||
it.only('should cover assert statements as if they are if statements when they pass', done => { |
||||
const contract = util.getCode('assert/Assert.sol'); |
||||
const info = getInstrumentedVersion(contract, filePath); |
||||
const coverage = new CoverageMap(); |
||||
coverage.addContract(info, filePath); |
||||
|
||||
vm.execute(info.contract, 'a', [true]).then(events => { |
||||
const mapping = coverage.generate(events, pathPrefix); |
||||
assert.deepEqual(mapping[filePath].l, { |
||||
5: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].b, { |
||||
1: [1, 0], |
||||
}); |
||||
assert.deepEqual(mapping[filePath].s, { |
||||
1: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].f, { |
||||
1: 1, |
||||
}); |
||||
done(); |
||||
}).catch(done); |
||||
}); |
||||
|
||||
it.only('should cover assert statements as if they are if statements when they fail', done => { |
||||
const contract = util.getCode('assert/Assert.sol'); |
||||
const info = getInstrumentedVersion(contract, filePath); |
||||
const coverage = new CoverageMap(); |
||||
coverage.addContract(info, filePath); |
||||
|
||||
vm.execute(info.contract, 'a', [false]).then(events => { |
||||
const mapping = coverage.generate(events, pathPrefix); |
||||
assert.deepEqual(mapping[filePath].l, { |
||||
5: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].b, { |
||||
1: [0, 1], |
||||
}); |
||||
assert.deepEqual(mapping[filePath].s, { |
||||
1: 1, |
||||
}); |
||||
assert.deepEqual(mapping[filePath].f, { |
||||
1: 1, |
||||
}); |
||||
done(); |
||||
}).catch(done); |
||||
}); |
||||
}); |
@ -0,0 +1,7 @@ |
||||
pragma solidity ^0.4.13; |
||||
|
||||
contract Test { |
||||
function a(bool test){ |
||||
assert(test); |
||||
} |
||||
} |
Loading…
Reference in new issue