diff --git a/contracts/exchange/compiler.json b/contracts/exchange/compiler.json index 6b74c612c2..6d739870f0 100644 --- a/contracts/exchange/compiler.json +++ b/contracts/exchange/compiler.json @@ -1,5 +1,5 @@ { - "artifactsDir": "./generated-artifacts", + "artifactsDir": "./test/generated-artifacts", "contractsDir": "./contracts", "useDockerisedSolc": false, "isOfflineMode": false, diff --git a/contracts/exchange/package.json b/contracts/exchange/package.json index 26787aec5e..95a807844c 100644 --- a/contracts/exchange/package.json +++ b/contracts/exchange/package.json @@ -19,12 +19,16 @@ "test:profiler": "SOLIDITY_PROFILER=true run-s build run_mocha profiler:report:html", "test:trace": "SOLIDITY_REVERT_TRACE=true run-s build run_mocha", "run_mocha": "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", - "compile": "sol-compiler", + "compile": "run-s compile:test compile:src", + "compile:test": "sol-compiler", + "compile:src": "sol-compiler --artifacts-dir generated-artifacts --contracts ${npm_package_config_whitelistedContracts}", "watch": "sol-compiler -w", - "clean": "shx rm -rf lib generated-artifacts generated-wrappers", - "generate_contract_wrappers": "abi-gen --debug --abis ${npm_package_config_abis} --output generated-wrappers --backend ethers", - "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", - "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "clean": "shx rm -rf lib test/generated-artifacts test/generated-wrappers generated-artifacts generated-wrappers", + "generate_contract_wrappers": "run-s generate_contract_wrappers:test generate_contract_wrappers:src", + "generate_contract_wrappers:test": "abi-gen --debug --abis ${npm_package_config_test_abis} --output test/generated-wrappers --backend ethers", + "generate_contract_wrappers:src": "abi-gen --debug --abis ${npm_package_config_src_abis} --output generated-wrappers --backend ethers", + "lint": "tslint --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./test/generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", + "fix": "tslint --fix --format stylish --project . --exclude ./generated-wrappers/**/* --exclude ./generated-artifacts/**/* --exclude ./test/generated-wrappers/**/* --exclude ./test/generated-artifacts/**/* --exclude **/lib/**/* && yarn lint-contracts", "coverage:report:text": "istanbul report text", "coverage:report:html": "istanbul report html && open coverage/index.html", "profiler:report:html": "istanbul report html && open coverage/index.html", @@ -35,8 +39,11 @@ "compile:truffle": "truffle compile" }, "config": { - "abis": "./generated-artifacts/@(Exchange|IAssetProxy|IAssetProxyDispatcher|IEIP1271Data|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|IProtocolFees|ISignatureValidator|ITransactions|ITransferSimulator|IWallet|IWrapperFunctions|IsolatedExchange|LibExchangeRichErrorDecoder|MixinAssetProxyDispatcher|MixinExchangeCore|MixinMatchOrders|MixinProtocolFees|MixinSignatureValidator|MixinTransactions|MixinTransferSimulator|MixinWrapperFunctions|ReentrancyTester|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestProtocolFeeCollector|TestProtocolFees|TestProtocolFeesReceiver|TestSignatureValidator|TestTransactions|TestValidatorWallet|TestWrapperFunctions).json", - "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." + "whitelistedContracts": "Exchange,IExchange", + "test-abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", + "test-abis": "./test/generated-artifacts/@(Exchange|IAssetProxy|IAssetProxyDispatcher|IEIP1271Data|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|IProtocolFees|ISignatureValidator|ITransactions|ITransferSimulator|IWallet|IWrapperFunctions|IsolatedExchange|LibExchangeRichErrorDecoder|MixinAssetProxyDispatcher|MixinExchangeCore|MixinMatchOrders|MixinProtocolFees|MixinSignatureValidator|MixinTransactions|MixinTransferSimulator|MixinWrapperFunctions|ReentrancyTester|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestProtocolFeeCollector|TestProtocolFees|TestProtocolFeesReceiver|TestSignatureValidator|TestTransactions|TestValidatorWallet|TestWrapperFunctions).json", + "src-abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.", + "src-abis": "./generated-artifacts/@(Exchange|IExchange).json" }, "repository": { "type": "git", diff --git a/contracts/exchange/src/artifacts.ts b/contracts/exchange/src/artifacts.ts index 34354204c4..37310d8640 100644 --- a/contracts/exchange/src/artifacts.ts +++ b/contracts/exchange/src/artifacts.ts @@ -6,74 +6,5 @@ import { ContractArtifact } from 'ethereum-types'; import * as Exchange from '../generated-artifacts/Exchange.json'; -import * as IAssetProxy from '../generated-artifacts/IAssetProxy.json'; -import * as IAssetProxyDispatcher from '../generated-artifacts/IAssetProxyDispatcher.json'; -import * as IEIP1271Data from '../generated-artifacts/IEIP1271Data.json'; -import * as IEIP1271Wallet from '../generated-artifacts/IEIP1271Wallet.json'; import * as IExchange from '../generated-artifacts/IExchange.json'; -import * as IExchangeCore from '../generated-artifacts/IExchangeCore.json'; -import * as IMatchOrders from '../generated-artifacts/IMatchOrders.json'; -import * as IProtocolFees from '../generated-artifacts/IProtocolFees.json'; -import * as ISignatureValidator from '../generated-artifacts/ISignatureValidator.json'; -import * as IsolatedExchange from '../generated-artifacts/IsolatedExchange.json'; -import * as ITransactions from '../generated-artifacts/ITransactions.json'; -import * as ITransferSimulator from '../generated-artifacts/ITransferSimulator.json'; -import * as IWallet from '../generated-artifacts/IWallet.json'; -import * as IWrapperFunctions from '../generated-artifacts/IWrapperFunctions.json'; -import * as LibExchangeRichErrorDecoder from '../generated-artifacts/LibExchangeRichErrorDecoder.json'; -import * as MixinAssetProxyDispatcher from '../generated-artifacts/MixinAssetProxyDispatcher.json'; -import * as MixinExchangeCore from '../generated-artifacts/MixinExchangeCore.json'; -import * as MixinMatchOrders from '../generated-artifacts/MixinMatchOrders.json'; -import * as MixinProtocolFees from '../generated-artifacts/MixinProtocolFees.json'; -import * as MixinSignatureValidator from '../generated-artifacts/MixinSignatureValidator.json'; -import * as MixinTransactions from '../generated-artifacts/MixinTransactions.json'; -import * as MixinTransferSimulator from '../generated-artifacts/MixinTransferSimulator.json'; -import * as MixinWrapperFunctions from '../generated-artifacts/MixinWrapperFunctions.json'; -import * as ReentrancyTester from '../generated-artifacts/ReentrancyTester.json'; -import * as TestAssetProxyDispatcher from '../generated-artifacts/TestAssetProxyDispatcher.json'; -import * as TestExchangeInternals from '../generated-artifacts/TestExchangeInternals.json'; -import * as TestLibExchangeRichErrorDecoder from '../generated-artifacts/TestLibExchangeRichErrorDecoder.json'; -import * as TestProtocolFeeCollector from '../generated-artifacts/TestProtocolFeeCollector.json'; -import * as TestProtocolFees from '../generated-artifacts/TestProtocolFees.json'; -import * as TestProtocolFeesReceiver from '../generated-artifacts/TestProtocolFeesReceiver.json'; -import * as TestSignatureValidator from '../generated-artifacts/TestSignatureValidator.json'; -import * as TestTransactions from '../generated-artifacts/TestTransactions.json'; -import * as TestValidatorWallet from '../generated-artifacts/TestValidatorWallet.json'; -import * as TestWrapperFunctions from '../generated-artifacts/TestWrapperFunctions.json'; -export const artifacts = { - Exchange: Exchange as ContractArtifact, - MixinAssetProxyDispatcher: MixinAssetProxyDispatcher as ContractArtifact, - MixinExchangeCore: MixinExchangeCore as ContractArtifact, - MixinMatchOrders: MixinMatchOrders as ContractArtifact, - MixinProtocolFees: MixinProtocolFees as ContractArtifact, - MixinSignatureValidator: MixinSignatureValidator as ContractArtifact, - MixinTransactions: MixinTransactions as ContractArtifact, - MixinTransferSimulator: MixinTransferSimulator as ContractArtifact, - MixinWrapperFunctions: MixinWrapperFunctions as ContractArtifact, - IAssetProxy: IAssetProxy as ContractArtifact, - IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact, - IEIP1271Data: IEIP1271Data as ContractArtifact, - IEIP1271Wallet: IEIP1271Wallet as ContractArtifact, - IExchange: IExchange as ContractArtifact, - IExchangeCore: IExchangeCore as ContractArtifact, - IMatchOrders: IMatchOrders as ContractArtifact, - IProtocolFees: IProtocolFees as ContractArtifact, - ISignatureValidator: ISignatureValidator as ContractArtifact, - ITransactions: ITransactions as ContractArtifact, - ITransferSimulator: ITransferSimulator as ContractArtifact, - IWallet: IWallet as ContractArtifact, - IWrapperFunctions: IWrapperFunctions as ContractArtifact, - LibExchangeRichErrorDecoder: LibExchangeRichErrorDecoder as ContractArtifact, - IsolatedExchange: IsolatedExchange as ContractArtifact, - ReentrancyTester: ReentrancyTester as ContractArtifact, - TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact, - TestExchangeInternals: TestExchangeInternals as ContractArtifact, - TestLibExchangeRichErrorDecoder: TestLibExchangeRichErrorDecoder as ContractArtifact, - TestProtocolFeeCollector: TestProtocolFeeCollector as ContractArtifact, - TestProtocolFees: TestProtocolFees as ContractArtifact, - TestProtocolFeesReceiver: TestProtocolFeesReceiver as ContractArtifact, - TestSignatureValidator: TestSignatureValidator as ContractArtifact, - TestTransactions: TestTransactions as ContractArtifact, - TestValidatorWallet: TestValidatorWallet as ContractArtifact, - TestWrapperFunctions: TestWrapperFunctions as ContractArtifact, -}; +export const artifacts = { Exchange: Exchange as ContractArtifact, IExchange: IExchange as ContractArtifact }; diff --git a/contracts/exchange/src/wrappers.ts b/contracts/exchange/src/wrappers.ts index 28922d2dfc..acb3e1d6c0 100644 --- a/contracts/exchange/src/wrappers.ts +++ b/contracts/exchange/src/wrappers.ts @@ -4,37 +4,4 @@ * ----------------------------------------------------------------------------- */ export * from '../generated-wrappers/exchange'; -export * from '../generated-wrappers/i_asset_proxy'; -export * from '../generated-wrappers/i_asset_proxy_dispatcher'; -export * from '../generated-wrappers/i_e_i_p1271_data'; -export * from '../generated-wrappers/i_e_i_p1271_wallet'; export * from '../generated-wrappers/i_exchange'; -export * from '../generated-wrappers/i_exchange_core'; -export * from '../generated-wrappers/i_match_orders'; -export * from '../generated-wrappers/i_protocol_fees'; -export * from '../generated-wrappers/i_signature_validator'; -export * from '../generated-wrappers/i_transactions'; -export * from '../generated-wrappers/i_transfer_simulator'; -export * from '../generated-wrappers/i_wallet'; -export * from '../generated-wrappers/i_wrapper_functions'; -export * from '../generated-wrappers/isolated_exchange'; -export * from '../generated-wrappers/lib_exchange_rich_error_decoder'; -export * from '../generated-wrappers/mixin_asset_proxy_dispatcher'; -export * from '../generated-wrappers/mixin_exchange_core'; -export * from '../generated-wrappers/mixin_match_orders'; -export * from '../generated-wrappers/mixin_protocol_fees'; -export * from '../generated-wrappers/mixin_signature_validator'; -export * from '../generated-wrappers/mixin_transactions'; -export * from '../generated-wrappers/mixin_transfer_simulator'; -export * from '../generated-wrappers/mixin_wrapper_functions'; -export * from '../generated-wrappers/reentrancy_tester'; -export * from '../generated-wrappers/test_asset_proxy_dispatcher'; -export * from '../generated-wrappers/test_exchange_internals'; -export * from '../generated-wrappers/test_lib_exchange_rich_error_decoder'; -export * from '../generated-wrappers/test_protocol_fee_collector'; -export * from '../generated-wrappers/test_protocol_fees'; -export * from '../generated-wrappers/test_protocol_fees_receiver'; -export * from '../generated-wrappers/test_signature_validator'; -export * from '../generated-wrappers/test_transactions'; -export * from '../generated-wrappers/test_validator_wallet'; -export * from '../generated-wrappers/test_wrapper_functions'; diff --git a/contracts/exchange/test/artifacts.ts b/contracts/exchange/test/artifacts.ts new file mode 100644 index 0000000000..8eb424b93b --- /dev/null +++ b/contracts/exchange/test/artifacts.ts @@ -0,0 +1,79 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +import { ContractArtifact } from 'ethereum-types'; + +import * as Exchange from '../test/generated-artifacts/Exchange.json'; +import * as IAssetProxy from '../test/generated-artifacts/IAssetProxy.json'; +import * as IAssetProxyDispatcher from '../test/generated-artifacts/IAssetProxyDispatcher.json'; +import * as IEIP1271Data from '../test/generated-artifacts/IEIP1271Data.json'; +import * as IEIP1271Wallet from '../test/generated-artifacts/IEIP1271Wallet.json'; +import * as IExchange from '../test/generated-artifacts/IExchange.json'; +import * as IExchangeCore from '../test/generated-artifacts/IExchangeCore.json'; +import * as IMatchOrders from '../test/generated-artifacts/IMatchOrders.json'; +import * as IProtocolFees from '../test/generated-artifacts/IProtocolFees.json'; +import * as ISignatureValidator from '../test/generated-artifacts/ISignatureValidator.json'; +import * as IsolatedExchange from '../test/generated-artifacts/IsolatedExchange.json'; +import * as ITransactions from '../test/generated-artifacts/ITransactions.json'; +import * as ITransferSimulator from '../test/generated-artifacts/ITransferSimulator.json'; +import * as IWallet from '../test/generated-artifacts/IWallet.json'; +import * as IWrapperFunctions from '../test/generated-artifacts/IWrapperFunctions.json'; +import * as LibExchangeRichErrorDecoder from '../test/generated-artifacts/LibExchangeRichErrorDecoder.json'; +import * as MixinAssetProxyDispatcher from '../test/generated-artifacts/MixinAssetProxyDispatcher.json'; +import * as MixinExchangeCore from '../test/generated-artifacts/MixinExchangeCore.json'; +import * as MixinMatchOrders from '../test/generated-artifacts/MixinMatchOrders.json'; +import * as MixinProtocolFees from '../test/generated-artifacts/MixinProtocolFees.json'; +import * as MixinSignatureValidator from '../test/generated-artifacts/MixinSignatureValidator.json'; +import * as MixinTransactions from '../test/generated-artifacts/MixinTransactions.json'; +import * as MixinTransferSimulator from '../test/generated-artifacts/MixinTransferSimulator.json'; +import * as MixinWrapperFunctions from '../test/generated-artifacts/MixinWrapperFunctions.json'; +import * as ReentrancyTester from '../test/generated-artifacts/ReentrancyTester.json'; +import * as TestAssetProxyDispatcher from '../test/generated-artifacts/TestAssetProxyDispatcher.json'; +import * as TestExchangeInternals from '../test/generated-artifacts/TestExchangeInternals.json'; +import * as TestLibExchangeRichErrorDecoder from '../test/generated-artifacts/TestLibExchangeRichErrorDecoder.json'; +import * as TestProtocolFeeCollector from '../test/generated-artifacts/TestProtocolFeeCollector.json'; +import * as TestProtocolFees from '../test/generated-artifacts/TestProtocolFees.json'; +import * as TestProtocolFeesReceiver from '../test/generated-artifacts/TestProtocolFeesReceiver.json'; +import * as TestSignatureValidator from '../test/generated-artifacts/TestSignatureValidator.json'; +import * as TestTransactions from '../test/generated-artifacts/TestTransactions.json'; +import * as TestValidatorWallet from '../test/generated-artifacts/TestValidatorWallet.json'; +import * as TestWrapperFunctions from '../test/generated-artifacts/TestWrapperFunctions.json'; +export const artifacts = { + Exchange: Exchange as ContractArtifact, + MixinAssetProxyDispatcher: MixinAssetProxyDispatcher as ContractArtifact, + MixinExchangeCore: MixinExchangeCore as ContractArtifact, + MixinMatchOrders: MixinMatchOrders as ContractArtifact, + MixinProtocolFees: MixinProtocolFees as ContractArtifact, + MixinSignatureValidator: MixinSignatureValidator as ContractArtifact, + MixinTransactions: MixinTransactions as ContractArtifact, + MixinTransferSimulator: MixinTransferSimulator as ContractArtifact, + MixinWrapperFunctions: MixinWrapperFunctions as ContractArtifact, + IAssetProxy: IAssetProxy as ContractArtifact, + IAssetProxyDispatcher: IAssetProxyDispatcher as ContractArtifact, + IEIP1271Data: IEIP1271Data as ContractArtifact, + IEIP1271Wallet: IEIP1271Wallet as ContractArtifact, + IExchange: IExchange as ContractArtifact, + IExchangeCore: IExchangeCore as ContractArtifact, + IMatchOrders: IMatchOrders as ContractArtifact, + IProtocolFees: IProtocolFees as ContractArtifact, + ISignatureValidator: ISignatureValidator as ContractArtifact, + ITransactions: ITransactions as ContractArtifact, + ITransferSimulator: ITransferSimulator as ContractArtifact, + IWallet: IWallet as ContractArtifact, + IWrapperFunctions: IWrapperFunctions as ContractArtifact, + LibExchangeRichErrorDecoder: LibExchangeRichErrorDecoder as ContractArtifact, + IsolatedExchange: IsolatedExchange as ContractArtifact, + ReentrancyTester: ReentrancyTester as ContractArtifact, + TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact, + TestExchangeInternals: TestExchangeInternals as ContractArtifact, + TestLibExchangeRichErrorDecoder: TestLibExchangeRichErrorDecoder as ContractArtifact, + TestProtocolFeeCollector: TestProtocolFeeCollector as ContractArtifact, + TestProtocolFees: TestProtocolFees as ContractArtifact, + TestProtocolFeesReceiver: TestProtocolFeesReceiver as ContractArtifact, + TestSignatureValidator: TestSignatureValidator as ContractArtifact, + TestTransactions: TestTransactions as ContractArtifact, + TestValidatorWallet: TestValidatorWallet as ContractArtifact, + TestWrapperFunctions: TestWrapperFunctions as ContractArtifact, +}; diff --git a/contracts/exchange/test/wrappers.ts b/contracts/exchange/test/wrappers.ts new file mode 100644 index 0000000000..7daa712abe --- /dev/null +++ b/contracts/exchange/test/wrappers.ts @@ -0,0 +1,40 @@ +/* + * ----------------------------------------------------------------------------- + * Warning: This file is auto-generated by contracts-gen. Don't edit manually. + * ----------------------------------------------------------------------------- + */ +export * from '../test/generated-wrappers/exchange'; +export * from '../test/generated-wrappers/i_asset_proxy'; +export * from '../test/generated-wrappers/i_asset_proxy_dispatcher'; +export * from '../test/generated-wrappers/i_e_i_p1271_data'; +export * from '../test/generated-wrappers/i_e_i_p1271_wallet'; +export * from '../test/generated-wrappers/i_exchange'; +export * from '../test/generated-wrappers/i_exchange_core'; +export * from '../test/generated-wrappers/i_match_orders'; +export * from '../test/generated-wrappers/i_protocol_fees'; +export * from '../test/generated-wrappers/i_signature_validator'; +export * from '../test/generated-wrappers/i_transactions'; +export * from '../test/generated-wrappers/i_transfer_simulator'; +export * from '../test/generated-wrappers/i_wallet'; +export * from '../test/generated-wrappers/i_wrapper_functions'; +export * from '../test/generated-wrappers/isolated_exchange'; +export * from '../test/generated-wrappers/lib_exchange_rich_error_decoder'; +export * from '../test/generated-wrappers/mixin_asset_proxy_dispatcher'; +export * from '../test/generated-wrappers/mixin_exchange_core'; +export * from '../test/generated-wrappers/mixin_match_orders'; +export * from '../test/generated-wrappers/mixin_protocol_fees'; +export * from '../test/generated-wrappers/mixin_signature_validator'; +export * from '../test/generated-wrappers/mixin_transactions'; +export * from '../test/generated-wrappers/mixin_transfer_simulator'; +export * from '../test/generated-wrappers/mixin_wrapper_functions'; +export * from '../test/generated-wrappers/reentrancy_tester'; +export * from '../test/generated-wrappers/test_asset_proxy_dispatcher'; +export * from '../test/generated-wrappers/test_exchange_internals'; +export * from '../test/generated-wrappers/test_lib_exchange_rich_error_decoder'; +export * from '../test/generated-wrappers/test_protocol_fee_collector'; +export * from '../test/generated-wrappers/test_protocol_fees'; +export * from '../test/generated-wrappers/test_protocol_fees_receiver'; +export * from '../test/generated-wrappers/test_signature_validator'; +export * from '../test/generated-wrappers/test_transactions'; +export * from '../test/generated-wrappers/test_validator_wallet'; +export * from '../test/generated-wrappers/test_wrapper_functions'; diff --git a/contracts/exchange/tsconfig.json b/contracts/exchange/tsconfig.json index c38484f4d5..06fbc962d6 100644 --- a/contracts/exchange/tsconfig.json +++ b/contracts/exchange/tsconfig.json @@ -4,40 +4,42 @@ "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "files": [ "generated-artifacts/Exchange.json", - "generated-artifacts/IAssetProxy.json", - "generated-artifacts/IAssetProxyDispatcher.json", - "generated-artifacts/IEIP1271Data.json", - "generated-artifacts/IEIP1271Wallet.json", "generated-artifacts/IExchange.json", - "generated-artifacts/IExchangeCore.json", - "generated-artifacts/IMatchOrders.json", - "generated-artifacts/IProtocolFees.json", - "generated-artifacts/ISignatureValidator.json", - "generated-artifacts/ITransactions.json", - "generated-artifacts/ITransferSimulator.json", - "generated-artifacts/IWallet.json", - "generated-artifacts/IWrapperFunctions.json", - "generated-artifacts/IsolatedExchange.json", - "generated-artifacts/LibExchangeRichErrorDecoder.json", - "generated-artifacts/MixinAssetProxyDispatcher.json", - "generated-artifacts/MixinExchangeCore.json", - "generated-artifacts/MixinMatchOrders.json", - "generated-artifacts/MixinProtocolFees.json", - "generated-artifacts/MixinSignatureValidator.json", - "generated-artifacts/MixinTransactions.json", - "generated-artifacts/MixinTransferSimulator.json", - "generated-artifacts/MixinWrapperFunctions.json", - "generated-artifacts/ReentrancyTester.json", - "generated-artifacts/TestAssetProxyDispatcher.json", - "generated-artifacts/TestExchangeInternals.json", - "generated-artifacts/TestLibExchangeRichErrorDecoder.json", - "generated-artifacts/TestProtocolFeeCollector.json", - "generated-artifacts/TestProtocolFees.json", - "generated-artifacts/TestProtocolFeesReceiver.json", - "generated-artifacts/TestSignatureValidator.json", - "generated-artifacts/TestTransactions.json", - "generated-artifacts/TestValidatorWallet.json", - "generated-artifacts/TestWrapperFunctions.json" + "test/generated-artifacts/Exchange.json", + "test/generated-artifacts/IAssetProxy.json", + "test/generated-artifacts/IAssetProxyDispatcher.json", + "test/generated-artifacts/IEIP1271Data.json", + "test/generated-artifacts/IEIP1271Wallet.json", + "test/generated-artifacts/IExchange.json", + "test/generated-artifacts/IExchangeCore.json", + "test/generated-artifacts/IMatchOrders.json", + "test/generated-artifacts/IProtocolFees.json", + "test/generated-artifacts/ISignatureValidator.json", + "test/generated-artifacts/ITransactions.json", + "test/generated-artifacts/ITransferSimulator.json", + "test/generated-artifacts/IWallet.json", + "test/generated-artifacts/IWrapperFunctions.json", + "test/generated-artifacts/IsolatedExchange.json", + "test/generated-artifacts/LibExchangeRichErrorDecoder.json", + "test/generated-artifacts/MixinAssetProxyDispatcher.json", + "test/generated-artifacts/MixinExchangeCore.json", + "test/generated-artifacts/MixinMatchOrders.json", + "test/generated-artifacts/MixinProtocolFees.json", + "test/generated-artifacts/MixinSignatureValidator.json", + "test/generated-artifacts/MixinTransactions.json", + "test/generated-artifacts/MixinTransferSimulator.json", + "test/generated-artifacts/MixinWrapperFunctions.json", + "test/generated-artifacts/ReentrancyTester.json", + "test/generated-artifacts/TestAssetProxyDispatcher.json", + "test/generated-artifacts/TestExchangeInternals.json", + "test/generated-artifacts/TestLibExchangeRichErrorDecoder.json", + "test/generated-artifacts/TestProtocolFeeCollector.json", + "test/generated-artifacts/TestProtocolFees.json", + "test/generated-artifacts/TestProtocolFeesReceiver.json", + "test/generated-artifacts/TestSignatureValidator.json", + "test/generated-artifacts/TestTransactions.json", + "test/generated-artifacts/TestValidatorWallet.json", + "test/generated-artifacts/TestWrapperFunctions.json" ], "exclude": ["./deploy/solc/solc_bin"] } diff --git a/packages/contracts-gen/src/contracts-gen.ts b/packages/contracts-gen/src/contracts-gen.ts index c5fb4be505..7cf87ff428 100644 --- a/packages/contracts-gen/src/contracts-gen.ts +++ b/packages/contracts-gen/src/contracts-gen.ts @@ -12,9 +12,13 @@ import * as prettier from 'prettier'; import toSnakeCase = require('to-snake-case'); const SOLIDITY_EXTENSION = '.sol'; -const DEFAULT_ARTIFACTS_DIR = 'artifacts'; +const DEFAULT_ARTIFACTS_DIR = 'test/artifacts'; const DEFAULT_CONTRACTS_DIR = 'contracts'; -const DEFAULT_WRAPPERS_DIR = 'generated-wrappers'; +const DEFAULT_WRAPPERS_DIR = 'test/generated-wrappers'; +const SRC_ARTIFACTS_TS_FILE_PATH = 'src/artifacts.ts'; +const TEST_ARTIFACTS_TS_FILE_PATH = 'test/artifacts.ts'; +const SRC_WRAPPERS_TS_FILE_PATH = 'src/wrappers.ts'; +const TEST_WRAPPERS_TS_FILE_PATH = 'test/wrappers.ts'; const AUTO_GENERATED_BANNER = `/* * ----------------------------------------------------------------------------- * Warning: This file is auto-generated by contracts-gen. Don't edit manually. @@ -27,25 +31,52 @@ const ALL_CONTRACTS_IDENTIFIER = '*'; const packageDir = process.cwd(); const compilerJSON = readJSONFile('compiler.json'); const compiler = new Compiler(compilerJSON); - const contracts = compiler.getContractNamesToCompile(); - const contractsDir = compilerJSON.contractsDir || DEFAULT_CONTRACTS_DIR; - const artifactsDir = compilerJSON.artifactsDir || DEFAULT_ARTIFACTS_DIR; - const wrappersDir = DEFAULT_WRAPPERS_DIR; - if (!_.isArray(contracts)) { + const testContracts = compiler.getContractNamesToCompile(); + if (!_.isArray(testContracts)) { throw new Error('Unable to run the generator bacause contracts key in compiler.json is not of type array'); } + const packageJSON = readJSONFile('package.json'); + let srcContracts = testContracts; + if (packageJSON.config !== undefined && packageJSON.config !== undefined) { + srcContracts = (packageJSON.config as any).whitelistedContracts.split(','); + } + const testContractsDir = compilerJSON.contractsDir || DEFAULT_CONTRACTS_DIR; + const testArtifactsDir = compilerJSON.artifactsDir || DEFAULT_ARTIFACTS_DIR; + const testWrappersDir = DEFAULT_WRAPPERS_DIR; const prettierConfig = await prettier.resolveConfig(packageDir); - generateCompilerJSONContractsList(contracts, contractsDir, prettierConfig); - generateArtifactsTs(contracts, artifactsDir, prettierConfig); - generateWrappersTs(contracts, wrappersDir, prettierConfig); - generateTsConfigJSONFilesList(contracts, artifactsDir, prettierConfig); - generatePackageJSONABIConfig(contracts, artifactsDir, prettierConfig); + generateCompilerJSONContractsList(testContracts, testContractsDir, prettierConfig); + generateArtifactsTs(testContracts, testArtifactsDir, TEST_ARTIFACTS_TS_FILE_PATH, prettierConfig); + const srcArtifactsDir = convertToTopLevelDir('testArtifactsDir', testArtifactsDir); + generateArtifactsTs(srcContracts, srcArtifactsDir, SRC_ARTIFACTS_TS_FILE_PATH, prettierConfig); + const srcWrappersDir = convertToTopLevelDir('testWrappersDir', testWrappersDir); + generateWrappersTs(testContracts, testWrappersDir, TEST_WRAPPERS_TS_FILE_PATH, prettierConfig); + generateWrappersTs(srcContracts, srcWrappersDir, SRC_WRAPPERS_TS_FILE_PATH, prettierConfig); + generateTsConfigJSONFilesList(testContracts, testArtifactsDir, srcContracts, srcArtifactsDir, prettierConfig); + generatePackageJSONABIConfig(testContracts, 'test-abis', testArtifactsDir, prettierConfig); + generatePackageJSONABIConfig(srcContracts, 'src-abis', srcArtifactsDir, prettierConfig); process.exit(0); })().catch(err => { logUtils.log(err); process.exit(1); }); +function convertToTopLevelDir(name: string, aPath: string): string { + let finalPath = aPath; + const hasDotPrefix = aPath.startsWith('./'); + if (hasDotPrefix) { + finalPath = aPath.substr(2); + } + const segments = finalPath.split('/'); + if (segments.length === 0) { + throw new Error(`Cannot have empty path for ${name}`); + } + if (segments.length === 1) { + return aPath; + } + segments.shift(); + return `${hasDotPrefix ? './' : ''}${segments.join('/')}`; +} + function generateCompilerJSONContractsList( contracts: string[], contractsDir: string, @@ -73,7 +104,7 @@ function generateCompilerJSONContractsList( fs.writeFileSync(COMPILER_JSON_FILE_PATH, formattedCompilerJSON); } -function generateArtifactsTs(contracts: string[], artifactsDir: string, prettierConfig: prettier.Options | null): void { +function generateArtifactsTs(contracts: string[], artifactsDir: string, artifactsTsFilePath: string, prettierConfig: prettier.Options | null): void { const imports = _.map(contracts, contract => { const contractName = path.basename(contract, SOLIDITY_EXTENSION); const importPath = path.join('..', artifactsDir, `${contractName}.json`); @@ -97,12 +128,11 @@ function generateArtifactsTs(contracts: string[], artifactsDir: string, prettier ${sortedImports.join('\n')} export const artifacts = {${artifacts.join('\n')}}; `; - const ARTIFACTS_TS_FILE_PATH = 'src/artifacts.ts'; - const formattedArtifactsTs = prettier.format(artifactsTs, { ...prettierConfig, filepath: ARTIFACTS_TS_FILE_PATH }); - fs.writeFileSync(ARTIFACTS_TS_FILE_PATH, formattedArtifactsTs); + const formattedArtifactsTs = prettier.format(artifactsTs, { ...prettierConfig, filepath: artifactsTsFilePath }); + fs.writeFileSync(artifactsTsFilePath, formattedArtifactsTs); } -function generateWrappersTs(contracts: string[], wrappersDir: string, prettierConfig: prettier.Options | null): void { +function generateWrappersTs(contracts: string[], wrappersDir: string, wrappersTsFilePath: string, prettierConfig: prettier.Options | null): void { const imports = _.map(contracts, contract => { const contractName = path.basename(contract, SOLIDITY_EXTENSION); const outputFileName = makeOutputFileName(contractName); @@ -114,23 +144,30 @@ function generateWrappersTs(contracts: string[], wrappersDir: string, prettierCo ${AUTO_GENERATED_BANNER} ${sortedImports.join('\n')} `; - const WRAPPERS_TS_FILE_PATH = 'src/wrappers.ts'; - const formattedArtifactsTs = prettier.format(wrappersTs, { ...prettierConfig, filepath: WRAPPERS_TS_FILE_PATH }); - fs.writeFileSync(WRAPPERS_TS_FILE_PATH, formattedArtifactsTs); + const formattedArtifactsTs = prettier.format(wrappersTs, { ...prettierConfig, filepath: wrappersTsFilePath }); + fs.writeFileSync(wrappersTsFilePath, formattedArtifactsTs); } function generateTsConfigJSONFilesList( - contracts: string[], - artifactsDir: string, + testContracts: string[], + testArtifactsDir: string, + srcContracts: string[], + srcArtifactsDir: string, prettierConfig: prettier.Options | null, ): void { const TS_CONFIG_FILE_PATH = 'tsconfig.json'; const tsConfig = readJSONFile(TS_CONFIG_FILE_PATH); - tsConfig.files = _.map(contracts, contract => { + const testFiles = _.map(testContracts, contract => { const contractName = path.basename(contract, SOLIDITY_EXTENSION); - const artifactPath = path.join(artifactsDir, `${contractName}.json`); + const artifactPath = path.join(testArtifactsDir, `${contractName}.json`); return artifactPath; }); + const srcFiles = _.map(srcContracts, contract => { + const contractName = path.basename(contract, SOLIDITY_EXTENSION); + const artifactPath = path.join(srcArtifactsDir, `${contractName}.json`); + return artifactPath; + }); + tsConfig.files = [...testFiles, ...srcFiles]; tsConfig.files = _.sortBy(tsConfig.files); const tsConfigString = JSON.stringify(tsConfig); const formattedTsConfig = prettier.format(tsConfigString, { ...prettierConfig, filepath: TS_CONFIG_FILE_PATH }); @@ -139,6 +176,7 @@ function generateTsConfigJSONFilesList( function generatePackageJSONABIConfig( contracts: string[], + configName: string, artifactsDir: string, prettierConfig: prettier.Options | null, ): void { @@ -152,8 +190,8 @@ function generatePackageJSONABIConfig( ...packageJSON, config: { ...packageJSON.config, - 'abis:comment': AUTO_GENERATED_BANNER_FOR_LISTS, - abis: `${artifactsDir}/@(${sortedContractNames.join('|')}).json`, + [`${configName}:comment`]: AUTO_GENERATED_BANNER_FOR_LISTS, + [configName]: `${artifactsDir}/@(${sortedContractNames.join('|')}).json`, }, }; const PACKAGE_JSON_FILE_PATH = 'package.json';