Support solidity v0.7.x
This commit is contained in:
parent
c4ead689a9
commit
e34bc77157
@ -42,6 +42,7 @@ import { ContractContentsByPath, ImportPrefixRemappings, SolcWrapper } from './s
|
|||||||
import { SolcWrapperV04 } from './solc_wrapper_v04';
|
import { SolcWrapperV04 } from './solc_wrapper_v04';
|
||||||
import { SolcWrapperV05 } from './solc_wrapper_v05';
|
import { SolcWrapperV05 } from './solc_wrapper_v05';
|
||||||
import { SolcWrapperV06 } from './solc_wrapper_v06';
|
import { SolcWrapperV06 } from './solc_wrapper_v06';
|
||||||
|
import { SolcWrapperV07 } from './solc_wrapper_v07';
|
||||||
|
|
||||||
export type TYPE_ALL_FILES_IDENTIFIER = '*';
|
export type TYPE_ALL_FILES_IDENTIFIER = '*';
|
||||||
export const ALL_CONTRACTS_IDENTIFIER = '*';
|
export const ALL_CONTRACTS_IDENTIFIER = '*';
|
||||||
@ -366,6 +367,9 @@ export class Compiler {
|
|||||||
if (solcVersion.startsWith('0.6')) {
|
if (solcVersion.startsWith('0.6')) {
|
||||||
return new SolcWrapperV06(solcVersion, this._opts);
|
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}`);
|
throw new Error(`Missing Solc wrapper implementation for version ${solcVersion}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
packages/sol-compiler/src/solc_wrapper_v07.ts
Normal file
3
packages/sol-compiler/src/solc_wrapper_v07.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import { SolcWrapperV06 } from './solc_wrapper_v06';
|
||||||
|
|
||||||
|
export const SolcWrapperV07 = SolcWrapperV06;
|
@ -3,12 +3,11 @@ import * as chai from 'chai';
|
|||||||
import { CompilerOptions, ContractArtifact } from 'ethereum-types';
|
import { CompilerOptions, ContractArtifact } from 'ethereum-types';
|
||||||
import 'mocha';
|
import 'mocha';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
import { Compiler } from '../src/compiler';
|
import { Compiler } from '../src/compiler';
|
||||||
import { fsWrapper } from '../src/utils/fs_wrapper';
|
import { fsWrapper } from '../src/utils/fs_wrapper';
|
||||||
|
|
||||||
import { exchange_binary } from './fixtures/exchange_bin';
|
import { exchange_binary } from './fixtures/exchange_bin';
|
||||||
import { v6_contract_binary } from './fixtures/v6_contract_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 { chaiSetup } from './util/chai_setup';
|
||||||
import { constants } from './util/constants';
|
import { constants } from './util/constants';
|
||||||
|
|
||||||
@ -138,4 +137,27 @@ describe('#Compiler', function(): void {
|
|||||||
const expectedBinaryWithoutMetadata = hexUtils.slice(v6_contract_binary, 0, -METADATA_SIZE);
|
const expectedBinaryWithoutMetadata = hexUtils.slice(v6_contract_binary, 0, -METADATA_SIZE);
|
||||||
expect(actualBinaryWithoutMetadata).to.eq(expectedBinaryWithoutMetadata);
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
37
packages/sol-compiler/test/fixtures/contracts/V7Contract.sol
vendored
Normal file
37
packages/sol-compiler/test/fixtures/contracts/V7Contract.sol
vendored
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
2
packages/sol-compiler/test/fixtures/v7_contract_bin.ts
vendored
Normal file
2
packages/sol-compiler/test/fixtures/v7_contract_bin.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
export const v7_contract_binary =
|
||||||
|
'0x6080604052348015600f57600080fd5b5060405161011238038061011283398181016040526020811015603157600080fd5b8101908080519060200190929190505050806000819055505060ba806100586000396000f3fe608060405236600a57005b348015601557600080fd5b506040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260048152602001807f6e6f70650000000000000000000000000000000000000000000000000000000081525060200191505060405180910390fdfea2646970667358221220d498aaab2683da1af2092969c6d8a0c3d992a9a9a0a5d19b54b5e704ab8fd5e364736f6c63430007000033';
|
Loading…
x
Reference in New Issue
Block a user