@0x/sol-compiler
: Address review feedback.
This commit is contained in:
parent
74647f0e88
commit
b9a68c0b8e
@ -91,7 +91,6 @@ export class Compiler {
|
||||
overrides: Partial<CompilerOptions> = {},
|
||||
file: string = 'compiler.json',
|
||||
): Promise<CompilerOptions> {
|
||||
// TODO: Look for config file in parent directories if not found in current directory
|
||||
const fileConfig: CompilerOptions = (await promisify(fs.stat)(file)).isFile
|
||||
? JSON.parse((await promisify(fs.readFile)(file, 'utf8')).toString())
|
||||
: {};
|
||||
|
@ -1,9 +1,3 @@
|
||||
import { CompilerOptions } from 'ethereum-types';
|
||||
|
||||
import { SolcWrapperV05 } from './solc_wrapper_v05';
|
||||
|
||||
export class SolcWrapperV04 extends SolcWrapperV05 {
|
||||
constructor(solcVersion: string, opts: CompilerOptions) {
|
||||
super(solcVersion, opts);
|
||||
}
|
||||
}
|
||||
export const SolcWrapperV04 = SolcWrapperV05;
|
||||
|
@ -32,14 +32,8 @@ export const DEFAULT_COMPILER_SETTINGS: solc.CompilerSettings = {
|
||||
export class SolcWrapperV05 extends SolcWrapper {
|
||||
protected readonly _compilerSettings: solc.CompilerSettings;
|
||||
|
||||
public static normalizeOutput(
|
||||
output: StandardOutput,
|
||||
importRemappings: ImportPrefixRemappings,
|
||||
opts: CompilerOptions,
|
||||
): StandardOutput {
|
||||
public static normalizeOutput(output: StandardOutput): StandardOutput {
|
||||
const _output = _.cloneDeep(output);
|
||||
// _output.sources = makeContractPathsRelative(_output.sources, opts.contractsDir!, importRemappings);
|
||||
// _output.contracts = makeContractPathsRelative(_output.contracts, opts.contractsDir!, importRemappings);
|
||||
// tslint:disable-next-line forin
|
||||
for (const contractPath in _output.contracts) {
|
||||
// tslint:disable-next-line forin
|
||||
@ -94,7 +88,7 @@ export class SolcWrapperV05 extends SolcWrapper {
|
||||
}
|
||||
return {
|
||||
input,
|
||||
output: SolcWrapperV05.normalizeOutput(output, importRemappings, this._opts),
|
||||
output: SolcWrapperV05.normalizeOutput(output),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -161,18 +161,15 @@ export async function compileDockerAsync(
|
||||
standardInput: solc.StandardInput,
|
||||
): Promise<solc.StandardOutput> {
|
||||
const standardInputStr = JSON.stringify(standardInput, null, 2);
|
||||
// prettier-ignore
|
||||
const dockerArgs = [
|
||||
'run',
|
||||
'-i',
|
||||
'-a',
|
||||
'stdin',
|
||||
'-a',
|
||||
'stdout',
|
||||
'-a',
|
||||
'stderr',
|
||||
'-a', 'stdin',
|
||||
'-a', 'stdout',
|
||||
'-a', 'stderr',
|
||||
`ethereum/solc:${solidityVersion}`,
|
||||
'solc',
|
||||
'--standard-json',
|
||||
'solc', '--standard-json',
|
||||
];
|
||||
return new Promise<solc.StandardOutput>((accept, reject) => {
|
||||
const p = spawn('docker', dockerArgs, { shell: true, stdio: ['pipe', 'inherit', 'inherit'] });
|
||||
@ -479,7 +476,7 @@ export function getDependencyNameToPackagePath(
|
||||
* Extract the solidity version (e.g., '0.5.9') from a solc version (e.g., `0.5.9+commit.34d3134f`).
|
||||
*/
|
||||
export function getSolidityVersionFromSolcVersion(solcVersion: string): string {
|
||||
const m = /(\d+\.\d+\.\d+)\+commit\.[a-f0-9]{8}/.exec(solcVersion);
|
||||
const m = /(\d+\.\d+\.\d+)\+commit\.[a-fA-F0-9]{8}/.exec(solcVersion);
|
||||
if (!m) {
|
||||
throw new Error(`Unable to parse solc version string "${solcVersion}"`);
|
||||
}
|
||||
@ -490,7 +487,7 @@ export function getSolidityVersionFromSolcVersion(solcVersion: string): string {
|
||||
* Strips any extra characters before and after the version + commit hash of a solc version string.
|
||||
*/
|
||||
export function normalizeSolcVersion(fullSolcVersion: string): string {
|
||||
const m = /\d+\.\d+\.\d+\+commit\.[a-f0-9]{8}/.exec(fullSolcVersion);
|
||||
const m = /\d+\.\d+\.\d+\+commit\.[a-fA-F0-9]{8}/.exec(fullSolcVersion);
|
||||
if (!m) {
|
||||
throw new Error(`Unable to parse solc version string "${fullSolcVersion}"`);
|
||||
}
|
||||
|
@ -1,19 +1,22 @@
|
||||
import { join } from 'path';
|
||||
|
||||
import { hexUtils } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import { CompilerOptions, ContractArtifact } from 'ethereum-types';
|
||||
import 'mocha';
|
||||
import { join } from 'path';
|
||||
|
||||
import { Compiler } from '../src/compiler';
|
||||
import { fsWrapper } from '../src/utils/fs_wrapper';
|
||||
|
||||
import { exchange_binary } from './fixtures/exchange_bin';
|
||||
import { v6_contract_binary } from './fixtures/v6_contract_bin';
|
||||
import { chaiSetup } from './util/chai_setup';
|
||||
import { constants } from './util/constants';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
|
||||
const METADATA_SIZE = 43;
|
||||
|
||||
describe('#Compiler', function(): void {
|
||||
this.timeout(constants.timeoutMs); // tslint:disable-line:no-invalid-this
|
||||
const artifactsDir = `${__dirname}/fixtures/artifacts`;
|
||||
@ -41,14 +44,12 @@ describe('#Compiler', function(): void {
|
||||
};
|
||||
const exchangeArtifactString = await fsWrapper.readFileAsync(exchangeArtifactPath, opts);
|
||||
const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString);
|
||||
// The last 43 bytes of the binaries are metadata which may not be equivalent
|
||||
const metadataByteLength = 43;
|
||||
const metadataHexLength = metadataByteLength * 2;
|
||||
const unlinkedBinaryWithoutMetadata = exchangeArtifact.compilerOutput.evm.bytecode.object.slice(
|
||||
2,
|
||||
-metadataHexLength,
|
||||
const unlinkedBinaryWithoutMetadata = hexUtils.slice(
|
||||
exchangeArtifact.compilerOutput.evm.bytecode.object,
|
||||
0,
|
||||
-METADATA_SIZE,
|
||||
);
|
||||
const exchangeBinaryWithoutMetadata = exchange_binary.slice(0, -metadataHexLength);
|
||||
const exchangeBinaryWithoutMetadata = hexUtils.slice(exchange_binary, 0, -METADATA_SIZE);
|
||||
expect(unlinkedBinaryWithoutMetadata).to.equal(exchangeBinaryWithoutMetadata);
|
||||
});
|
||||
it("should throw when Whatever.sol doesn't contain a Whatever contract", async () => {
|
||||
@ -129,7 +130,12 @@ describe('#Compiler', function(): void {
|
||||
};
|
||||
const exchangeArtifactString = await fsWrapper.readFileAsync(artifactPath, opts);
|
||||
const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString);
|
||||
const bin = exchangeArtifact.compilerOutput.evm.bytecode.object;
|
||||
expect(bin.slice(2)).to.length.to.be.gt(0);
|
||||
const actualBinaryWithoutMetadata = hexUtils.slice(
|
||||
exchangeArtifact.compilerOutput.evm.bytecode.object,
|
||||
0,
|
||||
-METADATA_SIZE,
|
||||
);
|
||||
const expectedBinaryWithoutMetadata = hexUtils.slice(v6_contract_binary, 0, -METADATA_SIZE);
|
||||
expect(actualBinaryWithoutMetadata).to.eq(expectedBinaryWithoutMetadata);
|
||||
});
|
||||
});
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
*/
|
||||
|
||||
pragma solidity ^0.6.4;
|
||||
pragma solidity 0.6.4;
|
||||
|
||||
|
||||
contract V6Contract {
|
||||
|
File diff suppressed because one or more lines are too long
2
packages/sol-compiler/test/fixtures/v6_contract_bin.ts
vendored
Normal file
2
packages/sol-compiler/test/fixtures/v6_contract_bin.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export const v6_contract_binary =
|
||||
'0x6080604052348015600f57600080fd5b5060405161011238038061011283398181016040526020811015603157600080fd5b8101908080519060200190929190505050806000819055505060ba806100586000396000f3fe608060405236600a57005b348015601557600080fd5b506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260048152602001807f6e6f70650000000000000000000000000000000000000000000000000000000081525060200191505060405180910390fdfea26469706673582212208084a572151fb41e40aa4d1197e387cba7b4f0cbd982e34682974038667b564764736f6c63430006040033';
|
Loading…
x
Reference in New Issue
Block a user