aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-03-09 23:44:44 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-03-12 10:37:29 +0800
commit3b158cb72649c19a6b569821d23672ea7454b45b (patch)
tree2d204372607c43ebe9629c265f841acbd5084a44
parent2298a34c37b373e265d3b4b4665d195cfa1c67fd (diff)
downloaddexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.tar
dexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.tar.gz
dexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.tar.bz2
dexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.tar.lz
dexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.tar.xz
dexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.tar.zst
dexon-sol-tools-3b158cb72649c19a6b569821d23672ea7454b45b.zip
Address feedback
-rw-r--r--packages/dev-utils/src/coverage.ts3
-rw-r--r--packages/sol-cov/src/coverage_subprovider.ts16
-rw-r--r--packages/sol-cov/src/source_maps.ts13
-rw-r--r--packages/subproviders/package.json1
-rw-r--r--packages/subproviders/src/globals.d.ts2
-rw-r--r--packages/web3-typescript-typings/index.d.ts4
6 files changed, 25 insertions, 14 deletions
diff --git a/packages/dev-utils/src/coverage.ts b/packages/dev-utils/src/coverage.ts
index db87e2285..a29acf5da 100644
--- a/packages/dev-utils/src/coverage.ts
+++ b/packages/dev-utils/src/coverage.ts
@@ -14,6 +14,7 @@ export const coverage = {
const artifactsPath = './src/artifacts';
const contractsPath = './src/contracts';
const networkId = 50;
- return new CoverageSubprovider(artifactsPath, contractsPath, networkId);
+ const defaultFromAddress = '0x5409ed021d9299bf6814279a6a1411a7e866a631';
+ return new CoverageSubprovider(artifactsPath, contractsPath, networkId, defaultFromAddress);
},
};
diff --git a/packages/sol-cov/src/coverage_subprovider.ts b/packages/sol-cov/src/coverage_subprovider.ts
index d3783abb2..f91b95c79 100644
--- a/packages/sol-cov/src/coverage_subprovider.ts
+++ b/packages/sol-cov/src/coverage_subprovider.ts
@@ -13,8 +13,10 @@ import { TraceInfoExistingContract, TraceInfoNewContract } from './types';
*/
export class CoverageSubprovider extends Subprovider {
private _coverageManager: CoverageManager;
- constructor(artifactsPath: string, sourcesPath: string, networkId: number) {
+ private _defaultFromAddress: string;
+ constructor(artifactsPath: string, sourcesPath: string, networkId: number, defaultFromAddress: string) {
super();
+ this._defaultFromAddress = defaultFromAddress;
this._coverageManager = new CoverageManager(
artifactsPath,
sourcesPath,
@@ -96,7 +98,7 @@ export class CoverageSubprovider extends Subprovider {
const traceInfo: TraceInfoNewContract = {
coveredPcs,
txHash,
- address,
+ address: address as 'NEW_CONTRACT',
bytecode: data as string,
};
this._coverageManager.appendTraceInfo(traceInfo);
@@ -116,9 +118,9 @@ export class CoverageSubprovider extends Subprovider {
const snapshotId = Number((await this.emitPayloadAsync({ method: 'evm_snapshot' })).result);
const txData = callData;
if (_.isUndefined(txData.from)) {
- txData.from = '0x5409ed021d9299bf6814279a6a1411a7e866a631'; // TODO
+ txData.from = this._defaultFromAddress;
}
- const txDataWithFromAddress = txData as Web3.TxData & { from: string };
+ const txDataWithFromAddress = txData as Web3.TxData;
try {
const txHash = (await this.emitPayloadAsync({
method: 'eth_sendTransaction',
@@ -128,7 +130,11 @@ export class CoverageSubprovider extends Subprovider {
} catch (err) {
await this._onTransactionSentAsync(txDataWithFromAddress, err, undefined);
}
- const didRevert = (await this.emitPayloadAsync({ method: 'evm_revert', params: [snapshotId] })).result;
+ const jsonRPCResponse = await this.emitPayloadAsync({ method: 'evm_revert', params: [snapshotId] });
+ const didRevert = jsonRPCResponse.result;
+ if (!didRevert) {
+ throw new Error('Failed to revert the snapshot');
+ }
}
private async _getContractCodeAsync(address: string): Promise<string> {
const payload = {
diff --git a/packages/sol-cov/src/source_maps.ts b/packages/sol-cov/src/source_maps.ts
index 795b15a9b..9b3ea9e24 100644
--- a/packages/sol-cov/src/source_maps.ts
+++ b/packages/sol-cov/src/source_maps.ts
@@ -11,7 +11,7 @@ export interface SourceLocation {
fileIndex: number;
}
-export const getLocationByOffset = (str: string) => {
+export function getLocationByOffset(str: string): LocationByOffset {
const locationByOffset: LocationByOffset = {};
let currentOffset = 0;
for (const char of str.split('')) {
@@ -24,11 +24,16 @@ export const getLocationByOffset = (str: string) => {
currentOffset++;
}
return locationByOffset;
-};
+}
// Parses a sourcemap string
// The solidity sourcemap format is documented here: https://github.com/ethereum/solidity/blob/develop/docs/miscellaneous.rst#source-mappings
-export const parseSourceMap = (sourceCodes: string[], srcMap: string, bytecodeHex: string, sources: string[]) => {
+export function parseSourceMap(
+ sourceCodes: string[],
+ srcMap: string,
+ bytecodeHex: string,
+ sources: string[],
+): { [programCounter: number]: SourceRange } {
const bytecode = Uint8Array.from(Buffer.from(bytecodeHex, 'hex'));
const pcToInstructionIndex: { [programCounter: number]: number } = getPcToInstructionIndexMapping(bytecode);
const locationByOffsetByFileIndex = _.map(sourceCodes, getLocationByOffset);
@@ -74,4 +79,4 @@ export const parseSourceMap = (sourceCodes: string[], srcMap: string, bytecodeHe
pcsToSourceRange[pc] = instructionIndexToSourceRange[instructionIndex];
}
return pcsToSourceRange;
-};
+}
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index 259265a53..9f969233f 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -23,7 +23,6 @@
"@0xproject/utils": "^0.4.1",
"@ledgerhq/hw-app-eth": "^4.3.0",
"@ledgerhq/hw-transport-u2f": "^4.3.0",
- "@0xproject/deployer": "^0.1.0",
"bn.js": "^4.11.8",
"es6-promisify": "^5.0.0",
"ethereumjs-tx": "^1.3.3",
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index fc0cdf038..e59f4ad8a 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -135,7 +135,7 @@ declare module 'hdkey' {
export = HDNode;
}
-// hdkey declarations
+// ganache-core declarations
declare module 'ganache-core' {
import * as Web3 from 'web3';
export interface GanacheOpts {
diff --git a/packages/web3-typescript-typings/index.d.ts b/packages/web3-typescript-typings/index.d.ts
index aec6e370a..cbe067b37 100644
--- a/packages/web3-typescript-typings/index.d.ts
+++ b/packages/web3-typescript-typings/index.d.ts
@@ -151,11 +151,11 @@ declare module 'web3' {
jsonrpc: string;
}
- export type OpCode = string; // TODO enum of all opcodes;
+ export type OpCode = string;
export interface StructLog {
depth: number;
- error: '';
+ error: string;
gas: number;
gasCost: number;
memory: string[];