diff --git a/contracts/exchange-libs/contracts/src/LibFillResults.sol b/contracts/exchange-libs/contracts/src/LibFillResults.sol index f0bb58d8c6..f4fe857f7a 100644 --- a/contracts/exchange-libs/contracts/src/LibFillResults.sol +++ b/contracts/exchange-libs/contracts/src/LibFillResults.sol @@ -171,7 +171,10 @@ library LibFillResults { /// @param fillResults1 The first FillResults. /// @param fillResults2 The second FillResults. /// @return The sum of both fill results. - function addFillResults(FillResults memory fillResults1, FillResults memory fillResults2) + function addFillResults( + FillResults memory fillResults1, + FillResults memory fillResults2 + ) internal pure returns (FillResults memory totalFillResults) diff --git a/contracts/exchange-libs/contracts/src/LibMath.sol b/contracts/exchange-libs/contracts/src/LibMath.sol index 5b431f30db..516a7f5ed0 100644 --- a/contracts/exchange-libs/contracts/src/LibMath.sol +++ b/contracts/exchange-libs/contracts/src/LibMath.sol @@ -42,7 +42,7 @@ library LibMath { pure returns (uint256 partialAmount) { - if (_isRoundingErrorFloor( + if (isRoundingErrorFloor( numerator, denominator, target @@ -73,7 +73,7 @@ library LibMath { pure returns (uint256 partialAmount) { - if (_isRoundingErrorCeil( + if (isRoundingErrorCeil( numerator, denominator, target diff --git a/contracts/exchange-libs/contracts/test/TestLibEIP712ExchangeDomain.sol b/contracts/exchange-libs/contracts/test/TestLibEIP712ExchangeDomain.sol new file mode 100644 index 0000000000..c3cbd9cc11 --- /dev/null +++ b/contracts/exchange-libs/contracts/test/TestLibEIP712ExchangeDomain.sol @@ -0,0 +1,36 @@ +/* + + 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.5.9; +pragma experimental ABIEncoderV2; + +import "../src/LibEIP712ExchangeDomain.sol"; + + +contract TestLibEIP712ExchangeDomain is + LibEIP712ExchangeDomain +{ + + constructor( + uint256 chainId, + address verifyingContractAddressIfExists + ) + public + LibEIP712ExchangeDomain(chainId, verifyingContractAddressIfExists) + {} +} diff --git a/contracts/exchange-libs/contracts/test/TestLibFillResults.sol b/contracts/exchange-libs/contracts/test/TestLibFillResults.sol new file mode 100644 index 0000000000..501d228762 --- /dev/null +++ b/contracts/exchange-libs/contracts/test/TestLibFillResults.sol @@ -0,0 +1,72 @@ +/* + + 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.5.9; +pragma experimental ABIEncoderV2; + +import "../src/LibOrder.sol"; +import "../src/LibFillResults.sol"; + + +contract TestLibFillResults { + + function calculateFillResults( + LibOrder.Order memory order, + uint256 takerAssetFilledAmount + ) + public + pure + returns (LibFillResults.FillResults memory fillResults) + { + fillResults = LibFillResults.calculateFillResults(order, takerAssetFilledAmount); + return fillResults; + } + + function calculateMatchedFillResults( + LibOrder.Order memory leftOrder, + LibOrder.Order memory rightOrder, + uint256 leftOrderTakerAssetFilledAmount, + uint256 rightOrderTakerAssetFilledAmount, + bool shouldMaximallyFillOrders + ) + public + pure + returns (LibFillResults.MatchedFillResults memory matchedFillResults) + { + matchedFillResults = LibFillResults.calculateMatchedFillResults( + leftOrder, + rightOrder, + leftOrderTakerAssetFilledAmount, + rightOrderTakerAssetFilledAmount, + shouldMaximallyFillOrders + ); + return matchedFillResults; + } + + function addFillResults( + LibFillResults.FillResults memory fillResults1, + LibFillResults.FillResults memory fillResults2 + ) + public + pure + returns (LibFillResults.FillResults memory totalFillResults) + { + totalFillResults = LibFillResults.addFillResults(fillResults1, fillResults2); + return totalFillResults; + } +} diff --git a/contracts/exchange-libs/contracts/test/TestLibOrder.sol b/contracts/exchange-libs/contracts/test/TestLibOrder.sol new file mode 100644 index 0000000000..a9e708ac45 --- /dev/null +++ b/contracts/exchange-libs/contracts/test/TestLibOrder.sol @@ -0,0 +1,44 @@ +/* + + 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.5.9; +pragma experimental ABIEncoderV2; + +import "../src/LibOrder.sol"; + + +contract TestLibOrder { + + function getOrderHash(LibOrder.Order memory order, bytes32 eip712ExchangeDomainHash) + public + pure + returns (bytes32 orderHash) + { + orderHash = LibOrder.getOrderHash(order, eip712ExchangeDomainHash); + return orderHash; + } + + function hashOrder(LibOrder.Order memory order) + public + pure + returns (bytes32 result) + { + result = LibOrder.hashOrder(order); + return result; + } +} diff --git a/contracts/exchange-libs/contracts/test/TestLibZeroExTransaction.sol b/contracts/exchange-libs/contracts/test/TestLibZeroExTransaction.sol new file mode 100644 index 0000000000..3706d29c94 --- /dev/null +++ b/contracts/exchange-libs/contracts/test/TestLibZeroExTransaction.sol @@ -0,0 +1,44 @@ +/* + + 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.5.9; +pragma experimental ABIEncoderV2; + +import "../src/LibZeroExTransaction.sol"; + + +contract TestLibZeroExTransaction { + + function getZeroExTransactionHash(LibZeroExTransaction.ZeroExTransaction memory transaction, bytes32 eip712ExchangeDomainHash) + public + pure + returns (bytes32 transactionHash) + { + transactionHash = LibZeroExTransaction.getTransactionHash(transaction, eip712ExchangeDomainHash); + return transactionHash; + } + + function hashZeroExTransaction(LibZeroExTransaction.ZeroExTransaction memory transaction) + public + pure + returns (bytes32 result) + { + result = LibZeroExTransaction.hashZeroExTransaction(transaction); + return result; + } +} \ No newline at end of file diff --git a/contracts/exchange-libs/contracts/test/TestLibs.sol b/contracts/exchange-libs/contracts/test/TestLibs.sol deleted file mode 100644 index d9e6136321..0000000000 --- a/contracts/exchange-libs/contracts/test/TestLibs.sol +++ /dev/null @@ -1,156 +0,0 @@ -/* - - 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.5.9; -pragma experimental ABIEncoderV2; - -import "../src/LibEIP712ExchangeDomain.sol"; -import "../src/LibMath.sol"; -import "../src/LibOrder.sol"; -import "../src/LibZeroExTransaction.sol"; -import "../src/LibFillResults.sol"; - - -// solhint-disable no-empty-blocks -contract TestLibs is - LibEIP712ExchangeDomain -{ - constructor (uint256 chainId) - public - LibEIP712ExchangeDomain(chainId, address(0)) - {} - - function getPartialAmountFloor( - uint256 numerator, - uint256 denominator, - uint256 target - ) - public - pure - returns (uint256 partialAmount) - { - partialAmount = LibMath.getPartialAmountFloor( - numerator, - denominator, - target - ); - return partialAmount; - } - - function getPartialAmountCeil( - uint256 numerator, - uint256 denominator, - uint256 target - ) - public - pure - returns (uint256 partialAmount) - { - partialAmount = LibMath.getPartialAmountCeil( - numerator, - denominator, - target - ); - return partialAmount; - } - - function safeGetPartialAmountFloor( - uint256 numerator, - uint256 denominator, - uint256 target - ) - public - pure - returns (uint256 partialAmount) - { - partialAmount = _safeGetPartialAmountFloor( - numerator, - denominator, - target - ); - return partialAmount; - } - - function safeGetPartialAmountCeil( - uint256 numerator, - uint256 denominator, - uint256 target - ) - public - pure - returns (uint256 partialAmount) - { - partialAmount = _safeGetPartialAmountCeil( - numerator, - denominator, - target - ); - return partialAmount; - } - - function isRoundingErrorFloor( - uint256 numerator, - uint256 denominator, - uint256 target - ) - public - pure - returns (bool isError) - { - isError = LibMath.isRoundingErrorFloor( - numerator, - denominator, - target - ); - return isError; - } - - function isRoundingErrorCeil( - uint256 numerator, - uint256 denominator, - uint256 target - ) - public - pure - returns (bool isError) - { - isError = LibMath.isRoundingErrorCeil( - numerator, - denominator, - target - ); - return isError; - } - - function getDomainSeparator() - public - view - returns (bytes32) - { - return EIP712_EXCHANGE_DOMAIN_HASH; - } - - function addFillResults(LibFillResults.FillResults memory totalFillResults, LibFillResults.FillResults memory singleFillResults) - public - pure - returns (LibFillResults.FillResults memory) - { - LibFillResults.addFillResults(totalFillResults, singleFillResults); - return totalFillResults; - } -}