diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-06-15 08:07:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-15 08:07:03 +0800 |
commit | ff0960b174ffb8759f9f96e1486372acf54bf840 (patch) | |
tree | 9193336e896e72ce4f53eec52e45e5427dd89ccd /packages/sol-cov/src/utils.ts | |
parent | e7eb220c503118631a6b23071c71b4b55df5b5cf (diff) | |
parent | 7032825e35e825e42196d4ccc23b1a1f7fb8038a (diff) | |
download | dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.tar dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.tar.gz dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.tar.bz2 dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.tar.lz dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.tar.xz dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.tar.zst dexon-sol-tools-ff0960b174ffb8759f9f96e1486372acf54bf840.zip |
Merge pull request #705 from 0xProject/feature/revert-trace-subprovider
Introduce subprovider for printing revert stack traces
Diffstat (limited to 'packages/sol-cov/src/utils.ts')
-rw-r--r-- | packages/sol-cov/src/utils.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/sol-cov/src/utils.ts b/packages/sol-cov/src/utils.ts index 0b32df02e..4f16a1cda 100644 --- a/packages/sol-cov/src/utils.ts +++ b/packages/sol-cov/src/utils.ts @@ -1,3 +1,6 @@ +import { addressUtils, BigNumber } from '@0xproject/utils'; +import { OpCode, StructLog } from 'ethereum-types'; +import { addHexPrefix } from 'ethereumjs-util'; import * as _ from 'lodash'; import { ContractData, LineColumn, SingleFileSourceRange } from './types'; @@ -42,4 +45,25 @@ export const utils = { }); return contractData; }, + isCallLike(op: OpCode): boolean { + return _.includes([OpCode.CallCode, OpCode.StaticCall, OpCode.Call, OpCode.DelegateCall], op); + }, + isEndOpcode(op: OpCode): boolean { + return _.includes([OpCode.Return, OpCode.Stop, OpCode.Revert, OpCode.Invalid, OpCode.SelfDestruct], op); + }, + getAddressFromStackEntry(stackEntry: string): string { + const hexBase = 16; + return addressUtils.padZeros(new BigNumber(addHexPrefix(stackEntry)).toString(hexBase)); + }, + normalizeStructLogs(structLogs: StructLog[]): StructLog[] { + if (structLogs[0].depth === 1) { + // Geth uses 1-indexed depth counter whilst ganache starts from 0 + const newStructLogs = _.map(structLogs, structLog => ({ + ...structLog, + depth: structLog.depth - 1, + })); + return newStructLogs; + } + return structLogs; + }, }; |