|
|
|
@ -3,7 +3,8 @@ |
|
|
|
|
* This file contains methods that produce a coverage map to pass to instanbul |
|
|
|
|
* from data generated by `instrumentSolidity.js` |
|
|
|
|
*/ |
|
|
|
|
const SolidityCoder = require('web3-eth-abi'); |
|
|
|
|
const { AbiCoder } = require('web3-eth-abi'); |
|
|
|
|
const SolidityCoder = AbiCoder(); |
|
|
|
|
const path = require('path'); |
|
|
|
|
const keccak = require('keccakjs'); |
|
|
|
|
const fs = require('fs'); |
|
|
|
@ -103,27 +104,27 @@ module.exports = class CoverageMap { |
|
|
|
|
const event = JSON.parse(events[idx]); |
|
|
|
|
|
|
|
|
|
if (event.topics.filter(t => this.lineTopics.indexOf(t) >= 0).length > 0) { |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], event.data.replace('0x', '')); |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], `0x${event.data}`); |
|
|
|
|
const canonicalContractPath = data[0]; |
|
|
|
|
this.coverage[canonicalContractPath].l[parseInt(data[1], 10)] += 1; |
|
|
|
|
} else if (event.topics.filter(t => this.functionTopics.indexOf(t) >= 0).length > 0) { |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], event.data.replace('0x', '')); |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], `0x${event.data}`); |
|
|
|
|
const canonicalContractPath = data[0]; |
|
|
|
|
this.coverage[canonicalContractPath].f[parseInt(data[1], 10)] += 1; |
|
|
|
|
} else if (event.topics.filter(t => this.branchTopics.indexOf(t) >= 0).length > 0) { |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256', 'uint256'], event.data.replace('0x', '')); |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256', 'uint256'], `0x${event.data}`); |
|
|
|
|
const canonicalContractPath = data[0]; |
|
|
|
|
this.coverage[canonicalContractPath].b[parseInt(data[1], 10)][parseInt(data[2], 10)] += 1; |
|
|
|
|
} else if (event.topics.filter(t => this.statementTopics.indexOf(t) >= 0).length > 0) { |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], event.data.replace('0x', '')); |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], `0x${event.data}`); |
|
|
|
|
const canonicalContractPath = data[0]; |
|
|
|
|
this.coverage[canonicalContractPath].s[parseInt(data[1], 10)] += 1; |
|
|
|
|
} else if (event.topics.filter(t => this.assertPreTopics.indexOf(t) >= 0).length > 0) { |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], event.data.replace('0x', '')); |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], `0x${event.data}`); |
|
|
|
|
const canonicalContractPath = data[0]; |
|
|
|
|
this.assertCoverage[canonicalContractPath][parseInt(data[1], 10)].preEvents += 1; |
|
|
|
|
} else if (event.topics.filter(t => this.assertPostTopics.indexOf(t) >= 0).length > 0) { |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], event.data.replace('0x', '')); |
|
|
|
|
const data = SolidityCoder.decodeParameters(['string', 'uint256'], `0x${event.data}`); |
|
|
|
|
const canonicalContractPath = data[0]; |
|
|
|
|
this.assertCoverage[canonicalContractPath][parseInt(data[1], 10)].postEvents += 1; |
|
|
|
|
} |
|
|
|
|