This commit is contained in:
Andre Medeiros 2018-08-21 16:23:00 -04:00
parent 2ebb6d6ba4
commit e9a121bee3
7 changed files with 386 additions and 8 deletions

View File

@ -3,10 +3,11 @@ const util = require('util');
const SourceMap = require('./source_map'); const SourceMap = require('./source_map');
class ContractSource { class ContractSource {
constructor(file, body) { constructor(file, path, body) {
let self = this; let self = this;
this.file = file; this.file = file;
this.path = path;
this.body = body; this.body = body;
this.lineLengths = body.split("\n").map((line) => { return line.length; }); this.lineLengths = body.split("\n").map((line) => { return line.length; });
@ -71,6 +72,7 @@ class ContractSource {
var pc = 0; var pc = 0;
var instructions = 0; var instructions = 0;
var previousSourceMap = null; var previousSourceMap = null;
do { do {
let sourceMap; let sourceMap;
@ -104,7 +106,7 @@ class ContractSource {
let coverage = { let coverage = {
code: this.body.trim().split("\n"), code: this.body.trim().split("\n"),
l: {}, l: {},
path: this.file, path: this.path,
s: {}, s: {},
b: {}, b: {},
f: {}, f: {},
@ -126,6 +128,7 @@ class ContractSource {
switch(node.nodeType) { switch(node.nodeType) {
case 'Assignment': case 'Assignment':
case 'EventDefinition':
case 'Literal': case 'Literal':
case 'PragmaDirective': case 'PragmaDirective':
case 'VariableDeclaration': case 'VariableDeclaration':
@ -171,8 +174,13 @@ class ContractSource {
sourceMapToNodeType[node.src] = [{type: 'b', id: node.id, body: {loc: location}}]; sourceMapToNodeType[node.src] = [{type: 'b', id: node.id, body: {loc: location}}];
break; break;
case 'EmitStatement':
children = [node.eventCall];
break;
case 'BinaryOperation': case 'BinaryOperation':
case 'ExpressionStatement': case 'ExpressionStatement':
case 'FunctionCall':
case 'Identifier': case 'Identifier':
case 'Return': case 'Return':
case 'UnaryOperation': case 'UnaryOperation':
@ -284,8 +292,6 @@ class ContractSource {
contractMatches = trace.structLogs.every((step) => { return bytecode[step.pc]; }); contractMatches = trace.structLogs.every((step) => { return bytecode[step.pc]; });
if(!contractMatches) break; if(!contractMatches) break;
console.log(sourceMapToNodeType);
console.log('---------------------------------------------------');
trace.structLogs.forEach((step) => { trace.structLogs.forEach((step) => {
step = bytecode[step.pc]; step = bytecode[step.pc];
if(!step.sourceMap || step.sourceMap == '' || step.sourceMap == SourceMap.empty()) return; if(!step.sourceMap || step.sourceMap == '' || step.sourceMap == SourceMap.empty()) return;

View File

@ -11,7 +11,7 @@ class ContractSources {
case '[object Object]': case '[object Object]':
Object.keys(files).forEach((file) => { Object.keys(files).forEach((file) => {
var basename = path.basename(file); var basename = path.basename(file);
this.files[basename] = new ContractSource(basename, files[file]); this.files[basename] = new ContractSource(basename, file, files[file]);
}); });
break; break;
@ -26,7 +26,7 @@ class ContractSources {
var basename = path.basename(file); var basename = path.basename(file);
try { try {
var content = fs.readFileSync(file).toString(); var content = fs.readFileSync(file).toString();
this.files[basename] = new ContractSource(basename, content); this.files[basename] = new ContractSource(basename, file, content);
} catch(e) { } catch(e) {
throw new Error(`Error loading ${file}: ${e.code}`); throw new Error(`Error loading ${file}: ${e.code}`);
} }

View File

@ -117,7 +117,7 @@ contract x {
} }
`.trim(); `.trim();
const cs = new ContractSource('contract.sol', contractSource); const cs = new ContractSource('contract.sol', '/tmp/contract.sol', contractSource);
describe('constructor', () => { describe('constructor', () => {
it('should set line offsets and line lengths correctly', (done) => { it('should set line offsets and line lengths correctly', (done) => {

View File

@ -30,5 +30,345 @@
"address": "0x3dA95F78cdD8B42c210185cB1c982573aab72550" "address": "0x3dA95F78cdD8B42c210185cB1c982573aab72550"
} }
} }
},
"0x4da0ea0ff0f1a72b8b10173a180b1d3549ae4acd0cacfad175545358194f8b37": {
"contracts": {
"0xb0587abc1626a87a151bad37fb75458d11e5bd18b725ef116afe4e4d16a5b4dd": {
"name": "Events",
"address": "0x2B879D0442Fdd7B38b564A7EE819610140536737"
},
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x22A0D5711fc84E4F41Bc559f06DE8a357E2DF911"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x8fd4208aB37153B95Ec7292e8107A15Ced86518E"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0xD5F7d7F78242E5a2195854F3B9A61E5438C317E0"
}
}
},
"0xc39fad3b75f2d1766c08104defffffc4b2676d139fc6ede6791158dc905ecd7a": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xBb767dAc7FfaFc544C6E2a5E828720807Ab7675c"
},
"0xb0587abc1626a87a151bad37fb75458d11e5bd18b725ef116afe4e4d16a5b4dd": {
"name": "Events",
"address": "0xb065364B1bf463eEDd840F50f55966997372d277"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0xa9B8aBE4085D5209724c4566692192ba5E9819b3"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x3510840C58A7cb21af316Ea7B2E06De042404419"
}
}
},
"0xd292a0772454ece84cd1ba7ad8beaef3129b2ea19855652d2d6fbdf6e48f8664": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xFd7f3BaCDa400C3766B6Ea88dc0b03c2d71830A0"
},
"0xb0587abc1626a87a151bad37fb75458d11e5bd18b725ef116afe4e4d16a5b4dd": {
"name": "Events",
"address": "0x17E5Cb5B09b2a02a8e258b6471A79638C31213B8"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x7d2e5eb1C2874a276AA17Db1bd6956e99C232A95"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x983ADa29eF1E4F4d631923b51D473623847d2993"
}
}
},
"0x04ffe1cb8589336ca41e088c01cfc50be29e61d937d08de8051832610fa27813": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xBe764E2902Fd02bF9Ae3b701ab2C376176b4c6c8"
},
"0xb0587abc1626a87a151bad37fb75458d11e5bd18b725ef116afe4e4d16a5b4dd": {
"name": "Events",
"address": "0xfd2D4d30B9B2D5Bf389B1D4227e67635F66707A2"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x3a3ca9796aC80a9858E50340E036361E18eB391e"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x9811E34FaC973E0FB0C3D689aDd68fB45908Db44"
}
}
},
"0x3e25fdfa3cb85f2a3d193ae8ec8304053dff3ca2d549cd464604d37ae3ba7683": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xf4dB6565f8484a91B7352aF3cc38fb2BB2Bc4B4e"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0xc06Bad1616d4f0861B711e47b7F86d776f117aBd"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x1B716E386414785BCBaeC86fdFb921c5e1A9F6B4"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x173F783735Fd0Ed40574Def8e64753f0D88aed28"
}
}
},
"0x210be77dbcabee4b9e01329b5c07cc1d3bd0755e70d6a37f01a0b90f4c4fbdb5": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xD217262dE7De4c53AA154d1F8c902dF8F62F2d16"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0xbc3eeCbC83C31f5C183eD2AF3Bc27E67E6e6320a"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0xA6917727b4D8BE5ca7ADba6bEc79ad5014e0cc89"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x07175DfE8FAc2f4c60A5E094a011FA7C995c183A"
}
}
},
"0x0fe2f492ba09a497c48e6a6e18152451a1df9e3026dbe6375d9cad36459ff805": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xB489b35fd2a077Be4174A71406B79617f13c2eB9"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x3CD0C176F86e205A1c6d10653dFE36B4741d331C"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x8Fa51164ffb5B2018f77B5d8dbC4f7904958110e"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0xa5B671DcdFe9C1c2746515E77A223D3CC2503F24"
}
}
},
"0xd02c104830e00b2ab0bbcd230ca0d3ad2ddf278903adc54deece0558d4a0d789": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xc524043bE42cDA9aCEE0da2858e775739Af827Bb"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x3fD6C056415b0f6DE3cD24354DFdF60ACBAA09dA"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0xA484d3C421d5718e88e07a4b8c6B422B23e663Fd"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x3936c29d0DEf923C04C1FEC526ADB8bDd643d457"
}
}
},
"0xbacb9f3add82ddb222dcd9af92663faf34123fbc345b1ac6c8a498c7c8da5352": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xC556E8eF0A3571cEB20914A29535873FE27f9a65"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0xbe80900094a4703CD4a52F4859AFe2A13AB21e5D"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x36722e515daF8c5d5B6375596F9661Bf6176EC8A"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x431da4C64DB331d0DFF4c4dC65211901272aCdd4"
}
}
},
"0x1da68d108e329b84a86a798fe37c46fe959840e4796d6595c45b290103c0a066": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xABA5133C82C19a76689EfF042126004e2c158016"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0xC5950B1dF0CA468e9a9C0bc4CA4Aa61e7FfA19aF"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x0097593cd16D3A8f7F4aa3a5D70AE97f38e16911"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x82C57B57fB53EfA4ba38A8824a2ecB28871eD8f8"
}
}
},
"0x1a8b1e473c97aaaee35f974cfe90f84c75a555d51589d92b86f01b6112245852": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0xa702BC37246357edBa423f6b3ec557De17609BFc"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x3d224a1d900e84a5E9ac9f2581f611B13e8cc391"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x237711cF639B571D024034F75c3a346702E492f7"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x267300E6661d18De9E9A66dE841104933a17d023"
}
}
},
"0x220d17d65e39ac1cdb6056858366ede170525f7c774fe9f807d0508dbaf583b5": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x22c5929AF2E60be9f91374B53Cc4E0C38B5Ea21d"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x927f56B47cF27EA6137EbA02a1aB567307982274"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x4Eb107f0cBff719047be32cc9762f2Fa09bdd9A5"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0xC2c132184165515f7987340A2058AF2d87d810AB"
}
}
},
"0xb0348f9b31088ec6d6212ea245a36fa7a5a8ad3a5f58b939b0ae2ba2aa3555e9": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x5b61D4d145cb2CBb9EcbF036f3dD04EE498a68AC"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x9D021c3b14E4430510824e49ec07364D287E94C3"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x4f423D366c498b664c15522e4c5f701e3b815856"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x7601fF5783F65f1e7C25c1ee7D54eb432f9d8040"
}
}
},
"0x83f27cbdcdd0cc7b535d39e35874989c6dff396a41e3f354fc02d15dcdb39430": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x7D8EfF31d9FdA0A9481C4fC3b0082B19fc27a839"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x032A136Bab0124c0E625f75F342ac4cC0c54cdC0"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x8855DC99a58c20935adA4fDe630a438797929ec4"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0xc0A6b55856cA1f79F15C1C685FD8500E6404c244"
}
}
},
"0x84853a0874e03f3c69c9cfa2be3ae0126fc70f7fca2ba5775c39fe7a09d3357c": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x50Ad1Bf838Bc7a01baA8544725db2efA72A2386F"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x2a2f677F227b177dA1576ef16D10480224d02060"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x1CE6Ed0e32662D15EEbB76675286Df41E45D6a15"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x63D0106dBE068b2B5c97D1bC85f13AfAaC950F9b"
}
}
},
"0x0903cf7f4103bd5dbc64e7c50a6f621f4891bc36fb3a0d3a4f57ea9047b4b6d5": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x8226BCd2DC7B533FDF6f3a491bDEC10ECa7489D7"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0x07496795da929c3691503cf8CAe0129C675a8E81"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0x1b64fE887111CD0893F77BCA0a4b7647Fc81c296"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0xade907729adbFab7Cb32543A7A1e949Ddca6A60D"
}
}
},
"0x6ea5d44c80efa645dd8f0974bd6530064eb8f8a87ad2c67da165ae3d6307b8fb": {
"contracts": {
"0x147efc3279dafa68a829854375819e056d8dc6582e2961fc18971944ae7b46f0": {
"name": "Branches",
"address": "0x1c97c55fC2E0F2E80B8BF890497A8c649b1E86Fd"
},
"0x34a25a69326908806a2984fce74cfef28cb6e70a24530be1d2a6afc35d759dc9": {
"name": "Events",
"address": "0xa0eD51e08985ba4AB428b7d90DD820A673BD4187"
},
"0x73ef69ce3bb1c70015ab500b19dd4863fbf4c41acd1d6c47237686a9e0017d10": {
"name": "Loops",
"address": "0xb20627198699698978933d5faae979f36829700d"
},
"0x33399485c5b2893d178ca38e3a0587e788a85b4c634ab302458da5104dad8219": {
"name": "SimpleStorage",
"address": "0x78c64BE76958C4ad2eFa2872EebC9e2AEA09c305"
}
}
} }
} }

View File

@ -0,0 +1,16 @@
pragma solidity ^0.4.23;
contract Events {
uint public balance;
event Deposit(uint value);
constructor(uint initialValue) public {
balance = initialValue;
}
function deposit(uint x) public {
balance = balance + x;
emit Deposit(x);
}
}

View File

@ -26,6 +26,6 @@ contract("Branches", function() {
}); });
it("should return the smaller number", function(done) { it("should return the smaller number", function(done) {
Branches.methods.smaller(10).send().then(() => { done() }); Branches.methods.smaller(10).send().then(() => { done(); });
}); });
}); });

View File

@ -0,0 +1,16 @@
/*global contract, config, it, assert*/
const Events = require('Embark/contracts/Events');
config({
contracts: {
"Events": {
args: [100]
}
}
});
contract("Events", function() {
it("should deposit", function(done) {
Events.methods.deposit(10).send().then(() => { done(); });
});
});