diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 20dc38b182..b345fc69aa 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -42,6 +42,7 @@ import { ContractContentsByPath, ImportPrefixRemappings, SolcWrapper } from './s import { SolcWrapperV04 } from './solc_wrapper_v04'; import { SolcWrapperV05 } from './solc_wrapper_v05'; import { SolcWrapperV06 } from './solc_wrapper_v06'; +import { SolcWrapperV07 } from './solc_wrapper_v07'; export type TYPE_ALL_FILES_IDENTIFIER = '*'; export const ALL_CONTRACTS_IDENTIFIER = '*'; @@ -366,6 +367,9 @@ export class Compiler { if (solcVersion.startsWith('0.6')) { return new SolcWrapperV06(solcVersion, this._opts); } + if (solcVersion.startsWith('0.7')) { + return new SolcWrapperV07(solcVersion, this._opts); + } throw new Error(`Missing Solc wrapper implementation for version ${solcVersion}`); } diff --git a/packages/sol-compiler/src/solc_wrapper_v07.ts b/packages/sol-compiler/src/solc_wrapper_v07.ts new file mode 100644 index 0000000000..4acdc9b587 --- /dev/null +++ b/packages/sol-compiler/src/solc_wrapper_v07.ts @@ -0,0 +1,3 @@ +import { SolcWrapperV06 } from './solc_wrapper_v06'; + +export const SolcWrapperV07 = SolcWrapperV06; diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts index 83fd3ad4c9..3b39c85485 100644 --- a/packages/sol-compiler/test/compiler_test.ts +++ b/packages/sol-compiler/test/compiler_test.ts @@ -3,12 +3,11 @@ 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 { v7_contract_binary } from './fixtures/v7_contract_bin'; import { chaiSetup } from './util/chai_setup'; import { constants } from './util/constants'; @@ -138,4 +137,27 @@ describe('#Compiler', function(): void { const expectedBinaryWithoutMetadata = hexUtils.slice(v6_contract_binary, 0, -METADATA_SIZE); expect(actualBinaryWithoutMetadata).to.eq(expectedBinaryWithoutMetadata); }); + it('should compile a V0.7 contract', async () => { + compilerOpts.contracts = ['V7Contract']; + + const artifactPath = `${artifactsDir}/V7Contract.json`; + if (fsWrapper.doesPathExistSync(artifactPath)) { + await fsWrapper.removeFileAsync(artifactPath); + } + + await new Compiler(compilerOpts).compileAsync(); + + const opts = { + encoding: 'utf8', + }; + const exchangeArtifactString = await fsWrapper.readFileAsync(artifactPath, opts); + const exchangeArtifact: ContractArtifact = JSON.parse(exchangeArtifactString); + const actualBinaryWithoutMetadata = hexUtils.slice( + exchangeArtifact.compilerOutput.evm.bytecode.object, + 0, + -METADATA_SIZE, + ); + const expectedBinaryWithoutMetadata = hexUtils.slice(v7_contract_binary, 0, -METADATA_SIZE); + expect(actualBinaryWithoutMetadata).to.eq(expectedBinaryWithoutMetadata); + }); }); diff --git a/packages/sol-compiler/test/fixtures/contracts/V7Contract.sol b/packages/sol-compiler/test/fixtures/contracts/V7Contract.sol new file mode 100644 index 0000000000..cb8561c3cf --- /dev/null +++ b/packages/sol-compiler/test/fixtures/contracts/V7Contract.sol @@ -0,0 +1,37 @@ +/* + + Copyright 2020 ZeroEx Intl. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +pragma solidity 0.7.0; + + +contract V7Contract { + + uint256 private _privateNumber; + + constructor(uint256 privateNumber) public { + _privateNumber = privateNumber; + } + + fallback() external { + revert('nope'); + } + + receive() payable external { + // no-op + } +} diff --git a/packages/sol-compiler/test/fixtures/v7_contract_bin.ts b/packages/sol-compiler/test/fixtures/v7_contract_bin.ts new file mode 100644 index 0000000000..abb3b6a407 --- /dev/null +++ b/packages/sol-compiler/test/fixtures/v7_contract_bin.ts @@ -0,0 +1,2 @@ +export const v7_contract_binary = + '0x6080604052348015600f57600080fd5b5060405161011238038061011283398181016040526020811015603157600080fd5b8101908080519060200190929190505050806000819055505060ba806100586000396000f3fe608060405236600a57005b348015601557600080fd5b506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260048152602001807f6e6f70650000000000000000000000000000000000000000000000000000000081525060200191505060405180910390fdfea2646970667358221220d498aaab2683da1af2092969c6d8a0c3d992a9a9a0a5d19b54b5e704ab8fd5e364736f6c63430007000033';