@0x/contracts: Create TestWrapperFunctions contract.

This commit is contained in:
Lawrence Forman
2019-08-04 01:24:13 -04:00
parent 8adfa52ae3
commit 29a82f8471
7 changed files with 145 additions and 4 deletions

View File

@@ -33,15 +33,16 @@
"src/interfaces/IExchangeCore.sol",
"src/interfaces/IMatchOrders.sol",
"src/interfaces/ISignatureValidator.sol",
"test/IsolatedExchange.sol",
"src/interfaces/ITransactions.sol",
"src/interfaces/IWallet.sol",
"src/interfaces/IWrapperFunctions.sol",
"test/IsolatedExchange.sol",
"test/ReentrantERC20Token.sol",
"test/TestAssetProxyDispatcher.sol",
"test/TestExchangeInternals.sol",
"test/TestLibExchangeRichErrorDecoder.sol",
"test/TestSignatureValidator.sol",
"test/TestValidatorWallet.sol"
"test/TestValidatorWallet.sol",
"test/TestWrapperFunctions.sol"
]
}

View File

@@ -0,0 +1,98 @@
/*
Copyright 2019 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.5;
pragma experimental ABIEncoderV2;
import "../src/Exchange.sol";
/// @dev A version of the Exchange contract with`_fillOrder()`,
/// `_cancelOrder()`, and `getOrderInfo()` overridden to test
/// `MixinWrapperFunctions`.
contract TestWrapperFunctions is
Exchange
{
// solhint-disable no-unused-vars
event FillOrderCalled(
Order order,
uint256 takerAssetFillAmount,
bytes signature
);
event CancelOrderCalled(
Order order
);
// solhint-disable no-empty-blocks
constructor ()
public
Exchange(0x74657374)
{}
/// @dev Overridden to only log arguments and revert with certain inputs.
function _fillOrder(
Order memory order,
uint256 takerAssetFillAmount,
bytes memory signature
)
internal
returns (FillResults memory fillResults)
{
emit FillOrderCalled(
order,
takerAssetFillAmount,
signature
);
// Fail if the salt is uint256(-1).
if (order.salt == uint256(-1)) {
revert("FILL_ORDER_FAILED");
}
}
/// @dev Overridden to only log arguments and revert with certain inputs.
function _cancelOrder(
Order memory order
)
internal
{
emit CancelOrderCalled(
order
);
// Fail if the salt is uint256(-1).
if (order.salt == uint256(-1)) {
revert("CANCEL_ORDER_FAILED");
}
}
/// @dev Overridden to be deterministic.
function getOrderInfo(Order memory order)
public
view
returns (OrderInfo memory orderInfo)
{
// Lower uint128 of `order.salt` is the `orderTakerAssetFilledAmount`.
orderInfo.orderTakerAssetFilledAmount = uint128(order.salt);
// High byte of `order.salt` is the `orderStatus`.
orderInfo.orderTakerAssetFilledAmount = uint8(order.salt >> 248);
// `orderHash` is just `keccak256(order.salt)`.
orderInfo.orderHash = keccak256(abi.encode(order.salt));
}
}

View File

@@ -34,7 +34,7 @@
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
},
"config": {
"abis": "./generated-artifacts/@(Exchange|ExchangeWrapper|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|IWallet|IWrapperFunctions|IsolatedExchange|ReentrantERC20Token|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestSignatureValidator|TestValidatorWallet|Whitelist).json",
"abis": "./generated-artifacts/@(Exchange|ExchangeWrapper|IAssetProxyDispatcher|IEIP1271Wallet|IExchange|IExchangeCore|IMatchOrders|ISignatureValidator|ITransactions|IWallet|IWrapperFunctions|IsolatedExchange|ReentrantERC20Token|TestAssetProxyDispatcher|TestExchangeInternals|TestLibExchangeRichErrorDecoder|TestSignatureValidator|TestValidatorWallet|TestWrapperFunctions|Whitelist).json",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
},
"repository": {

View File

@@ -23,6 +23,7 @@ import * as TestExchangeInternals from '../generated-artifacts/TestExchangeInter
import * as TestLibExchangeRichErrorDecoder from '../generated-artifacts/TestLibExchangeRichErrorDecoder.json';
import * as TestSignatureValidator from '../generated-artifacts/TestSignatureValidator.json';
import * as TestValidatorWallet from '../generated-artifacts/TestValidatorWallet.json';
import * as TestWrapperFunctions from '../generated-artifacts/TestWrapperFunctions.json';
import * as Whitelist from '../generated-artifacts/Whitelist.json';
export const artifacts = {
ExchangeWrapper: ExchangeWrapper as ContractArtifact,
@@ -34,14 +35,15 @@ export const artifacts = {
IExchangeCore: IExchangeCore as ContractArtifact,
IMatchOrders: IMatchOrders as ContractArtifact,
ISignatureValidator: ISignatureValidator as ContractArtifact,
IsolatedExchange: IsolatedExchange as ContractArtifact,
ITransactions: ITransactions as ContractArtifact,
IWallet: IWallet as ContractArtifact,
IWrapperFunctions: IWrapperFunctions as ContractArtifact,
IsolatedExchange: IsolatedExchange as ContractArtifact,
ReentrantERC20Token: ReentrantERC20Token as ContractArtifact,
TestAssetProxyDispatcher: TestAssetProxyDispatcher as ContractArtifact,
TestExchangeInternals: TestExchangeInternals as ContractArtifact,
TestLibExchangeRichErrorDecoder: TestLibExchangeRichErrorDecoder as ContractArtifact,
TestSignatureValidator: TestSignatureValidator as ContractArtifact,
TestValidatorWallet: TestValidatorWallet as ContractArtifact,
TestWrapperFunctions: TestWrapperFunctions as ContractArtifact,
};

View File

@@ -21,4 +21,5 @@ export * from '../generated-wrappers/test_exchange_internals';
export * from '../generated-wrappers/test_lib_exchange_rich_error_decoder';
export * from '../generated-wrappers/test_signature_validator';
export * from '../generated-wrappers/test_validator_wallet';
export * from '../generated-wrappers/test_wrapper_functions';
export * from '../generated-wrappers/whitelist';

View File

@@ -0,0 +1,38 @@
import {
blockchainTests,
constants,
describe,
expect,
hexRandom,
} from '@0x/contracts-test-utils';
import { OrderWithoutDomain as Order } from '@0x/types';
import {
artifacts,
TestWrapperFunctionsContract,
TestWrapperFunctionsFillOrderCalledEventArgs as FillOrderCalledEventArgs,
} from '../src';
blockchainTests.only('Exchange wrapper functions unit tests.', env => {
const randomAddress = () => hexRandom(constants.ADDRESS_LENGTH);
const randomAssetData = () => hexRandom(34);
const DEFAULT_ORDER: Order = {
makerAddress: randomAddress(),
takerAddress: randomAddress(),
};
let testContract: TestWrapperFunctionsContract;
before(async () => {
testContract = await TestWrapperFunctionsContract.deployFrom0xArtifactAsync(
artifacts.TestWrapperFunctions,
env.provider,
env.txDefaults,
);
});
describe('getOrdersInfo', () => {
it('works', async () => {
testContract.getOrdersInfo.callAsync(orders);
});
});
});

View File

@@ -21,6 +21,7 @@
"generated-artifacts/TestLibExchangeRichErrorDecoder.json",
"generated-artifacts/TestSignatureValidator.json",
"generated-artifacts/TestValidatorWallet.json",
"generated-artifacts/TestWrapperFunctions.json",
"generated-artifacts/Whitelist.json"
],
"exclude": ["./deploy/solc/solc_bin"]