Change Whitelist error messages to conform to rest and added revert reason checks to transactions tests
This commit is contained in:
@@ -23,13 +23,13 @@ import "../../protocol/Exchange/interfaces/IExchange.sol";
|
|||||||
import "../../protocol/Exchange/libs/LibOrder.sol";
|
import "../../protocol/Exchange/libs/LibOrder.sol";
|
||||||
import "../../utils/Ownable/Ownable.sol";
|
import "../../utils/Ownable/Ownable.sol";
|
||||||
|
|
||||||
contract Whitelist is
|
contract Whitelist is
|
||||||
Ownable
|
Ownable
|
||||||
{
|
{
|
||||||
// Revert reasons
|
// Revert reasons
|
||||||
string constant MAKER_NOT_WHITELISTED = "Maker address not whitelisted.";
|
string constant MAKER_NOT_WHITELISTED = "MAKER_NOT_WHITELISTED"; // Maker address not whitelisted.
|
||||||
string constant TAKER_NOT_WHITELISTED = "Taker address not whitelisted.";
|
string constant TAKER_NOT_WHITELISTED = "TAKER_NOT_WHITELISTED"; // Taker address not whitelisted.
|
||||||
string constant INVALID_SENDER = "Sender must equal transaction origin.";
|
string constant INVALID_SENDER = "INVALID_SENDER"; // Sender must equal transaction origin.
|
||||||
|
|
||||||
// Mapping of address => whitelist status.
|
// Mapping of address => whitelist status.
|
||||||
mapping (address => bool) public isWhitelisted;
|
mapping (address => bool) public isWhitelisted;
|
||||||
@@ -77,7 +77,7 @@ contract Whitelist is
|
|||||||
public
|
public
|
||||||
{
|
{
|
||||||
address takerAddress = msg.sender;
|
address takerAddress = msg.sender;
|
||||||
|
|
||||||
// This contract must be the entry point for the transaction.
|
// This contract must be the entry point for the transaction.
|
||||||
require(
|
require(
|
||||||
takerAddress == tx.origin,
|
takerAddress == tx.origin,
|
||||||
|
@@ -183,4 +183,6 @@ export enum ContractLibErrors {
|
|||||||
IndexOutOfBounds = 'INDEX_OUT_OF_BOUNDS',
|
IndexOutOfBounds = 'INDEX_OUT_OF_BOUNDS',
|
||||||
AuthorizedAddressMismatch = 'AUTHORIZED_ADDRESS_MISMATCH',
|
AuthorizedAddressMismatch = 'AUTHORIZED_ADDRESS_MISMATCH',
|
||||||
OnlyContractOwner = 'ONLY_CONTRACT_OWNER',
|
OnlyContractOwner = 'ONLY_CONTRACT_OWNER',
|
||||||
|
MakerNotWhitelisted = 'MAKER_NOT_WHITELISTED',
|
||||||
|
TakerNotWhitelisted = 'TAKER_NOT_WHITELISTED',
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,9 @@ import { ExchangeContract } from '../../src/generated_contract_wrappers/exchange
|
|||||||
import { ExchangeWrapperContract } from '../../src/generated_contract_wrappers/exchange_wrapper';
|
import { ExchangeWrapperContract } from '../../src/generated_contract_wrappers/exchange_wrapper';
|
||||||
import { WhitelistContract } from '../../src/generated_contract_wrappers/whitelist';
|
import { WhitelistContract } from '../../src/generated_contract_wrappers/whitelist';
|
||||||
import { artifacts } from '../../src/utils/artifacts';
|
import { artifacts } from '../../src/utils/artifacts';
|
||||||
import { expectRevertOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
|
import {
|
||||||
|
expectRevertReasonOrAlwaysFailingTransactionAsync,
|
||||||
|
} from '../../src/utils/assertions';
|
||||||
import { chaiSetup } from '../../src/utils/chai_setup';
|
import { chaiSetup } from '../../src/utils/chai_setup';
|
||||||
import { constants } from '../../src/utils/constants';
|
import { constants } from '../../src/utils/constants';
|
||||||
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
|
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
|
||||||
@@ -18,7 +20,7 @@ import { ExchangeWrapper } from '../../src/utils/exchange_wrapper';
|
|||||||
import { OrderFactory } from '../../src/utils/order_factory';
|
import { OrderFactory } from '../../src/utils/order_factory';
|
||||||
import { orderUtils } from '../../src/utils/order_utils';
|
import { orderUtils } from '../../src/utils/order_utils';
|
||||||
import { TransactionFactory } from '../../src/utils/transaction_factory';
|
import { TransactionFactory } from '../../src/utils/transaction_factory';
|
||||||
import { ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types';
|
import { ContractLibErrors, ERC20BalancesByOwner, SignedTransaction } from '../../src/utils/types';
|
||||||
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
|
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
|
||||||
|
|
||||||
chaiSetup.configure();
|
chaiSetup.configure();
|
||||||
@@ -59,6 +61,12 @@ describe('Exchange transactions', () => {
|
|||||||
after(async () => {
|
after(async () => {
|
||||||
await blockchainLifecycle.revertAsync();
|
await blockchainLifecycle.revertAsync();
|
||||||
});
|
});
|
||||||
|
beforeEach(async () => {
|
||||||
|
await blockchainLifecycle.startAsync();
|
||||||
|
});
|
||||||
|
afterEach(async () => {
|
||||||
|
await blockchainLifecycle.revertAsync();
|
||||||
|
});
|
||||||
before(async () => {
|
before(async () => {
|
||||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||||
const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts);
|
const usedAddresses = ([owner, senderAddress, makerAddress, takerAddress, feeRecipientAddress] = accounts);
|
||||||
@@ -101,13 +109,6 @@ describe('Exchange transactions', () => {
|
|||||||
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address);
|
makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address);
|
||||||
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address);
|
takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address);
|
||||||
});
|
});
|
||||||
beforeEach(async () => {
|
|
||||||
await blockchainLifecycle.startAsync();
|
|
||||||
});
|
|
||||||
afterEach(async () => {
|
|
||||||
await blockchainLifecycle.revertAsync();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('executeTransaction', () => {
|
describe('executeTransaction', () => {
|
||||||
describe('fillOrder', () => {
|
describe('fillOrder', () => {
|
||||||
let takerAssetFillAmount: BigNumber;
|
let takerAssetFillAmount: BigNumber;
|
||||||
@@ -126,8 +127,9 @@ describe('Exchange transactions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if not called by specified sender', async () => {
|
it('should throw if not called by specified sender', async () => {
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
exchangeWrapper.executeTransactionAsync(signedTx, takerAddress),
|
exchangeWrapper.executeTransactionAsync(signedTx, takerAddress),
|
||||||
|
ContractLibErrors.FailedExecution,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -168,8 +170,9 @@ describe('Exchange transactions', () => {
|
|||||||
|
|
||||||
it('should throw if the a 0x transaction with the same transactionHash has already been executed', async () => {
|
it('should throw if the a 0x transaction with the same transactionHash has already been executed', async () => {
|
||||||
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
|
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
exchangeWrapper.executeTransactionAsync(signedTx, senderAddress),
|
exchangeWrapper.executeTransactionAsync(signedTx, senderAddress),
|
||||||
|
ContractLibErrors.InvalidTxHash,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -187,15 +190,17 @@ describe('Exchange transactions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw if not called by specified sender', async () => {
|
it('should throw if not called by specified sender', async () => {
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
exchangeWrapper.executeTransactionAsync(signedTx, makerAddress),
|
exchangeWrapper.executeTransactionAsync(signedTx, makerAddress),
|
||||||
|
ContractLibErrors.FailedExecution,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should cancel the order when signed by maker and called by sender', async () => {
|
it('should cancel the order when signed by maker and called by sender', async () => {
|
||||||
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
|
await exchangeWrapper.executeTransactionAsync(signedTx, senderAddress);
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
exchangeWrapper.fillOrderAsync(signedOrder, senderAddress),
|
exchangeWrapper.fillOrderAsync(signedOrder, senderAddress),
|
||||||
|
ContractLibErrors.OrderUnfillable,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -238,7 +243,7 @@ describe('Exchange transactions', () => {
|
|||||||
signedOrder.signature,
|
signedOrder.signature,
|
||||||
);
|
);
|
||||||
const signedFillTx = takerTransactionFactory.newSignedTransaction(fillData);
|
const signedFillTx = takerTransactionFactory.newSignedTransaction(fillData);
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
exchangeWrapperContract.fillOrder.sendTransactionAsync(
|
exchangeWrapperContract.fillOrder.sendTransactionAsync(
|
||||||
orderWithoutExchangeAddress,
|
orderWithoutExchangeAddress,
|
||||||
takerAssetFillAmount,
|
takerAssetFillAmount,
|
||||||
@@ -247,6 +252,7 @@ describe('Exchange transactions', () => {
|
|||||||
signedFillTx.signature,
|
signedFillTx.signature,
|
||||||
{ from: takerAddress },
|
{ from: takerAddress },
|
||||||
),
|
),
|
||||||
|
ContractLibErrors.FailedExecution,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -357,7 +363,7 @@ describe('Exchange transactions', () => {
|
|||||||
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
|
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
|
||||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||||
const salt = generatePseudoRandomSalt();
|
const salt = generatePseudoRandomSalt();
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
whitelist.fillOrderIfWhitelisted.sendTransactionAsync(
|
whitelist.fillOrderIfWhitelisted.sendTransactionAsync(
|
||||||
orderWithoutExchangeAddress,
|
orderWithoutExchangeAddress,
|
||||||
takerAssetFillAmount,
|
takerAssetFillAmount,
|
||||||
@@ -365,6 +371,7 @@ describe('Exchange transactions', () => {
|
|||||||
signedOrder.signature,
|
signedOrder.signature,
|
||||||
{ from: takerAddress },
|
{ from: takerAddress },
|
||||||
),
|
),
|
||||||
|
ContractLibErrors.MakerNotWhitelisted,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -378,7 +385,7 @@ describe('Exchange transactions', () => {
|
|||||||
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
|
orderWithoutExchangeAddress = orderUtils.getOrderWithoutExchangeAddress(signedOrder);
|
||||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||||
const salt = generatePseudoRandomSalt();
|
const salt = generatePseudoRandomSalt();
|
||||||
return expectRevertOrAlwaysFailingTransactionAsync(
|
return expectRevertReasonOrAlwaysFailingTransactionAsync(
|
||||||
whitelist.fillOrderIfWhitelisted.sendTransactionAsync(
|
whitelist.fillOrderIfWhitelisted.sendTransactionAsync(
|
||||||
orderWithoutExchangeAddress,
|
orderWithoutExchangeAddress,
|
||||||
takerAssetFillAmount,
|
takerAssetFillAmount,
|
||||||
@@ -386,6 +393,7 @@ describe('Exchange transactions', () => {
|
|||||||
signedOrder.signature,
|
signedOrder.signature,
|
||||||
{ from: takerAddress },
|
{ from: takerAddress },
|
||||||
),
|
),
|
||||||
|
ContractLibErrors.TakerNotWhitelisted,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user