This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 466
Sol-cov artifact Adapters (truffle) #589
Merged
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
ae220c3
Add solcVersion to CompilerOpts
LogvinovLeon 842f2ea
Fix a bug in FS resolver causing it to try reading directories
LogvinovLeon 60b1fdd
Only look at *.sol files in NameResolver
LogvinovLeon 974575b
Make sol-cov work with truffle and other artifact adapters
LogvinovLeon 427a291
Support all opcodes in a trace parser
LogvinovLeon b86248f
Add CHANGELOG entries
LogvinovLeon 1ff34bd
Remove web3Factory.create and remove dev-tools dependency on sol-cov
LogvinovLeon 56d1b01
Introduce CONFIG_FILE
LogvinovLeon 8267950
Assign then return
LogvinovLeon 6aafda4
Assign then pass
LogvinovLeon 86f17fb
Rename ZeroExArtifactAdapter to SolCompilerArtifactAdapter
LogvinovLeon ac925aa
Improve a CHANGELOG comment
LogvinovLeon 334ef5c
Improve a CHANGELOG comment
LogvinovLeon 08b08ef
Match class names with file names
LogvinovLeon d9907f2
Use a hidden directory for temp artifacts
LogvinovLeon 5c9bde2
Remove a comment
LogvinovLeon e4fe497
Refactor ContractData lookup
LogvinovLeon 253bada
Fix import paths
LogvinovLeon 2f35e47
Change publish command name
LogvinovLeon f8c628b
Updated CHANGELOGS
LogvinovLeon fa4e694
Updated CHANGELOGS
LogvinovLeon 84a1b56
Publish
LogvinovLeon ac52ad8
Use loglevel instead of verbose flag
LogvinovLeon 83c37c6
Address feedback
LogvinovLeon 0c53d27
Use BlockParamLiteral.Latest
LogvinovLeon 447b305
Suppport subcalls in constructor
LogvinovLeon 6540343
Remove trace.json
LogvinovLeon 06be580
Fix a bug in CALL-like opcode handling
LogvinovLeon 9740199
Fix sol-cov tests
LogvinovLeon 127b3e7
Fix sol-compiler version
LogvinovLeon 6e0aef5
Fix depth tracking in a tracer
LogvinovLeon f756003
Merge branch 'v2-prototype' into feature/truffle-sol-cov
LogvinovLeon 8c7f090
Add a more verbose comment for self-destruct
LogvinovLeon d49f2c4
Parse compiler.json in SolCompilerArtifactsAdapter
LogvinovLeon ebc750d
Address feedback
LogvinovLeon 48e6695
Fix NameResolver
LogvinovLeon 0a72541
Merge branch 'v2-prototype' into feature/truffle-sol-cov
LogvinovLeon 6a77e0f
Move contract utils
LogvinovLeon c9aef16
Fix linter issues
LogvinovLeon 2ddd53b
Fix trace test
LogvinovLeon bf18a90
Upgrade solidity parser
LogvinovLeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ export interface TraceByContractAddress { | |
[contractAddress: string]: StructLog[]; | ||
} | ||
|
||
function getAddressFromStackEntry(stackEntry: string): string { | ||
return addressUtils.padZeros(new BigNumber(addHexPrefix(stackEntry)).toString(16)); | ||
} | ||
|
||
export function getTracesByContractAddress(structLogs: StructLog[], startAddress: string): TraceByContractAddress { | ||
const traceByContractAddress: TraceByContractAddress = {}; | ||
let currentTraceSegment = []; | ||
|
@@ -16,26 +20,32 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress | |
for (let i = 0; i < structLogs.length; i++) { | ||
const structLog = structLogs[i]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
if (structLog.depth !== callStack.length - 1) { | ||
throw new Error("Malformed trace. trace depth doesn't match call stack depth"); | ||
throw new Error("Malformed trace. Trace depth doesn't match call stack depth"); | ||
} | ||
// After that check we have a guarantee that call stack is never empty | ||
// If it would: callStack.length - 1 === structLog.depth === -1 | ||
// That means that we can always safely pop from it | ||
currentTraceSegment.push(structLog); | ||
|
||
if (_.includes([OpCode.CallCode, OpCode.StaticCall, OpCode.Call, OpCode.DelegateCall], structLog.op)) { | ||
const isCallLike = _.includes( | ||
[OpCode.CallCode, OpCode.StaticCall, OpCode.Call, OpCode.DelegateCall], | ||
structLog.op, | ||
); | ||
const isEndOpcode = _.includes( | ||
[OpCode.Return, OpCode.Stop, OpCode.Revert, OpCode.Invalid, OpCode.SelfDestruct], | ||
structLog.op, | ||
); | ||
if (isCallLike) { | ||
const currentAddress = _.last(callStack) as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be nice to actually have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Array has a pop method. We're not poping here. |
||
const jumpAddressOffset = 1; | ||
const newAddress = addressUtils.padZeros( | ||
new BigNumber(addHexPrefix(structLog.stack[structLog.stack.length - jumpAddressOffset - 1])).toString( | ||
16, | ||
), | ||
const newAddress = getAddressFromStackEntry( | ||
structLog.stack[structLog.stack.length - jumpAddressOffset - 1], | ||
); | ||
if (structLog === _.last(structLogs)) { | ||
throw new Error('CALL-like opcode can not be the last one'); | ||
throw new Error('Malformed trace. CALL-like opcode can not be the last one'); | ||
} | ||
// Sometimes calls don't change the execution context (current address). When we do a transfer to an | ||
// externally owned account - it does the call and immidiately returns because there is no fallback | ||
// externally owned account - it does the call and immediately returns because there is no fallback | ||
// function. We manually check if the call depth had changed to handle that case. | ||
const nextStructLog = structLogs[i + 1]; | ||
if (nextStructLog.depth !== structLog.depth) { | ||
|
@@ -45,9 +55,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress | |
); | ||
currentTraceSegment = []; | ||
} | ||
} else if ( | ||
_.includes([OpCode.Return, OpCode.Stop, OpCode.Revert, OpCode.Invalid, OpCode.SelfDestruct], structLog.op) | ||
) { | ||
} else if (isEndOpcode) { | ||
const currentAddress = callStack.pop() as string; | ||
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat( | ||
currentTraceSegment, | ||
|
@@ -81,7 +89,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress | |
); | ||
currentTraceSegment = []; | ||
} else { | ||
throw new Error('Shit broke'); | ||
throw new Error('Malformed trace. Unexpected call depth change'); | ||
} | ||
} | ||
} | ||
|
@@ -90,7 +98,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress | |
throw new Error('Malformed trace. Call stack non empty at the end'); | ||
} | ||
if (currentTraceSegment.length !== 0) { | ||
throw new Error('Malformed trace. currentTraceSegment non empty at the end'); | ||
throw new Error('Malformed trace. Current trace segment non empty at the end'); | ||
} | ||
return traceByContractAddress; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So only one of either the
bytecode
or theruntimeBytecode
needs to match? Can you leave a comment here about why that is?