aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/utils.ts
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-06-20 01:19:38 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-06-20 01:19:38 +0800
commit7454e16aae476b3908123dadab0cf9fdf6ab5990 (patch)
tree3477ace66bc71c2aa4e09b85dd1923087effac1b /packages/sol-cov/src/utils.ts
parent2cc7289b7b3c3177230957ff2384c58bed4266f3 (diff)
parente4acad60e91943c2dcbdd55b7766b543e78df6f6 (diff)
downloaddexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.tar
dexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.tar.gz
dexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.tar.bz2
dexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.tar.lz
dexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.tar.xz
dexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.tar.zst
dexon-sol-tools-7454e16aae476b3908123dadab0cf9fdf6ab5990.zip
Merge branch 'v2-prototype' of https://github.com/0xProject/0x-monorepo into feature/website/portal-v2-analytics
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;
+ },
};