diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2018-07-23 23:00:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-23 23:00:06 +0800 |
commit | 554b18a466d5cc65271daa61aba96138ce7408f0 (patch) | |
tree | 75976e979b713fb47c9462f1a3bc30a184cc568c | |
parent | 855b6b1dc5597f360451232ff6dfc91beb3a9f50 (diff) | |
parent | c2ae9f62a41466c714a5e2232782d08261464b9c (diff) | |
download | dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.tar dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.tar.gz dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.tar.bz2 dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.tar.lz dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.tar.xz dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.tar.zst dexon-sol-tools-554b18a466d5cc65271daa61aba96138ce7408f0.zip |
Merge pull request #906 from 0xProject/refactor/contracts/examples
[contracts] Add `examples` directory
14 files changed, 124 insertions, 26 deletions
diff --git a/packages/contracts/compiler.json b/packages/contracts/compiler.json index 2a7f8bbb9..dba836bde 100644 --- a/packages/contracts/compiler.json +++ b/packages/contracts/compiler.json @@ -39,12 +39,13 @@ "MultiSigWalletWithTimeLock", "TestAssetProxyOwner", "TestAssetProxyDispatcher", + "TestConstants", "TestLibBytes", "TestLibs", "TestSignatureValidator", - "TestValidator", - "TestWallet", "TokenRegistry", + "Validator", + "Wallet", "Whitelist", "WETH9", "ZRXToken" diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 066f9b41a..d42e11813 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -20,11 +20,14 @@ "test:coverage": "SOLIDITY_COVERAGE=true run-s build run_mocha coverage:report:text coverage:report:lcov", "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", + "run_mocha": + "mocha --require source-map-support/register --require make-promises-safe 'lib/test/**/*.js' --timeout 100000 --bail --exit", "compile": "sol-compiler --contracts-dir src", "clean": "shx rm -rf lib generated_contract_wrappers", - "generate_contract_wrappers": "abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output generated_contract_wrappers --backend ethers", - "lint": "tslint --project . --exclude **/src/generated_contract_wrappers/**/* --exclude **/lib/**/* && yarn lint-contracts", + "generate_contract_wrappers": + "abi-gen --abis ${npm_package_config_abis} --template ../contract_templates/contract.handlebars --partials '../contract_templates/partials/**/*.handlebars' --output generated_contract_wrappers --backend ethers", + "lint": + "tslint --project . --exclude **/src/generated_contract_wrappers/**/* --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", @@ -33,7 +36,8 @@ "lint-contracts": "solhint src/2.0.0/**/**/**/**/*.sol" }, "config": { - "abis": "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyOwner|TestAssetProxyDispatcher|TestLibBytes|TestLibs|TestSignatureValidator|TestValidator|TestWallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json" + "abis": + "../migrations/artifacts/2.0.0/@(AssetProxyOwner|DummyERC20Token|DummyERC721Receiver|DummyERC721Token|ERC20Proxy|ERC721Proxy|Forwarder|Exchange|ExchangeWrapper|IAssetData|IAssetProxy|MixinAuthorizable|MultiSigWallet|MultiSigWalletWithTimeLock|TestAssetProxyOwner|TestAssetProxyDispatcher|TestConstants|TestLibBytes|TestLibs|TestSignatureValidator|Validator|Wallet|TokenRegistry|Whitelist|WETH9|ZRXToken).json" }, "repository": { "type": "git", diff --git a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol b/packages/contracts/src/2.0.0/examples/ExchangeWrapper/ExchangeWrapper.sol index 2fa0e3c5e..2fa0e3c5e 100644 --- a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol +++ b/packages/contracts/src/2.0.0/examples/ExchangeWrapper/ExchangeWrapper.sol diff --git a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol b/packages/contracts/src/2.0.0/examples/Validator/Validator.sol index 6278aede0..72ed528ba 100644 --- a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol +++ b/packages/contracts/src/2.0.0/examples/Validator/Validator.sol @@ -21,7 +21,7 @@ pragma solidity 0.4.24; import "../../protocol/Exchange/interfaces/IValidator.sol"; -contract TestValidator is +contract Validator is IValidator { @@ -29,7 +29,7 @@ contract TestValidator is // solhint-disable-next-line var-name-mixedcase address internal VALID_SIGNER; - /// @dev constructs a new `TestValidator` with a single valid signer. + /// @dev constructs a new `Validator` with a single valid signer. /// @param validSigner The sole, valid signer. constructor (address validSigner) public { VALID_SIGNER = validSigner; diff --git a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol b/packages/contracts/src/2.0.0/examples/Wallet/Wallet.sol index 0415823e3..b75021a31 100644 --- a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol +++ b/packages/contracts/src/2.0.0/examples/Wallet/Wallet.sol @@ -22,7 +22,7 @@ import "../../protocol/Exchange/interfaces/IWallet.sol"; import "../../utils/LibBytes/LibBytes.sol"; -contract TestWallet is +contract Wallet is IWallet { using LibBytes for bytes; @@ -31,7 +31,7 @@ contract TestWallet is // solhint-disable-next-line var-name-mixedcase address internal WALLET_OWNER; - /// @dev constructs a new `TestWallet` with a single owner. + /// @dev constructs a new `Wallet` with a single owner. /// @param walletOwner The owner of this wallet. constructor (address walletOwner) public { WALLET_OWNER = walletOwner; diff --git a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol b/packages/contracts/src/2.0.0/examples/Whitelist/Whitelist.sol index 60cac26ea..60cac26ea 100644 --- a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol +++ b/packages/contracts/src/2.0.0/examples/Whitelist/Whitelist.sol diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol b/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol index 53f5a14e0..6a70c9f60 100644 --- a/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol +++ b/packages/contracts/src/2.0.0/protocol/AssetProxy/ERC721Proxy.sol @@ -93,7 +93,7 @@ contract ERC721Proxy is // | | 4 | 12 + 20 | 1. token address | // | | 36 | | 2. tokenId | - // We construct calldata for the `token.safeTransferFrom` ABI. + // We construct calldata for the `token.transferFrom` ABI. // The layout of this calldata is in the table below. // // | Area | Offset | Length | Contents | @@ -116,7 +116,7 @@ contract ERC721Proxy is } /////// Setup Header Area /////// - // This area holds the 4-byte `transferFromSelector`. + // This area holds the 4-byte `transferFrom` selector. // Any trailing data in transferFromSelector will be // overwritten in the next `mstore` call. mstore(0, 0x23b872dd00000000000000000000000000000000000000000000000000000000) diff --git a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol index 6918d755e..8d2732cd3 100644 --- a/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol +++ b/packages/contracts/src/2.0.0/protocol/Exchange/libs/LibConstants.sol @@ -19,11 +19,23 @@ pragma solidity 0.4.24; +// solhint-disable max-line-length contract LibConstants { // Asset data for ZRX token. Used for fee transfers. // @TODO: Hardcode constant when we deploy. Currently // not constant to make testing easier. + + // The proxyId for ZRX_ASSET_DATA is bytes4(keccak256("ERC20Token(address)")) = 0xf47261b0 + + // Kovan ZRX address is 0x6ff6c0ff1d68b964901f986d4c9fa3ac68346570. + // The ABI encoded proxyId and address is 0xf47261b00000000000000000000000006ff6c0ff1d68b964901f986d4c9fa3ac68346570 + // bytes constant public ZRX_ASSET_DATA = "\xf4\x72\x61\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6f\xf6\xc0\xff\x1d\x68\xb9\x64\x90\x1f\x98\x6d\x4c\x9f\xa3\xac\x68\x34\x65\x70"; + + // Mainnet ZRX address is 0xe41d2489571d322189246dafa5ebde1f4699f498. + // The ABI encoded proxyId and address is 0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498 + // bytes constant public ZRX_ASSET_DATA = "\xf4\x72\x61\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe4\x1d\x24\x89\x57\x1d\x32\x21\x89\x24\x6d\xaf\xa5\xeb\xde\x1f\x46\x99\xf4\x98"; + // solhint-disable-next-line var-name-mixedcase bytes public ZRX_ASSET_DATA; @@ -34,3 +46,4 @@ contract LibConstants { ZRX_ASSET_DATA = zrxAssetData; } } +// solhint-enable max-line-length diff --git a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol index 97801166a..9272b18a8 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol @@ -22,7 +22,10 @@ import "../Mintable/Mintable.sol"; import "../../utils/Ownable/Ownable.sol"; -contract DummyERC20Token is Mintable, Ownable { +contract DummyERC20Token is + Mintable, + Ownable +{ string public name; string public symbol; uint256 public decimals; diff --git a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol index 07986f4bb..ad71fc9a1 100644 --- a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol +++ b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol @@ -21,7 +21,9 @@ pragma solidity 0.4.24; import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol"; -contract TestAssetProxyDispatcher is MixinAssetProxyDispatcher { +contract TestAssetProxyDispatcher is + MixinAssetProxyDispatcher +{ function publicDispatchTransferFrom( bytes memory assetData, address from, diff --git a/packages/contracts/src/2.0.0/test/TestConstants/TestConstants.sol b/packages/contracts/src/2.0.0/test/TestConstants/TestConstants.sol new file mode 100644 index 000000000..1275d007b --- /dev/null +++ b/packages/contracts/src/2.0.0/test/TestConstants/TestConstants.sol @@ -0,0 +1,57 @@ +/* + + Copyright 2018 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.4.24; + +import "../../utils/LibBytes/LibBytes.sol"; + + +// solhint-disable max-line-length +contract TestConstants { + + using LibBytes for bytes; + + bytes4 constant internal ERC20_PROXY_ID = bytes4(keccak256("ERC20Token(address)")); + + address constant internal KOVAN_ZRX_ADDRESS = 0x6Ff6C0Ff1d68b964901F986d4C9FA3ac68346570; + bytes constant internal KOVAN_ZRX_ASSET_DATA = "\xf4\x72\x61\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x6f\xf6\xc0\xff\x1d\x68\xb9\x64\x90\x1f\x98\x6d\x4c\x9f\xa3\xac\x68\x34\x65\x70"; + + address constant internal MAINNET_ZRX_ADDRESS = 0xE41d2489571d322189246DaFA5ebDe1F4699F498; + bytes constant public MAINNET_ZRX_ASSET_DATA = "\xf4\x72\x61\xb0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe4\x1d\x24\x89\x57\x1d\x32\x21\x89\x24\x6d\xaf\xa5\xeb\xde\x1f\x46\x99\xf4\x98"; + + function assertValidZrxAssetData() + public + pure + returns (bool) + { + bytes memory kovanZrxAssetData = abi.encodeWithSelector(ERC20_PROXY_ID, KOVAN_ZRX_ADDRESS); + require( + kovanZrxAssetData.equals(KOVAN_ZRX_ASSET_DATA), + "INVALID_KOVAN_ZRX_ASSET_DATA" + ); + + bytes memory mainetZrxAssetData = abi.encodeWithSelector(ERC20_PROXY_ID, MAINNET_ZRX_ADDRESS); + require( + mainetZrxAssetData.equals(MAINNET_ZRX_ASSET_DATA), + "INVALID_MAINNET_ZRX_ASSET_DATA" + ); + + return true; + } +} +// solhint-enable max-line-length
\ No newline at end of file diff --git a/packages/contracts/test/exchange/libs.ts b/packages/contracts/test/exchange/libs.ts index 2e95fa96c..51794d8a3 100644 --- a/packages/contracts/test/exchange/libs.ts +++ b/packages/contracts/test/exchange/libs.ts @@ -4,6 +4,7 @@ import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as chai from 'chai'; +import { TestConstantsContract } from '../../generated_contract_wrappers/test_constants'; import { TestLibsContract } from '../../generated_contract_wrappers/test_libs'; import { addressUtils } from '../utils/address_utils'; import { artifacts } from '../utils/artifacts'; @@ -21,6 +22,7 @@ describe('Exchange libs', () => { let signedOrder: SignedOrder; let orderFactory: OrderFactory; let libs: TestLibsContract; + let testConstants: TestConstantsContract; before(async () => { await blockchainLifecycle.startAsync(); @@ -32,6 +34,11 @@ describe('Exchange libs', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); const makerAddress = accounts[0]; libs = await TestLibsContract.deployFrom0xArtifactAsync(artifacts.TestLibs, provider, txDefaults); + testConstants = await TestConstantsContract.deployFrom0xArtifactAsync( + artifacts.TestConstants, + provider, + txDefaults, + ); const defaultOrderParams = { ...constants.STATIC_ORDER_PARAMS, @@ -52,6 +59,15 @@ describe('Exchange libs', () => { await blockchainLifecycle.revertAsync(); }); + describe('LibConstants', () => { + describe('ZRX_ASSET_DATA', () => { + it('should have the correct ZRX_ASSET_DATA', async () => { + const isValid = await testConstants.assertValidZrxAssetData.callAsync(); + expect(isValid).to.be.equal(true); + }); + }); + }); + describe('LibOrder', () => { describe('getOrderSchema', () => { it('should output the correct order schema hash', async () => { diff --git a/packages/contracts/test/exchange/signature_validator.ts b/packages/contracts/test/exchange/signature_validator.ts index ef154bf9b..f2bb42c75 100644 --- a/packages/contracts/test/exchange/signature_validator.ts +++ b/packages/contracts/test/exchange/signature_validator.ts @@ -9,8 +9,8 @@ import { TestSignatureValidatorContract, TestSignatureValidatorSignatureValidatorApprovalEventArgs, } from '../../generated_contract_wrappers/test_signature_validator'; -import { TestValidatorContract } from '../../generated_contract_wrappers/test_validator'; -import { TestWalletContract } from '../../generated_contract_wrappers/test_wallet'; +import { ValidatorContract } from '../../generated_contract_wrappers/validator'; +import { WalletContract } from '../../generated_contract_wrappers/wallet'; import { addressUtils } from '../utils/address_utils'; import { artifacts } from '../utils/artifacts'; import { expectContractCallFailed } from '../utils/assertions'; @@ -29,8 +29,8 @@ describe('MixinSignatureValidator', () => { let signedOrder: SignedOrder; let orderFactory: OrderFactory; let signatureValidator: TestSignatureValidatorContract; - let testWallet: TestWalletContract; - let testValidator: TestValidatorContract; + let testWallet: WalletContract; + let testValidator: ValidatorContract; let signerAddress: string; let signerPrivateKey: Buffer; let notSignerAddress: string; @@ -53,14 +53,14 @@ describe('MixinSignatureValidator', () => { provider, txDefaults, ); - testWallet = await TestWalletContract.deployFrom0xArtifactAsync( - artifacts.TestWallet, + testWallet = await WalletContract.deployFrom0xArtifactAsync( + artifacts.Wallet, provider, txDefaults, signerAddress, ); - testValidator = await TestValidatorContract.deployFrom0xArtifactAsync( - artifacts.TestValidator, + testValidator = await ValidatorContract.deployFrom0xArtifactAsync( + artifacts.Validator, provider, txDefaults, signerAddress, diff --git a/packages/contracts/test/utils/artifacts.ts b/packages/contracts/test/utils/artifacts.ts index d3f808218..63bd555a4 100644 --- a/packages/contracts/test/utils/artifacts.ts +++ b/packages/contracts/test/utils/artifacts.ts @@ -15,12 +15,13 @@ import * as MultiSigWallet from '../../artifacts/MultiSigWallet.json'; import * as MultiSigWalletWithTimeLock from '../../artifacts/MultiSigWalletWithTimeLock.json'; import * as TestAssetProxyDispatcher from '../../artifacts/TestAssetProxyDispatcher.json'; import * as TestAssetProxyOwner from '../../artifacts/TestAssetProxyOwner.json'; +import * as TestConstants from '../../artifacts/TestConstants.json'; import * as TestLibBytes from '../../artifacts/TestLibBytes.json'; import * as TestLibs from '../../artifacts/TestLibs.json'; import * as TestSignatureValidator from '../../artifacts/TestSignatureValidator.json'; -import * as TestValidator from '../../artifacts/TestValidator.json'; -import * as TestWallet from '../../artifacts/TestWallet.json'; import * as TokenRegistry from '../../artifacts/TokenRegistry.json'; +import * as Validator from '../../artifacts/Validator.json'; +import * as Wallet from '../../artifacts/Wallet.json'; import * as EtherToken from '../../artifacts/WETH9.json'; import * as Whitelist from '../../artifacts/Whitelist.json'; import * as ZRX from '../../artifacts/ZRXToken.json'; @@ -42,11 +43,12 @@ export const artifacts = { MultiSigWalletWithTimeLock: (MultiSigWalletWithTimeLock as any) as ContractArtifact, TestAssetProxyOwner: (TestAssetProxyOwner as any) as ContractArtifact, TestAssetProxyDispatcher: (TestAssetProxyDispatcher as any) as ContractArtifact, + TestConstants: (TestConstants as any) as ContractArtifact, TestLibBytes: (TestLibBytes as any) as ContractArtifact, TestLibs: (TestLibs as any) as ContractArtifact, TestSignatureValidator: (TestSignatureValidator as any) as ContractArtifact, - TestValidator: (TestValidator as any) as ContractArtifact, - TestWallet: (TestWallet as any) as ContractArtifact, + Validator: (Validator as any) as ContractArtifact, + Wallet: (Wallet as any) as ContractArtifact, TokenRegistry: (TokenRegistry as any) as ContractArtifact, Whitelist: (Whitelist as any) as ContractArtifact, ZRX: (ZRX as any) as ContractArtifact, |