@0x/contracts-exchange
: Update tests for new/consolidated signature types.
`@0x/contracts-exchange`: Update `Whitelist` example for new signature types.
This commit is contained in:
committed by
Amir Bandeali
parent
4734acbe61
commit
d6ba03916a
@@ -79,15 +79,23 @@
|
||||
"pr": 1868
|
||||
},
|
||||
{
|
||||
"note": "Always check `OrderValidator` and `WalletOrderValidator` signature types on every fill",
|
||||
"note": "Add `EIP1271Wallet` signature type",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Rename `WalletOrderValidator` to `OrderWallet` signature type",
|
||||
"note": "Remove `WalletOrderValidator` and `OrderValidator` signature types",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Rename `SignatureWalletOrderValidatorError` to `SignatureOrderWalletError`",
|
||||
"note": "Make the regular `Validator` signature type have EIP1271 behavior",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Always check signature types that are validated via contract (not just on first fill).",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Remove unecessary rich revert error types.",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
@@ -95,19 +103,7 @@
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Add `EIP1271Wallet` and `EIP1271OrderWallet` to `SignatureType`",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Always check `OrderValidator`, `OrderWallet`, `EIP1271OrderWallet` signature types on every fill",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Add `validatorAddress` field to `SignatureValidatorError` and `SignatureOrderValidatorError` rich reverts",
|
||||
"pr": 1885
|
||||
},
|
||||
{
|
||||
"note": "Add separate `SignatureOrderValidatorNotApprovedError` for `OrderValidator` signatures",
|
||||
"note": "Add `validatorAddress` field to `SignatureValidatorError` rich reverts",
|
||||
"pr": 1885
|
||||
}
|
||||
]
|
||||
|
@@ -23,10 +23,12 @@ import "../src/interfaces/IExchange.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol";
|
||||
import "@0x/contracts-exchange-libs/contracts/src/LibZeroExTransaction.sol";
|
||||
import "@0x/contracts-utils/contracts/src/Ownable.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibEIP1271.sol";
|
||||
|
||||
|
||||
contract Whitelist is
|
||||
Ownable
|
||||
Ownable,
|
||||
LibEIP1271
|
||||
{
|
||||
// Mapping of address => whitelist status.
|
||||
mapping (address => bool) public isWhitelisted;
|
||||
@@ -59,24 +61,28 @@ contract Whitelist is
|
||||
isWhitelisted[target] = isApproved;
|
||||
}
|
||||
|
||||
/// @dev Verifies signer is same as signer of current Ethereum transaction.
|
||||
/// @dev Verifies a ZeroExTransaction's 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 data The abi-encoded ZeroExTransaction.
|
||||
/// @param signature Proof of signing.
|
||||
/// @return Validity of order signature.
|
||||
/// @return magicValue `EIP1271_MAGIC_VALUE` if the signature is authorized.
|
||||
// solhint-disable no-unused-vars
|
||||
function isValidSignature(
|
||||
bytes32 hash,
|
||||
address signerAddress,
|
||||
bytes calldata data,
|
||||
bytes calldata signature
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (bool isValid)
|
||||
returns (bytes4 magicValue)
|
||||
{
|
||||
// Decode the ZeroExTransaction.
|
||||
LibZeroExTransaction.ZeroExTransaction memory transaction =
|
||||
abi.decode(data, (LibZeroExTransaction.ZeroExTransaction));
|
||||
// solhint-disable-next-line avoid-tx-origin
|
||||
return signerAddress == tx.origin;
|
||||
if (transaction.signerAddress == tx.origin) {
|
||||
magicValue = EIP1271_MAGIC_VALUE;
|
||||
}
|
||||
}
|
||||
// solhint-enable no-unused-vars
|
||||
|
||||
|
@@ -196,10 +196,10 @@ contract TestValidatorWallet is
|
||||
view
|
||||
returns (bytes32 hash)
|
||||
{
|
||||
// HACK(dorothy-zbornak): First we want the hash, which is the second
|
||||
// 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));
|
||||
(, 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];
|
||||
|
@@ -22,6 +22,7 @@ import {
|
||||
constants,
|
||||
ERC20BalancesByOwner,
|
||||
getLatestBlockTimestampAsync,
|
||||
hexConcat,
|
||||
increaseTimeAndMineBlockAsync,
|
||||
OrderFactory,
|
||||
OrderStatus,
|
||||
@@ -36,7 +37,6 @@ import { BigNumber, providerUtils, StringRevertError } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||
import ethUtil = require('ethereumjs-util');
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { Erc1155Wrapper } from '../../erc1155/lib/src';
|
||||
@@ -267,9 +267,13 @@ describe('Exchange core', () => {
|
||||
constants.INITIAL_ERC20_BALANCE,
|
||||
);
|
||||
// Approve the validator.
|
||||
await exchange.setSignatureValidatorApproval.awaitTransactionSuccessAsync(validatorWallet.address, true, {
|
||||
from: makerAddress,
|
||||
});
|
||||
await exchange.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
true,
|
||||
{
|
||||
from: makerAddress,
|
||||
},
|
||||
);
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
@@ -277,11 +281,8 @@ describe('Exchange core', () => {
|
||||
});
|
||||
|
||||
it('should revert if `Validator` signature type rejects during a second fill', async () => {
|
||||
const signature = Buffer.concat([
|
||||
ethUtil.toBuffer(validatorWallet.address),
|
||||
ethUtil.toBuffer([SignatureType.Validator]),
|
||||
]);
|
||||
signedOrder.signature = ethUtil.bufferToHex(signature);
|
||||
const signatureHex = hexConcat(validatorWallet.address, SignatureType.Validator);
|
||||
signedOrder.signature = signatureHex;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
@@ -312,9 +313,9 @@ describe('Exchange core', () => {
|
||||
});
|
||||
|
||||
it('should revert if `Wallet` signature type rejects during a second fill', async () => {
|
||||
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.Wallet])]);
|
||||
const signatureHex = hexConcat(SignatureType.Wallet);
|
||||
signedOrder.makerAddress = validatorWallet.address;
|
||||
signedOrder.signature = ethUtil.bufferToHex(signature);
|
||||
signedOrder.signature = signatureHex;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
@@ -345,9 +346,9 @@ describe('Exchange core', () => {
|
||||
});
|
||||
|
||||
it('should revert if `EIP1271Wallet` signature type rejects during a second fill', async () => {
|
||||
const signature = Buffer.concat([ethUtil.toBuffer([SignatureType.EIP1271Wallet])]);
|
||||
const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
|
||||
signedOrder.makerAddress = validatorWallet.address;
|
||||
signedOrder.signature = ethUtil.bufferToHex(signature);
|
||||
signedOrder.signature = signatureHex;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1101,13 +1101,10 @@ describe('Exchange transactions', () => {
|
||||
exchangeInstance.address,
|
||||
);
|
||||
const isApproved = true;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await exchangeInstance.setSignatureValidatorApproval.sendTransactionAsync(
|
||||
whitelistContract.address,
|
||||
isApproved,
|
||||
{ from: takerAddress },
|
||||
),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
await exchangeInstance.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
whitelistContract.address,
|
||||
isApproved,
|
||||
{ from: takerAddress },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1161,18 +1158,16 @@ describe('Exchange transactions', () => {
|
||||
|
||||
it('should fill the order if maker and taker have been whitelisted', async () => {
|
||||
const isApproved = true;
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await whitelistContract.updateWhitelistStatus.sendTransactionAsync(makerAddress, isApproved, {
|
||||
from: owner,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
await whitelistContract.updateWhitelistStatus.awaitTransactionSuccessAsync(
|
||||
makerAddress,
|
||||
isApproved,
|
||||
{ from: owner },
|
||||
);
|
||||
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await whitelistContract.updateWhitelistStatus.sendTransactionAsync(takerAddress, isApproved, {
|
||||
from: owner,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
await whitelistContract.updateWhitelistStatus.awaitTransactionSuccessAsync(
|
||||
takerAddress,
|
||||
isApproved,
|
||||
{ from: owner },
|
||||
);
|
||||
|
||||
const signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
|
Reference in New Issue
Block a user