diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-07-10 02:08:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-10 02:08:28 +0800 |
commit | 4b60a3cbab3a97125499cb89d9c253deebfb7d2d (patch) | |
tree | 3cd745f49d55406e95453bf3efac6383fba5f038 /packages/contracts/src/2.0.0/test | |
parent | 9f08916cf18ad3e2686811933116122eea0890b9 (diff) | |
parent | 17956efe351e3ec0b1e9cdeee8292ebb0b4e563c (diff) | |
download | dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.gz dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.bz2 dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.lz dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.xz dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.tar.zst dexon-0x-contracts-4b60a3cbab3a97125499cb89d9c253deebfb7d2d.zip |
Merge branch 'v2-prototype' into abi-gen-ignore-unchanged
Diffstat (limited to 'packages/contracts/src/2.0.0/test')
13 files changed, 93 insertions, 92 deletions
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 7a2702449..97801166a 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC20Token/DummyERC20Token.sol @@ -16,8 +16,7 @@ */ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; +pragma solidity 0.4.24; import "../Mintable/Mintable.sol"; import "../../utils/Ownable/Ownable.sol"; diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol index b027ac960..5dce74a14 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC721Receiver/DummyERC721Receiver.sol @@ -23,7 +23,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; import "../../tokens/ERC721Token/IERC721Receiver.sol"; diff --git a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol index de76f10c5..627746a52 100644 --- a/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol +++ b/packages/contracts/src/2.0.0/test/DummyERC721Token/DummyERC721Token.sol @@ -16,13 +16,13 @@ */ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; +pragma solidity 0.4.24; import "../../tokens/ERC721Token/ERC721Token.sol"; import "../../utils/Ownable/Ownable.sol"; +// solhint-disable no-empty-blocks contract DummyERC721Token is Ownable, ERC721Token diff --git a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol b/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol index f20e2a944..2fa0e3c5e 100644 --- a/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol +++ b/packages/contracts/src/2.0.0/test/ExchangeWrapper/ExchangeWrapper.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; pragma experimental ABIEncoderV2; import "../../protocol/Exchange/interfaces/IExchange.sol"; @@ -27,7 +27,7 @@ contract ExchangeWrapper { // Exchange contract. // solhint-disable-next-line var-name-mixedcase - IExchange EXCHANGE; + IExchange internal EXCHANGE; constructor (address _exchange) public @@ -35,6 +35,35 @@ contract ExchangeWrapper { EXCHANGE = IExchange(_exchange); } + /// @dev Cancels all orders created by sender with a salt less than or equal to the targetOrderEpoch + /// and senderAddress equal to this contract. + /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled. + /// @param salt Arbitrary value to gaurantee uniqueness of 0x transaction hash. + /// @param makerSignature Proof that maker wishes to call this function with given params. + function cancelOrdersUpTo( + uint256 targetOrderEpoch, + uint256 salt, + bytes makerSignature + ) + external + { + address makerAddress = msg.sender; + + // Encode arguments into byte array. + bytes memory data = abi.encodeWithSelector( + EXCHANGE.cancelOrdersUpTo.selector, + targetOrderEpoch + ); + + // Call `cancelOrdersUpTo` via `executeTransaction`. + EXCHANGE.executeTransaction( + salt, + makerAddress, + data, + makerSignature + ); + } + /// @dev Fills an order using `msg.sender` as the taker. /// @param order Order struct containing order specifications. /// @param takerAssetFillAmount Desired amount of takerAsset to sell. @@ -68,33 +97,4 @@ contract ExchangeWrapper { takerSignature ); } - - /// @dev Cancels all orders created by sender with a salt less than or equal to the targetOrderEpoch - /// and senderAddress equal to this contract. - /// @param targetOrderEpoch Orders created with a salt less or equal to this value will be cancelled. - /// @param salt Arbitrary value to gaurantee uniqueness of 0x transaction hash. - /// @param makerSignature Proof that maker wishes to call this function with given params. - function cancelOrdersUpTo( - uint256 targetOrderEpoch, - uint256 salt, - bytes makerSignature - ) - external - { - address makerAddress = msg.sender; - - // Encode arguments into byte array. - bytes memory data = abi.encodeWithSelector( - EXCHANGE.cancelOrdersUpTo.selector, - targetOrderEpoch - ); - - // Call `cancelOrdersUpTo` via `executeTransaction`. - EXCHANGE.executeTransaction( - salt, - makerAddress, - data, - makerSignature - ); - } } diff --git a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol index bccb74ce8..767cc8d25 100644 --- a/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol +++ b/packages/contracts/src/2.0.0/test/Mintable/Mintable.sol @@ -16,8 +16,7 @@ */ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; +pragma solidity 0.4.24; import "../../tokens/UnlimitedAllowanceToken/UnlimitedAllowanceToken.sol"; import "../../utils/SafeMath/SafeMath.sol"; @@ -27,7 +26,10 @@ import "../../utils/SafeMath/SafeMath.sol"; * Mintable * Base contract that creates a mintable UnlimitedAllowanceToken */ -contract Mintable is UnlimitedAllowanceToken, SafeMath { +contract Mintable is + UnlimitedAllowanceToken, + SafeMath +{ function mint(uint256 _value) public { 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 be7fea7d3..07986f4bb 100644 --- a/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol +++ b/packages/contracts/src/2.0.0/test/TestAssetProxyDispatcher/TestAssetProxyDispatcher.sol @@ -16,8 +16,7 @@ */ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; +pragma solidity 0.4.24; import "../../protocol/Exchange/MixinAssetProxyDispatcher.sol"; @@ -27,7 +26,8 @@ contract TestAssetProxyDispatcher is MixinAssetProxyDispatcher { bytes memory assetData, address from, address to, - uint256 amount) + uint256 amount + ) public { dispatchTransferFrom(assetData, from, to, amount); diff --git a/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol b/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol index ddcc62f35..d6b6b29f2 100644 --- a/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol +++ b/packages/contracts/src/2.0.0/test/TestAssetProxyOwner/TestAssetProxyOwner.sol @@ -16,14 +16,16 @@ */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; import "../../protocol/AssetProxyOwner/AssetProxyOwner.sol"; +// solhint-disable no-empty-blocks contract TestAssetProxyOwner is AssetProxyOwner { + constructor( address[] memory _owners, address[] memory _assetProxyContracts, @@ -32,11 +34,11 @@ contract TestAssetProxyOwner is ) public AssetProxyOwner(_owners, _assetProxyContracts, _required, _secondsTimeLocked) - { - } + {} function testValidRemoveAuthorizedAddressAtIndexTx(uint256 id) public + view validRemoveAuthorizedAddressAtIndexTx(id) returns (bool) { diff --git a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol index f52f635e1..00d861e61 100644 --- a/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol +++ b/packages/contracts/src/2.0.0/test/TestLibBytes/TestLibBytes.sol @@ -16,8 +16,7 @@ */ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; +pragma solidity 0.4.24; import "../../utils/LibBytes/LibBytes.sol"; diff --git a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol index df8eb55ce..5a349527b 100644 --- a/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol +++ b/packages/contracts/src/2.0.0/test/TestLibs/TestLibs.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; pragma experimental ABIEncoderV2; import "../../protocol/Exchange/libs/LibMath.sol"; @@ -32,7 +32,8 @@ contract TestLibs is function publicGetPartialAmount( uint256 numerator, uint256 denominator, - uint256 target) + uint256 target + ) public pure returns (uint256 partialAmount) @@ -48,7 +49,8 @@ contract TestLibs is function publicIsRoundingError( uint256 numerator, uint256 denominator, - uint256 target) + uint256 target + ) public pure returns (bool isError) diff --git a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol index 591ae3378..e1a610469 100644 --- a/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol +++ b/packages/contracts/src/2.0.0/test/TestSignatureValidator/TestSignatureValidator.sol @@ -16,8 +16,7 @@ */ -pragma solidity ^0.4.24; -pragma experimental ABIEncoderV2; +pragma solidity 0.4.24; import "../../protocol/Exchange/MixinSignatureValidator.sol"; import "../../protocol/Exchange/MixinTransactions.sol"; diff --git a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol b/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol index 5076dedc9..6278aede0 100644 --- a/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol +++ b/packages/contracts/src/2.0.0/test/TestValidator/TestValidator.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; import "../../protocol/Exchange/interfaces/IValidator.sol"; @@ -27,7 +27,7 @@ contract TestValidator is // The single valid signer for this wallet. // solhint-disable-next-line var-name-mixedcase - address VALID_SIGNER; + address internal VALID_SIGNER; /// @dev constructs a new `TestValidator` with a single valid signer. /// @param validSigner The sole, valid signer. @@ -40,6 +40,7 @@ contract TestValidator is /// @param signerAddress Address that should have signed the given hash. /// @param signature Proof of signing. /// @return Validity of signature. + // solhint-disable no-unused-vars function isValidSignature( bytes32 hash, address signerAddress, @@ -51,4 +52,5 @@ contract TestValidator is { return (signerAddress == VALID_SIGNER); } + // solhint-enable no-unused-vars } diff --git a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol b/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol index 07dfac588..0415823e3 100644 --- a/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol +++ b/packages/contracts/src/2.0.0/test/TestWallet/TestWallet.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; import "../../protocol/Exchange/interfaces/IWallet.sol"; import "../../utils/LibBytes/LibBytes.sol"; @@ -27,11 +27,9 @@ contract TestWallet is { using LibBytes for bytes; - string constant LENGTH_65_REQUIRED = "LENGTH_65_REQUIRED"; - // The owner of this wallet. // solhint-disable-next-line var-name-mixedcase - address WALLET_OWNER; + address internal WALLET_OWNER; /// @dev constructs a new `TestWallet` with a single owner. /// @param walletOwner The owner of this wallet. @@ -54,7 +52,7 @@ contract TestWallet is { require( eip712Signature.length == 65, - LENGTH_65_REQUIRED + "LENGTH_65_REQUIRED" ); uint8 v = uint8(eip712Signature[0]); diff --git a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol b/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol index 07bd7d531..60cac26ea 100644 --- a/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol +++ b/packages/contracts/src/2.0.0/test/Whitelist/Whitelist.sol @@ -16,7 +16,7 @@ */ -pragma solidity ^0.4.24; +pragma solidity 0.4.24; pragma experimental ABIEncoderV2; import "../../protocol/Exchange/interfaces/IExchange.sol"; @@ -27,28 +27,22 @@ import "../../utils/Ownable/Ownable.sol"; contract Whitelist is Ownable { - // Revert reasons - string constant MAKER_NOT_WHITELISTED = "MAKER_NOT_WHITELISTED"; // Maker address not whitelisted. - string constant TAKER_NOT_WHITELISTED = "TAKER_NOT_WHITELISTED"; // Taker address not whitelisted. - string constant INVALID_SENDER = "INVALID_SENDER"; // Sender must equal transaction origin. // Mapping of address => whitelist status. mapping (address => bool) public isWhitelisted; // Exchange contract. - // solhint-disable-next-line var-name-mixedcase - IExchange EXCHANGE; + // solhint-disable var-name-mixedcase + IExchange internal EXCHANGE; + bytes internal TX_ORIGIN_SIGNATURE; + // solhint-enable var-name-mixedcase - byte constant VALIDATOR_SIGNATURE_BYTE = "\x06"; - // solhint-disable-next-line var-name-mixedcase - bytes TX_ORIGIN_SIGNATURE; + byte constant internal VALIDATOR_SIGNATURE_BYTE = "\x06"; constructor (address _exchange) public { - // solhint-disable-next-line var-name-mixedcase EXCHANGE = IExchange(_exchange); - // solhint-disable-next-line var-name-mixedcase TX_ORIGIN_SIGNATURE = abi.encodePacked(address(this), VALIDATOR_SIGNATURE_BYTE); } @@ -65,6 +59,27 @@ contract Whitelist is isWhitelisted[target] = isApproved; } + /// @dev Verifies signer is same as signer of current Ethereum transaction. + /// NOTE: This function can currently be used to validate signatures coming from outside of this contract. + /// Extra safety checks can be added for a production contract. + /// @param signerAddress Address that should have signed the given hash. + /// @param signature Proof of signing. + /// @return Validity of order signature. + // solhint-disable no-unused-vars + function isValidSignature( + bytes32 hash, + address signerAddress, + bytes signature + ) + external + view + returns (bool isValid) + { + // solhint-disable-next-line avoid-tx-origin + return signerAddress == tx.origin; + } + // solhint-enable no-unused-vars + /// @dev Fills an order using `msg.sender` as the taker. /// The transaction will revert if both the maker and taker are not whitelisted. /// Orders should specify this contract as the `senderAddress` in order to gaurantee @@ -85,20 +100,21 @@ contract Whitelist is // This contract must be the entry point for the transaction. require( + // solhint-disable-next-line avoid-tx-origin takerAddress == tx.origin, - INVALID_SENDER + "INVALID_SENDER" ); // Check if maker is on the whitelist. require( isWhitelisted[order.makerAddress], - MAKER_NOT_WHITELISTED + "MAKER_NOT_WHITELISTED" ); // Check if taker is on the whitelist. require( isWhitelisted[takerAddress], - TAKER_NOT_WHITELISTED + "TAKER_NOT_WHITELISTED" ); // Encode arguments into byte array. @@ -117,22 +133,4 @@ contract Whitelist is TX_ORIGIN_SIGNATURE ); } - - /// @dev Verifies signer is same as signer of current Ethereum transaction. - /// NOTE: This function can currently be used to validate signatures coming from outside of this contract. - /// Extra safety checks can be added for a production contract. - /// @param signerAddress Address that should have signed the given hash. - /// @param signature Proof of signing. - /// @return Validity of order signature. - function isValidSignature( - bytes32 hash, - address signerAddress, - bytes signature - ) - external - view - returns (bool isValid) - { - return signerAddress == tx.origin; - } } |