Fix sol-profiler bugs

This commit is contained in:
Michael Zhu 2020-06-17 12:08:29 -07:00
parent 9215a73b6c
commit 21a202dd16
7 changed files with 20 additions and 11 deletions

View File

@ -5,7 +5,7 @@ import { stripHexPrefix } from 'ethereumjs-util';
import * as _ from 'lodash';
const ZERO_BYTE_CALL_DATA_COST = 4;
const NON_ZERO_BYTE_CALL_DATA_COST = 68;
const NON_ZERO_BYTE_CALL_DATA_COST = 16;
const WORD_SIZE = 32;
const G_MEMORY = 3;
const G_QUAD_COEF = 512;
@ -29,7 +29,7 @@ export const costUtils = {
const callDataCost = zeroBytesCost + nonZeroBytesCost;
logUtils.header('Call data breakdown', '-');
logUtils.table({
'call data size (bytes)': callData.length,
'call data size (bytes)': callDataBuf.byteLength,
callDataCost,
zeroBytesCost,
nonZeroBytesCost,

View File

@ -9,7 +9,7 @@ export class FSResolver extends Resolver {
// tslint:disable-next-line:prefer-function-over-method
public resolveIfExists(importPath: string): ContractSource | undefined {
if (fs.existsSync(importPath) && fs.lstatSync(importPath).isFile()) {
const fileContent = fs.readFileSync(importPath).toString();
const fileContent = fs.readFileSync(importPath).toString('ascii');
const absolutePath = path.resolve(importPath);
return { source: fileContent, path: importPath, absolutePath } as any;
}

View File

@ -14,12 +14,13 @@ export class NameResolver extends EnumerableResolver {
this._contractsDir = contractsDir;
}
public resolveIfExists(lookupContractName: string): ContractSource | undefined {
const lookupContractNameNormalized = path.basename(lookupContractName, SOLIDITY_FILE_EXTENSION);
let contractSource: ContractSource | undefined;
const onFile = (filePath: string) => {
const contractName = path.basename(filePath, SOLIDITY_FILE_EXTENSION);
if (contractName === lookupContractName) {
if (contractName === lookupContractNameNormalized) {
const absoluteContractPath = path.join(this._contractsDir, filePath);
const source = fs.readFileSync(absoluteContractPath).toString();
const source = fs.readFileSync(absoluteContractPath).toString('ascii');
contractSource = { source, path: filePath, absolutePath: absoluteContractPath };
return true;
}
@ -32,7 +33,7 @@ export class NameResolver extends EnumerableResolver {
const contractSources: ContractSource[] = [];
const onFile = (filePath: string) => {
const absoluteContractPath = path.join(this._contractsDir, filePath);
const source = fs.readFileSync(absoluteContractPath).toString();
const source = fs.readFileSync(absoluteContractPath).toString('ascii');
const contractSource = { source, path: filePath, absolutePath: absoluteContractPath };
contractSources.push(contractSource);
};

View File

@ -30,7 +30,7 @@ export class NPMResolver extends Resolver {
packageScopeIfExists === undefined ? packageName : path.join(packageScopeIfExists, packageName);
const lookupPath = path.join(currentPath, 'node_modules', packagePath, pathWithinPackage);
if (fs.existsSync(lookupPath) && fs.lstatSync(lookupPath).isFile()) {
const fileContent = fs.readFileSync(lookupPath).toString();
const fileContent = fs.readFileSync(lookupPath).toString('ascii');
return { source: fileContent, path: importPath, absolutePath: lookupPath };
}
currentPath = path.dirname(currentPath);

View File

@ -15,7 +15,7 @@ export class RelativeFSResolver extends Resolver {
public resolveIfExists(importPath: string): ContractSource | undefined {
const filePath = path.resolve(path.join(this._contractsDir, importPath));
if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
const fileContent = fs.readFileSync(filePath).toString();
const fileContent = fs.readFileSync(filePath).toString('ascii');
return { source: fileContent, path: importPath, absolutePath: filePath };
}
return undefined;

View File

@ -10,7 +10,7 @@ export class URLResolver extends Resolver {
const FILE_URL_PREXIF = 'file://';
if (importPath.startsWith(FILE_URL_PREXIF)) {
const filePath = importPath.substr(FILE_URL_PREXIF.length);
const fileContent = fs.readFileSync(filePath).toString();
const fileContent = fs.readFileSync(filePath).toString('ascii');
return { source: fileContent, path: importPath, absolutePath: filePath };
}
return undefined;

View File

@ -1,4 +1,11 @@
import { FallthroughResolver, FSResolver, NPMResolver, RelativeFSResolver, URLResolver } from '@0x/sol-resolver';
import {
FallthroughResolver,
FSResolver,
NameResolver,
NPMResolver,
RelativeFSResolver,
URLResolver,
} from '@0x/sol-resolver';
import { logUtils } from '@0x/utils';
import { CompilerOptions, ContractArtifact } from 'ethereum-types';
import * as fs from 'fs';
@ -40,6 +47,7 @@ export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter {
this._resolver.appendResolver(new NPMResolver(packagePath));
this._resolver.appendResolver(new RelativeFSResolver(this._sourcesPath));
this._resolver.appendResolver(new FSResolver());
this._resolver.appendResolver(new NameResolver(this._sourcesPath));
}
public async collectContractsDataAsync(): Promise<ContractData[]> {
const artifactsGlob = `${this._artifactsPath}/**/*.json`;
@ -47,7 +55,7 @@ export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter {
const contractsData: ContractData[] = [];
for (const artifactFileName of artifactFileNames) {
const artifact: ContractArtifact = JSON.parse(fs.readFileSync(artifactFileName).toString());
if (artifact.compilerOutput.evm === undefined) {
if (artifact.compilerOutput === undefined || artifact.compilerOutput.evm === undefined) {
logUtils.warn(`${artifactFileName} doesn't contain bytecode. Skipping...`);
continue;
}