aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 02:05:24 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-05-23 06:27:17 +0800
commit83c37c6a7a320326975c8afd9d49a42c9afcefd4 (patch)
treedd58346c8211d7f289a2c822a2309fe932442579 /packages/sol-cov
parentac52ad88a1884979c74f418398bbf428d727cf34 (diff)
downloaddexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.gz
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.bz2
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.lz
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.xz
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.tar.zst
dexon-sol-tools-83c37c6a7a320326975c8afd9d49a42c9afcefd4.zip
Address feedback
Diffstat (limited to 'packages/sol-cov')
-rw-r--r--packages/sol-cov/src/coverage_manager.ts4
-rw-r--r--packages/sol-cov/src/trace.ts27
-rw-r--r--packages/sol-cov/test/sol_compiler_artifact_adapter_test.ts (renamed from packages/sol-cov/test/collect_contracts_data_test.ts)2
3 files changed, 11 insertions, 22 deletions
diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts
index 3aa62acff..ef893527a 100644
--- a/packages/sol-cov/src/coverage_manager.ts
+++ b/packages/sol-cov/src/coverage_manager.ts
@@ -139,12 +139,12 @@ export class CoverageManager {
constructor(
artifactAdapter: AbstractArtifactAdapter,
getContractCodeAsync: (address: string) => Promise<string>,
- verbose: boolean,
+ isVerbose: boolean,
) {
this._getContractCodeAsync = getContractCodeAsync;
this._artifactAdapter = artifactAdapter;
this._logger = getLogger('sol-cov');
- this._logger.setLevel(verbose ? levels.TRACE : levels.ERROR);
+ this._logger.setLevel(isVerbose ? levels.TRACE : levels.ERROR);
}
public appendTraceInfo(traceInfo: TraceInfo): void {
this._traceInfos.push(traceInfo);
diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts
index 30508898b..81c8bb0ff 100644
--- a/packages/sol-cov/src/trace.ts
+++ b/packages/sol-cov/src/trace.ts
@@ -1,5 +1,5 @@
import { OpCode, StructLog, TransactionTrace } from '@0xproject/types';
-import { BigNumber, logUtils } from '@0xproject/utils';
+import { addressUtils, BigNumber, logUtils } from '@0xproject/utils';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import * as fs from 'fs';
import * as _ from 'lodash';
@@ -7,17 +7,13 @@ import * as _ from 'lodash';
export interface TraceByContractAddress {
[contractAddress: string]: StructLog[];
}
-function padZeros(address: string): string {
- return addHexPrefix(_.padStart(stripHexPrefix(address), 40, '0'));
-}
export function getTracesByContractAddress(structLogs: StructLog[], startAddress: string): TraceByContractAddress {
const traceByContractAddress: TraceByContractAddress = {};
let currentTraceSegment = [];
const callStack = [startAddress];
- // tslint:disable-next-line: prefer-for-of
- for (let i = 0; i < structLogs.length; ++i) {
- const structLog = structLogs[i];
+ // tslint:disable-next-line:prefer-for-of
+ for (const structLog of structLogs) {
if (structLog.depth !== callStack.length - 1) {
throw new Error("Malformed trace. trace depth doesn't match call stack depth");
}
@@ -26,26 +22,19 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
// That means that we can always safely pop from it
currentTraceSegment.push(structLog);
- if (
- structLog.op === OpCode.CallCode ||
- structLog.op === OpCode.StaticCall ||
- structLog.op === OpCode.Call ||
- structLog.op === OpCode.DelegateCall
- ) {
+ if (_.includes([OpCode.CallCode, OpCode.StaticCall, OpCode.Call, OpCode.DelegateCall], structLog.op)) {
const currentAddress = _.last(callStack) as string;
const jumpAddressOffset = structLog.op === OpCode.DelegateCall ? 4 : 2;
- const newAddress = padZeros(new BigNumber(addHexPrefix(structLog.stack[jumpAddressOffset])).toString(16));
+ const newAddress = addressUtils.padZeros(
+ new BigNumber(addHexPrefix(structLog.stack[jumpAddressOffset])).toString(16),
+ );
callStack.push(newAddress);
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
currentTraceSegment,
);
currentTraceSegment = [];
} else if (
- structLog.op === OpCode.Return ||
- structLog.op === OpCode.Stop ||
- structLog.op === OpCode.Revert ||
- structLog.op === OpCode.Invalid ||
- structLog.op === OpCode.SelfDestruct
+ _.includes([OpCode.Return, OpCode.Stop, OpCode.Revert, OpCode.Invalid, OpCode.SelfDestruct], structLog.op)
) {
const currentAddress = callStack.pop() as string;
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
diff --git a/packages/sol-cov/test/collect_contracts_data_test.ts b/packages/sol-cov/test/sol_compiler_artifact_adapter_test.ts
index d423bc603..0ebad669b 100644
--- a/packages/sol-cov/test/collect_contracts_data_test.ts
+++ b/packages/sol-cov/test/sol_compiler_artifact_adapter_test.ts
@@ -8,7 +8,7 @@ import { SolCompilerArtifactAdapter } from '../src/artifact_adapters/sol_compile
const expect = chai.expect;
-describe('Collect contracts data', () => {
+describe('SolCompilerArtifactAdapter', () => {
describe('#collectContractsData', () => {
it('correctly collects contracts data', async () => {
const artifactsPath = path.resolve(__dirname, 'fixtures/artifacts');