aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/utils.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-06-15 04:58:28 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-06-15 04:58:54 +0800
commit7ab921669bf52c1cb2d43350b2cccc8efe91bdbd (patch)
tree3ed0e1047f6b9bb04ce7084cb0b98bdb5cb5b78a /packages/sol-cov/src/utils.ts
parent4efd28c092e74b438d0397069c0c55cc90c537f2 (diff)
downloaddexon-0x-contracts-7ab921669bf52c1cb2d43350b2cccc8efe91bdbd.tar.gz
dexon-0x-contracts-7ab921669bf52c1cb2d43350b2cccc8efe91bdbd.tar.zst
dexon-0x-contracts-7ab921669bf52c1cb2d43350b2cccc8efe91bdbd.zip
Introduce subprovider for printing revert stack traces
Diffstat (limited to 'packages/sol-cov/src/utils.ts')
-rw-r--r--packages/sol-cov/src/utils.ts24
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;
+ },
};