Remove TestValidatorWallet DataType
This commit is contained in:
@@ -25,6 +25,7 @@ import "@0x/contracts-exchange-libs/contracts/src/LibEIP712ExchangeDomain.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||
import "../src/interfaces/IEIP1271Data.sol";
|
||||
|
||||
|
||||
// solhint-disable no-unused-vars
|
||||
@@ -40,16 +41,6 @@ contract TestValidatorWallet is
|
||||
/// @dev Revert reason for `Revert` `ValidatorAction`.
|
||||
string constant public REVERT_REASON = "you shall not pass";
|
||||
|
||||
enum DataType {
|
||||
// No data type; only expecting a hash (default)
|
||||
None,
|
||||
// An Order
|
||||
Order,
|
||||
// A ZeroExTransaction
|
||||
ZeroExTransaction,
|
||||
NTypes
|
||||
}
|
||||
|
||||
enum ValidatorAction {
|
||||
// Return failure (default)
|
||||
Reject,
|
||||
@@ -74,8 +65,6 @@ contract TestValidatorWallet is
|
||||
uint256 internal _state = 1;
|
||||
/// @dev What action to execute when a hash is validated .
|
||||
mapping (bytes32 => ValidatorAction) internal _hashActions;
|
||||
/// @dev The data type of a hash.
|
||||
mapping (bytes32 => DataType) internal _hashDataTypes;
|
||||
/// @dev keccak256 of the expected signature data for a hash.
|
||||
mapping (bytes32 => bytes32) internal _hashSignatureHashes;
|
||||
|
||||
@@ -99,24 +88,18 @@ contract TestValidatorWallet is
|
||||
|
||||
/// @dev Prepares this contract to validate a signature.
|
||||
/// @param hash The hash.
|
||||
/// @param dataType The data type associated with the hash.
|
||||
/// @param action Action to take.
|
||||
/// @param signatureHash keccak256 of the expected signature data.
|
||||
function prepare(
|
||||
bytes32 hash,
|
||||
DataType dataType,
|
||||
ValidatorAction action,
|
||||
bytes32 signatureHash
|
||||
)
|
||||
external
|
||||
{
|
||||
if (uint8(dataType) >= uint8(DataType.NTypes)) {
|
||||
revert("UNSUPPORTED_DATA_TYPE");
|
||||
}
|
||||
if (uint8(action) >= uint8(ValidatorAction.NTypes)) {
|
||||
revert("UNSUPPORTED_VALIDATOR_ACTION");
|
||||
}
|
||||
_hashDataTypes[hash] = dataType;
|
||||
_hashActions[hash] = action;
|
||||
_hashSignatureHashes[hash] = signatureHash;
|
||||
}
|
||||
@@ -206,41 +189,39 @@ contract TestValidatorWallet is
|
||||
}
|
||||
|
||||
function _decodeAndValidateHashFromEncodedData(bytes memory data)
|
||||
private
|
||||
view
|
||||
returns (bytes32 hash)
|
||||
private
|
||||
view
|
||||
returns (bytes32 hash)
|
||||
{
|
||||
// First we want the hash, which is the second
|
||||
// encoded parameter. We will initially treat all fields as inline
|
||||
// `bytes32`s and ignore the first one to extract it.
|
||||
(, hash) = abi.decode(data, (bytes32, bytes32));
|
||||
// Now we can figure out what the data type is from a previous call to
|
||||
// `prepare()`.
|
||||
DataType dataType = _hashDataTypes[hash];
|
||||
require(
|
||||
dataType != DataType.None,
|
||||
"EXPECTED_NO_DATA_TYPE"
|
||||
);
|
||||
if (dataType == DataType.Order) {
|
||||
// Decode the first parameter as an `Order` type.
|
||||
LibOrder.Order memory order = abi.decode(data, (LibOrder.Order));
|
||||
bytes4 dataId = data.readBytes4(0);
|
||||
if (dataId == IEIP1271Data(address(0)).OrderWithHash.selector) {
|
||||
// Decode the order and hash
|
||||
LibOrder.Order memory order;
|
||||
(order, hash) = abi.decode(
|
||||
data.slice(4, data.length - 1),
|
||||
(LibOrder.Order, bytes32)
|
||||
);
|
||||
// Use the Exchange to calculate the hash of the order and assert
|
||||
// that it matches the one we extracted previously.
|
||||
require(
|
||||
LibOrder.getTypedDataHash(order, _exchange.EIP712_EXCHANGE_DOMAIN_HASH()) == hash,
|
||||
"UNEXPECTED_ORDER_HASH"
|
||||
);
|
||||
} else {
|
||||
assert(dataType == DataType.ZeroExTransaction);
|
||||
// Decode the first parameter as a `ZeroExTransaction` type.
|
||||
LibZeroExTransaction.ZeroExTransaction memory transaction =
|
||||
abi.decode(data, (LibZeroExTransaction.ZeroExTransaction));
|
||||
} else if (dataId == IEIP1271Data(address(0)).ZeroExTransactionWithHash.selector) {
|
||||
// Decode the transaction and hash
|
||||
LibZeroExTransaction.ZeroExTransaction memory transaction;
|
||||
(transaction, hash) = abi.decode(
|
||||
data.slice(4, data.length - 1),
|
||||
(LibZeroExTransaction.ZeroExTransaction, bytes32)
|
||||
);
|
||||
// Use the Exchange to calculate the hash of the transaction and assert
|
||||
// that it matches the one we extracted previously.
|
||||
require(
|
||||
LibZeroExTransaction.getTypedDataHash(transaction, _exchange.EIP712_EXCHANGE_DOMAIN_HASH()) == hash,
|
||||
"UNEXPECTED_TRANSACTION_HASH"
|
||||
);
|
||||
} else {
|
||||
revert("EXPECTED_NO_DATA_TYPE");
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,6 @@ import {
|
||||
ExchangeWrapper,
|
||||
TestValidatorWalletContract,
|
||||
ValidatorWalletAction,
|
||||
ValidatorWalletDataType,
|
||||
} from '../src';
|
||||
|
||||
import { FillOrderWrapper } from './assertion_wrappers/fill_order_wrapper';
|
||||
@@ -267,7 +266,6 @@ blockchainTests.resets('Exchange core', () => {
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
ValidatorWalletAction.Accept,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
@@ -276,7 +274,6 @@ blockchainTests.resets('Exchange core', () => {
|
||||
// Reject the signature check for the second fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
ValidatorWalletAction.Reject,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
@@ -300,7 +297,6 @@ blockchainTests.resets('Exchange core', () => {
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
ValidatorWalletAction.Accept,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
@@ -309,7 +305,6 @@ blockchainTests.resets('Exchange core', () => {
|
||||
// Reject the signature check for the second fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
ValidatorWalletAction.Reject,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
@@ -333,7 +328,6 @@ blockchainTests.resets('Exchange core', () => {
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
ValidatorWalletAction.Accept,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
@@ -342,7 +336,6 @@ blockchainTests.resets('Exchange core', () => {
|
||||
// Reject the signature check for the second fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
ValidatorWalletAction.Reject,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
|
||||
@@ -29,7 +29,7 @@ import {
|
||||
TestValidatorWalletContract,
|
||||
} from '../src';
|
||||
|
||||
import { ValidatorWalletAction, ValidatorWalletDataType } from './utils';
|
||||
import { ValidatorWalletAction } from './utils';
|
||||
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
@@ -333,7 +333,6 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
if (validatorAction !== undefined) {
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
_hashHex,
|
||||
ValidatorWalletDataType.None,
|
||||
validatorAction,
|
||||
expectedSignatureHashHex,
|
||||
);
|
||||
@@ -458,7 +457,6 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
if (validatorAction !== undefined) {
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletDataType.Order,
|
||||
validatorAction,
|
||||
expectedSignatureHashHex,
|
||||
);
|
||||
@@ -755,7 +753,6 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
if (validatorAction !== undefined) {
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
transactionHashHex,
|
||||
ValidatorWalletDataType.ZeroExTransaction,
|
||||
validatorAction,
|
||||
expectedSignatureHashHex,
|
||||
);
|
||||
|
||||
@@ -40,10 +40,3 @@ export enum ValidatorWalletAction {
|
||||
ReturnNothing = 6,
|
||||
NTypes = 7,
|
||||
}
|
||||
|
||||
export enum ValidatorWalletDataType {
|
||||
None = 0,
|
||||
Order = 1,
|
||||
ZeroExTransaction = 2,
|
||||
NTypes = 3,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user