Create test contracts for each exchange lib
This commit is contained in:
@@ -171,7 +171,10 @@ library LibFillResults {
|
|||||||
/// @param fillResults1 The first FillResults.
|
/// @param fillResults1 The first FillResults.
|
||||||
/// @param fillResults2 The second FillResults.
|
/// @param fillResults2 The second FillResults.
|
||||||
/// @return The sum of both fill results.
|
/// @return The sum of both fill results.
|
||||||
function addFillResults(FillResults memory fillResults1, FillResults memory fillResults2)
|
function addFillResults(
|
||||||
|
FillResults memory fillResults1,
|
||||||
|
FillResults memory fillResults2
|
||||||
|
)
|
||||||
internal
|
internal
|
||||||
pure
|
pure
|
||||||
returns (FillResults memory totalFillResults)
|
returns (FillResults memory totalFillResults)
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ library LibMath {
|
|||||||
pure
|
pure
|
||||||
returns (uint256 partialAmount)
|
returns (uint256 partialAmount)
|
||||||
{
|
{
|
||||||
if (_isRoundingErrorFloor(
|
if (isRoundingErrorFloor(
|
||||||
numerator,
|
numerator,
|
||||||
denominator,
|
denominator,
|
||||||
target
|
target
|
||||||
@@ -73,7 +73,7 @@ library LibMath {
|
|||||||
pure
|
pure
|
||||||
returns (uint256 partialAmount)
|
returns (uint256 partialAmount)
|
||||||
{
|
{
|
||||||
if (_isRoundingErrorCeil(
|
if (isRoundingErrorCeil(
|
||||||
numerator,
|
numerator,
|
||||||
denominator,
|
denominator,
|
||||||
target
|
target
|
||||||
|
|||||||
@@ -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)
|
||||||
|
{}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
contracts/exchange-libs/contracts/test/TestLibOrder.sol
Normal file
44
contracts/exchange-libs/contracts/test/TestLibOrder.sol
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user