update abi-gen with new method interfaces (#2325)
* update abi-gen with new method interfaces * wip: get all packages to build * wip: get all packages to build * Fix two contract wrapper calls * Export necessary types part of the contract wrapper public interfaces * Revive and fix wrapper_unit_tests * Remove duplicate type * Fix lib_exchange_rich_error_decoder tests * Fix remaining test failures in contracts-* packages * Prettier fixes * remove transactionHelper * lint and update changelogs * Fix prettier * Revert changes to reference docs * Add back changelog already published and add revert changelog entry * Add missing CHANGELOG entries * Add missing comma * Update mesh-rpc-client dep * Update Mesh RPC logic in @0x/orderbook to v6.0.1-beta * Align package versions
This commit is contained in:
@@ -154,9 +154,9 @@ export class FillOrderWrapper {
|
||||
): Promise<void> {
|
||||
// Get init state
|
||||
await this._blockchainBalanceStore.updateBalancesAsync();
|
||||
const initTakerAssetFilledAmount = await this._exchange.filled.callAsync(
|
||||
orderHashUtils.getOrderHashHex(signedOrder),
|
||||
);
|
||||
const initTakerAssetFilledAmount = await this._exchange
|
||||
.filled(orderHashUtils.getOrderHashHex(signedOrder))
|
||||
.callAsync();
|
||||
// Assert init state of exchange
|
||||
await this._assertOrderStateAsync(signedOrder, initTakerAssetFilledAmount);
|
||||
// Simulate and execute fill then assert outputs
|
||||
@@ -187,18 +187,12 @@ export class FillOrderWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber } = {},
|
||||
): Promise<[FillResults, FillEventArgs, TransactionReceiptWithDecodedLogs]> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const fillResults = await this._exchange.fillOrder.callAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from },
|
||||
);
|
||||
const txReceipt = await this._exchange.fillOrder.awaitTransactionSuccessAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from },
|
||||
);
|
||||
const fillResults = await this._exchange
|
||||
.fillOrder(params.order, params.takerAssetFillAmount, params.signature)
|
||||
.callAsync({ from });
|
||||
const txReceipt = await this._exchange
|
||||
.fillOrder(params.order, params.takerAssetFillAmount, params.signature)
|
||||
.awaitTransactionSuccessAsync({ from });
|
||||
const fillEvent = FillOrderWrapper._extractFillEventsfromReceipt(txReceipt)[0];
|
||||
return [fillResults, fillEvent, txReceipt];
|
||||
}
|
||||
@@ -213,7 +207,7 @@ export class FillOrderWrapper {
|
||||
order: SignedOrder,
|
||||
expectedFilledAmount: BigNumber = new BigNumber(0),
|
||||
): Promise<void> {
|
||||
const orderInfo = await this._exchange.getOrderInfo.callAsync(order);
|
||||
const orderInfo = await this._exchange.getOrderInfo(order).callAsync();
|
||||
// Check filled amount of order.
|
||||
const actualFilledAmount = orderInfo.orderTakerAssetFilledAmount;
|
||||
expect(actualFilledAmount, 'order filled amount').to.be.bignumber.equal(expectedFilledAmount);
|
||||
|
@@ -152,22 +152,22 @@ blockchainTests.resets('Exchange core', () => {
|
||||
exchange.address,
|
||||
);
|
||||
// Configure ERC20Proxy
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: owner });
|
||||
await erc20Proxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await erc20Proxy.addAuthorizedAddress(multiAssetProxy.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
|
||||
// Configure ERC721Proxy
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: owner });
|
||||
await erc721Proxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await erc721Proxy.addAuthorizedAddress(multiAssetProxy.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
|
||||
// Configure ERC1155Proxy
|
||||
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: owner });
|
||||
await erc1155Proxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await erc1155Proxy.addAuthorizedAddress(multiAssetProxy.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
|
||||
// Configure MultiAssetProxy
|
||||
await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, { from: owner });
|
||||
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, { from: owner });
|
||||
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(staticCallProxy.address, { from: owner });
|
||||
await multiAssetProxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await multiAssetProxy.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await multiAssetProxy.registerAssetProxy(erc721Proxy.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await multiAssetProxy.registerAssetProxy(staticCallProxy.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
|
||||
// Configure Exchange
|
||||
exchangeWrapper = new ExchangeWrapper(exchange);
|
||||
@@ -211,10 +211,10 @@ blockchainTests.resets('Exchange core', () => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultMakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerAssetAddress),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeAssetAddress),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultMakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultTakerAssetAddress).callAsync(),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeAssetAddress).callAsync(),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeAssetAddress).callAsync(),
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
@@ -252,24 +252,19 @@ blockchainTests.resets('Exchange core', () => {
|
||||
describe('callback signature types', () => {
|
||||
beforeEach(async () => {
|
||||
// Approve the ERC20 proxy with the test validator wallet.
|
||||
await validatorWallet.approveERC20.awaitTransactionSuccessAsync(
|
||||
erc20TokenA.address,
|
||||
erc20Proxy.address,
|
||||
constants.INITIAL_ERC20_ALLOWANCE,
|
||||
);
|
||||
await validatorWallet
|
||||
.approveERC20(erc20TokenA.address, erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE)
|
||||
.awaitTransactionSuccessAsync();
|
||||
// Mint some ERC20 tokens to the test validator wallet.
|
||||
await erc20TokenA.setBalance.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
constants.INITIAL_ERC20_BALANCE,
|
||||
);
|
||||
await erc20TokenA
|
||||
.setBalance(validatorWallet.address, constants.INITIAL_ERC20_BALANCE)
|
||||
.awaitTransactionSuccessAsync();
|
||||
// Approve the validator.
|
||||
await exchange.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
true,
|
||||
{
|
||||
await exchange
|
||||
.setSignatureValidatorApproval(validatorWallet.address, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: makerAddress,
|
||||
},
|
||||
);
|
||||
});
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
@@ -281,19 +276,15 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder.signature = signatureHex;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletAction.Accept,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, ValidatorWalletAction.Accept, constants.NULL_BYTES)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const fillAmount = signedOrder.takerAssetAmount.div(10);
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillAmount });
|
||||
// Reject the signature check for the second fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletAction.Reject,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, ValidatorWalletAction.Reject, constants.NULL_BYTES)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: fillAmount,
|
||||
});
|
||||
@@ -312,19 +303,15 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder.signature = signatureHex;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletAction.Accept,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, ValidatorWalletAction.Accept, constants.NULL_BYTES)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const fillAmount = signedOrder.takerAssetAmount.div(10);
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillAmount });
|
||||
// Reject the signature check for the second fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletAction.Reject,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, ValidatorWalletAction.Reject, constants.NULL_BYTES)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: fillAmount,
|
||||
});
|
||||
@@ -343,19 +330,15 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder.signature = signatureHex;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Allow the signature check for the first fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletAction.Accept,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, ValidatorWalletAction.Accept, constants.NULL_BYTES)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const fillAmount = signedOrder.takerAssetAmount.div(10);
|
||||
await exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount: fillAmount });
|
||||
// Reject the signature check for the second fill.
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
ValidatorWalletAction.Reject,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, ValidatorWalletAction.Reject, constants.NULL_BYTES)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const tx = exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, {
|
||||
takerAssetFillAmount: fillAmount,
|
||||
});
|
||||
@@ -420,9 +403,11 @@ blockchainTests.resets('Exchange core', () => {
|
||||
describe('Fill transfer ordering', () => {
|
||||
it('should allow the maker to exchange assets received by the taker', async () => {
|
||||
// Set maker/taker assetData to the same asset
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
const takerAssetAmount = new BigNumber(1);
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync([takerAssetAmount], [takerAssetData]);
|
||||
const makerAssetData = await devUtils
|
||||
.encodeMultiAssetData([takerAssetAmount], [takerAssetData])
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
@@ -432,33 +417,33 @@ blockchainTests.resets('Exchange core', () => {
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
});
|
||||
// Set maker balance to 0 so that the asset must be received by the taker in order for the fill to succeed
|
||||
await erc20TokenA.setBalance.awaitTransactionSuccessAsync(makerAddress, constants.ZERO_AMOUNT, {
|
||||
await erc20TokenA.setBalance(makerAddress, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
|
||||
});
|
||||
it('should allow the taker to pay fees with an asset that received by the maker', async () => {
|
||||
const makerAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const makerAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
takerFeeAssetData: makerAssetData,
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: new BigNumber(1),
|
||||
});
|
||||
// Set taker balance to 0 so that the asset must be received by the maker in order for the fill to succeed
|
||||
await erc20TokenA.setBalance.awaitTransactionSuccessAsync(takerAddress, constants.ZERO_AMOUNT, {
|
||||
await erc20TokenA.setBalance(takerAddress, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
|
||||
});
|
||||
it('should allow the maker to pay fees with an asset that received by the taker', async () => {
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerFeeAssetData: takerAssetData,
|
||||
makerFee: new BigNumber(1),
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
});
|
||||
// Set maker balance to 0 so that the asset must be received by the taker in order for the fill to succeed
|
||||
await erc20TokenB.setBalance.awaitTransactionSuccessAsync(makerAddress, constants.ZERO_AMOUNT, {
|
||||
await erc20TokenB.setBalance(makerAddress, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
|
||||
@@ -466,19 +451,16 @@ blockchainTests.resets('Exchange core', () => {
|
||||
});
|
||||
describe('Testing exchange of ERC20 tokens with no return values', () => {
|
||||
before(async () => {
|
||||
await noReturnErc20Token.setBalance.awaitTransactionSuccessAsync(
|
||||
makerAddress,
|
||||
constants.INITIAL_ERC20_BALANCE,
|
||||
);
|
||||
await noReturnErc20Token.approve.awaitTransactionSuccessAsync(
|
||||
erc20Proxy.address,
|
||||
constants.INITIAL_ERC20_ALLOWANCE,
|
||||
{ from: makerAddress },
|
||||
);
|
||||
await noReturnErc20Token
|
||||
.setBalance(makerAddress, constants.INITIAL_ERC20_BALANCE)
|
||||
.awaitTransactionSuccessAsync();
|
||||
await noReturnErc20Token
|
||||
.approve(erc20Proxy.address, constants.INITIAL_ERC20_ALLOWANCE)
|
||||
.awaitTransactionSuccessAsync({ from: makerAddress });
|
||||
});
|
||||
it('should transfer the correct amounts when makerAssetAmount === takerAssetAmount', async () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(noReturnErc20Token.address),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(noReturnErc20Token.address).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
});
|
||||
@@ -486,7 +468,7 @@ blockchainTests.resets('Exchange core', () => {
|
||||
});
|
||||
it('should transfer the correct amounts when makerAssetAmount > takerAssetAmount', async () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(noReturnErc20Token.address),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(noReturnErc20Token.address).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
});
|
||||
@@ -494,7 +476,7 @@ blockchainTests.resets('Exchange core', () => {
|
||||
});
|
||||
it('should transfer the correct amounts when makerAssetAmount < takerAssetAmount', async () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(noReturnErc20Token.address),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(noReturnErc20Token.address).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(200), 18),
|
||||
});
|
||||
@@ -671,14 +653,14 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetAmount: new BigNumber(1),
|
||||
takerAssetAmount: new BigNumber(1),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, makerAssetId).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, takerAssetId).callAsync(),
|
||||
});
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Verify pre-conditions
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf(makerAssetId).callAsync();
|
||||
expect(initialOwnerMakerAsset).to.be.bignumber.not.equal(makerAddress);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf(takerAssetId).callAsync();
|
||||
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
@@ -698,14 +680,14 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetAmount: new BigNumber(1),
|
||||
takerAssetAmount: new BigNumber(1),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, makerAssetId).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, takerAssetId).callAsync(),
|
||||
});
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Verify pre-conditions
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf(makerAssetId).callAsync();
|
||||
expect(initialOwnerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf(takerAssetId).callAsync();
|
||||
expect(initialOwnerTakerAsset).to.be.bignumber.not.equal(takerAddress);
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
@@ -725,14 +707,14 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetAmount: new BigNumber(2),
|
||||
takerAssetAmount: new BigNumber(1),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, makerAssetId).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, takerAssetId).callAsync(),
|
||||
});
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Verify pre-conditions
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf(makerAssetId).callAsync();
|
||||
expect(initialOwnerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf(takerAssetId).callAsync();
|
||||
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
@@ -752,14 +734,14 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetAmount: new BigNumber(1),
|
||||
takerAssetAmount: new BigNumber(500),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, makerAssetId).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, takerAssetId).callAsync(),
|
||||
});
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
// Verify pre-conditions
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
|
||||
const initialOwnerMakerAsset = await erc721Token.ownerOf(makerAssetId).callAsync();
|
||||
expect(initialOwnerMakerAsset).to.be.bignumber.equal(makerAddress);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
|
||||
const initialOwnerTakerAsset = await erc721Token.ownerOf(takerAssetId).callAsync();
|
||||
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount;
|
||||
@@ -778,8 +760,8 @@ blockchainTests.resets('Exchange core', () => {
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetAmount: new BigNumber(1),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), 18),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, makerAssetId),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC721AssetData(erc721Token.address, makerAssetId).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultTakerAssetAddress).callAsync(),
|
||||
});
|
||||
// Call Exchange
|
||||
const takerAssetFillAmount = signedOrder.takerAssetAmount.div(2);
|
||||
@@ -797,12 +779,12 @@ blockchainTests.resets('Exchange core', () => {
|
||||
it('should allow multiple assets to be exchanged for a single asset', async () => {
|
||||
const makerAmounts = [new BigNumber(10), new BigNumber(20)];
|
||||
const makerNestedAssetData = [
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync(),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync(),
|
||||
];
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync(makerAmounts, makerNestedAssetData);
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData(makerAmounts, makerNestedAssetData).callAsync();
|
||||
const makerAssetAmount = new BigNumber(1);
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(feeToken.address);
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData(feeToken.address).callAsync();
|
||||
const takerAssetAmount = new BigNumber(10);
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
@@ -817,18 +799,18 @@ blockchainTests.resets('Exchange core', () => {
|
||||
it('should allow multiple assets to be exchanged for multiple assets', async () => {
|
||||
const makerAmounts = [new BigNumber(10), new BigNumber(20)];
|
||||
const makerNestedAssetData = [
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync(),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync(),
|
||||
];
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync(makerAmounts, makerNestedAssetData);
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData(makerAmounts, makerNestedAssetData).callAsync();
|
||||
const makerAssetAmount = new BigNumber(1);
|
||||
const takerAmounts = [new BigNumber(10), new BigNumber(1)];
|
||||
const takerAssetId = erc721TakerAssetIds[0];
|
||||
const takerNestedAssetData = [
|
||||
await devUtils.encodeERC20AssetData.callAsync(feeToken.address),
|
||||
await devUtils.encodeERC721AssetData.callAsync(erc721Token.address, takerAssetId),
|
||||
await devUtils.encodeERC20AssetData(feeToken.address).callAsync(),
|
||||
await devUtils.encodeERC721AssetData(erc721Token.address, takerAssetId).callAsync(),
|
||||
];
|
||||
const takerAssetData = await devUtils.encodeMultiAssetData.callAsync(takerAmounts, takerNestedAssetData);
|
||||
const takerAssetData = await devUtils.encodeMultiAssetData(takerAmounts, takerNestedAssetData).callAsync();
|
||||
const takerAssetAmount = new BigNumber(1);
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
@@ -843,12 +825,12 @@ blockchainTests.resets('Exchange core', () => {
|
||||
it('should allow an order selling multiple assets to be partially filled', async () => {
|
||||
const makerAmounts = [new BigNumber(10), new BigNumber(20)];
|
||||
const makerNestedAssetData = [
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync(),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync(),
|
||||
];
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData.callAsync(makerAmounts, makerNestedAssetData);
|
||||
const makerAssetData = await devUtils.encodeMultiAssetData(makerAmounts, makerNestedAssetData).callAsync();
|
||||
const makerAssetAmount = new BigNumber(30);
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData.callAsync(feeToken.address);
|
||||
const takerAssetData = await devUtils.encodeERC20AssetData(feeToken.address).callAsync();
|
||||
const takerAssetAmount = new BigNumber(10);
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
@@ -865,12 +847,12 @@ blockchainTests.resets('Exchange core', () => {
|
||||
it('should allow an order buying multiple assets to be partially filled', async () => {
|
||||
const takerAmounts = [new BigNumber(10), new BigNumber(20)];
|
||||
const takerNestedAssetData = [
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address),
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync(),
|
||||
await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync(),
|
||||
];
|
||||
const takerAssetData = await devUtils.encodeMultiAssetData.callAsync(takerAmounts, takerNestedAssetData);
|
||||
const takerAssetData = await devUtils.encodeMultiAssetData(takerAmounts, takerNestedAssetData).callAsync();
|
||||
const takerAssetAmount = new BigNumber(30);
|
||||
const makerAssetData = await devUtils.encodeERC20AssetData.callAsync(feeToken.address);
|
||||
const makerAssetData = await devUtils.encodeERC20AssetData(feeToken.address).callAsync();
|
||||
const makerAssetAmount = new BigNumber(10);
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
@@ -896,18 +878,22 @@ blockchainTests.resets('Exchange core', () => {
|
||||
const makerAssetAmount = new BigNumber(1);
|
||||
const takerAssetAmount = new BigNumber(1);
|
||||
const receiverCallbackData = '0x';
|
||||
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const makerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
const takerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
@@ -931,18 +917,22 @@ blockchainTests.resets('Exchange core', () => {
|
||||
const makerAssetAmount = new BigNumber(1);
|
||||
const takerAssetAmount = new BigNumber(1);
|
||||
const receiverCallbackData = '0x';
|
||||
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const makerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
const takerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
@@ -965,18 +955,22 @@ blockchainTests.resets('Exchange core', () => {
|
||||
const makerAssetAmount = new BigNumber(1);
|
||||
const takerAssetAmount = new BigNumber(1);
|
||||
const receiverCallbackData = '0x';
|
||||
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const makerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
const takerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
@@ -1005,18 +999,22 @@ blockchainTests.resets('Exchange core', () => {
|
||||
const makerAssetAmount = new BigNumber(1);
|
||||
const takerAssetAmount = new BigNumber(1);
|
||||
const receiverCallbackData = '0x';
|
||||
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const makerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
const takerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
@@ -1050,18 +1048,22 @@ blockchainTests.resets('Exchange core', () => {
|
||||
const makerAssetAmount = new BigNumber(10);
|
||||
const takerAssetAmount = new BigNumber(20);
|
||||
const receiverCallbackData = '0x';
|
||||
const makerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const takerAssetData = await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
);
|
||||
const makerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
makerAssetsToTransfer,
|
||||
makerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
const takerAssetData = await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Contract.address,
|
||||
takerAssetsToTransfer,
|
||||
takerValuesToTransfer,
|
||||
receiverCallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({
|
||||
makerAssetData,
|
||||
takerAssetData,
|
||||
@@ -1086,12 +1088,10 @@ blockchainTests.resets('Exchange core', () => {
|
||||
);
|
||||
});
|
||||
it('should revert if the staticcall is unsuccessful', async () => {
|
||||
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(new BigNumber(1));
|
||||
const assetData = await devUtils.encodeStaticCallAssetData.callAsync(
|
||||
staticCallTarget.address,
|
||||
staticCallData,
|
||||
constants.KECCAK256_NULL,
|
||||
);
|
||||
const staticCallData = staticCallTarget.assertEvenNumber(new BigNumber(1)).getABIEncodedTransactionData();
|
||||
const assetData = await devUtils
|
||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, constants.KECCAK256_NULL)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({ makerAssetData: assetData });
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyTransferError(
|
||||
@@ -1103,28 +1103,26 @@ blockchainTests.resets('Exchange core', () => {
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should fill the order if the staticcall is successful', async () => {
|
||||
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(
|
||||
constants.ZERO_AMOUNT,
|
||||
);
|
||||
const assetData = await devUtils.encodeStaticCallAssetData.callAsync(
|
||||
staticCallTarget.address,
|
||||
staticCallData,
|
||||
constants.KECCAK256_NULL,
|
||||
);
|
||||
const staticCallData = staticCallTarget
|
||||
.assertEvenNumber(constants.ZERO_AMOUNT)
|
||||
.getABIEncodedTransactionData();
|
||||
const assetData = await devUtils
|
||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, constants.KECCAK256_NULL)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({ makerAssetData: assetData });
|
||||
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
|
||||
});
|
||||
it('should revert if the staticcall is unsuccessful using the MultiAssetProxy', async () => {
|
||||
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(new BigNumber(1));
|
||||
const staticCallAssetData = await devUtils.encodeStaticCallAssetData.callAsync(
|
||||
staticCallTarget.address,
|
||||
staticCallData,
|
||||
constants.KECCAK256_NULL,
|
||||
);
|
||||
const assetData = await devUtils.encodeMultiAssetData.callAsync(
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
[await devUtils.encodeERC20AssetData.callAsync(defaultMakerAssetAddress), staticCallAssetData],
|
||||
);
|
||||
const staticCallData = staticCallTarget.assertEvenNumber(new BigNumber(1)).getABIEncodedTransactionData();
|
||||
const staticCallAssetData = await devUtils
|
||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, constants.KECCAK256_NULL)
|
||||
.callAsync();
|
||||
const assetData = await devUtils
|
||||
.encodeMultiAssetData(
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
[await devUtils.encodeERC20AssetData(defaultMakerAssetAddress).callAsync(), staticCallAssetData],
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({ makerAssetData: assetData });
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyTransferError(
|
||||
@@ -1136,18 +1134,18 @@ blockchainTests.resets('Exchange core', () => {
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should fill the order is the staticcall is successful using the MultiAssetProxy', async () => {
|
||||
const staticCallData = staticCallTarget.assertEvenNumber.getABIEncodedTransactionData(
|
||||
constants.ZERO_AMOUNT,
|
||||
);
|
||||
const staticCallAssetData = await devUtils.encodeStaticCallAssetData.callAsync(
|
||||
staticCallTarget.address,
|
||||
staticCallData,
|
||||
constants.KECCAK256_NULL,
|
||||
);
|
||||
const assetData = await devUtils.encodeMultiAssetData.callAsync(
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
[await devUtils.encodeERC20AssetData.callAsync(defaultMakerAssetAddress), staticCallAssetData],
|
||||
);
|
||||
const staticCallData = staticCallTarget
|
||||
.assertEvenNumber(constants.ZERO_AMOUNT)
|
||||
.getABIEncodedTransactionData();
|
||||
const staticCallAssetData = await devUtils
|
||||
.encodeStaticCallAssetData(staticCallTarget.address, staticCallData, constants.KECCAK256_NULL)
|
||||
.callAsync();
|
||||
const assetData = await devUtils
|
||||
.encodeMultiAssetData(
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
[await devUtils.encodeERC20AssetData(defaultMakerAssetAddress).callAsync(), staticCallAssetData],
|
||||
)
|
||||
.callAsync();
|
||||
signedOrder = await orderFactory.newSignedOrderAsync({ makerAssetData: assetData });
|
||||
await fillOrderWrapper.fillOrderAndAssertEffectsAsync(signedOrder, takerAddress);
|
||||
});
|
||||
|
@@ -79,10 +79,10 @@ describe('AssetProxyDispatcher', () => {
|
||||
txDefaults,
|
||||
dependencyArtifacts,
|
||||
);
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(assetProxyDispatcher.address, {
|
||||
await erc20Proxy.addAuthorizedAddress(assetProxyDispatcher.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(assetProxyDispatcher.address, {
|
||||
await erc721Proxy.addAuthorizedAddress(assetProxyDispatcher.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
});
|
||||
@@ -94,34 +94,34 @@ describe('AssetProxyDispatcher', () => {
|
||||
});
|
||||
describe('registerAssetProxy', () => {
|
||||
it('should record proxy upon registration', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy(AssetProxyId.ERC20).callAsync();
|
||||
expect(proxyAddress).to.be.equal(erc20Proxy.address);
|
||||
});
|
||||
|
||||
it('should be able to record multiple proxies', async () => {
|
||||
// Record first proxy
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
let proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
|
||||
let proxyAddress = await assetProxyDispatcher.getAssetProxy(AssetProxyId.ERC20).callAsync();
|
||||
expect(proxyAddress).to.be.equal(erc20Proxy.address);
|
||||
// Record another proxy
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc721Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC721);
|
||||
proxyAddress = await assetProxyDispatcher.getAssetProxy(AssetProxyId.ERC721).callAsync();
|
||||
expect(proxyAddress).to.be.equal(erc721Proxy.address);
|
||||
});
|
||||
|
||||
it('should revert if a proxy with the same id is already registered', async () => {
|
||||
// Initial registration
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy(AssetProxyId.ERC20).callAsync();
|
||||
expect(proxyAddress).to.be.equal(erc20Proxy.address);
|
||||
// Deploy a new version of the ERC20 Transfer Proxy contract
|
||||
const newErc20TransferProxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(
|
||||
@@ -131,7 +131,7 @@ describe('AssetProxyDispatcher', () => {
|
||||
dependencyArtifacts,
|
||||
);
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyExistsError(AssetProxyId.ERC20, proxyAddress);
|
||||
const tx = assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(newErc20TransferProxy.address, {
|
||||
const tx = assetProxyDispatcher.registerAssetProxy(newErc20TransferProxy.address).sendTransactionAsync({
|
||||
from: owner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
@@ -139,7 +139,7 @@ describe('AssetProxyDispatcher', () => {
|
||||
|
||||
it('should revert if requesting address is not owner', async () => {
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwner, owner);
|
||||
const tx = assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, {
|
||||
const tx = assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).sendTransactionAsync({
|
||||
from: notOwner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
@@ -147,7 +147,7 @@ describe('AssetProxyDispatcher', () => {
|
||||
|
||||
it('should revert if the proxy is not a contract address', async () => {
|
||||
const errMessage = 'VM Exception while processing transaction: revert';
|
||||
const tx = assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(notOwner, {
|
||||
const tx = assetProxyDispatcher.registerAssetProxy(notOwner).sendTransactionAsync({
|
||||
from: owner,
|
||||
});
|
||||
return expect(tx).to.be.rejectedWith(errMessage);
|
||||
@@ -156,7 +156,7 @@ describe('AssetProxyDispatcher', () => {
|
||||
it('should log an event with correct arguments when an asset proxy is registered', async () => {
|
||||
const logDecoder = new LogDecoder(web3Wrapper, artifacts);
|
||||
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await assetProxyDispatcher.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).sendTransactionAsync({
|
||||
from: owner,
|
||||
}),
|
||||
);
|
||||
@@ -169,15 +169,15 @@ describe('AssetProxyDispatcher', () => {
|
||||
|
||||
describe('getAssetProxy', () => {
|
||||
it('should return correct address of registered proxy', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy(AssetProxyId.ERC20).callAsync();
|
||||
expect(proxyAddress).to.be.equal(erc20Proxy.address);
|
||||
});
|
||||
|
||||
it('should return NULL address if requesting non-existent proxy', async () => {
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy.callAsync(AssetProxyId.ERC20);
|
||||
const proxyAddress = await assetProxyDispatcher.getAssetProxy(AssetProxyId.ERC20).callAsync();
|
||||
expect(proxyAddress).to.be.equal(constants.NULL_ADDRESS);
|
||||
});
|
||||
});
|
||||
@@ -186,23 +186,18 @@ describe('AssetProxyDispatcher', () => {
|
||||
const orderHash = orderUtils.generatePseudoRandomOrderHash();
|
||||
it('should dispatch transfer to registered proxy', async () => {
|
||||
// Register ERC20 proxy
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
// Construct metadata for ERC20 proxy
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
|
||||
// Perform a transfer from makerAddress to takerAddress
|
||||
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
const amount = new BigNumber(10);
|
||||
await assetProxyDispatcher.dispatchTransferFrom.awaitTransactionSuccessAsync(
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
amount,
|
||||
{ from: owner },
|
||||
);
|
||||
await assetProxyDispatcher
|
||||
.dispatchTransferFrom(orderHash, encodedAssetData, makerAddress, takerAddress, amount)
|
||||
.awaitTransactionSuccessAsync({ from: owner });
|
||||
// Verify transfer was successful
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances[makerAddress][erc20TokenA.address]).to.be.bignumber.equal(
|
||||
@@ -215,23 +210,18 @@ describe('AssetProxyDispatcher', () => {
|
||||
|
||||
it('should not dispatch a transfer if amount == 0', async () => {
|
||||
// Register ERC20 proxy
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
// Construct metadata for ERC20 proxy
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
|
||||
// Perform a transfer from makerAddress to takerAddress
|
||||
const erc20Balances = await erc20Wrapper.getBalancesAsync();
|
||||
const amount = constants.ZERO_AMOUNT;
|
||||
const txReceipt = await assetProxyDispatcher.dispatchTransferFrom.awaitTransactionSuccessAsync(
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
amount,
|
||||
{ from: owner },
|
||||
);
|
||||
const txReceipt = await assetProxyDispatcher
|
||||
.dispatchTransferFrom(orderHash, encodedAssetData, makerAddress, takerAddress, amount)
|
||||
.awaitTransactionSuccessAsync({ from: owner });
|
||||
expect(txReceipt.logs.length).to.be.equal(0);
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances).to.deep.equal(erc20Balances);
|
||||
@@ -239,7 +229,7 @@ describe('AssetProxyDispatcher', () => {
|
||||
|
||||
it('should revert if dispatching to unregistered proxy', async () => {
|
||||
// Construct metadata for ERC20 proxy
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
|
||||
// Perform a transfer from makerAddress to takerAddress
|
||||
const amount = new BigNumber(10);
|
||||
@@ -248,70 +238,58 @@ describe('AssetProxyDispatcher', () => {
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
);
|
||||
const tx = assetProxyDispatcher.dispatchTransferFrom.sendTransactionAsync(
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
amount,
|
||||
{ from: owner },
|
||||
);
|
||||
const tx = assetProxyDispatcher
|
||||
.dispatchTransferFrom(orderHash, encodedAssetData, makerAddress, takerAddress, amount)
|
||||
.sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert with the correct error when assetData length < 4 bytes', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const encodedAssetData = (await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address)).slice(0, 8);
|
||||
const encodedAssetData = (await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync()).slice(0, 8);
|
||||
const amount = new BigNumber(1);
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
|
||||
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
);
|
||||
const tx = assetProxyDispatcher.dispatchTransferFrom.sendTransactionAsync(
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
amount,
|
||||
{ from: owner },
|
||||
);
|
||||
const tx = assetProxyDispatcher
|
||||
.dispatchTransferFrom(orderHash, encodedAssetData, makerAddress, takerAddress, amount)
|
||||
.sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert if assetData is not padded to 32 bytes (excluding the id)', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
// Shave off the last byte
|
||||
const encodedAssetData = (await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address)).slice(0, 72);
|
||||
const encodedAssetData = (await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync()).slice(
|
||||
0,
|
||||
72,
|
||||
);
|
||||
const amount = new BigNumber(1);
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
|
||||
ExchangeRevertErrors.AssetProxyDispatchErrorCode.InvalidAssetDataLength,
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
);
|
||||
const tx = assetProxyDispatcher.dispatchTransferFrom.sendTransactionAsync(
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
amount,
|
||||
{ from: owner },
|
||||
);
|
||||
const tx = assetProxyDispatcher
|
||||
.dispatchTransferFrom(orderHash, encodedAssetData, makerAddress, takerAddress, amount)
|
||||
.sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert with the reason provided by the AssetProxy when a transfer fails', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await erc20TokenA.approve.awaitTransactionSuccessAsync(erc20Proxy.address, constants.ZERO_AMOUNT, {
|
||||
await erc20TokenA.approve(erc20Proxy.address, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
|
||||
from: makerAddress,
|
||||
});
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const encodedAssetData = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
const amount = new BigNumber(1);
|
||||
const nestedError = new StringRevertError(RevertReason.TransferFailed).encode();
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyTransferError(
|
||||
@@ -319,25 +297,20 @@ describe('AssetProxyDispatcher', () => {
|
||||
encodedAssetData,
|
||||
nestedError,
|
||||
);
|
||||
const tx = assetProxyDispatcher.dispatchTransferFrom.sendTransactionAsync(
|
||||
orderHash,
|
||||
encodedAssetData,
|
||||
makerAddress,
|
||||
takerAddress,
|
||||
amount,
|
||||
{ from: owner },
|
||||
);
|
||||
const tx = assetProxyDispatcher
|
||||
.dispatchTransferFrom(orderHash, encodedAssetData, makerAddress, takerAddress, amount)
|
||||
.sendTransactionAsync({ from: owner });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
describe('simulateDispatchTransferFromCalls', () => {
|
||||
it('should revert with the information specific to the failed transfer', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
|
||||
await erc20TokenB.approve.awaitTransactionSuccessAsync(erc20Proxy.address, constants.ZERO_AMOUNT, {
|
||||
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
|
||||
await erc20TokenB.approve(erc20Proxy.address, constants.ZERO_AMOUNT).awaitTransactionSuccessAsync({
|
||||
from: makerAddress,
|
||||
});
|
||||
const transferIndexAsBytes32 = '0x0000000000000000000000000000000000000000000000000000000000000001';
|
||||
@@ -347,59 +320,67 @@ describe('AssetProxyDispatcher', () => {
|
||||
assetDataB,
|
||||
nestedError,
|
||||
);
|
||||
const tx = assetProxyDispatcher.simulateDispatchTransferFromCalls.sendTransactionAsync(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
);
|
||||
const tx = assetProxyDispatcher
|
||||
.simulateDispatchTransferFromCalls(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
)
|
||||
.sendTransactionAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should forward the revert reason from the underlying failed transfer', async () => {
|
||||
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
|
||||
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
|
||||
const transferIndexAsBytes32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
||||
const expectedError = new ExchangeRevertErrors.AssetProxyDispatchError(
|
||||
ExchangeRevertErrors.AssetProxyDispatchErrorCode.UnknownAssetProxy,
|
||||
transferIndexAsBytes32,
|
||||
assetDataA,
|
||||
);
|
||||
const tx = assetProxyDispatcher.simulateDispatchTransferFromCalls.sendTransactionAsync(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert with TRANSFERS_SUCCESSFUL if no transfers fail', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
from: owner,
|
||||
});
|
||||
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
|
||||
const tx = assetProxyDispatcher.simulateDispatchTransferFromCalls.sendTransactionAsync(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
);
|
||||
return expect(tx).to.revertWith(RevertReason.TransfersSuccessful);
|
||||
});
|
||||
it('should not modify balances if all transfers are successful', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
from: owner,
|
||||
});
|
||||
const assetDataA = await devUtils.encodeERC20AssetData.callAsync(erc20TokenA.address);
|
||||
const assetDataB = await devUtils.encodeERC20AssetData.callAsync(erc20TokenB.address);
|
||||
const balances = await erc20Wrapper.getBalancesAsync();
|
||||
try {
|
||||
await assetProxyDispatcher.simulateDispatchTransferFromCalls.awaitTransactionSuccessAsync(
|
||||
const tx = assetProxyDispatcher
|
||||
.simulateDispatchTransferFromCalls(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
);
|
||||
)
|
||||
.sendTransactionAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert with TRANSFERS_SUCCESSFUL if no transfers fail', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
|
||||
const tx = assetProxyDispatcher
|
||||
.simulateDispatchTransferFromCalls(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
)
|
||||
.sendTransactionAsync();
|
||||
return expect(tx).to.revertWith(RevertReason.TransfersSuccessful);
|
||||
});
|
||||
it('should not modify balances if all transfers are successful', async () => {
|
||||
await assetProxyDispatcher.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
const assetDataA = await devUtils.encodeERC20AssetData(erc20TokenA.address).callAsync();
|
||||
const assetDataB = await devUtils.encodeERC20AssetData(erc20TokenB.address).callAsync();
|
||||
const balances = await erc20Wrapper.getBalancesAsync();
|
||||
try {
|
||||
await assetProxyDispatcher
|
||||
.simulateDispatchTransferFromCalls(
|
||||
[assetDataA, assetDataB],
|
||||
[makerAddress, makerAddress],
|
||||
[takerAddress, takerAddress],
|
||||
[new BigNumber(1), new BigNumber(1)],
|
||||
)
|
||||
.awaitTransactionSuccessAsync();
|
||||
} catch (err) {
|
||||
const newBalances = await erc20Wrapper.getBalancesAsync();
|
||||
expect(newBalances).to.deep.equal(balances);
|
||||
|
@@ -25,7 +25,6 @@ blockchainTests('ExchangeTransferSimulator', env => {
|
||||
let recipient: string;
|
||||
let exampleAssetData: string;
|
||||
let exchangeTransferSimulator: ExchangeTransferSimulator;
|
||||
let txHash: string;
|
||||
let erc20ProxyAddress: string;
|
||||
const devUtils = new DevUtilsContract(constants.NULL_ADDRESS, env.provider);
|
||||
before(async function(): Promise<void> {
|
||||
@@ -65,7 +64,7 @@ blockchainTests('ExchangeTransferSimulator', env => {
|
||||
totalSupply,
|
||||
);
|
||||
|
||||
exampleAssetData = await devUtils.encodeERC20AssetData.callAsync(dummyERC20Token.address);
|
||||
exampleAssetData = await devUtils.encodeERC20AssetData(dummyERC20Token.address).callAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await env.blockchainLifecycle.startAsync();
|
||||
@@ -103,10 +102,9 @@ blockchainTests('ExchangeTransferSimulator', env => {
|
||||
).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerAllowance);
|
||||
});
|
||||
it("throws if the user doesn't have enough balance", async () => {
|
||||
txHash = await dummyERC20Token.approve.sendTransactionAsync(erc20ProxyAddress, transferAmount, {
|
||||
await dummyERC20Token.approve(erc20ProxyAddress, transferAmount).awaitTransactionSuccessAsync({
|
||||
from: sender,
|
||||
});
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
return expect(
|
||||
exchangeTransferSimulator.transferFromAsync(
|
||||
exampleAssetData,
|
||||
@@ -119,15 +117,12 @@ blockchainTests('ExchangeTransferSimulator', env => {
|
||||
).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerBalance);
|
||||
});
|
||||
it('updates balances and proxyAllowance after transfer', async () => {
|
||||
txHash = await dummyERC20Token.transfer.sendTransactionAsync(sender, transferAmount, {
|
||||
await dummyERC20Token.transfer(sender, transferAmount).awaitTransactionSuccessAsync({
|
||||
from: coinbase,
|
||||
});
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
|
||||
txHash = await dummyERC20Token.approve.sendTransactionAsync(erc20ProxyAddress, transferAmount, {
|
||||
await dummyERC20Token.approve(erc20ProxyAddress, transferAmount).awaitTransactionSuccessAsync({
|
||||
from: sender,
|
||||
});
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
|
||||
await exchangeTransferSimulator.transferFromAsync(
|
||||
exampleAssetData,
|
||||
@@ -146,18 +141,14 @@ blockchainTests('ExchangeTransferSimulator', env => {
|
||||
expect(senderProxyAllowance).to.be.bignumber.equal(0);
|
||||
});
|
||||
it("doesn't update proxyAllowance after transfer if unlimited", async () => {
|
||||
txHash = await dummyERC20Token.transfer.sendTransactionAsync(sender, transferAmount, {
|
||||
await dummyERC20Token.transfer(sender, transferAmount).awaitTransactionSuccessAsync({
|
||||
from: coinbase,
|
||||
});
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
txHash = await dummyERC20Token.approve.sendTransactionAsync(
|
||||
erc20ProxyAddress,
|
||||
constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS,
|
||||
{
|
||||
await dummyERC20Token
|
||||
.approve(erc20ProxyAddress, constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: sender,
|
||||
},
|
||||
);
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(txHash);
|
||||
});
|
||||
await exchangeTransferSimulator.transferFromAsync(
|
||||
exampleAssetData,
|
||||
sender,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs';
|
||||
import { blockchainTests, constants, expect, hexRandom, LogDecoder } from '@0x/contracts-test-utils';
|
||||
import { blockchainTests, constants, expect, hexRandom } from '@0x/contracts-test-utils';
|
||||
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
|
||||
@@ -21,7 +21,6 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
const randomHash = () => hexRandom(constants.WORD_LENGTH);
|
||||
const randomAssetData = () => hexRandom(36);
|
||||
let testExchange: TestExchangeInternalsContract;
|
||||
let logDecoder: LogDecoder;
|
||||
let senderAddress: string;
|
||||
const DEFAULT_PROTOCOL_MULTIPLIER = new BigNumber(150000);
|
||||
const DEFAULT_GAS_PRICE = new BigNumber(200000);
|
||||
@@ -37,7 +36,6 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
{},
|
||||
new BigNumber(CHAIN_ID),
|
||||
);
|
||||
logDecoder = new LogDecoder(env.web3Wrapper, artifacts);
|
||||
});
|
||||
|
||||
blockchainTests('assertValidMatch', () => {
|
||||
@@ -82,7 +80,9 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
leftOrder.makerAssetAmount,
|
||||
rightOrder.makerAssetAmount,
|
||||
);
|
||||
return expect(testExchange.assertValidMatch.callAsync(leftOrder, rightOrder)).to.revertWith(expectedError);
|
||||
return expect(testExchange.assertValidMatch(leftOrder, rightOrder).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
|
||||
it('should revert if the taker asset multiplication should overflow', async () => {
|
||||
@@ -99,7 +99,9 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
leftOrder.takerAssetAmount,
|
||||
rightOrder.takerAssetAmount,
|
||||
);
|
||||
return expect(testExchange.assertValidMatch.callAsync(leftOrder, rightOrder)).to.revertWith(expectedError);
|
||||
return expect(testExchange.assertValidMatch(leftOrder, rightOrder).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
|
||||
it('should revert if the prices of the left order is less than the price of the right order', async () => {
|
||||
@@ -114,7 +116,9 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
const orderHashHexLeft = orderHashUtils.getOrderHashHex(leftOrder);
|
||||
const orderHashHexRight = orderHashUtils.getOrderHashHex(rightOrder);
|
||||
const expectedError = new ExchangeRevertErrors.NegativeSpreadError(orderHashHexLeft, orderHashHexRight);
|
||||
return expect(testExchange.assertValidMatch.callAsync(leftOrder, rightOrder)).to.revertWith(expectedError);
|
||||
return expect(testExchange.assertValidMatch(leftOrder, rightOrder).callAsync()).to.revertWith(
|
||||
expectedError,
|
||||
);
|
||||
});
|
||||
|
||||
it('should succeed if the prices of the left and right orders are equal', async () => {
|
||||
@@ -126,7 +130,7 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(100, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(50, 18),
|
||||
});
|
||||
return expect(testExchange.assertValidMatch.callAsync(leftOrder, rightOrder)).to.be.fulfilled('');
|
||||
return expect(testExchange.assertValidMatch(leftOrder, rightOrder).callAsync()).to.be.fulfilled('');
|
||||
});
|
||||
|
||||
it('should succeed if the price of the left order is higher than the price of the right', async () => {
|
||||
@@ -138,7 +142,7 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(100, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(50, 18),
|
||||
});
|
||||
return expect(testExchange.assertValidMatch.callAsync(leftOrder, rightOrder)).to.be.fulfilled('');
|
||||
return expect(testExchange.assertValidMatch(leftOrder, rightOrder).callAsync()).to.be.fulfilled('');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -185,17 +189,12 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
// CAll `testUpdateFilledState()`, which will set the `filled`
|
||||
// state for this order to `orderTakerAssetFilledAmount` before
|
||||
// calling `_updateFilledState()`.
|
||||
const receipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await testExchange.testUpdateFilledState.sendTransactionAsync(
|
||||
order,
|
||||
takerAddress,
|
||||
orderHash,
|
||||
orderTakerAssetFilledAmount,
|
||||
fillResults,
|
||||
),
|
||||
);
|
||||
const receipt = await testExchange
|
||||
.testUpdateFilledState(order, takerAddress, orderHash, orderTakerAssetFilledAmount, fillResults)
|
||||
.awaitTransactionSuccessAsync();
|
||||
|
||||
// Grab the new `filled` state for this order.
|
||||
const actualFilledState = await testExchange.filled.callAsync(orderHash);
|
||||
const actualFilledState = await testExchange.filled(orderHash).callAsync();
|
||||
// Assert the `filled` state for this order.
|
||||
expect(actualFilledState).to.bignumber.eq(expectedFilledState);
|
||||
// Assert the logs.
|
||||
@@ -247,13 +246,15 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
takerAssetFillAmount,
|
||||
);
|
||||
return expect(
|
||||
testExchange.testUpdateFilledState.awaitTransactionSuccessAsync(
|
||||
order,
|
||||
randomAddress(),
|
||||
randomHash(),
|
||||
orderTakerAssetFilledAmount,
|
||||
fillResults,
|
||||
),
|
||||
testExchange
|
||||
.testUpdateFilledState(
|
||||
order,
|
||||
randomAddress(),
|
||||
randomHash(),
|
||||
orderTakerAssetFilledAmount,
|
||||
fillResults,
|
||||
)
|
||||
.awaitTransactionSuccessAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
@@ -287,9 +288,9 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
takerFeePaid: ONE_ETHER.times(0.025),
|
||||
protocolFeePaid: constants.ZERO_AMOUNT,
|
||||
};
|
||||
const receipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await testExchange.settleOrder.sendTransactionAsync(orderHash, order, takerAddress, fillResults),
|
||||
);
|
||||
const receipt = await testExchange
|
||||
.settleOrder(orderHash, order, takerAddress, fillResults)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const logs = receipt.logs as Array<
|
||||
LogWithDecodedArgs<TestExchangeInternalsDispatchTransferFromCalledEventArgs>
|
||||
>;
|
||||
@@ -380,14 +381,16 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
);
|
||||
|
||||
// Ensure that the call to `settleMatchOrders()` fails with the expected error.
|
||||
const tx = testExchange.settleMatchOrders.sendTransactionAsync(
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
leftOrder,
|
||||
rightOrder,
|
||||
takerAddress,
|
||||
matchedFillResults,
|
||||
);
|
||||
const tx = testExchange
|
||||
.settleMatchOrders(
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
leftOrder,
|
||||
rightOrder,
|
||||
takerAddress,
|
||||
matchedFillResults,
|
||||
)
|
||||
.sendTransactionAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -419,14 +422,16 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
|
||||
// The call to `settleMatchOrders()` should be successful.
|
||||
return expect(
|
||||
testExchange.settleMatchOrders.sendTransactionAsync(
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
leftOrder,
|
||||
rightOrder,
|
||||
takerAddress,
|
||||
matchedFillResults,
|
||||
),
|
||||
testExchange
|
||||
.settleMatchOrders(
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
leftOrder,
|
||||
rightOrder,
|
||||
takerAddress,
|
||||
matchedFillResults,
|
||||
)
|
||||
.sendTransactionAsync(),
|
||||
).to.be.fulfilled('');
|
||||
});
|
||||
|
||||
@@ -460,16 +465,16 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
rightOrder.takerFeeAssetData = leftOrder.takerFeeAssetData;
|
||||
|
||||
// Call settleMatchOrders and collect the logs
|
||||
const receipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await testExchange.settleMatchOrders.sendTransactionAsync(
|
||||
const receipt = await testExchange
|
||||
.settleMatchOrders(
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
leftOrder,
|
||||
rightOrder,
|
||||
takerAddress,
|
||||
matchedFillResults,
|
||||
),
|
||||
);
|
||||
)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const logs = receipt.logs as Array<
|
||||
LogWithDecodedArgs<TestExchangeInternalsDispatchTransferFromCalledEventArgs>
|
||||
>;
|
||||
@@ -554,16 +559,16 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
};
|
||||
|
||||
// Call settleMatchOrders and collect the logs
|
||||
const receipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await testExchange.settleMatchOrders.sendTransactionAsync(
|
||||
const receipt = await testExchange
|
||||
.settleMatchOrders(
|
||||
leftOrderHash,
|
||||
rightOrderHash,
|
||||
leftOrder,
|
||||
rightOrder,
|
||||
takerAddress,
|
||||
matchedFillResults,
|
||||
),
|
||||
);
|
||||
)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const logs = receipt.logs as Array<
|
||||
LogWithDecodedArgs<TestExchangeInternalsDispatchTransferFromCalledEventArgs>
|
||||
>;
|
||||
|
@@ -14,7 +14,7 @@ import * as _ from 'lodash';
|
||||
import { artifacts } from './artifacts';
|
||||
import { TestLibExchangeRichErrorDecoderContract } from './wrappers';
|
||||
|
||||
blockchainTests.resets('LibExchangeRichErrorDecoder', ({ provider, txDefaults }) => {
|
||||
blockchainTests.resets.only('LibExchangeRichErrorDecoder', ({ provider, txDefaults }) => {
|
||||
const ASSET_PROXY_ID_LENGTH = 4;
|
||||
const SIGNATURE_LENGTH = 66;
|
||||
const ASSET_DATA_LENGTH = 36;
|
||||
@@ -38,7 +38,7 @@ blockchainTests.resets('LibExchangeRichErrorDecoder', ({ provider, txDefaults })
|
||||
// Solidity counterparts.
|
||||
const endpointName = `decode${revert.name}`;
|
||||
const callAsync = (_encoded: string) => {
|
||||
return (decoder as any)[endpointName].callAsync.call((decoder as any)[endpointName], _encoded);
|
||||
return (decoder as any)[endpointName](_encoded).callAsync.call((decoder as any)[endpointName]);
|
||||
};
|
||||
describe(`${endpointName}()`, async () => {
|
||||
it('decodes encoded parameters', async () => {
|
||||
|
@@ -146,28 +146,28 @@ describe('matchOrders', () => {
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc1155Proxy.address, owner);
|
||||
await exchangeWrapper.registerAssetProxyAsync(multiAssetProxyContract.address, owner);
|
||||
// Authorize proxies.
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, { from: owner });
|
||||
await multiAssetProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(exchange.address, {
|
||||
await erc20Proxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await erc721Proxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await erc1155Proxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
await multiAssetProxyContract.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxyContract.address, {
|
||||
await erc20Proxy.addAuthorizedAddress(multiAssetProxyContract.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxyContract.address, {
|
||||
await erc721Proxy.addAuthorizedAddress(multiAssetProxyContract.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxyContract.address, {
|
||||
await erc1155Proxy.addAuthorizedAddress(multiAssetProxyContract.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, {
|
||||
await multiAssetProxyContract.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, {
|
||||
await multiAssetProxyContract.registerAssetProxy(erc721Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
await multiAssetProxyContract.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, {
|
||||
await multiAssetProxyContract.registerAssetProxy(erc1155Proxy.address).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
|
||||
@@ -182,10 +182,10 @@ describe('matchOrders', () => {
|
||||
const defaultOrderParamsLeft = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress: makerAddressLeft,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeTokenAddress).callAsync(),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeTokenAddress).callAsync(),
|
||||
feeRecipientAddress: feeRecipientAddressLeft,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
@@ -193,10 +193,10 @@ describe('matchOrders', () => {
|
||||
const defaultOrderParamsRight = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultFeeTokenAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeTokenAddress).callAsync(),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData(defaultFeeTokenAddress).callAsync(),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
@@ -349,8 +349,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(83, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(49, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -403,8 +403,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -454,8 +454,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(83, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(49, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -503,8 +503,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -548,8 +548,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(2126, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1063, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -1173,7 +1173,7 @@ describe('matchOrders', () => {
|
||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
feeRecipientAddress: makerAddressLeft,
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
@@ -1270,7 +1270,7 @@ describe('matchOrders', () => {
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(2, 18),
|
||||
});
|
||||
@@ -1297,7 +1297,7 @@ describe('matchOrders', () => {
|
||||
it('should revert if the right maker asset is not equal to the left taker asset', async () => {
|
||||
// Create orders to match
|
||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
});
|
||||
@@ -1451,8 +1451,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(87, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(48, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -1539,8 +1539,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -1590,8 +1590,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(87, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(48, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -1636,8 +1636,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -1681,8 +1681,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(89, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -1800,8 +1800,8 @@ describe('matchOrders', () => {
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
makerAddress: makerAddressRight,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(2126, 0),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(1063, 0),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
@@ -2254,7 +2254,7 @@ describe('matchOrders', () => {
|
||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
feeRecipientAddress: makerAddressLeft,
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
@@ -2351,7 +2351,7 @@ describe('matchOrders', () => {
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
});
|
||||
const signedOrderRight = await orderFactoryRight.newSignedOrderAsync({
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20TakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20TakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(2, 18),
|
||||
});
|
||||
@@ -2378,7 +2378,7 @@ describe('matchOrders', () => {
|
||||
it('should revert if the right maker asset is not equal to the left taker asset', async () => {
|
||||
// Create orders to match
|
||||
const signedOrderLeft = await orderFactoryLeft.newSignedOrderAsync({
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultERC20MakerAssetAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultERC20MakerAssetAddress).callAsync(),
|
||||
makerAssetAmount: Web3Wrapper.toBaseUnitAmount(5, 18),
|
||||
takerAssetAmount: Web3Wrapper.toBaseUnitAmount(10, 18),
|
||||
});
|
||||
@@ -2687,29 +2687,29 @@ describe('matchOrders', () => {
|
||||
let nameToMultiAssetAsset: { [name: string]: [BigNumber[], string[]] };
|
||||
|
||||
async function getAssetDataAsync(assetType: AssetType): Promise<string> {
|
||||
const encodeERC20AssetData = await devUtils.encodeERC20AssetData.callAsync;
|
||||
const encodeERC721AssetData = await devUtils.encodeERC721AssetData.callAsync;
|
||||
const encodeERC1155AssetData = await devUtils.encodeERC1155AssetData.callAsync;
|
||||
const encodeMultiAssetData = await devUtils.encodeMultiAssetData.callAsync;
|
||||
if (nameToERC20Asset[assetType] !== undefined) {
|
||||
const tokenAddress = nameToERC20Asset[assetType];
|
||||
return encodeERC20AssetData(tokenAddress);
|
||||
return devUtils.encodeERC20AssetData(tokenAddress).callAsync();
|
||||
}
|
||||
if (nameToERC721Asset[assetType] !== undefined) {
|
||||
const [tokenAddress, tokenId] = nameToERC721Asset[assetType];
|
||||
return encodeERC721AssetData(tokenAddress, tokenId);
|
||||
return devUtils.encodeERC721AssetData(tokenAddress, tokenId).callAsync();
|
||||
}
|
||||
if (nameToERC1155FungibleAsset[assetType] !== undefined) {
|
||||
const [tokenAddress, tokenId] = nameToERC1155FungibleAsset[assetType];
|
||||
return encodeERC1155AssetData(tokenAddress, [tokenId], [ONE], constants.NULL_BYTES);
|
||||
return devUtils
|
||||
.encodeERC1155AssetData(tokenAddress, [tokenId], [ONE], constants.NULL_BYTES)
|
||||
.callAsync();
|
||||
}
|
||||
if (nameToERC1155NonFungibleAsset[assetType] !== undefined) {
|
||||
const [tokenAddress, tokenId] = nameToERC1155NonFungibleAsset[assetType];
|
||||
return encodeERC1155AssetData(tokenAddress, [tokenId], [ONE], constants.NULL_BYTES);
|
||||
return devUtils
|
||||
.encodeERC1155AssetData(tokenAddress, [tokenId], [ONE], constants.NULL_BYTES)
|
||||
.callAsync();
|
||||
}
|
||||
if (nameToMultiAssetAsset[assetType] !== undefined) {
|
||||
const [amounts, nestedAssetData] = nameToMultiAssetAsset[assetType];
|
||||
return encodeMultiAssetData(amounts, nestedAssetData);
|
||||
return devUtils.encodeMultiAssetData(amounts, nestedAssetData).callAsync();
|
||||
}
|
||||
throw new Error(`Unknown asset type: ${assetType}`);
|
||||
}
|
||||
@@ -2755,49 +2755,57 @@ describe('matchOrders', () => {
|
||||
MULTI_ASSET_A: [
|
||||
[ONE, TWO],
|
||||
[
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[0].address),
|
||||
await devUtils.encodeERC1155AssetData.callAsync(
|
||||
defaultERC1155AssetAddress,
|
||||
[erc1155FungibleTokens[0]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
),
|
||||
await devUtils.encodeERC20AssetData(erc20Tokens[0].address).callAsync(),
|
||||
await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
defaultERC1155AssetAddress,
|
||||
[erc1155FungibleTokens[0]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
)
|
||||
.callAsync(),
|
||||
],
|
||||
],
|
||||
MULTI_ASSET_B: [
|
||||
[ONE, TWO],
|
||||
[
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[1].address),
|
||||
await devUtils.encodeERC1155AssetData.callAsync(
|
||||
defaultERC1155AssetAddress,
|
||||
[erc1155FungibleTokens[1]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
),
|
||||
await devUtils.encodeERC20AssetData(erc20Tokens[1].address).callAsync(),
|
||||
await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
defaultERC1155AssetAddress,
|
||||
[erc1155FungibleTokens[1]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
)
|
||||
.callAsync(),
|
||||
],
|
||||
],
|
||||
MULTI_ASSET_C: [
|
||||
[ONE, TWO],
|
||||
[
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[2].address),
|
||||
await devUtils.encodeERC1155AssetData.callAsync(
|
||||
defaultERC1155AssetAddress,
|
||||
[erc1155FungibleTokens[2]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
),
|
||||
await devUtils.encodeERC20AssetData(erc20Tokens[2].address).callAsync(),
|
||||
await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
defaultERC1155AssetAddress,
|
||||
[erc1155FungibleTokens[2]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
)
|
||||
.callAsync(),
|
||||
],
|
||||
],
|
||||
MULTI_ASSET_D: [
|
||||
[ONE, TWO],
|
||||
[
|
||||
await devUtils.encodeERC20AssetData.callAsync(erc20Tokens[3].address),
|
||||
await devUtils.encodeERC1155AssetData.callAsync(
|
||||
erc1155Token.address,
|
||||
[erc1155FungibleTokens[3]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
),
|
||||
await devUtils.encodeERC20AssetData(erc20Tokens[3].address).callAsync(),
|
||||
await devUtils
|
||||
.encodeERC1155AssetData(
|
||||
erc1155Token.address,
|
||||
[erc1155FungibleTokens[3]],
|
||||
[ONE],
|
||||
constants.NULL_BYTES,
|
||||
)
|
||||
.callAsync(),
|
||||
],
|
||||
],
|
||||
};
|
||||
|
@@ -32,244 +32,223 @@ blockchainTests('Protocol Fee Payments', env => {
|
||||
|
||||
blockchainTests.resets('fillOrder Protocol Fees', () => {
|
||||
it('should not pay protocol fee when there is no registered protocol fee collector', async () => {
|
||||
await testProtocolFeesReceiver.testFillOrderProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
false,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testFillOrderProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, false)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not forward ETH when too little value is sent', async () => {
|
||||
await testProtocolFeesReceiver.testFillOrderProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testFillOrderProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.minus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay protocol fee in ETH when the correct value is sent', async () => {
|
||||
await testProtocolFeesReceiver.testFillOrderProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testFillOrderProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay protocol fee in ETH when extra value is sent', async () => {
|
||||
await testProtocolFeesReceiver.testFillOrderProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testFillOrderProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.plus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('matchOrders Protocol Fees', () => {
|
||||
it('should not pay protocol fee when there is no registered protocol fee collector', async () => {
|
||||
await testProtocolFeesReceiver.testMatchOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
false,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testMatchOrdersProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, false)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not forward ETH twice when too little value is sent', async () => {
|
||||
await testProtocolFeesReceiver.testMatchOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testMatchOrdersProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.minus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay protocol fee in ETH and then not forward ETH when exactly one protocol fee is sent', async () => {
|
||||
await testProtocolFeesReceiver.testMatchOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testMatchOrdersProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay protocol fee in ETH and then not forward ETH when a bit more than one protocol fee is sent', async () => {
|
||||
await testProtocolFeesReceiver.testMatchOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testMatchOrdersProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.plus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay protocol fee in ETH when exactly double the protocol fee is sent', async () => {
|
||||
await testProtocolFeesReceiver.testMatchOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testMatchOrdersProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.times(2),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay protocol fee in ETH when more than double the protocol fee is sent', async () => {
|
||||
await testProtocolFeesReceiver.testMatchOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testMatchOrdersProtocolFees(testProtocolFees.address, DEFAULT_PROTOCOL_FEE_MULTIPLIER, true)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.times(2).plus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
blockchainTests.resets('batchFillOrder ProtocolFees', () => {
|
||||
it('should not pay protocol fees when there is not a protocolFeeCollector registered', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2), // If successful, create a `batchFillOrders` with 2 orders.
|
||||
false,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2), // If successful, create a `batchFillOrders` with 2 orders.
|
||||
false,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not forward ETH when less than one protocol fee is sent and only one order is in the batch', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(1),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(1),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.minus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay one protocol fee in ETH when the exact protocol fee is sent and only one order is in the batch', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(1),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(1),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay one protocol fee in ETH when more than the exact protocol fee is sent and only one order is in the batch', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(1),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(1),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.plus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not forward ETH twice when an insuffiecent amount of ETH for one protocol fee is sent', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.minus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay a protocol in ETH and not forward ETH for the second when exactly one protocol fee in ETH is sent', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay both protocol fees in ETH when exactly two protocol fees in ETH is sent', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(2),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.times(2),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay two protocol fees in ETH and then not forward ETH for a third when exactly two protocol fees in ETH is sent', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(3),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(3),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.times(2),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should pay three protocol fees in ETH when more than three protocol fees in ETH is sent', async () => {
|
||||
await testProtocolFeesReceiver.testBatchFillOrdersProtocolFees.awaitTransactionSuccessAsync(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(3),
|
||||
true,
|
||||
{
|
||||
await testProtocolFeesReceiver
|
||||
.testBatchFillOrdersProtocolFees(
|
||||
testProtocolFees.address,
|
||||
DEFAULT_PROTOCOL_FEE_MULTIPLIER,
|
||||
new BigNumber(3),
|
||||
true,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: DEFAULT_GAS_PRICE,
|
||||
value: DEFAULT_PROTOCOL_FEE.times(3).plus(10),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -43,7 +43,7 @@ blockchainTests.resets('MixinProtocolFees', env => {
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(nonOwner, owner);
|
||||
|
||||
// Ensure that the transaction reverts with the expected rich error.
|
||||
const tx = exchange.setProtocolFeeCollectorAddress.sendTransactionAsync(protocolFeeCollector, {
|
||||
const tx = exchange.setProtocolFeeCollectorAddress(protocolFeeCollector).sendTransactionAsync({
|
||||
from: nonOwner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
@@ -51,15 +51,14 @@ blockchainTests.resets('MixinProtocolFees', env => {
|
||||
|
||||
it('should succeed and emit an ProtocolFeeMultiplier event if msg.sender == owner', async () => {
|
||||
// Call the `setProtocolFeeMultiplier()` function and get the receipt.
|
||||
const receipt = await exchange.setProtocolFeeMultiplier.awaitTransactionSuccessAsync(
|
||||
protocolFeeMultiplier,
|
||||
{
|
||||
const receipt = await exchange
|
||||
.setProtocolFeeMultiplier(protocolFeeMultiplier)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// Verify that the protocolFeeCollector address was actually updated to the correct address.
|
||||
const updated = await exchange.protocolFeeMultiplier.callAsync();
|
||||
const updated = await exchange.protocolFeeMultiplier().callAsync();
|
||||
expect(updated).bignumber.to.be.eq(protocolFeeMultiplier);
|
||||
|
||||
// Ensure that the correct `ProtocolFeeCollectorAddress` event was logged.
|
||||
@@ -76,7 +75,7 @@ blockchainTests.resets('MixinProtocolFees', env => {
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(nonOwner, owner);
|
||||
|
||||
// Ensure that the transaction reverts with the expected rich error.
|
||||
const tx = exchange.setProtocolFeeCollectorAddress.sendTransactionAsync(protocolFeeCollector, {
|
||||
const tx = exchange.setProtocolFeeCollectorAddress(protocolFeeCollector).sendTransactionAsync({
|
||||
from: nonOwner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
@@ -84,15 +83,14 @@ blockchainTests.resets('MixinProtocolFees', env => {
|
||||
|
||||
it('should succeed and emit an ProtocolFeeCollectorAddress event if msg.sender == owner', async () => {
|
||||
// Call the `setProtocolFeeCollectorAddress()` function and get the receipt.
|
||||
const receipt = await exchange.setProtocolFeeCollectorAddress.awaitTransactionSuccessAsync(
|
||||
protocolFeeCollector,
|
||||
{
|
||||
const receipt = await exchange
|
||||
.setProtocolFeeCollectorAddress(protocolFeeCollector)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// Verify that the protocolFeeCollector address was actually updated to the correct address.
|
||||
const updated = await exchange.protocolFeeCollector.callAsync();
|
||||
const updated = await exchange.protocolFeeCollector().callAsync();
|
||||
expect(updated).to.be.eq(protocolFeeCollector);
|
||||
|
||||
// Ensure that the correct `UpdatedProtocolFeeCollectorAddress` event was logged.
|
||||
@@ -109,23 +107,23 @@ blockchainTests.resets('MixinProtocolFees', env => {
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(nonOwner, owner);
|
||||
|
||||
// Ensure that the transaction reverts with the expected rich error.
|
||||
const tx = exchange.detachProtocolFeeCollector.sendTransactionAsync({
|
||||
const tx = exchange.detachProtocolFeeCollector().sendTransactionAsync({
|
||||
from: nonOwner,
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should succeed and emit an ProtocolFeeCollectorAddress event if msg.sender == owner', async () => {
|
||||
await exchange.setProtocolFeeCollectorAddress.awaitTransactionSuccessAsync(protocolFeeCollector, {
|
||||
await exchange.setProtocolFeeCollectorAddress(protocolFeeCollector).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
|
||||
const receipt = await exchange.detachProtocolFeeCollector.awaitTransactionSuccessAsync({
|
||||
const receipt = await exchange.detachProtocolFeeCollector().awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
|
||||
// Verify that the protocolFeeCollector address was actually updated to the correct address.
|
||||
const updated = await exchange.protocolFeeCollector.callAsync();
|
||||
const updated = await exchange.protocolFeeCollector().callAsync();
|
||||
expect(updated).to.be.eq(constants.NULL_ADDRESS);
|
||||
|
||||
// Ensure that the correct `UpdatedProtocolFeeCollectorAddress` event was logged.
|
||||
|
@@ -102,8 +102,8 @@ blockchainTests.resets('Reentrancy Tests', env => {
|
||||
for (const fn of NON_REENTRANT_FUNCTIONS) {
|
||||
it(`${fn.name}()`, async () => {
|
||||
const inputs = createFunctionInputs(fn.inputs);
|
||||
const callData = (testerContract as any)[fn.name].getABIEncodedTransactionData(...inputs);
|
||||
const isReentrant = await testerContract.isReentrant.callAsync(callData);
|
||||
const callData = (testerContract as any)[fn.name](...inputs).getABIEncodedTransactionData();
|
||||
const isReentrant = await testerContract.isReentrant(callData).callAsync();
|
||||
expect(isReentrant).to.be.false();
|
||||
});
|
||||
}
|
||||
@@ -113,8 +113,8 @@ blockchainTests.resets('Reentrancy Tests', env => {
|
||||
for (const fn of REENTRANT_FUNCTIONS) {
|
||||
it(`${fn.name}()`, async () => {
|
||||
const inputs = createFunctionInputs(fn.inputs);
|
||||
const callData = (testerContract as any)[fn.name].getABIEncodedTransactionData(...inputs);
|
||||
const isReentrant = await testerContract.isReentrant.callAsync(callData);
|
||||
const callData = (testerContract as any)[fn.name](...inputs).getABIEncodedTransactionData();
|
||||
const isReentrant = await testerContract.isReentrant(callData).callAsync();
|
||||
expect(isReentrant).to.be.true();
|
||||
});
|
||||
}
|
||||
|
@@ -58,16 +58,14 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
{},
|
||||
signatureValidator.address,
|
||||
);
|
||||
validatorWalletRevertReason = await validatorWallet.REVERT_REASON.callAsync();
|
||||
validatorWalletRevertReason = await validatorWallet.REVERT_REASON().callAsync();
|
||||
|
||||
// Approve the validator for both signers.
|
||||
await Promise.all(
|
||||
[signerAddress, notSignerAddress].map(async (addr: string) => {
|
||||
return signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
true,
|
||||
{ from: addr },
|
||||
);
|
||||
return signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, true)
|
||||
.awaitTransactionSuccessAsync({ from: addr });
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -299,7 +297,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
it('should return true when SignatureType=Presigned and signer has presigned hash', async () => {
|
||||
const hashHex = getCurrentHashHex();
|
||||
// Presign the hash
|
||||
await signatureValidator.preSign.awaitTransactionSuccessAsync(hashHex, { from: signerAddress });
|
||||
await signatureValidator.preSign(hashHex).awaitTransactionSuccessAsync({ from: signerAddress });
|
||||
// Validate presigned signature
|
||||
const signatureHex = hexConcat(SignatureType.PreSigned);
|
||||
const isValidSignature = await validateAsync(hashHex, signerAddress, signatureHex);
|
||||
@@ -333,13 +331,11 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
? constants.NULL_BYTES
|
||||
: hashBytes(validatorExpectedSignatureHex);
|
||||
if (validatorAction !== undefined) {
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
_hashHex,
|
||||
validatorAction,
|
||||
expectedSignatureHashHex,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(_hashHex, validatorAction, expectedSignatureHashHex)
|
||||
.awaitTransactionSuccessAsync();
|
||||
}
|
||||
return signatureValidator.isValidHashSignature.callAsync(_hashHex, _signerAddress, signatureHex);
|
||||
return signatureValidator.isValidHashSignature(_hashHex, _signerAddress, signatureHex).callAsync();
|
||||
};
|
||||
|
||||
it('should revert when signerAddress == 0', async () => {
|
||||
@@ -388,11 +384,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const trezorSignatureType = ethUtil.toBuffer(`0x${SignatureType.EthSign}`);
|
||||
const signature = Buffer.concat([v, r, s, trezorSignatureType]);
|
||||
const signatureHex = ethUtil.bufferToHex(signature);
|
||||
const isValidSignature = await signatureValidator.isValidHashSignature.callAsync(
|
||||
messageHash,
|
||||
signer,
|
||||
signatureHex,
|
||||
);
|
||||
const isValidSignature = await signatureValidator
|
||||
.isValidHashSignature(messageHash, signer, signatureHex)
|
||||
.callAsync();
|
||||
expect(isValidSignature).to.be.true();
|
||||
});
|
||||
|
||||
@@ -406,11 +400,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const trezorSignatureType = ethUtil.toBuffer(`0x${SignatureType.EthSign}`);
|
||||
const signature = Buffer.concat([v, r, s, trezorSignatureType]);
|
||||
const signatureHex = ethUtil.bufferToHex(signature);
|
||||
const isValidSignature = await signatureValidator.isValidHashSignature.callAsync(
|
||||
messageHash,
|
||||
signer,
|
||||
signatureHex,
|
||||
);
|
||||
const isValidSignature = await signatureValidator
|
||||
.isValidHashSignature(messageHash, signer, signatureHex)
|
||||
.callAsync();
|
||||
expect(isValidSignature).to.be.true();
|
||||
});
|
||||
|
||||
@@ -427,10 +419,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress,
|
||||
feeRecipientAddress: randomAddress(),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(randomAddress()),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData(randomAddress()).callAsync(),
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
exchangeAddress: signatureValidator.address,
|
||||
@@ -455,13 +447,11 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
? constants.NULL_BYTES
|
||||
: hashBytes(validatorExpectedSignatureHex);
|
||||
if (validatorAction !== undefined) {
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
orderHashHex,
|
||||
validatorAction,
|
||||
expectedSignatureHashHex,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(orderHashHex, validatorAction, expectedSignatureHashHex)
|
||||
.awaitTransactionSuccessAsync();
|
||||
}
|
||||
return signatureValidator.isValidOrderSignature.callAsync(order, signatureHex);
|
||||
return signatureValidator.isValidOrderSignature(order, signatureHex).callAsync();
|
||||
};
|
||||
|
||||
it('should revert when signerAddress == 0', async () => {
|
||||
@@ -477,7 +467,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
constants.NULL_ADDRESS,
|
||||
signatureHex,
|
||||
);
|
||||
const tx = signatureValidator.isValidOrderSignature.callAsync(nullMakerOrder, signatureHex);
|
||||
const tx = signatureValidator.isValidOrderSignature(nullMakerOrder, signatureHex).callAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -526,7 +516,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -543,7 +533,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -560,7 +550,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -573,11 +563,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
|
||||
it('should revert when SignatureType=Validator and signature is shorter than 21 bytes', async () => {
|
||||
// Set approval of signature validator to false
|
||||
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
false,
|
||||
{ from: signedOrder.makerAddress },
|
||||
);
|
||||
await signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, false)
|
||||
.awaitTransactionSuccessAsync({ from: signedOrder.makerAddress });
|
||||
// Doesn't have to contain a real signature since our wallet contract
|
||||
// just does a hash comparison.
|
||||
const signatureHex = hexConcat(SignatureType.Validator);
|
||||
@@ -594,11 +582,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
|
||||
it('should revert when SignatureType=Validator, signature is valid and validator is not approved', async () => {
|
||||
// Set approval of signature validator to false
|
||||
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
false,
|
||||
{ from: signedOrder.makerAddress },
|
||||
);
|
||||
await signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, false)
|
||||
.awaitTransactionSuccessAsync({ from: signedOrder.makerAddress });
|
||||
// Doesn't have to contain a real signature since our wallet contract
|
||||
// just does a hash comparison.
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
@@ -663,7 +649,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, SignatureType.EIP1271Wallet);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -680,7 +666,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
// just does a hash comparison.
|
||||
const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -695,7 +681,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
signedOrder.makerAddress = validatorWallet.address;
|
||||
const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -710,21 +696,21 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
|
||||
signedOrder.makerAddress = notSignerAddress;
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
notSignerAddress,
|
||||
data,
|
||||
signatureHex,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const tx = signatureValidator.isValidOrderSignature.callAsync(signedOrder, signatureHex);
|
||||
const tx = signatureValidator.isValidOrderSignature(signedOrder, signatureHex).callAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert when signer is an EOA and SignatureType=Validator', async () => {
|
||||
const signatureHex = hexConcat(notSignerAddress, SignatureType.Validator);
|
||||
const orderHashHex = orderHashUtils.getOrderHashHex(signedOrder);
|
||||
const data = eip1271Data.OrderWithHash.getABIEncodedTransactionData(signedOrder, orderHashHex);
|
||||
const data = eip1271Data.OrderWithHash(signedOrder, orderHashHex).getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
notSignerAddress,
|
||||
data,
|
||||
@@ -732,12 +718,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
// Register an EOA as a validator.
|
||||
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
notSignerAddress,
|
||||
true,
|
||||
{ from: signerAddress },
|
||||
);
|
||||
const tx = signatureValidator.isValidOrderSignature.callAsync(signedOrder, signatureHex);
|
||||
await signatureValidator
|
||||
.setSignatureValidatorApproval(notSignerAddress, true)
|
||||
.awaitTransactionSuccessAsync({ from: signerAddress });
|
||||
const tx = signatureValidator.isValidOrderSignature(signedOrder, signatureHex).callAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -787,13 +771,11 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
? constants.NULL_BYTES
|
||||
: hashBytes(validatorExpectedSignatureHex);
|
||||
if (validatorAction !== undefined) {
|
||||
await validatorWallet.prepare.awaitTransactionSuccessAsync(
|
||||
transactionHashHex,
|
||||
validatorAction,
|
||||
expectedSignatureHashHex,
|
||||
);
|
||||
await validatorWallet
|
||||
.prepare(transactionHashHex, validatorAction, expectedSignatureHashHex)
|
||||
.awaitTransactionSuccessAsync();
|
||||
}
|
||||
return signatureValidator.isValidTransactionSignature.callAsync(transaction, signatureHex);
|
||||
return signatureValidator.isValidTransactionSignature(transaction, signatureHex).callAsync();
|
||||
};
|
||||
|
||||
it('should revert when signerAddress == 0', async () => {
|
||||
@@ -809,7 +791,7 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
constants.NULL_ADDRESS,
|
||||
signatureHex,
|
||||
);
|
||||
const tx = signatureValidator.isValidTransactionSignature.callAsync(nullSignerTransaction, signatureHex);
|
||||
const tx = signatureValidator.isValidTransactionSignature(nullSignerTransaction, signatureHex).callAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -856,11 +838,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
|
||||
it('should revert when SignatureType=Validator and signature is shorter than 21 bytes', async () => {
|
||||
// Set approval of signature validator to false
|
||||
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
false,
|
||||
{ from: signedTransaction.signerAddress },
|
||||
);
|
||||
await signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, false)
|
||||
.awaitTransactionSuccessAsync({ from: signedTransaction.signerAddress });
|
||||
// Doesn't have to contain a real signature since our wallet contract
|
||||
// just does a hash comparison.
|
||||
const signatureHex = hexConcat(SignatureType.Validator);
|
||||
@@ -879,10 +859,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -904,10 +883,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -924,10 +902,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, validatorWallet.address, SignatureType.Validator);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -940,11 +917,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
|
||||
it('should revert when SignatureType=Validator, signature is valid and validator is not approved', async () => {
|
||||
// Set approval of signature validator to false
|
||||
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
false,
|
||||
{ from: signedTransaction.signerAddress },
|
||||
);
|
||||
await signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, false)
|
||||
.awaitTransactionSuccessAsync({ from: signedTransaction.signerAddress });
|
||||
// Doesn't have to contain a real signature since our wallet contract
|
||||
// just does a hash comparison.
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
@@ -1009,10 +984,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
const signatureDataHex = generateRandomSignature();
|
||||
const signatureHex = hexConcat(signatureDataHex, SignatureType.EIP1271Wallet);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -1034,10 +1008,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
// just does a hash comparison.
|
||||
const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -1054,10 +1027,9 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
// just does a hash comparison.
|
||||
const signatureHex = hexConcat(generateRandomSignature(), SignatureType.EIP1271Wallet);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
validatorWallet.address,
|
||||
data,
|
||||
@@ -1071,27 +1043,25 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
it('should revert when signer is an EOA and SignatureType=EIP1271Wallet', async () => {
|
||||
const signatureHex = hexConcat(SignatureType.EIP1271Wallet);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
signedTransaction.signerAddress,
|
||||
data,
|
||||
signatureHex,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const tx = signatureValidator.isValidTransactionSignature.callAsync(signedTransaction, signatureHex);
|
||||
const tx = signatureValidator.isValidTransactionSignature(signedTransaction, signatureHex).callAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('should revert when signer is an EOA and SignatureType=Validator', async () => {
|
||||
const signatureHex = hexConcat(notSignerAddress, SignatureType.Validator);
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(signedTransaction);
|
||||
const data = eip1271Data.ZeroExTransactionWithHash.getABIEncodedTransactionData(
|
||||
signedTransaction,
|
||||
transactionHashHex,
|
||||
);
|
||||
const data = eip1271Data
|
||||
.ZeroExTransactionWithHash(signedTransaction, transactionHashHex)
|
||||
.getABIEncodedTransactionData();
|
||||
const expectedError = new ExchangeRevertErrors.EIP1271SignatureError(
|
||||
notSignerAddress,
|
||||
data,
|
||||
@@ -1099,12 +1069,10 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
// Register an EOA as a validator.
|
||||
await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
notSignerAddress,
|
||||
true,
|
||||
{ from: signerAddress },
|
||||
);
|
||||
const tx = signatureValidator.isValidTransactionSignature.callAsync(signedTransaction, signatureHex);
|
||||
await signatureValidator
|
||||
.setSignatureValidatorApproval(notSignerAddress, true)
|
||||
.awaitTransactionSuccessAsync({ from: signerAddress });
|
||||
const tx = signatureValidator.isValidTransactionSignature(signedTransaction, signatureHex).callAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -1134,13 +1102,11 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
|
||||
it('should emit a SignatureValidatorApprovalSet with correct args when a validator is approved', async () => {
|
||||
const approval = true;
|
||||
const res = await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
approval,
|
||||
{
|
||||
const res = await signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, approval)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: signerAddress,
|
||||
},
|
||||
);
|
||||
});
|
||||
expect(res.logs.length).to.equal(1);
|
||||
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<
|
||||
TestSignatureValidatorSignatureValidatorApprovalEventArgs
|
||||
@@ -1152,13 +1118,11 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
});
|
||||
it('should emit a SignatureValidatorApprovalSet with correct args when a validator is disapproved', async () => {
|
||||
const approval = false;
|
||||
const res = await signatureValidator.setSignatureValidatorApproval.awaitTransactionSuccessAsync(
|
||||
validatorWallet.address,
|
||||
approval,
|
||||
{
|
||||
const res = await signatureValidator
|
||||
.setSignatureValidatorApproval(validatorWallet.address, approval)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: signerAddress,
|
||||
},
|
||||
);
|
||||
});
|
||||
expect(res.logs.length).to.equal(1);
|
||||
const log = signatureValidatorLogDecoder.decodeLogOrThrow(res.logs[0]) as LogWithDecodedArgs<
|
||||
TestSignatureValidatorSignatureValidatorApprovalEventArgs
|
||||
|
@@ -101,7 +101,7 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
exchangeWrapper = new ExchangeWrapper(exchangeInstance);
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc20Proxy.address, owner);
|
||||
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeInstance.address, { from: owner });
|
||||
await erc20Proxy.addAuthorizedAddress(exchangeInstance.address).awaitTransactionSuccessAsync({ from: owner });
|
||||
|
||||
defaultMakerTokenAddress = erc20TokenA.address;
|
||||
defaultTakerTokenAddress = erc20TokenB.address;
|
||||
@@ -112,10 +112,10 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress,
|
||||
feeRecipientAddress,
|
||||
makerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultMakerTokenAddress),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerTokenAddress),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultMakerFeeTokenAddress),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData.callAsync(defaultTakerFeeTokenAddress),
|
||||
makerAssetData: await devUtils.encodeERC20AssetData(defaultMakerTokenAddress).callAsync(),
|
||||
takerAssetData: await devUtils.encodeERC20AssetData(defaultTakerTokenAddress).callAsync(),
|
||||
makerFeeAssetData: await devUtils.encodeERC20AssetData(defaultMakerFeeTokenAddress).callAsync(),
|
||||
takerFeeAssetData: await devUtils.encodeERC20AssetData(defaultTakerFeeTokenAddress).callAsync(),
|
||||
exchangeAddress: exchangeInstance.address,
|
||||
chainId,
|
||||
};
|
||||
@@ -179,11 +179,9 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
actualGasPrice,
|
||||
transaction.gasPrice,
|
||||
);
|
||||
const tx = exchangeInstance.executeTransaction.sendTransactionAsync(
|
||||
transaction,
|
||||
transaction.signature,
|
||||
{ gasPrice: actualGasPrice, from: senderAddress },
|
||||
);
|
||||
const tx = exchangeInstance
|
||||
.executeTransaction(transaction, transaction.signature)
|
||||
.sendTransactionAsync({ gasPrice: actualGasPrice, from: senderAddress });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the actual gasPrice is less than expected', async () => {
|
||||
@@ -200,11 +198,9 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
actualGasPrice,
|
||||
transaction.gasPrice,
|
||||
);
|
||||
const tx = exchangeInstance.executeTransaction.sendTransactionAsync(
|
||||
transaction,
|
||||
transaction.signature,
|
||||
{ gasPrice: actualGasPrice, from: senderAddress },
|
||||
);
|
||||
const tx = exchangeInstance
|
||||
.executeTransaction(transaction, transaction.signature)
|
||||
.sendTransactionAsync({ gasPrice: actualGasPrice, from: senderAddress });
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
@@ -288,13 +284,11 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
const orders = [order];
|
||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
const returnData = await exchangeInstance.executeTransaction.callAsync(
|
||||
transaction,
|
||||
transaction.signature,
|
||||
{
|
||||
const returnData = await exchangeInstance
|
||||
.executeTransaction(transaction, transaction.signature)
|
||||
.callAsync({
|
||||
from: senderAddress,
|
||||
},
|
||||
);
|
||||
});
|
||||
const abi = artifacts.Exchange.compilerOutput.abi;
|
||||
const methodAbi = abi.filter(abiItem => (abiItem as MethodAbi).name === fnName)[0] as MethodAbi;
|
||||
const abiEncoder = new AbiEncoder.Method(methodAbi);
|
||||
@@ -328,10 +322,9 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
const transactionHashHex = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const recursiveData = exchangeInstance.executeTransaction.getABIEncodedTransactionData(
|
||||
transaction,
|
||||
transaction.signature,
|
||||
);
|
||||
const recursiveData = exchangeInstance
|
||||
.executeTransaction(transaction, transaction.signature)
|
||||
.getABIEncodedTransactionData();
|
||||
const recursiveTransaction = await takerTransactionFactory.newSignedTransactionAsync({
|
||||
data: recursiveData,
|
||||
});
|
||||
@@ -353,10 +346,9 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
const orders = [await orderFactory.newSignedOrderAsync()];
|
||||
const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders);
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
const recursiveData = exchangeInstance.executeTransaction.getABIEncodedTransactionData(
|
||||
transaction,
|
||||
constants.NULL_BYTES,
|
||||
);
|
||||
const recursiveData = exchangeInstance
|
||||
.executeTransaction(transaction, constants.NULL_BYTES)
|
||||
.getABIEncodedTransactionData();
|
||||
const recursiveTransaction = await takerTransactionFactory.newSignedTransactionAsync({
|
||||
data: recursiveData,
|
||||
});
|
||||
@@ -539,7 +531,7 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
describe('cancelOrdersUpTo', () => {
|
||||
it('should be successful if signed by maker and called by sender', async () => {
|
||||
const targetEpoch = constants.ZERO_AMOUNT;
|
||||
const data = exchangeInstance.cancelOrdersUpTo.getABIEncodedTransactionData(targetEpoch);
|
||||
const data = exchangeInstance.cancelOrdersUpTo(targetEpoch).getABIEncodedTransactionData();
|
||||
const transaction = await makerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
const transactionReceipt = await exchangeWrapper.executeTransactionAsync(transaction, senderAddress);
|
||||
const cancelLogs = transactionReceipt.logs.filter(
|
||||
@@ -553,7 +545,7 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
});
|
||||
it('should be successful if called by maker without a signature', async () => {
|
||||
const targetEpoch = constants.ZERO_AMOUNT;
|
||||
const data = exchangeInstance.cancelOrdersUpTo.getABIEncodedTransactionData(targetEpoch);
|
||||
const data = exchangeInstance.cancelOrdersUpTo(targetEpoch).getABIEncodedTransactionData();
|
||||
const transaction = await makerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
const transactionReceipt = await exchangeWrapper.executeTransactionAsync(transaction, makerAddress);
|
||||
const cancelLogs = transactionReceipt.logs.filter(
|
||||
@@ -570,34 +562,33 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
it('should preSign a hash for the signer', async () => {
|
||||
const order = await orderFactory.newSignedOrderAsync();
|
||||
const orderHash = orderHashUtils.getOrderHashHex(order);
|
||||
const data = exchangeInstance.preSign.getABIEncodedTransactionData(orderHash);
|
||||
const data = exchangeInstance.preSign(orderHash).getABIEncodedTransactionData();
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
let isPreSigned = await exchangeInstance.preSigned.callAsync(orderHash, takerAddress);
|
||||
let isPreSigned = await exchangeInstance.preSigned(orderHash, takerAddress).callAsync();
|
||||
expect(isPreSigned).to.be.eq(false);
|
||||
await exchangeWrapper.executeTransactionAsync(transaction, senderAddress);
|
||||
isPreSigned = await exchangeInstance.preSigned.callAsync(orderHash, takerAddress);
|
||||
isPreSigned = await exchangeInstance.preSigned(orderHash, takerAddress).callAsync();
|
||||
expect(isPreSigned).to.be.eq(true);
|
||||
});
|
||||
it('should preSign a hash for the caller if called without a signature', async () => {
|
||||
const order = await orderFactory.newSignedOrderAsync();
|
||||
const orderHash = orderHashUtils.getOrderHashHex(order);
|
||||
const data = exchangeInstance.preSign.getABIEncodedTransactionData(orderHash);
|
||||
const data = exchangeInstance.preSign(orderHash).getABIEncodedTransactionData();
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
transaction.signature = constants.NULL_BYTES;
|
||||
let isPreSigned = await exchangeInstance.preSigned.callAsync(orderHash, takerAddress);
|
||||
let isPreSigned = await exchangeInstance.preSigned(orderHash, takerAddress).callAsync();
|
||||
expect(isPreSigned).to.be.eq(false);
|
||||
await exchangeWrapper.executeTransactionAsync(transaction, takerAddress);
|
||||
isPreSigned = await exchangeInstance.preSigned.callAsync(orderHash, takerAddress);
|
||||
isPreSigned = await exchangeInstance.preSigned(orderHash, takerAddress).callAsync();
|
||||
expect(isPreSigned).to.be.eq(true);
|
||||
});
|
||||
});
|
||||
describe('setSignatureValidatorApproval', () => {
|
||||
it('should approve a validator for the signer', async () => {
|
||||
const shouldApprove = true;
|
||||
const data = exchangeInstance.setSignatureValidatorApproval.getABIEncodedTransactionData(
|
||||
validatorAddress,
|
||||
shouldApprove,
|
||||
);
|
||||
const data = exchangeInstance
|
||||
.setSignatureValidatorApproval(validatorAddress, shouldApprove)
|
||||
.getABIEncodedTransactionData();
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
const transactionReceipt = await exchangeWrapper.executeTransactionAsync(transaction, senderAddress);
|
||||
const validatorApprovalLogs = transactionReceipt.logs.filter(
|
||||
@@ -615,10 +606,9 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
});
|
||||
it('should approve a validator for the caller if called with no signature', async () => {
|
||||
const shouldApprove = true;
|
||||
const data = exchangeInstance.setSignatureValidatorApproval.getABIEncodedTransactionData(
|
||||
validatorAddress,
|
||||
shouldApprove,
|
||||
);
|
||||
const data = exchangeInstance
|
||||
.setSignatureValidatorApproval(validatorAddress, shouldApprove)
|
||||
.getABIEncodedTransactionData();
|
||||
const transaction = await takerTransactionFactory.newSignedTransactionAsync({ data });
|
||||
transaction.signature = constants.NULL_BYTES;
|
||||
const transactionReceipt = await exchangeWrapper.executeTransactionAsync(transaction, takerAddress);
|
||||
@@ -839,11 +829,12 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
const data2 = exchangeDataEncoder.encodeOrdersToExchangeData(ExchangeFunctionName.FillOrder, [order2]);
|
||||
const transaction1 = await takerTransactionFactory.newSignedTransactionAsync({ data: data1 });
|
||||
const transaction2 = await taker2TransactionFactory.newSignedTransactionAsync({ data: data2 });
|
||||
const returnData = await exchangeInstance.batchExecuteTransactions.callAsync(
|
||||
[transaction1, transaction2],
|
||||
[transaction1.signature, transaction2.signature],
|
||||
{ from: senderAddress },
|
||||
);
|
||||
const returnData = await exchangeInstance
|
||||
.batchExecuteTransactions(
|
||||
[transaction1, transaction2],
|
||||
[transaction1.signature, transaction2.signature],
|
||||
)
|
||||
.callAsync({ from: senderAddress });
|
||||
const abi = artifacts.Exchange.compilerOutput.abi;
|
||||
const methodAbi = abi.filter(
|
||||
abiItem => (abiItem as MethodAbi).name === ExchangeFunctionName.FillOrder,
|
||||
@@ -945,11 +936,12 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
]);
|
||||
const transaction1 = await takerTransactionFactory.newSignedTransactionAsync({ data: data1 });
|
||||
const transaction2 = await makerTransactionFactory.newSignedTransactionAsync({ data: data2 });
|
||||
const returnData = await exchangeInstance.batchExecuteTransactions.callAsync(
|
||||
[transaction1, transaction2],
|
||||
[transaction1.signature, transaction2.signature],
|
||||
{ from: senderAddress },
|
||||
);
|
||||
const returnData = await exchangeInstance
|
||||
.batchExecuteTransactions(
|
||||
[transaction1, transaction2],
|
||||
[transaction1.signature, transaction2.signature],
|
||||
)
|
||||
.callAsync({ from: senderAddress });
|
||||
const abi = artifacts.Exchange.compilerOutput.abi;
|
||||
const methodAbi = abi.filter(
|
||||
abiItem => (abiItem as MethodAbi).name === ExchangeFunctionName.FillOrder,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { blockchainTests, constants, describe, expect, hexRandom, TransactionHelper } from '@0x/contracts-test-utils';
|
||||
import { blockchainTests, constants, describe, expect, hexRandom } from '@0x/contracts-test-utils';
|
||||
import { ExchangeRevertErrors, transactionHashUtils } from '@0x/order-utils';
|
||||
import { EIP712DomainWithDefaultSchema, ZeroExTransaction } from '@0x/types';
|
||||
import { BigNumber, StringRevertError } from '@0x/utils';
|
||||
@@ -30,8 +30,6 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
const DEADBEEF_RETURN_DATA = '0xdeadbeef';
|
||||
const INVALID_SIGNATURE = '0x0000';
|
||||
|
||||
const transactionHelper = new TransactionHelper(web3Wrapper, artifacts);
|
||||
|
||||
before(async () => {
|
||||
// A list of available addresses to use during testing.
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
@@ -55,11 +53,9 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
* Generates calldata for a call to `executable()` in the `TestTransactions` contract.
|
||||
*/
|
||||
function getExecutableCallData(shouldSucceed: boolean, callData: string, returnData: string): string {
|
||||
return (transactionsContract as any).executable.getABIEncodedTransactionData(
|
||||
shouldSucceed,
|
||||
callData,
|
||||
returnData,
|
||||
);
|
||||
return (transactionsContract as any)
|
||||
.executable(shouldSucceed, callData, returnData)
|
||||
.getABIEncodedTransactionData();
|
||||
}
|
||||
|
||||
interface GenerateZeroExTransactionParams {
|
||||
@@ -110,10 +106,9 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
);
|
||||
|
||||
// Call the `batchExecuteTransactions()` function and ensure that it reverts with the expected revert error.
|
||||
const tx = transactionsContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
[transaction],
|
||||
[randomSignature()],
|
||||
);
|
||||
const tx = transactionsContract
|
||||
.batchExecuteTransactions([transaction], [randomSignature()])
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -133,10 +128,9 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
);
|
||||
|
||||
// Call the `batchExecuteTransactions()` function and ensure that it reverts with the expected revert error.
|
||||
const tx = transactionsContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
[transaction1, transaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
);
|
||||
const tx = transactionsContract
|
||||
.batchExecuteTransactions([transaction1, transaction2], [randomSignature(), randomSignature()])
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -156,10 +150,9 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
);
|
||||
|
||||
// Call the `batchExecuteTransactions()` function and ensure that it reverts with the expected revert error.
|
||||
const tx = transactionsContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
[transaction1, transaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
);
|
||||
const tx = transactionsContract
|
||||
.batchExecuteTransactions([transaction1, transaction2], [randomSignature(), randomSignature()])
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -177,13 +170,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
ExchangeRevertErrors.TransactionErrorCode.AlreadyExecuted,
|
||||
transactionHash2,
|
||||
);
|
||||
const tx = transactionsContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
[transaction1, transaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.batchExecuteTransactions([transaction1, transaction2], [randomSignature(), randomSignature()])
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[0],
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -196,15 +187,12 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const validSignature = randomSignature();
|
||||
|
||||
const [result, receipt] = await transactionHelper.getResultAndReceiptAsync(
|
||||
transactionsContract.batchExecuteTransactions,
|
||||
[transaction],
|
||||
[validSignature],
|
||||
{ from: accounts[0] },
|
||||
);
|
||||
const contractFn = transactionsContract.batchExecuteTransactions([transaction], [validSignature]);
|
||||
const result = await contractFn.callAsync({ from: accounts[0] });
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync({ from: accounts[0] });
|
||||
|
||||
expect(result.length).to.be.eq(1);
|
||||
const returnData = transactionsContract.executeTransaction.getABIDecodedReturnData(result[0]);
|
||||
const returnData = transactionsContract.getABIDecodedReturnData<void>('executeTransaction', result[0]);
|
||||
expect(returnData).to.equal(DEADBEEF_RETURN_DATA);
|
||||
|
||||
// Ensure that the correct number of events were logged.
|
||||
@@ -234,18 +222,18 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
const transactionHash1 = transactionHashUtils.getTransactionHashHex(transaction1);
|
||||
const transactionHash2 = transactionHashUtils.getTransactionHashHex(transaction2);
|
||||
|
||||
const [result, receipt] = await transactionHelper.getResultAndReceiptAsync(
|
||||
transactionsContract.batchExecuteTransactions,
|
||||
const contractFn = transactionsContract.batchExecuteTransactions(
|
||||
[transaction1, transaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
{ from: accounts[0] },
|
||||
);
|
||||
const result = await contractFn.callAsync({ from: accounts[0] });
|
||||
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync({ from: accounts[0] });
|
||||
expect(result.length).to.be.eq(2);
|
||||
expect(transactionsContract.executeTransaction.getABIDecodedReturnData(result[0])).to.equal(
|
||||
expect(transactionsContract.getABIDecodedReturnData('executeTransaction', result[0])).to.equal(
|
||||
DEADBEEF_RETURN_DATA,
|
||||
);
|
||||
expect(transactionsContract.executeTransaction.getABIDecodedReturnData(result[1])).to.equal(returnData2);
|
||||
expect(transactionsContract.getABIDecodedReturnData('executeTransaction', result[1])).to.equal(returnData2);
|
||||
|
||||
// Verify that the correct number of events were logged.
|
||||
const logs = receipt.logs as Array<LogWithDecodedArgs<TestTransactionsTransactionExecutionEventArgs>>;
|
||||
@@ -270,17 +258,18 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
const innerTransaction2 = await generateZeroExTransactionAsync({ signerAddress: accounts[1] });
|
||||
const innerBatchExecuteTransaction = await generateZeroExTransactionAsync({
|
||||
signerAddress: accounts[2],
|
||||
callData: transactionsContract.batchExecuteTransactions.getABIEncodedTransactionData(
|
||||
[innerTransaction1, innerTransaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
),
|
||||
callData: transactionsContract
|
||||
.batchExecuteTransactions(
|
||||
[innerTransaction1, innerTransaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
)
|
||||
.getABIEncodedTransactionData(),
|
||||
});
|
||||
const outerExecuteTransaction = await generateZeroExTransactionAsync({
|
||||
signerAddress: accounts[1],
|
||||
callData: transactionsContract.executeTransaction.getABIEncodedTransactionData(
|
||||
innerBatchExecuteTransaction,
|
||||
randomSignature(),
|
||||
),
|
||||
callData: transactionsContract
|
||||
.executeTransaction(innerBatchExecuteTransaction, randomSignature())
|
||||
.getABIEncodedTransactionData(),
|
||||
});
|
||||
const innerBatchExecuteTransactionHash = transactionHashUtils.getTransactionHashHex(
|
||||
innerBatchExecuteTransaction,
|
||||
@@ -294,11 +283,9 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
outerExecuteTransactionHash,
|
||||
innerExpectedError.encode(),
|
||||
);
|
||||
const tx = transactionsContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
[outerExecuteTransaction],
|
||||
[randomSignature()],
|
||||
{ from: accounts[2] },
|
||||
);
|
||||
const tx = transactionsContract
|
||||
.batchExecuteTransactions([outerExecuteTransaction], [randomSignature()])
|
||||
.awaitTransactionSuccessAsync({ from: accounts[2] });
|
||||
return expect(tx).to.revertWith(outerExpectedError);
|
||||
});
|
||||
it('should allow recursion as long as currentContextAddress is not set', async () => {
|
||||
@@ -307,34 +294,32 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
// From this point on, all transactions and calls will have the same sender, which does not change currentContextAddress when called
|
||||
const innerBatchExecuteTransaction = await generateZeroExTransactionAsync({
|
||||
signerAddress: accounts[2],
|
||||
callData: transactionsContract.batchExecuteTransactions.getABIEncodedTransactionData(
|
||||
[innerTransaction1, innerTransaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
),
|
||||
callData: transactionsContract
|
||||
.batchExecuteTransactions(
|
||||
[innerTransaction1, innerTransaction2],
|
||||
[randomSignature(), randomSignature()],
|
||||
)
|
||||
.getABIEncodedTransactionData(),
|
||||
});
|
||||
const outerExecuteTransaction = await generateZeroExTransactionAsync({
|
||||
signerAddress: accounts[2],
|
||||
callData: transactionsContract.executeTransaction.getABIEncodedTransactionData(
|
||||
innerBatchExecuteTransaction,
|
||||
randomSignature(),
|
||||
),
|
||||
callData: transactionsContract
|
||||
.executeTransaction(innerBatchExecuteTransaction, randomSignature())
|
||||
.getABIEncodedTransactionData(),
|
||||
});
|
||||
return expect(
|
||||
transactionsContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
[outerExecuteTransaction],
|
||||
[randomSignature()],
|
||||
{ from: accounts[2] },
|
||||
),
|
||||
transactionsContract
|
||||
.batchExecuteTransactions([outerExecuteTransaction], [randomSignature()])
|
||||
.awaitTransactionSuccessAsync({ from: accounts[2] }),
|
||||
).to.be.fulfilled('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('executeTransaction', () => {
|
||||
function getExecuteTransactionCallData(transaction: ZeroExTransaction, signature: string): string {
|
||||
return (transactionsContract as any).executeTransaction.getABIEncodedTransactionData(
|
||||
transaction,
|
||||
signature,
|
||||
);
|
||||
return (transactionsContract as any)
|
||||
.executeTransaction(transaction, signature)
|
||||
.getABIEncodedTransactionData();
|
||||
}
|
||||
it('should revert if the current time is past the expiration time', async () => {
|
||||
const transaction = await generateZeroExTransactionAsync({
|
||||
@@ -345,10 +330,9 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
ExchangeRevertErrors.TransactionErrorCode.Expired,
|
||||
transactionHash,
|
||||
);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
transaction,
|
||||
randomSignature(),
|
||||
);
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(transaction, randomSignature())
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the transaction is submitted with a gasPrice that does not equal the required gasPrice', async () => {
|
||||
@@ -360,13 +344,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
actualGasPrice,
|
||||
transaction.gasPrice,
|
||||
);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
transaction,
|
||||
randomSignature(),
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(transaction, randomSignature())
|
||||
.awaitTransactionSuccessAsync({
|
||||
gasPrice: actualGasPrice,
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if reentrancy occurs in the middle of an executeTransaction call and msg.sender != signer for both calls', async () => {
|
||||
@@ -384,13 +366,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
accounts[0],
|
||||
).encode();
|
||||
const expectedError = new ExchangeRevertErrors.TransactionExecutionError(outerTransactionHash, errorData);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
outerTransaction,
|
||||
validSignature,
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(outerTransaction, validSignature)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[1], // Different then the signing addresses
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if reentrancy occurs in the middle of an executeTransaction call and msg.sender != signer and then msg.sender == signer', async () => {
|
||||
@@ -408,13 +388,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
accounts[0],
|
||||
).encode();
|
||||
const expectedError = new ExchangeRevertErrors.TransactionExecutionError(outerTransactionHash, errorData);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
outerTransaction,
|
||||
validSignature,
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(outerTransaction, validSignature)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[1], // Different then the signing addresses
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should allow reentrancy in the middle of an executeTransaction call if msg.sender == signer for both calls', async () => {
|
||||
@@ -426,7 +404,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
returnData: DEADBEEF_RETURN_DATA,
|
||||
});
|
||||
return expect(
|
||||
transactionsContract.executeTransaction.awaitTransactionSuccessAsync(outerTransaction, validSignature, {
|
||||
transactionsContract.executeTransaction(outerTransaction, validSignature).awaitTransactionSuccessAsync({
|
||||
from: accounts[0],
|
||||
}),
|
||||
).to.be.fulfilled('');
|
||||
@@ -440,7 +418,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
returnData: DEADBEEF_RETURN_DATA,
|
||||
});
|
||||
return expect(
|
||||
transactionsContract.executeTransaction.awaitTransactionSuccessAsync(outerTransaction, validSignature, {
|
||||
transactionsContract.executeTransaction(outerTransaction, validSignature).awaitTransactionSuccessAsync({
|
||||
from: accounts[0],
|
||||
}),
|
||||
).to.be.fulfilled('');
|
||||
@@ -451,17 +429,16 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
// Use the transaction in execute transaction.
|
||||
await expect(
|
||||
transactionsContract.executeTransaction.awaitTransactionSuccessAsync(transaction, validSignature),
|
||||
transactionsContract.executeTransaction(transaction, validSignature).awaitTransactionSuccessAsync(),
|
||||
).to.be.fulfilled('');
|
||||
// Use the same transaction to make another call
|
||||
const expectedError = new ExchangeRevertErrors.TransactionError(
|
||||
ExchangeRevertErrors.TransactionErrorCode.AlreadyExecuted,
|
||||
transactionHash,
|
||||
);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
transaction,
|
||||
validSignature,
|
||||
);
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(transaction, validSignature)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the signer != msg.sender and the signature is not valid', async () => {
|
||||
@@ -473,13 +450,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
accounts[1],
|
||||
INVALID_SIGNATURE,
|
||||
);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
transaction,
|
||||
INVALID_SIGNATURE,
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(transaction, INVALID_SIGNATURE)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[0],
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the signer == msg.sender but the delegatecall fails', async () => {
|
||||
@@ -494,13 +469,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
transactionHash,
|
||||
executableError.encode(),
|
||||
);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
transaction,
|
||||
randomSignature(),
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(transaction, randomSignature())
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[1],
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the signer != msg.sender and the signature is valid but the delegatecall fails', async () => {
|
||||
@@ -516,13 +489,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
transactionHash,
|
||||
executableError.encode(),
|
||||
);
|
||||
const tx = transactionsContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
transaction,
|
||||
validSignature,
|
||||
{
|
||||
const tx = transactionsContract
|
||||
.executeTransaction(transaction, validSignature)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[0],
|
||||
},
|
||||
);
|
||||
});
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
it('should succeed with the correct return hash and event emitted when msg.sender != signer', async () => {
|
||||
@@ -534,14 +505,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
});
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
|
||||
const [result, receipt] = await transactionHelper.getResultAndReceiptAsync(
|
||||
transactionsContract.executeTransaction,
|
||||
transaction,
|
||||
validSignature,
|
||||
{ from: accounts[0] },
|
||||
);
|
||||
const contractFn = transactionsContract.executeTransaction(transaction, validSignature);
|
||||
const result = await contractFn.callAsync({ from: accounts[0] });
|
||||
|
||||
expect(transactionsContract.executeTransaction.getABIDecodedReturnData(result)).to.equal(
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync({ from: accounts[0] });
|
||||
expect(transactionsContract.getABIDecodedReturnData('executeTransaction', result)).to.equal(
|
||||
DEADBEEF_RETURN_DATA,
|
||||
);
|
||||
|
||||
@@ -565,14 +533,11 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
});
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
|
||||
const [result, receipt] = await transactionHelper.getResultAndReceiptAsync(
|
||||
transactionsContract.executeTransaction,
|
||||
transaction,
|
||||
validSignature,
|
||||
{ from: accounts[0] },
|
||||
);
|
||||
const contractFn = transactionsContract.executeTransaction(transaction, validSignature);
|
||||
const result = await contractFn.callAsync({ from: accounts[0] });
|
||||
|
||||
expect(transactionsContract.executeTransaction.getABIDecodedReturnData(result)).to.equal(
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync({ from: accounts[0] });
|
||||
expect(transactionsContract.getABIDecodedReturnData('executeTransaction', result)).to.equal(
|
||||
DEADBEEF_RETURN_DATA,
|
||||
);
|
||||
|
||||
@@ -600,7 +565,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
transactionHash,
|
||||
);
|
||||
expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature()),
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the gasPrice is less than required', async () => {
|
||||
@@ -613,7 +578,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
transaction.gasPrice,
|
||||
);
|
||||
expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature(), {
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync({
|
||||
gasPrice: actualGasPrice,
|
||||
}),
|
||||
).to.revertWith(expectedError);
|
||||
@@ -628,30 +593,30 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
transaction.gasPrice,
|
||||
);
|
||||
expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature(), {
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync({
|
||||
gasPrice: actualGasPrice,
|
||||
}),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if currentContextAddress is non-zero', async () => {
|
||||
await transactionsContract.setCurrentContextAddress.awaitTransactionSuccessAsync(accounts[0]);
|
||||
await transactionsContract.setCurrentContextAddress(accounts[0]).awaitTransactionSuccessAsync();
|
||||
const transaction = await generateZeroExTransactionAsync();
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
const expectedError = new ExchangeRevertErrors.TransactionInvalidContextError(transactionHash, accounts[0]);
|
||||
expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature()),
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if the transaction has already been executed', async () => {
|
||||
const transaction = await generateZeroExTransactionAsync();
|
||||
const transactionHash = transactionHashUtils.getTransactionHashHex(transaction);
|
||||
await transactionsContract.setTransactionExecuted.awaitTransactionSuccessAsync(transactionHash);
|
||||
await transactionsContract.setTransactionExecuted(transactionHash).awaitTransactionSuccessAsync();
|
||||
const expectedError = new ExchangeRevertErrors.TransactionError(
|
||||
ExchangeRevertErrors.TransactionErrorCode.AlreadyExecuted,
|
||||
transactionHash,
|
||||
);
|
||||
expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature()),
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync(),
|
||||
).to.revertWith(expectedError);
|
||||
});
|
||||
it('should revert if signer != msg.sender and the signature is invalid', async () => {
|
||||
@@ -664,7 +629,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
INVALID_SIGNATURE,
|
||||
);
|
||||
expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, INVALID_SIGNATURE, {
|
||||
transactionsContract.assertExecutableTransaction(transaction, INVALID_SIGNATURE).callAsync({
|
||||
from: accounts[1],
|
||||
}),
|
||||
).to.revertWith(expectedError);
|
||||
@@ -672,7 +637,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
it('should be successful if signer == msg.sender and the signature is invalid', async () => {
|
||||
const transaction = await generateZeroExTransactionAsync({ signerAddress: accounts[0] });
|
||||
return expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, INVALID_SIGNATURE, {
|
||||
transactionsContract.assertExecutableTransaction(transaction, INVALID_SIGNATURE).callAsync({
|
||||
from: accounts[0],
|
||||
}),
|
||||
).to.be.fulfilled('');
|
||||
@@ -680,7 +645,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
it('should be successful if signer == msg.sender and the signature is valid', async () => {
|
||||
const transaction = await generateZeroExTransactionAsync({ signerAddress: accounts[0] });
|
||||
return expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature(), {
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync({
|
||||
from: accounts[0],
|
||||
}),
|
||||
).to.be.fulfilled('');
|
||||
@@ -688,7 +653,7 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
it('should be successful if not expired, the gasPrice is correct, the tx has not been executed, currentContextAddress has not been set, signer != msg.sender, and the signature is valid', async () => {
|
||||
const transaction = await generateZeroExTransactionAsync({ signerAddress: accounts[0] });
|
||||
return expect(
|
||||
transactionsContract.assertExecutableTransaction.callAsync(transaction, randomSignature(), {
|
||||
transactionsContract.assertExecutableTransaction(transaction, randomSignature()).callAsync({
|
||||
from: accounts[1],
|
||||
}),
|
||||
).to.be.fulfilled('');
|
||||
@@ -698,30 +663,27 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
describe('setCurrentContextAddressIfRequired', () => {
|
||||
it('should set the currentContextAddress if signer not equal to sender', async () => {
|
||||
const randomAddress = hexRandom(20);
|
||||
await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(
|
||||
randomAddress,
|
||||
randomAddress,
|
||||
);
|
||||
const currentContextAddress = await transactionsContract.currentContextAddress.callAsync();
|
||||
await transactionsContract
|
||||
.setCurrentContextAddressIfRequired(randomAddress, randomAddress)
|
||||
.awaitTransactionSuccessAsync();
|
||||
const currentContextAddress = await transactionsContract.currentContextAddress().callAsync();
|
||||
expect(currentContextAddress).to.eq(randomAddress);
|
||||
});
|
||||
it('should not set the currentContextAddress if signer equal to sender', async () => {
|
||||
const randomAddress = hexRandom(20);
|
||||
await transactionsContract.setCurrentContextAddressIfRequired.awaitTransactionSuccessAsync(
|
||||
accounts[0],
|
||||
randomAddress,
|
||||
{
|
||||
await transactionsContract
|
||||
.setCurrentContextAddressIfRequired(accounts[0], randomAddress)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from: accounts[0],
|
||||
},
|
||||
);
|
||||
const currentContextAddress = await transactionsContract.currentContextAddress.callAsync();
|
||||
});
|
||||
const currentContextAddress = await transactionsContract.currentContextAddress().callAsync();
|
||||
expect(currentContextAddress).to.eq(constants.NULL_ADDRESS);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCurrentContext', () => {
|
||||
it('should return the sender address when there is not a saved context address', async () => {
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress().callAsync({
|
||||
from: accounts[0],
|
||||
});
|
||||
expect(currentContextAddress).to.be.eq(accounts[0]);
|
||||
@@ -729,10 +691,10 @@ blockchainTests.resets('Transaction Unit Tests', ({ provider, web3Wrapper, txDef
|
||||
|
||||
it('should return the sender address when there is a saved context address', async () => {
|
||||
// Set the current context address to the taker address
|
||||
await transactionsContract.setCurrentContextAddress.awaitTransactionSuccessAsync(accounts[1]);
|
||||
await transactionsContract.setCurrentContextAddress(accounts[1]).awaitTransactionSuccessAsync();
|
||||
|
||||
// Ensure that the queried current context address is the same as the address that was set.
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress.callAsync({
|
||||
const currentContextAddress = await transactionsContract.getCurrentContextAddress().callAsync({
|
||||
from: accounts[0],
|
||||
});
|
||||
expect(currentContextAddress).to.be.eq(accounts[1]);
|
||||
|
@@ -10,11 +10,11 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP
|
||||
this._devUtilsContract = devUtilsContract;
|
||||
}
|
||||
public async getBalanceAsync(assetData: string, userAddress: string): Promise<BigNumber> {
|
||||
const balance = await this._devUtilsContract.getBalance.callAsync(userAddress, assetData);
|
||||
const balance = await this._devUtilsContract.getBalance(userAddress, assetData).callAsync();
|
||||
return balance;
|
||||
}
|
||||
public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise<BigNumber> {
|
||||
const proxyAllowance = await this._devUtilsContract.getAssetProxyAllowance.callAsync(userAddress, assetData);
|
||||
const proxyAllowance = await this._devUtilsContract.getAssetProxyAllowance(userAddress, assetData).callAsync();
|
||||
return proxyAllowance;
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ export class AssetWrapper {
|
||||
});
|
||||
}
|
||||
public async getBalanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (proxyId) {
|
||||
case AssetProxyId.ERC20: {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
@@ -44,9 +44,9 @@ export class AssetWrapper {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
|
||||
.decodeERC721AssetData(assetData)
|
||||
.callAsync();
|
||||
const isOwner = await assetWrapper.isOwnerAsync(userAddress, tokenAddress, tokenId);
|
||||
const balance = isOwner ? ONE_NFT_UNIT : ZERO_NFT_UNIT;
|
||||
return balance;
|
||||
@@ -59,7 +59,7 @@ export class AssetWrapper {
|
||||
assetProxyAddress,
|
||||
tokenAddress,
|
||||
tokenIds,
|
||||
] = await this._devUtils.decodeERC1155AssetData.callAsync(assetData);
|
||||
] = await this._devUtils.decodeERC1155AssetData(assetData).callAsync();
|
||||
const assetWrapper = assetProxyWrapper.getContractWrapper(tokenAddress);
|
||||
const balances = await Promise.all(
|
||||
_.map(tokenIds).map(tokenId => assetWrapper.getBalanceAsync(userAddress, tokenId)),
|
||||
@@ -68,9 +68,9 @@ export class AssetWrapper {
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
|
||||
.decodeMultiAssetData(assetData)
|
||||
.callAsync();
|
||||
const nestedBalances = await Promise.all(
|
||||
nestedAssetData.map(async _nestedAssetData => this.getBalanceAsync(userAddress, _nestedAssetData)),
|
||||
);
|
||||
@@ -84,7 +84,7 @@ export class AssetWrapper {
|
||||
}
|
||||
}
|
||||
public async setBalanceAsync(userAddress: string, assetData: string, desiredBalance: BigNumber): Promise<void> {
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (proxyId) {
|
||||
case AssetProxyId.ERC20: {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
@@ -100,9 +100,9 @@ export class AssetWrapper {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
|
||||
.decodeERC721AssetData(assetData)
|
||||
.callAsync();
|
||||
const doesTokenExist = erc721Wrapper.doesTokenExistAsync(tokenAddress, tokenId);
|
||||
if (!doesTokenExist && desiredBalance.gte(1)) {
|
||||
await erc721Wrapper.mintAsync(tokenAddress, tokenId, userAddress);
|
||||
@@ -134,7 +134,7 @@ export class AssetWrapper {
|
||||
tokenAddress,
|
||||
tokenIds,
|
||||
tokenValues,
|
||||
] = await this._devUtils.decodeERC1155AssetData.callAsync(assetData);
|
||||
] = await this._devUtils.decodeERC1155AssetData(assetData).callAsync();
|
||||
const assetWrapper = assetProxyWrapper.getContractWrapper(tokenAddress);
|
||||
const tokenValuesSum = BigNumber.sum(...tokenValues);
|
||||
let tokenValueRatios = tokenValues;
|
||||
@@ -197,9 +197,9 @@ export class AssetWrapper {
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
|
||||
.decodeMultiAssetData(assetData)
|
||||
.callAsync();
|
||||
const amountsSum = BigNumber.sum(...amounts);
|
||||
let assetAmountRatios = amounts;
|
||||
if (!amountsSum.eq(0)) {
|
||||
@@ -220,7 +220,7 @@ export class AssetWrapper {
|
||||
assetData: string,
|
||||
desiredBalance: BigNumber,
|
||||
): Promise<void> {
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (proxyId) {
|
||||
case AssetProxyId.ERC20:
|
||||
case AssetProxyId.ERC721:
|
||||
@@ -235,7 +235,7 @@ export class AssetWrapper {
|
||||
}
|
||||
}
|
||||
public async getProxyAllowanceAsync(userAddress: string, assetData: string): Promise<BigNumber> {
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (proxyId) {
|
||||
case AssetProxyId.ERC20: {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
@@ -247,9 +247,9 @@ export class AssetWrapper {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const assetWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
|
||||
.decodeERC721AssetData(assetData)
|
||||
.callAsync();
|
||||
const isProxyApprovedForAll = await assetWrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
|
||||
if (isProxyApprovedForAll) {
|
||||
return constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
|
||||
@@ -263,9 +263,9 @@ export class AssetWrapper {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyAddress, tokenAddress] = await this._devUtils.decodeERC1155AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyAddress, tokenAddress] = await this._devUtils
|
||||
.decodeERC1155AssetData(assetData)
|
||||
.callAsync();
|
||||
const isApprovedForAll = await assetProxyWrapper.isProxyApprovedForAllAsync(userAddress, tokenAddress);
|
||||
if (!isApprovedForAll) {
|
||||
// ERC1155 is all or nothing.
|
||||
@@ -275,9 +275,9 @@ export class AssetWrapper {
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
|
||||
.decodeMultiAssetData(assetData)
|
||||
.callAsync();
|
||||
const allowances = await Promise.all(
|
||||
nestedAssetData.map(async _nestedAssetData =>
|
||||
this.getProxyAllowanceAsync(userAddress, _nestedAssetData),
|
||||
@@ -294,7 +294,7 @@ export class AssetWrapper {
|
||||
assetData: string,
|
||||
desiredAllowance: BigNumber,
|
||||
): Promise<void> {
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const proxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (proxyId) {
|
||||
case AssetProxyId.ERC20: {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
@@ -315,9 +315,9 @@ export class AssetWrapper {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const erc721Wrapper = this._proxyIdToAssetWrappers[proxyId] as ERC721Wrapper;
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils.decodeERC721AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, tokenAddress, tokenId] = await this._devUtils
|
||||
.decodeERC721AssetData(assetData)
|
||||
.callAsync();
|
||||
|
||||
const doesTokenExist = await erc721Wrapper.doesTokenExistAsync(tokenAddress, tokenId);
|
||||
if (!doesTokenExist) {
|
||||
@@ -352,9 +352,9 @@ export class AssetWrapper {
|
||||
// tslint:disable-next-line:no-unnecessary-type-assertion
|
||||
const assetProxyWrapper = this._proxyIdToAssetWrappers[proxyId] as ERC1155ProxyWrapper;
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyAddress, tokenAddress] = await this._devUtils.decodeERC1155AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyAddress, tokenAddress] = await this._devUtils
|
||||
.decodeERC1155AssetData(assetData)
|
||||
.callAsync();
|
||||
// ERC1155 allowances are all or nothing.
|
||||
const shouldApprovedForAll = desiredAllowance.gt(0);
|
||||
const currentAllowance = await this.getProxyAllowanceAsync(userAddress, assetData);
|
||||
@@ -369,9 +369,9 @@ export class AssetWrapper {
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils.decodeMultiAssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [assetProxyId, amounts, nestedAssetData] = await this._devUtils
|
||||
.decodeMultiAssetData(assetData)
|
||||
.callAsync();
|
||||
await Promise.all(
|
||||
nestedAssetData.map(async _nestedAssetData =>
|
||||
this.setProxyAllowanceAsync(userAddress, _nestedAssetData, desiredAllowance),
|
||||
|
@@ -77,7 +77,7 @@ export class ExchangeTransferSimulator {
|
||||
tradeSide: TradeSide,
|
||||
transferType: TransferType,
|
||||
): Promise<void> {
|
||||
const assetProxyId = await this._devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const assetProxyId = await this._devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (assetProxyId) {
|
||||
case AssetProxyId.ERC1155:
|
||||
case AssetProxyId.ERC20:
|
||||
@@ -110,7 +110,7 @@ export class ExchangeTransferSimulator {
|
||||
break;
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
const decodedAssetData = await this._devUtils.decodeMultiAssetData.callAsync(assetData);
|
||||
const decodedAssetData = await this._devUtils.decodeMultiAssetData(assetData).callAsync();
|
||||
await this._decreaseBalanceAsync(assetData, from, amountInBaseUnits);
|
||||
await this._increaseBalanceAsync(assetData, to, amountInBaseUnits);
|
||||
for (const [index, nestedAssetDataElement] of decodedAssetData[2].entries()) {
|
||||
|
@@ -24,17 +24,14 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const txReceipt = await this.exchangeContract.fillOrder.awaitTransactionSuccessAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from },
|
||||
);
|
||||
const txReceipt = await this.exchangeContract
|
||||
.fillOrder(params.order, params.takerAssetFillAmount, params.signature)
|
||||
.awaitTransactionSuccessAsync({ from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async cancelOrderAsync(signedOrder: SignedOrder, from: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createCancel(signedOrder);
|
||||
const txReceipt = await this.exchangeContract.cancelOrder.awaitTransactionSuccessAsync(params.order, { from });
|
||||
const txReceipt = await this.exchangeContract.cancelOrder(params.order).awaitTransactionSuccessAsync({ from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async fillOrKillOrderAsync(
|
||||
@@ -43,12 +40,9 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber; gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const txReceipt = await this.exchangeContract.fillOrKillOrder.awaitTransactionSuccessAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const txReceipt = await this.exchangeContract
|
||||
.fillOrKillOrder(params.order, params.takerAssetFillAmount, params.signature)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
return txReceipt;
|
||||
}
|
||||
public async batchFillOrdersAsync(
|
||||
@@ -56,111 +50,113 @@ export class ExchangeWrapper {
|
||||
from: string,
|
||||
opts: { takerAssetFillAmounts?: BigNumber[]; gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.batchFillOrders.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.takerAssetFillAmounts === undefined
|
||||
? orders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: opts.takerAssetFillAmounts,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchFillOrders(
|
||||
orders,
|
||||
opts.takerAssetFillAmounts === undefined
|
||||
? orders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: opts.takerAssetFillAmounts,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async batchFillOrKillOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
opts: { takerAssetFillAmounts?: BigNumber[]; gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.batchFillOrKillOrders.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.takerAssetFillAmounts === undefined
|
||||
? orders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: opts.takerAssetFillAmounts,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchFillOrKillOrders(
|
||||
orders,
|
||||
opts.takerAssetFillAmounts === undefined
|
||||
? orders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: opts.takerAssetFillAmounts,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async batchFillOrdersNoThrowAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
opts: { takerAssetFillAmounts?: BigNumber[]; gas?: number; gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.batchFillOrdersNoThrow.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.takerAssetFillAmounts === undefined
|
||||
? orders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: opts.takerAssetFillAmounts,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gas: opts.gas, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchFillOrdersNoThrow(
|
||||
orders,
|
||||
opts.takerAssetFillAmounts === undefined
|
||||
? orders.map(signedOrder => signedOrder.takerAssetAmount)
|
||||
: opts.takerAssetFillAmounts,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gas: opts.gas, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async marketSellOrdersNoThrowAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
opts: { takerAssetFillAmount: BigNumber; gas?: number; gasPrice?: BigNumber },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.marketSellOrdersNoThrow.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.takerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gas: opts.gas, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.marketSellOrdersNoThrow(
|
||||
orders,
|
||||
opts.takerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gas: opts.gas, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async marketBuyOrdersNoThrowAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
opts: { makerAssetFillAmount: BigNumber; gas?: number; gasPrice?: BigNumber },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.marketBuyOrdersNoThrow.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.makerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.marketBuyOrdersNoThrow(orders, opts.makerAssetFillAmount, orders.map(signedOrder => signedOrder.signature))
|
||||
.awaitTransactionSuccessAsync({ from, gas: opts.gas });
|
||||
}
|
||||
public async marketSellOrdersFillOrKillAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
opts: { takerAssetFillAmount: BigNumber; gas?: number },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.marketSellOrdersFillOrKill.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.takerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.marketSellOrdersFillOrKill(
|
||||
orders,
|
||||
opts.takerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gas: opts.gas });
|
||||
}
|
||||
public async marketBuyOrdersFillOrKillAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
opts: { makerAssetFillAmount: BigNumber; gas?: number },
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.marketBuyOrdersFillOrKill.awaitTransactionSuccessAsync(
|
||||
orders,
|
||||
opts.makerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
{ from, gas: opts.gas },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.marketBuyOrdersFillOrKill(
|
||||
orders,
|
||||
opts.makerAssetFillAmount,
|
||||
orders.map(signedOrder => signedOrder.signature),
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gas: opts.gas });
|
||||
}
|
||||
public async batchCancelOrdersAsync(
|
||||
orders: SignedOrder[],
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.batchCancelOrders.awaitTransactionSuccessAsync(orders, { from });
|
||||
return this.exchangeContract.batchCancelOrders(orders).awaitTransactionSuccessAsync({ from });
|
||||
}
|
||||
public async cancelOrdersUpToAsync(salt: BigNumber, from: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const txReceipt = await this.exchangeContract.cancelOrdersUpTo.awaitTransactionSuccessAsync(salt, { from });
|
||||
const txReceipt = await this.exchangeContract.cancelOrdersUpTo(salt).awaitTransactionSuccessAsync({ from });
|
||||
return txReceipt;
|
||||
}
|
||||
public async registerAssetProxyAsync(
|
||||
assetProxyAddress: string,
|
||||
from: string,
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const txReceipt = await this.exchangeContract.registerAssetProxy.awaitTransactionSuccessAsync(
|
||||
assetProxyAddress,
|
||||
{
|
||||
const txReceipt = await this.exchangeContract
|
||||
.registerAssetProxy(assetProxyAddress)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from,
|
||||
},
|
||||
);
|
||||
});
|
||||
return txReceipt;
|
||||
}
|
||||
public async executeTransactionAsync(
|
||||
@@ -168,11 +164,9 @@ export class ExchangeWrapper {
|
||||
from: string,
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.executeTransaction.awaitTransactionSuccessAsync(
|
||||
signedTransaction,
|
||||
signedTransaction.signature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.executeTransaction(signedTransaction, signedTransaction.signature)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async batchExecuteTransactionsAsync(
|
||||
signedTransactions: SignedZeroExTransaction[],
|
||||
@@ -180,29 +174,27 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const signatures = signedTransactions.map(signedTransaction => signedTransaction.signature);
|
||||
return this.exchangeContract.batchExecuteTransactions.awaitTransactionSuccessAsync(
|
||||
signedTransactions,
|
||||
signatures,
|
||||
{
|
||||
return this.exchangeContract
|
||||
.batchExecuteTransactions(signedTransactions, signatures)
|
||||
.awaitTransactionSuccessAsync({
|
||||
from,
|
||||
gasPrice: opts.gasPrice,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
public async getTakerAssetFilledAmountAsync(orderHashHex: string): Promise<BigNumber> {
|
||||
const filledAmount = await this.exchangeContract.filled.callAsync(orderHashHex);
|
||||
const filledAmount = await this.exchangeContract.filled(orderHashHex).callAsync();
|
||||
return filledAmount;
|
||||
}
|
||||
public async isCancelledAsync(orderHashHex: string): Promise<boolean> {
|
||||
const isCancelled = await this.exchangeContract.cancelled.callAsync(orderHashHex);
|
||||
const isCancelled = await this.exchangeContract.cancelled(orderHashHex).callAsync();
|
||||
return isCancelled;
|
||||
}
|
||||
public async getOrderEpochAsync(makerAddress: string, senderAddress: string): Promise<BigNumber> {
|
||||
const orderEpoch = await this.exchangeContract.orderEpoch.callAsync(makerAddress, senderAddress);
|
||||
const orderEpoch = await this.exchangeContract.orderEpoch(makerAddress, senderAddress).callAsync();
|
||||
return orderEpoch;
|
||||
}
|
||||
public async getOrderInfoAsync(signedOrder: SignedOrder): Promise<OrderInfo> {
|
||||
const orderInfo = await this.exchangeContract.getOrderInfo.callAsync(signedOrder);
|
||||
const orderInfo = await this.exchangeContract.getOrderInfo(signedOrder).callAsync();
|
||||
return orderInfo;
|
||||
}
|
||||
public async batchMatchOrdersAsync(
|
||||
@@ -212,26 +204,18 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createBatchMatchOrders(signedOrdersLeft, signedOrdersRight);
|
||||
return this.exchangeContract.batchMatchOrders.awaitTransactionSuccessAsync(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchMatchOrders(params.leftOrders, params.rightOrders, params.leftSignatures, params.rightSignatures)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async batchMatchOrdersRawAsync(
|
||||
params: BatchMatchOrder,
|
||||
from: string,
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.batchMatchOrders.awaitTransactionSuccessAsync(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchMatchOrders(params.leftOrders, params.rightOrders, params.leftSignatures, params.rightSignatures)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async getBatchMatchOrdersResultsAsync(
|
||||
signedOrdersLeft: SignedOrder[],
|
||||
@@ -240,13 +224,9 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<BatchMatchedFillResults> {
|
||||
const params = orderUtils.createBatchMatchOrders(signedOrdersLeft, signedOrdersRight);
|
||||
const batchMatchedFillResults = await this.exchangeContract.batchMatchOrders.callAsync(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const batchMatchedFillResults = await this.exchangeContract
|
||||
.batchMatchOrders(params.leftOrders, params.rightOrders, params.leftSignatures, params.rightSignatures)
|
||||
.callAsync({ from, gasPrice: opts.gasPrice });
|
||||
return batchMatchedFillResults;
|
||||
}
|
||||
public async batchMatchOrdersWithMaximalFillAsync(
|
||||
@@ -256,26 +236,28 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createBatchMatchOrders(signedOrdersLeft, signedOrdersRight);
|
||||
return this.exchangeContract.batchMatchOrdersWithMaximalFill.awaitTransactionSuccessAsync(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchMatchOrdersWithMaximalFill(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async batchMatchOrdersWithMaximalFillRawAsync(
|
||||
params: BatchMatchOrder,
|
||||
from: string,
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
return this.exchangeContract.batchMatchOrdersWithMaximalFill.awaitTransactionSuccessAsync(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.batchMatchOrdersWithMaximalFill(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async getBatchMatchOrdersWithMaximalFillResultsAsync(
|
||||
signedOrdersLeft: SignedOrder[],
|
||||
@@ -284,13 +266,14 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<BatchMatchedFillResults> {
|
||||
const params = orderUtils.createBatchMatchOrders(signedOrdersLeft, signedOrdersRight);
|
||||
const batchMatchedFillResults = await this.exchangeContract.batchMatchOrdersWithMaximalFill.callAsync(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const batchMatchedFillResults = await this.exchangeContract
|
||||
.batchMatchOrdersWithMaximalFill(
|
||||
params.leftOrders,
|
||||
params.rightOrders,
|
||||
params.leftSignatures,
|
||||
params.rightSignatures,
|
||||
)
|
||||
.callAsync({ from, gasPrice: opts.gasPrice });
|
||||
return batchMatchedFillResults;
|
||||
}
|
||||
public async matchOrdersAsync(
|
||||
@@ -300,13 +283,9 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createMatchOrders(signedOrderLeft, signedOrderRight);
|
||||
const txReceipt = await this.exchangeContract.matchOrders.awaitTransactionSuccessAsync(
|
||||
params.left,
|
||||
params.right,
|
||||
params.leftSignature,
|
||||
params.rightSignature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const txReceipt = await this.exchangeContract
|
||||
.matchOrders(params.left, params.right, params.leftSignature, params.rightSignature)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
return txReceipt;
|
||||
}
|
||||
public async getMatchOrdersResultsAsync(
|
||||
@@ -316,13 +295,9 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<MatchedFillResults> {
|
||||
const params = orderUtils.createMatchOrders(signedOrderLeft, signedOrderRight);
|
||||
const matchedFillResults = await this.exchangeContract.matchOrders.callAsync(
|
||||
params.left,
|
||||
params.right,
|
||||
params.leftSignature,
|
||||
params.rightSignature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const matchedFillResults = await this.exchangeContract
|
||||
.matchOrders(params.left, params.right, params.leftSignature, params.rightSignature)
|
||||
.callAsync({ from, gasPrice: opts.gasPrice });
|
||||
return matchedFillResults;
|
||||
}
|
||||
public async matchOrdersWithMaximalFillAsync(
|
||||
@@ -332,13 +307,9 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber } = {},
|
||||
): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const params = orderUtils.createMatchOrders(signedOrderLeft, signedOrderRight);
|
||||
return this.exchangeContract.matchOrdersWithMaximalFill.awaitTransactionSuccessAsync(
|
||||
params.left,
|
||||
params.right,
|
||||
params.leftSignature,
|
||||
params.rightSignature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
return this.exchangeContract
|
||||
.matchOrdersWithMaximalFill(params.left, params.right, params.leftSignature, params.rightSignature)
|
||||
.awaitTransactionSuccessAsync({ from, gasPrice: opts.gasPrice });
|
||||
}
|
||||
public async getMatchOrdersWithMaximalFillResultsAsync(
|
||||
signedOrderLeft: SignedOrder,
|
||||
@@ -347,13 +318,9 @@ export class ExchangeWrapper {
|
||||
opts: { gasPrice?: BigNumber },
|
||||
): Promise<MatchedFillResults> {
|
||||
const params = orderUtils.createMatchOrders(signedOrderLeft, signedOrderRight);
|
||||
const matchedFillResults = await this.exchangeContract.matchOrdersWithMaximalFill.callAsync(
|
||||
params.left,
|
||||
params.right,
|
||||
params.leftSignature,
|
||||
params.rightSignature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const matchedFillResults = await this.exchangeContract
|
||||
.matchOrdersWithMaximalFill(params.left, params.right, params.leftSignature, params.rightSignature)
|
||||
.callAsync({ from, gasPrice: opts.gasPrice });
|
||||
return matchedFillResults;
|
||||
}
|
||||
public async getFillOrderResultsAsync(
|
||||
@@ -362,21 +329,16 @@ export class ExchangeWrapper {
|
||||
opts: { takerAssetFillAmount?: BigNumber; gasPrice?: BigNumber } = {},
|
||||
): Promise<FillResults> {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const fillResults = await this.exchangeContract.fillOrder.callAsync(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
{ from, gasPrice: opts.gasPrice },
|
||||
);
|
||||
const fillResults = await this.exchangeContract
|
||||
.fillOrder(params.order, params.takerAssetFillAmount, params.signature)
|
||||
.callAsync({ from, gasPrice: opts.gasPrice });
|
||||
return fillResults;
|
||||
}
|
||||
public abiEncodeFillOrder(signedOrder: SignedOrder, opts: { takerAssetFillAmount?: BigNumber } = {}): string {
|
||||
const params = orderUtils.createFill(signedOrder, opts.takerAssetFillAmount);
|
||||
const data = this.exchangeContract.fillOrder.getABIEncodedTransactionData(
|
||||
params.order,
|
||||
params.takerAssetFillAmount,
|
||||
params.signature,
|
||||
);
|
||||
const data = this.exchangeContract
|
||||
.fillOrder(params.order, params.takerAssetFillAmount, params.signature)
|
||||
.getABIEncodedTransactionData();
|
||||
return data;
|
||||
}
|
||||
public abiDecodeFillOrder(data: string): AbiDecodedFillOrderData {
|
||||
|
@@ -128,37 +128,37 @@ export async function fillOrderCombinatorialUtilsFactoryAsync(
|
||||
await exchangeWrapper.registerAssetProxyAsync(erc1155Proxy.address, ownerAddress);
|
||||
await exchangeWrapper.registerAssetProxyAsync(multiAssetProxy.address, ownerAddress);
|
||||
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, {
|
||||
await erc20Proxy.addAuthorizedAddress(exchangeContract.address).awaitTransactionSuccessAsync({
|
||||
from: ownerAddress,
|
||||
});
|
||||
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, {
|
||||
await erc721Proxy.addAuthorizedAddress(exchangeContract.address).awaitTransactionSuccessAsync({
|
||||
from: ownerAddress,
|
||||
});
|
||||
|
||||
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, {
|
||||
await erc1155Proxy.addAuthorizedAddress(exchangeContract.address).awaitTransactionSuccessAsync({
|
||||
from: ownerAddress,
|
||||
});
|
||||
|
||||
await multiAssetProxy.addAuthorizedAddress.awaitTransactionSuccessAsync(exchangeContract.address, {
|
||||
await multiAssetProxy.addAuthorizedAddress(exchangeContract.address).awaitTransactionSuccessAsync({
|
||||
from: ownerAddress,
|
||||
});
|
||||
|
||||
await erc20Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, { from: ownerAddress });
|
||||
await erc20Proxy.addAuthorizedAddress(multiAssetProxy.address).awaitTransactionSuccessAsync({ from: ownerAddress });
|
||||
|
||||
await erc721Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, {
|
||||
await erc721Proxy.addAuthorizedAddress(multiAssetProxy.address).awaitTransactionSuccessAsync({
|
||||
from: ownerAddress,
|
||||
});
|
||||
|
||||
await erc1155Proxy.addAuthorizedAddress.awaitTransactionSuccessAsync(multiAssetProxy.address, {
|
||||
await erc1155Proxy.addAuthorizedAddress(multiAssetProxy.address).awaitTransactionSuccessAsync({
|
||||
from: ownerAddress,
|
||||
});
|
||||
|
||||
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc20Proxy.address, { from: ownerAddress });
|
||||
await multiAssetProxy.registerAssetProxy(erc20Proxy.address).awaitTransactionSuccessAsync({ from: ownerAddress });
|
||||
|
||||
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc721Proxy.address, { from: ownerAddress });
|
||||
await multiAssetProxy.registerAssetProxy(erc721Proxy.address).awaitTransactionSuccessAsync({ from: ownerAddress });
|
||||
|
||||
await multiAssetProxy.registerAssetProxy.awaitTransactionSuccessAsync(erc1155Proxy.address, { from: ownerAddress });
|
||||
await multiAssetProxy.registerAssetProxy(erc1155Proxy.address).awaitTransactionSuccessAsync({ from: ownerAddress });
|
||||
|
||||
const orderFactory = new OrderFactoryFromScenario(
|
||||
devUtils,
|
||||
|
@@ -1,10 +1,4 @@
|
||||
import {
|
||||
constants,
|
||||
filterLogsToArguments,
|
||||
MutatorContractFunction,
|
||||
TransactionHelper,
|
||||
txDefaults as testTxDefaults,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { constants, filterLogsToArguments, txDefaults as testTxDefaults } from '@0x/contracts-test-utils';
|
||||
import { orderHashUtils } from '@0x/order-utils';
|
||||
import { FillResults, Order, OrderInfo, SignatureType } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
@@ -41,7 +35,6 @@ export const DEFAULT_BAD_SIGNATURE = createBadSignature();
|
||||
export class IsolatedExchangeWrapper {
|
||||
public static readonly CHAIN_ID = 1337;
|
||||
public readonly instance: IsolatedExchangeContract;
|
||||
public readonly txHelper: TransactionHelper;
|
||||
public lastTxEvents: IsolatedExchangeEvents = createEmptyEvents();
|
||||
public lastTxBalanceChanges: AssetBalances = {};
|
||||
|
||||
@@ -71,19 +64,18 @@ export class IsolatedExchangeWrapper {
|
||||
|
||||
public constructor(web3Wrapper: Web3Wrapper, instance: IsolatedExchangeContract) {
|
||||
this.instance = instance;
|
||||
this.txHelper = new TransactionHelper(web3Wrapper, artifacts);
|
||||
}
|
||||
|
||||
public async getTakerAssetFilledAmountAsync(order: Order): Promise<BigNumber> {
|
||||
return this.instance.filled.callAsync(this.getOrderHash(order));
|
||||
return this.instance.filled(this.getOrderHash(order)).callAsync();
|
||||
}
|
||||
|
||||
public async cancelOrderAsync(order: Order, txOpts?: TxData): Promise<void> {
|
||||
await this.instance.cancelOrder.awaitTransactionSuccessAsync(order, txOpts);
|
||||
await this.instance.cancelOrder(order).awaitTransactionSuccessAsync(txOpts);
|
||||
}
|
||||
|
||||
public async cancelOrdersUpToAsync(epoch: BigNumber, txOpts?: TxData): Promise<void> {
|
||||
await this.instance.cancelOrdersUpTo.awaitTransactionSuccessAsync(epoch, txOpts);
|
||||
await this.instance.cancelOrdersUpTo(epoch).awaitTransactionSuccessAsync(txOpts);
|
||||
}
|
||||
|
||||
public async fillOrderAsync(
|
||||
@@ -92,13 +84,14 @@ export class IsolatedExchangeWrapper {
|
||||
signature: string = DEFAULT_GOOD_SIGNATURE,
|
||||
txOpts?: TxData,
|
||||
): Promise<FillResults> {
|
||||
return this._runFillContractFunctionAsync(
|
||||
this.instance.fillOrder,
|
||||
order,
|
||||
new BigNumber(takerAssetFillAmount),
|
||||
signature,
|
||||
txOpts,
|
||||
);
|
||||
this.lastTxEvents = createEmptyEvents();
|
||||
this.lastTxBalanceChanges = {};
|
||||
const fillOrderFn = this.instance.fillOrder(order, new BigNumber(takerAssetFillAmount), signature);
|
||||
const result = await fillOrderFn.callAsync();
|
||||
const receipt = await fillOrderFn.awaitTransactionSuccessAsync(txOpts);
|
||||
this.lastTxEvents = extractEvents(receipt.logs);
|
||||
this.lastTxBalanceChanges = getBalanceChangesFromTransferFromCalls(this.lastTxEvents.transferFromCalls);
|
||||
return result;
|
||||
}
|
||||
|
||||
public getOrderHash(order: Order): string {
|
||||
@@ -110,7 +103,7 @@ export class IsolatedExchangeWrapper {
|
||||
}
|
||||
|
||||
public async getOrderInfoAsync(order: Order): Promise<OrderInfo> {
|
||||
return this.instance.getOrderInfo.callAsync(order);
|
||||
return this.instance.getOrderInfo(order).callAsync();
|
||||
}
|
||||
|
||||
public getBalanceChange(assetData: string, address: string): BigNumber {
|
||||
@@ -122,23 +115,6 @@ export class IsolatedExchangeWrapper {
|
||||
}
|
||||
return constants.ZERO_AMOUNT;
|
||||
}
|
||||
|
||||
protected async _runFillContractFunctionAsync<
|
||||
TCallAsyncArgs extends any[],
|
||||
TAwaitTransactionSuccessAsyncArgs extends any[],
|
||||
TResult
|
||||
>(
|
||||
contractFunction: MutatorContractFunction<TCallAsyncArgs, TAwaitTransactionSuccessAsyncArgs, TResult>,
|
||||
// tslint:disable-next-line: trailing-comma
|
||||
...args: TAwaitTransactionSuccessAsyncArgs
|
||||
): Promise<TResult> {
|
||||
this.lastTxEvents = createEmptyEvents();
|
||||
this.lastTxBalanceChanges = {};
|
||||
const [result, receipt] = await this.txHelper.getResultAndReceiptAsync(contractFunction, ...args);
|
||||
this.lastTxEvents = extractEvents(receipt.logs);
|
||||
this.lastTxBalanceChanges = getBalanceChangesFromTransferFromCalls(this.lastTxEvents.transferFromCalls);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -631,11 +631,11 @@ async function transferAssetAsync(
|
||||
matchResults: MatchResults,
|
||||
devUtils: DevUtilsContract,
|
||||
): Promise<void> {
|
||||
const assetProxyId = await devUtils.decodeAssetProxyId.callAsync(assetData);
|
||||
const assetProxyId = await devUtils.decodeAssetProxyId(assetData).callAsync();
|
||||
switch (assetProxyId) {
|
||||
case AssetProxyId.ERC20: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [proxyId, assetAddress] = await devUtils.decodeERC20AssetData.callAsync(assetData); // tslint:disable-line-no-unused-variable
|
||||
const [proxyId, assetAddress] = await devUtils.decodeERC20AssetData(assetData).callAsync(); // tslint:disable-line-no-unused-variable
|
||||
const fromBalances = matchResults.balances.erc20[fromAddress];
|
||||
const toBalances = matchResults.balances.erc20[toAddress];
|
||||
fromBalances[assetAddress] = fromBalances[assetAddress].minus(amount);
|
||||
@@ -644,7 +644,7 @@ async function transferAssetAsync(
|
||||
}
|
||||
case AssetProxyId.ERC721: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [proxyId, assetAddress, tokenId] = await devUtils.decodeERC721AssetData.callAsync(assetData); // tslint:disable-line-no-unused-variable
|
||||
const [proxyId, assetAddress, tokenId] = await devUtils.decodeERC721AssetData(assetData).callAsync(); // tslint:disable-line-no-unused-variable
|
||||
const fromTokens = matchResults.balances.erc721[fromAddress][assetAddress];
|
||||
const toTokens = matchResults.balances.erc721[toAddress][assetAddress];
|
||||
if (amount.gte(1)) {
|
||||
@@ -658,9 +658,9 @@ async function transferAssetAsync(
|
||||
}
|
||||
case AssetProxyId.ERC1155: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [proxyId, assetAddress, tokenIds, tokenValues] = await devUtils.decodeERC1155AssetData.callAsync(
|
||||
assetData,
|
||||
);
|
||||
const [proxyId, assetAddress, tokenIds, tokenValues] = await devUtils
|
||||
.decodeERC1155AssetData(assetData)
|
||||
.callAsync();
|
||||
const fromBalances = matchResults.balances.erc1155[fromAddress][assetAddress];
|
||||
const toBalances = matchResults.balances.erc1155[toAddress][assetAddress];
|
||||
for (const i of _.times(tokenIds.length)) {
|
||||
@@ -685,7 +685,7 @@ async function transferAssetAsync(
|
||||
}
|
||||
case AssetProxyId.MultiAsset: {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
const [proxyId, amounts, nestedAssetData] = await devUtils.decodeMultiAssetData.callAsync(assetData); // tslint:disable-line-no-unused-variable
|
||||
const [proxyId, amounts, nestedAssetData] = await devUtils.decodeMultiAssetData(assetData).callAsync(); // tslint:disable-line-no-unused-variable
|
||||
for (const i of _.times(amounts.length)) {
|
||||
const nestedAmount = amount.times(amounts[i]);
|
||||
const _nestedAssetData = nestedAssetData[i];
|
||||
|
@@ -96,52 +96,59 @@ export class OrderFactoryFromScenario {
|
||||
|
||||
switch (orderScenario.makerAssetDataScenario) {
|
||||
case AssetDataScenario.ERC20EighteenDecimals:
|
||||
makerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20EighteenDecimalTokenAddresses[0],
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC20FiveDecimals:
|
||||
makerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20FiveDecimalTokenAddresses[0],
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC721:
|
||||
makerAssetData = await this._devUtils.encodeERC721AssetData.callAsync(
|
||||
this._erc721TokenAddress,
|
||||
erc721MakerAssetIds[0],
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeERC721AssetData(this._erc721TokenAddress, erc721MakerAssetIds[0])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC20ZeroDecimals:
|
||||
makerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20ZeroDecimalTokenAddresses[0],
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[0])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC1155Fungible:
|
||||
makerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155FungibleMakerTokenIds[0]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeERC1155AssetData(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155FungibleMakerTokenIds[0]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC1155NonFungible:
|
||||
makerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155NonFungibleMakerTokenIds[0]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeERC1155AssetData(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155NonFungibleMakerTokenIds[0]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.MultiAssetERC20:
|
||||
makerAssetData = await this._devUtils.encodeMultiAssetData.callAsync(
|
||||
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
|
||||
[
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20EighteenDecimalTokenAddresses[0],
|
||||
),
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(this._erc20FiveDecimalTokenAddresses[0]),
|
||||
],
|
||||
);
|
||||
makerAssetData = await this._devUtils
|
||||
.encodeMultiAssetData(
|
||||
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
|
||||
[
|
||||
await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[0])
|
||||
.callAsync(),
|
||||
await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[0])
|
||||
.callAsync(),
|
||||
],
|
||||
)
|
||||
.callAsync();
|
||||
break;
|
||||
default:
|
||||
throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.makerAssetDataScenario);
|
||||
@@ -149,52 +156,59 @@ export class OrderFactoryFromScenario {
|
||||
|
||||
switch (orderScenario.takerAssetDataScenario) {
|
||||
case AssetDataScenario.ERC20EighteenDecimals:
|
||||
takerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20EighteenDecimalTokenAddresses[1],
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC20FiveDecimals:
|
||||
takerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20FiveDecimalTokenAddresses[1],
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC721:
|
||||
takerAssetData = await this._devUtils.encodeERC721AssetData.callAsync(
|
||||
this._erc721TokenAddress,
|
||||
erc721TakerAssetIds[0],
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeERC721AssetData(this._erc721TokenAddress, erc721TakerAssetIds[0])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC20ZeroDecimals:
|
||||
takerAssetData = await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20ZeroDecimalTokenAddresses[1],
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20ZeroDecimalTokenAddresses[1])
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC1155Fungible:
|
||||
takerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155FungibleTakerTokenIds[1]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeERC1155AssetData(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155FungibleTakerTokenIds[1]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.ERC1155NonFungible:
|
||||
takerAssetData = await this._devUtils.encodeERC1155AssetData.callAsync(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155NonFungibleTakerTokenIds[0]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeERC1155AssetData(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155NonFungibleTakerTokenIds[0]],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
)
|
||||
.callAsync();
|
||||
break;
|
||||
case AssetDataScenario.MultiAssetERC20:
|
||||
takerAssetData = await this._devUtils.encodeMultiAssetData.callAsync(
|
||||
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
|
||||
[
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(
|
||||
this._erc20EighteenDecimalTokenAddresses[1],
|
||||
),
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(this._erc20FiveDecimalTokenAddresses[1]),
|
||||
],
|
||||
);
|
||||
takerAssetData = await this._devUtils
|
||||
.encodeMultiAssetData(
|
||||
[ONE_UNITS_EIGHTEEN_DECIMALS, ONE_UNITS_FIVE_DECIMALS],
|
||||
[
|
||||
await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20EighteenDecimalTokenAddresses[1])
|
||||
.callAsync(),
|
||||
await this._devUtils
|
||||
.encodeERC20AssetData(this._erc20FiveDecimalTokenAddresses[1])
|
||||
.callAsync(),
|
||||
],
|
||||
)
|
||||
.callAsync();
|
||||
break;
|
||||
default:
|
||||
throw errorUtils.spawnSwitchErr('AssetDataScenario', orderScenario.takerAssetDataScenario);
|
||||
@@ -327,53 +341,61 @@ export class OrderFactoryFromScenario {
|
||||
case FeeAssetDataScenario.ERC20EighteenDecimals:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(erc20EighteenDecimalTokenAddress),
|
||||
await this._devUtils.encodeERC20AssetData(erc20EighteenDecimalTokenAddress).callAsync(),
|
||||
];
|
||||
case FeeAssetDataScenario.ERC20FiveDecimals:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(erc20FiveDecimalTokenAddress),
|
||||
await this._devUtils.encodeERC20AssetData(erc20FiveDecimalTokenAddress).callAsync(),
|
||||
];
|
||||
case FeeAssetDataScenario.ERC20ZeroDecimals:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(erc20ZeroDecimalTokenAddress),
|
||||
await this._devUtils.encodeERC20AssetData(erc20ZeroDecimalTokenAddress).callAsync(),
|
||||
];
|
||||
case FeeAssetDataScenario.ERC721:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeERC721AssetData.callAsync(this._erc721TokenAddress, erc721AssetId),
|
||||
await this._devUtils.encodeERC721AssetData(this._erc721TokenAddress, erc721AssetId).callAsync(),
|
||||
];
|
||||
case FeeAssetDataScenario.ERC1155Fungible:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeERC1155AssetData.callAsync(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155FungibleTokenId],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
),
|
||||
await this._devUtils
|
||||
.encodeERC1155AssetData(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155FungibleTokenId],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
)
|
||||
.callAsync(),
|
||||
];
|
||||
case FeeAssetDataScenario.ERC1155NonFungible:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeERC1155AssetData.callAsync(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155NonFungibleAssetId],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
),
|
||||
await this._devUtils
|
||||
.encodeERC1155AssetData(
|
||||
this._erc1155TokenAddress,
|
||||
[erc1155NonFungibleAssetId],
|
||||
[ONE_UNITS_ZERO_DECIMALS],
|
||||
erc1155CallbackData,
|
||||
)
|
||||
.callAsync(),
|
||||
];
|
||||
case FeeAssetDataScenario.MultiAssetERC20:
|
||||
return [
|
||||
feeAmount,
|
||||
await this._devUtils.encodeMultiAssetData.callAsync(
|
||||
[POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS, POINT_ZERO_FIVE_UNITS_FIVE_DECIMALS],
|
||||
[
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(erc20EighteenDecimalTokenAddress),
|
||||
await this._devUtils.encodeERC20AssetData.callAsync(erc20FiveDecimalTokenAddress),
|
||||
],
|
||||
),
|
||||
await this._devUtils
|
||||
.encodeMultiAssetData(
|
||||
[POINT_ZERO_FIVE_UNITS_EIGHTEEN_DECIMALS, POINT_ZERO_FIVE_UNITS_FIVE_DECIMALS],
|
||||
[
|
||||
await this._devUtils
|
||||
.encodeERC20AssetData(erc20EighteenDecimalTokenAddress)
|
||||
.callAsync(),
|
||||
await this._devUtils.encodeERC20AssetData(erc20FiveDecimalTokenAddress).callAsync(),
|
||||
],
|
||||
)
|
||||
.callAsync(),
|
||||
];
|
||||
default:
|
||||
throw errorUtils.spawnSwitchErr('FeeAssetDataScenario', feeAssetDataScenario);
|
||||
|
@@ -13,13 +13,15 @@ export class SimpleERC20BalanceAndProxyAllowanceFetcher implements AbstractBalan
|
||||
public async getBalanceAsync(_assetData: string, userAddress: string): Promise<BigNumber> {
|
||||
// HACK: We cheat and don't pass in the assetData since it's always the same token used
|
||||
// in our tests.
|
||||
const balance = await this._erc20TokenContract.balanceOf.callAsync(userAddress);
|
||||
const balance = await this._erc20TokenContract.balanceOf(userAddress).callAsync();
|
||||
return balance;
|
||||
}
|
||||
public async getProxyAllowanceAsync(_assetData: string, userAddress: string): Promise<BigNumber> {
|
||||
// HACK: We cheat and don't pass in the assetData since it's always the same token used
|
||||
// in our tests.
|
||||
const proxyAllowance = await this._erc20TokenContract.allowance.callAsync(userAddress, this._erc20ProxyAddress);
|
||||
const proxyAllowance = await this._erc20TokenContract
|
||||
.allowance(userAddress, this._erc20ProxyAddress)
|
||||
.callAsync();
|
||||
return proxyAllowance;
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,6 @@
|
||||
import { ContractTxFunctionObj } from '@0x/base-contract';
|
||||
import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs';
|
||||
import {
|
||||
blockchainTests,
|
||||
constants,
|
||||
describe,
|
||||
expect,
|
||||
hexRandom,
|
||||
MutatorContractFunction,
|
||||
TransactionHelper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { blockchainTests, constants, describe, expect, hexRandom } from '@0x/contracts-test-utils';
|
||||
import { ReferenceFunctions as UtilReferenceFunctions } from '@0x/contracts-utils';
|
||||
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
|
||||
import { FillResults, Order } from '@0x/types';
|
||||
@@ -44,13 +37,11 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
protocolFeePaid: constants.ZERO_AMOUNT,
|
||||
};
|
||||
let testContract: TestWrapperFunctionsContract;
|
||||
let txHelper: TransactionHelper;
|
||||
let owner: string;
|
||||
let senderAddress: string;
|
||||
|
||||
before(async () => {
|
||||
[owner, senderAddress] = await env.getAccountAddressesAsync();
|
||||
txHelper = new TransactionHelper(env.web3Wrapper, artifacts);
|
||||
testContract = await TestWrapperFunctionsContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TestWrapperFunctions,
|
||||
env.provider,
|
||||
@@ -62,7 +53,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
|
||||
// Set the protocol fee multiplier.
|
||||
await testContract.setProtocolFeeMultiplier.awaitTransactionSuccessAsync(protocolFeeMultiplier, {
|
||||
await testContract.setProtocolFeeMultiplier(protocolFeeMultiplier).awaitTransactionSuccessAsync({
|
||||
from: owner,
|
||||
});
|
||||
});
|
||||
@@ -152,12 +143,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signature = createOrderSignature(order);
|
||||
const expectedResult = getExpectedFillResults(order, signature);
|
||||
const expectedCalls = [[order, fillAmount, signature]];
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.fillOrKillOrder,
|
||||
order,
|
||||
fillAmount,
|
||||
signature,
|
||||
);
|
||||
const contractFn = testContract.fillOrKillOrder(order, fillAmount, signature);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -175,7 +163,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
fillAmount,
|
||||
fillAmount.minus(1),
|
||||
);
|
||||
const tx = testContract.fillOrKillOrder.awaitTransactionSuccessAsync(order, fillAmount, signature);
|
||||
const tx = testContract.fillOrKillOrder(order, fillAmount, signature).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -192,7 +180,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
fillAmount,
|
||||
fillAmount.plus(1),
|
||||
);
|
||||
const tx = testContract.fillOrKillOrder.awaitTransactionSuccessAsync(order, fillAmount, signature);
|
||||
const tx = testContract.fillOrKillOrder(order, fillAmount, signature).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -203,7 +191,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
});
|
||||
const signature = createOrderSignature(order);
|
||||
const expectedError = ALWAYS_FAILING_SALT_REVERT_ERROR;
|
||||
const tx = testContract.fillOrKillOrder.awaitTransactionSuccessAsync(order, fillAmount, signature);
|
||||
const tx = testContract.fillOrKillOrder(order, fillAmount, signature).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
@@ -215,12 +203,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signature = createOrderSignature(order);
|
||||
const expectedResult = getExpectedFillResults(order, signature);
|
||||
const expectedCalls = [[order, fillAmount, signature]];
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.fillOrderNoThrow,
|
||||
order,
|
||||
fillAmount,
|
||||
signature,
|
||||
);
|
||||
const contractFn = testContract.fillOrderNoThrow(order, fillAmount, signature);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -232,12 +217,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
});
|
||||
const signature = createOrderSignature(order);
|
||||
const expectedResult = EMPTY_FILL_RESULTS;
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.fillOrderNoThrow,
|
||||
order,
|
||||
fillAmount,
|
||||
signature,
|
||||
);
|
||||
const contractFn = testContract.fillOrderNoThrow(order, fillAmount, signature);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, []);
|
||||
});
|
||||
@@ -245,12 +227,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
|
||||
describe('batchFillOrders', () => {
|
||||
it('works with no fills', async () => {
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrders,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
const contractFn = testContract.batchFillOrders([], [], []);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq([]);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, []);
|
||||
});
|
||||
@@ -262,12 +241,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrders(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -279,12 +255,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrders(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -298,12 +271,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrders(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -314,7 +284,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const fillAmounts = _.times(COUNT - 1, i => orders[i].takerAssetAmount);
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedError = new AnyRevertError(); // Just a generic revert.
|
||||
const tx = txHelper.getResultAndReceiptAsync(testContract.batchFillOrders, orders, fillAmounts, signatures);
|
||||
const tx = testContract.batchFillOrders(orders, fillAmounts, signatures).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -324,19 +294,16 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const fillAmounts = _.times(COUNT, i => orders[i].takerAssetAmount);
|
||||
const signatures = _.times(COUNT - 1, i => createOrderSignature(orders[i]));
|
||||
const expectedError = new AnyRevertError(); // Just a generic revert.
|
||||
const tx = txHelper.getResultAndReceiptAsync(testContract.batchFillOrders, orders, fillAmounts, signatures);
|
||||
const tx = testContract.batchFillOrders(orders, fillAmounts, signatures).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('batchFillOrKillOrders', () => {
|
||||
it('works with no fills', async () => {
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
const contractFn = testContract.batchFillOrKillOrders([], [], []);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq([]);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, []);
|
||||
});
|
||||
@@ -348,12 +315,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrKillOrders(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -365,12 +329,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrKillOrders(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -384,12 +345,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrKillOrders(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -410,12 +368,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
failingAmount,
|
||||
failingAmount.minus(1),
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.batchFillOrKillOrders(orders, fillAmounts, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -435,12 +390,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
failingAmount,
|
||||
failingAmount.plus(1),
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.batchFillOrKillOrders(orders, fillAmounts, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -450,12 +402,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const fillAmounts = _.times(COUNT - 1, i => orders[i].takerAssetAmount);
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedError = new AnyRevertError(); // Just a generic revert.
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.batchFillOrKillOrders(orders, fillAmounts, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -465,24 +414,18 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const fillAmounts = _.times(COUNT, i => orders[i].takerAssetAmount);
|
||||
const signatures = _.times(COUNT - 1, i => createOrderSignature(orders[i]));
|
||||
const expectedError = new AnyRevertError(); // Just a generic revert.
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrKillOrders,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.batchFillOrKillOrders(orders, fillAmounts, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('batchFillOrdersNoThrow', () => {
|
||||
it('works with no fills', async () => {
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
const contractFn = testContract.batchFillOrdersNoThrow([], [], []);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq([]);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, []);
|
||||
});
|
||||
@@ -494,12 +437,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrdersNoThrow(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -511,12 +451,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrdersNoThrow(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -530,12 +467,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrdersNoThrow(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -551,12 +485,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const expectedResult = _.times(COUNT, i => getExpectedFillResults(orders[i], signatures[i]));
|
||||
const expectedCalls = _.zip(orders, fillAmounts, signatures);
|
||||
expectedCalls.splice(FAILING_ORDER_INDEX, 1);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.batchFillOrdersNoThrow(orders, fillAmounts, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls as any);
|
||||
});
|
||||
@@ -567,12 +498,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const fillAmounts = _.times(COUNT - 1, i => orders[i].takerAssetAmount);
|
||||
const signatures = _.times(COUNT, i => createOrderSignature(orders[i]));
|
||||
const expectedError = new AnyRevertError(); // Just a generic revert.
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.batchFillOrdersNoThrow(orders, fillAmounts, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -582,24 +510,21 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const fillAmounts = _.times(COUNT, i => orders[i].takerAssetAmount);
|
||||
const signatures = _.times(COUNT - 1, i => createOrderSignature(orders[i]));
|
||||
const expectedError = new AnyRevertError(); // Just a generic revert.
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.batchFillOrdersNoThrow,
|
||||
orders,
|
||||
fillAmounts,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.batchFillOrdersNoThrow(orders, fillAmounts, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
type ExpectedFillOrderCallArgs = [Order, BigNumber, string];
|
||||
type MarketSellBuyArgs = [Order[], BigNumber, string[], ...any[]];
|
||||
type MarketSellBuyContractFunction = MutatorContractFunction<MarketSellBuyArgs, MarketSellBuyArgs, FillResults>;
|
||||
type MarketSellBuyContractFn = (...args: MarketSellBuyArgs) => ContractTxFunctionObj<FillResults>;
|
||||
type MarketSellBuySimulator = (...args: MarketSellBuyArgs) => [FillResults, ExpectedFillOrderCallArgs[]];
|
||||
|
||||
describe('marketSell*', () => {
|
||||
function defineCommonMarketSellOrdersTests(
|
||||
getContractFn: () => MarketSellBuyContractFunction,
|
||||
getContractFn: () => MarketSellBuyContractFn,
|
||||
simulator: MarketSellBuySimulator,
|
||||
): void {
|
||||
it('works with one order', async () => {
|
||||
@@ -613,12 +538,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
const [expectedResult, expectedCalls] = simulator(orders, takerAssetFillAmount, signatures);
|
||||
expect(expectedCalls.length).to.eq(COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -634,12 +556,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
const [expectedResult, expectedCalls] = simulator(orders, takerAssetFillAmount, signatures);
|
||||
expect(expectedCalls.length).to.eq(COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -657,12 +576,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
const [expectedResult, expectedCalls] = simulator(orders, takerAssetFillAmount, signatures);
|
||||
expect(expectedCalls.length).to.eq(COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -680,12 +596,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const [expectedResult, expectedCalls] = simulator(orders, takerAssetFillAmount, signatures);
|
||||
// It should stop filling after the penultimate order.
|
||||
expect(expectedCalls.length).to.eq(COUNT - 1);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -706,12 +619,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const [expectedResult, expectedCalls] = simulator(orders, takerAssetFillAmount, signatures);
|
||||
// It should stop filling after first order.
|
||||
expect(expectedCalls.length).to.eq(1);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -727,20 +637,16 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
orders[0].takerAssetAmount,
|
||||
orders[1].takerAssetAmount,
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(getContractFn(), orders, takerAssetFillAmount, signatures);
|
||||
const tx = getContractFn()(orders, takerAssetFillAmount, signatures).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('returns empty fill results with no orders', async () => {
|
||||
const [expectedResult, expectedCalls] = simulator([], constants.ZERO_AMOUNT, []);
|
||||
expect(expectedCalls.length).to.eq(0);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
[],
|
||||
constants.ZERO_AMOUNT,
|
||||
[],
|
||||
);
|
||||
|
||||
const fnWithArgs = getContractFn()([], constants.ZERO_AMOUNT, []);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -767,7 +673,10 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
}
|
||||
|
||||
describe('marketSellOrdersNoThrow', () => {
|
||||
defineCommonMarketSellOrdersTests(() => testContract.marketSellOrdersNoThrow, simulateMarketSellOrders);
|
||||
defineCommonMarketSellOrdersTests(
|
||||
() => testContract.marketSellOrdersNoThrow.bind(testContract),
|
||||
simulateMarketSellOrders,
|
||||
);
|
||||
|
||||
it('works when any fills revert', async () => {
|
||||
const COUNT = 4;
|
||||
@@ -789,12 +698,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
signatures,
|
||||
);
|
||||
expect(expectedCalls.length).to.eq(COUNT - BAD_ORDERS_COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketSellOrdersNoThrow,
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.marketSellOrdersNoThrow(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -814,19 +720,19 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
signatures,
|
||||
);
|
||||
expect(expectedCalls.length).to.eq(0);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketSellOrdersNoThrow,
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.marketSellOrdersNoThrow(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
});
|
||||
|
||||
describe('marketSellOrdersFillOrKill', () => {
|
||||
defineCommonMarketSellOrdersTests(() => testContract.marketSellOrdersNoThrow, simulateMarketSellOrders);
|
||||
defineCommonMarketSellOrdersTests(
|
||||
() => testContract.marketSellOrdersNoThrow.bind(testContract),
|
||||
simulateMarketSellOrders,
|
||||
);
|
||||
|
||||
it('reverts when filled < `takerAssetFillAmount`', async () => {
|
||||
const COUNT = 4;
|
||||
@@ -842,12 +748,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
takerAssetFillAmount,
|
||||
takerAssetFillAmount.minus(1),
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketSellOrdersFillOrKill,
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.marketSellOrdersFillOrKill(orders, takerAssetFillAmount, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -871,12 +774,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
signatures,
|
||||
);
|
||||
expect(expectedCalls.length).to.eq(COUNT - BAD_ORDERS_COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketSellOrdersFillOrKill,
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.marketSellOrdersFillOrKill(orders, takerAssetFillAmount, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -907,12 +807,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
takerAssetFillAmount,
|
||||
takerAssetFillAmount.minus(1),
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketSellOrdersFillOrKill,
|
||||
orders,
|
||||
takerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.marketSellOrdersFillOrKill(orders, takerAssetFillAmount, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
@@ -920,7 +817,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
|
||||
describe('marketBuy*', () => {
|
||||
function defineCommonMarketBuyOrdersTests(
|
||||
getContractFn: () => MarketSellBuyContractFunction,
|
||||
getContractFn: () => MarketSellBuyContractFn,
|
||||
simulator: MarketSellBuySimulator,
|
||||
): void {
|
||||
it('works with one order', async () => {
|
||||
@@ -934,12 +831,10 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
const [expectedResult, expectedCalls] = simulator(orders, makerAssetFillAmount, signatures);
|
||||
expect(expectedCalls.length).to.eq(COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -955,12 +850,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
const [expectedResult, expectedCalls] = simulator(orders, makerAssetFillAmount, signatures);
|
||||
expect(expectedCalls.length).to.eq(COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -978,12 +870,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
);
|
||||
const [expectedResult, expectedCalls] = simulator(orders, makerAssetFillAmount, signatures);
|
||||
expect(expectedCalls.length).to.eq(COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1001,12 +890,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const [expectedResult, expectedCalls] = simulator(orders, makerAssetFillAmount, signatures);
|
||||
// It should stop filling after the penultimate order.
|
||||
expect(expectedCalls.length).to.eq(COUNT - 1);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1027,12 +913,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const [expectedResult, expectedCalls] = simulator(orders, makerAssetFillAmount, signatures);
|
||||
// It should stop filling after first order.
|
||||
expect(expectedCalls.length).to.eq(1);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = getContractFn()(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1046,7 +929,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
orders[0].takerAssetAmount,
|
||||
makerAssetFillAmount,
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(getContractFn(), orders, makerAssetFillAmount, signatures);
|
||||
const tx = getContractFn()(orders, makerAssetFillAmount, signatures).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -1059,7 +942,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
orders[0].takerAssetAmount.times(makerAssetFillAmount),
|
||||
orders[0].makerAssetAmount,
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(getContractFn(), orders, makerAssetFillAmount, signatures);
|
||||
const tx = getContractFn()(orders, makerAssetFillAmount, signatures).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -1081,20 +964,16 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
orders[0].makerAssetAmount,
|
||||
orders[1].makerAssetAmount,
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(getContractFn(), orders, makerAssetFillAmount, signatures);
|
||||
const tx = getContractFn()(orders, makerAssetFillAmount, signatures).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('returns empty fill results with no orders', async () => {
|
||||
const [expectedResult, expectedCalls] = simulator([], constants.ZERO_AMOUNT, []);
|
||||
expect(expectedCalls.length).to.eq(0);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
getContractFn(),
|
||||
[],
|
||||
constants.ZERO_AMOUNT,
|
||||
[],
|
||||
);
|
||||
|
||||
const fnWithArgs = getContractFn()([], constants.ZERO_AMOUNT, []);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1126,7 +1005,10 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
}
|
||||
|
||||
describe('marketBuyOrdersNoThrow', () => {
|
||||
defineCommonMarketBuyOrdersTests(() => testContract.marketBuyOrdersNoThrow, simulateMarketBuyOrdersNoThrow);
|
||||
defineCommonMarketBuyOrdersTests(
|
||||
() => testContract.marketBuyOrdersNoThrow.bind(testContract),
|
||||
simulateMarketBuyOrdersNoThrow,
|
||||
);
|
||||
|
||||
it('works when any fills revert', async () => {
|
||||
const COUNT = 4;
|
||||
@@ -1148,12 +1030,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
signatures,
|
||||
);
|
||||
expect(expectedCalls.length).to.eq(COUNT - BAD_ORDERS_COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketBuyOrdersNoThrow,
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.marketBuyOrdersNoThrow(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1173,12 +1052,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
signatures,
|
||||
);
|
||||
expect(expectedCalls.length).to.eq(0);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketBuyOrdersNoThrow,
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const contractFn = testContract.marketBuyOrdersNoThrow(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await contractFn.callAsync();
|
||||
const receipt = await contractFn.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1186,7 +1062,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
|
||||
describe('marketBuyOrdersFillOrKill', () => {
|
||||
defineCommonMarketBuyOrdersTests(
|
||||
() => testContract.marketBuyOrdersFillOrKill,
|
||||
() => testContract.marketBuyOrdersFillOrKill.bind(testContract),
|
||||
simulateMarketBuyOrdersNoThrow,
|
||||
);
|
||||
|
||||
@@ -1204,12 +1080,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
makerAssetFillAmount,
|
||||
makerAssetFillAmount.minus(1),
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketBuyOrdersFillOrKill,
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.marketBuyOrdersFillOrKill(orders, makerAssetFillAmount, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
@@ -1233,12 +1106,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
signatures,
|
||||
);
|
||||
expect(expectedCalls.length).to.eq(COUNT - BAD_ORDERS_COUNT);
|
||||
const [actualResult, receipt] = await txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketBuyOrdersFillOrKill,
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const fnWithArgs = testContract.marketBuyOrdersFillOrKill(orders, makerAssetFillAmount, signatures);
|
||||
const actualResult = await fnWithArgs.callAsync();
|
||||
const receipt = await fnWithArgs.awaitTransactionSuccessAsync();
|
||||
expect(actualResult).to.deep.eq(expectedResult);
|
||||
assertFillOrderCallsFromLogs(receipt.logs, expectedCalls);
|
||||
});
|
||||
@@ -1269,12 +1139,9 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
makerAssetFillAmount,
|
||||
makerAssetFillAmount.minus(1),
|
||||
);
|
||||
const tx = txHelper.getResultAndReceiptAsync(
|
||||
testContract.marketBuyOrdersFillOrKill,
|
||||
orders,
|
||||
makerAssetFillAmount,
|
||||
signatures,
|
||||
);
|
||||
const tx = testContract
|
||||
.marketBuyOrdersFillOrKill(orders, makerAssetFillAmount, signatures)
|
||||
.awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
@@ -1294,15 +1161,15 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
}
|
||||
|
||||
it('works with no orders', async () => {
|
||||
const [, receipt] = await txHelper.getResultAndReceiptAsync(testContract.batchCancelOrders, []);
|
||||
assertCancelOrderCallsFromLogs(receipt.logs, []);
|
||||
const { logs } = await testContract.batchCancelOrders([]).awaitTransactionSuccessAsync();
|
||||
assertCancelOrderCallsFromLogs(logs, []);
|
||||
});
|
||||
|
||||
it('works with many orders', async () => {
|
||||
const COUNT = 8;
|
||||
const orders = _.times(COUNT, () => randomOrder({ makerAddress: senderAddress }));
|
||||
const [, receipt] = await txHelper.getResultAndReceiptAsync(testContract.batchCancelOrders, orders);
|
||||
assertCancelOrderCallsFromLogs(receipt.logs, orders);
|
||||
const { logs } = await testContract.batchCancelOrders(orders).awaitTransactionSuccessAsync();
|
||||
assertCancelOrderCallsFromLogs(logs, orders);
|
||||
});
|
||||
|
||||
it('works with duplicate orders', async () => {
|
||||
@@ -1310,8 +1177,8 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const COUNT = 6;
|
||||
const uniqueOrders = _.times(UNIQUE_ORDERS, () => randomOrder({ makerAddress: senderAddress }));
|
||||
const orders = _.shuffle(_.flatten(_.times(COUNT / UNIQUE_ORDERS, () => uniqueOrders)));
|
||||
const [, receipt] = await txHelper.getResultAndReceiptAsync(testContract.batchCancelOrders, orders);
|
||||
assertCancelOrderCallsFromLogs(receipt.logs, orders);
|
||||
const { logs } = await testContract.batchCancelOrders(orders).awaitTransactionSuccessAsync();
|
||||
assertCancelOrderCallsFromLogs(logs, orders);
|
||||
});
|
||||
|
||||
it('reverts if one `_cancelOrder()` reverts', async () => {
|
||||
@@ -1321,7 +1188,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
const failingOrder = orders[FAILING_ORDER_INDEX];
|
||||
failingOrder.salt = ALWAYS_FAILING_SALT;
|
||||
const expectedError = ALWAYS_FAILING_SALT_REVERT_ERROR;
|
||||
const tx = txHelper.getResultAndReceiptAsync(testContract.batchCancelOrders, orders);
|
||||
const tx = testContract.batchCancelOrders(orders).awaitTransactionSuccessAsync();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user