aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-06-27 09:38:30 +0800
committerGitHub <noreply@github.com>2018-06-27 09:38:30 +0800
commit73c36fe2d20c0e477458e6c07b837b08f8d424c6 (patch)
tree1cb07f3bdc14812cd4eb67610a93f8e6c2670d16 /packages/contracts/test
parent744e6e60c51b2bfd081920b58a73e566113fee0e (diff)
parentec3e9efdaaf35f408f708b359f648d6addbfa1f2 (diff)
downloaddexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.tar
dexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.tar.gz
dexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.tar.bz2
dexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.tar.lz
dexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.tar.xz
dexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.tar.zst
dexon-sol-tools-73c36fe2d20c0e477458e6c07b837b08f8d424c6.zip
Merge pull request #773 from 0xProject/feature/contracts/abi-calldata-proxy
Optimize transfer
Diffstat (limited to 'packages/contracts/test')
-rw-r--r--packages/contracts/test/asset_proxy/authorizable.ts17
-rw-r--r--packages/contracts/test/asset_proxy/decoder.ts84
-rw-r--r--packages/contracts/test/asset_proxy/proxies.ts116
-rw-r--r--packages/contracts/test/exchange/core.ts41
4 files changed, 45 insertions, 213 deletions
diff --git a/packages/contracts/test/asset_proxy/authorizable.ts b/packages/contracts/test/asset_proxy/authorizable.ts
index c2295dda6..8c9d0495d 100644
--- a/packages/contracts/test/asset_proxy/authorizable.ts
+++ b/packages/contracts/test/asset_proxy/authorizable.ts
@@ -5,10 +5,7 @@ import * as chai from 'chai';
import { MixinAuthorizableContract } from '../../src/generated_contract_wrappers/mixin_authorizable';
import { artifacts } from '../../src/utils/artifacts';
-import {
- expectRevertOrAlwaysFailingTransactionAsync,
- expectRevertReasonOrAlwaysFailingTransactionAsync,
-} from '../../src/utils/assertions';
+import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
@@ -118,10 +115,11 @@ describe('Authorizable', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
const index = new BigNumber(0);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
from: notOwner,
}),
+ RevertReason.OnlyContractOwner,
);
});
it('should throw if index is >= authorities.length', async () => {
@@ -130,18 +128,20 @@ describe('Authorizable', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
const index = new BigNumber(1);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
from: owner,
}),
+ RevertReason.IndexOutOfBounds,
);
});
it('should throw if owner attempts to remove an address that is not authorized', async () => {
const index = new BigNumber(0);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address, index, {
from: owner,
}),
+ RevertReason.TargetNotAuthorized,
);
});
it('should throw if address at index does not match target', async () => {
@@ -156,10 +156,11 @@ describe('Authorizable', () => {
constants.AWAIT_TRANSACTION_MINED_MS,
);
const address1Index = new BigNumber(0);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
authorizable.removeAuthorizedAddressAtIndex.sendTransactionAsync(address2, address1Index, {
from: owner,
}),
+ RevertReason.AuthorizedAddressMismatch,
);
});
it('should allow owner to remove an authorized address', async () => {
diff --git a/packages/contracts/test/asset_proxy/decoder.ts b/packages/contracts/test/asset_proxy/decoder.ts
deleted file mode 100644
index 902255caf..000000000
--- a/packages/contracts/test/asset_proxy/decoder.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import { BlockchainLifecycle } from '@0xproject/dev-utils';
-import { assetProxyUtils, generatePseudoRandomSalt } from '@0xproject/order-utils';
-import { BigNumber } from '@0xproject/utils';
-import * as chai from 'chai';
-import ethUtil = require('ethereumjs-util');
-
-import { TestAssetDataDecodersContract } from '../../src/generated_contract_wrappers/test_asset_data_decoders';
-import { artifacts } from '../../src/utils/artifacts';
-import { chaiSetup } from '../../src/utils/chai_setup';
-import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
-
-chaiSetup.configure();
-const expect = chai.expect;
-const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
-
-describe('TestAssetDataDecoders', () => {
- let testAssetProxyDecoder: TestAssetDataDecodersContract;
- let testAddress: string;
-
- before(async () => {
- await blockchainLifecycle.startAsync();
- });
- after(async () => {
- await blockchainLifecycle.revertAsync();
- });
- before(async () => {
- // Setup accounts & addresses
- const accounts = await web3Wrapper.getAvailableAddressesAsync();
- testAddress = accounts[0];
- testAssetProxyDecoder = await TestAssetDataDecodersContract.deployFrom0xArtifactAsync(
- artifacts.TestAssetDataDecoders,
- provider,
- txDefaults,
- );
- });
- beforeEach(async () => {
- await blockchainLifecycle.startAsync();
- });
- afterEach(async () => {
- await blockchainLifecycle.revertAsync();
- });
-
- describe('Asset Data Decoders', () => {
- it('should correctly decode ERC721 asset data', async () => {
- const tokenId = generatePseudoRandomSalt();
- const encodedAssetData = assetProxyUtils.encodeERC721AssetData(testAddress, tokenId);
- const expectedDecodedAssetData = assetProxyUtils.decodeERC721AssetData(encodedAssetData);
- let decodedTokenAddress: string;
- let decodedTokenId: BigNumber;
- let decodedData: string;
- [
- decodedTokenAddress,
- decodedTokenId,
- decodedData,
- ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedAssetData);
- expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress);
- expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedAssetData.tokenId);
- expect(decodedData).to.be.equal(expectedDecodedAssetData.receiverData);
- });
-
- it('should correctly decode ERC721 asset data with receiver data', async () => {
- const tokenId = generatePseudoRandomSalt();
- const receiverDataFirst32Bytes = ethUtil.bufferToHex(
- assetProxyUtils.encodeUint256(generatePseudoRandomSalt()),
- );
- const receiverDataExtraBytes = 'FFFF';
- // We add extra bytes to generate a value that doesn't fit perfectly into one word
- const receiverData = receiverDataFirst32Bytes + receiverDataExtraBytes;
- const encodedAssetData = assetProxyUtils.encodeERC721AssetData(testAddress, tokenId, receiverData);
- const expectedDecodedAssetData = assetProxyUtils.decodeERC721AssetData(encodedAssetData);
- let decodedTokenAddress: string;
- let decodedTokenId: BigNumber;
- let decodedReceiverData: string;
- [
- decodedTokenAddress,
- decodedTokenId,
- decodedReceiverData,
- ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedAssetData);
- expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress);
- expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedAssetData.tokenId);
- expect(decodedReceiverData).to.be.equal(expectedDecodedAssetData.receiverData);
- });
- });
-});
diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts
index 7960e46d2..595839519 100644
--- a/packages/contracts/test/asset_proxy/proxies.ts
+++ b/packages/contracts/test/asset_proxy/proxies.ts
@@ -5,7 +5,6 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import ethUtil = require('ethereumjs-util');
-import * as _ from 'lodash';
import { DummyERC20TokenContract } from '../../src/generated_contract_wrappers/dummy_e_r_c20_token';
import {
@@ -16,10 +15,7 @@ import { DummyERC721TokenContract } from '../../src/generated_contract_wrappers/
import { ERC20ProxyContract } from '../../src/generated_contract_wrappers/e_r_c20_proxy';
import { ERC721ProxyContract } from '../../src/generated_contract_wrappers/e_r_c721_proxy';
import { artifacts } from '../../src/utils/artifacts';
-import {
- expectRevertOrAlwaysFailingTransactionAsync,
- expectRevertReasonOrAlwaysFailingTransactionAsync,
-} from '../../src/utils/assertions';
+import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -189,58 +185,6 @@ describe('Asset Transfer Proxies', () => {
});
});
- describe('batchTransferFrom', () => {
- it('should succesfully make multiple token transfers', async () => {
- const erc20Balances = await erc20Wrapper.getBalancesAsync();
-
- const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
- const amount = new BigNumber(10);
- const numTransfers = 2;
- const assetData = _.times(numTransfers, () => encodedAssetData);
- const fromAddresses = _.times(numTransfers, () => makerAddress);
- const toAddresses = _.times(numTransfers, () => takerAddress);
- const amounts = _.times(numTransfers, () => amount);
-
- const txHash = await erc20Proxy.batchTransferFrom.sendTransactionAsync(
- assetData,
- fromAddresses,
- toAddresses,
- amounts,
- { from: exchangeAddress },
- );
- const res = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- const newBalances = await erc20Wrapper.getBalancesAsync();
-
- expect(res.logs.length).to.equal(numTransfers);
- expect(newBalances[makerAddress][zrxToken.address]).to.be.bignumber.equal(
- erc20Balances[makerAddress][zrxToken.address].minus(amount.times(numTransfers)),
- );
- expect(newBalances[takerAddress][zrxToken.address]).to.be.bignumber.equal(
- erc20Balances[takerAddress][zrxToken.address].add(amount.times(numTransfers)),
- );
- });
-
- it('should throw if not called by an authorized address', async () => {
- const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
- const amount = new BigNumber(10);
- const numTransfers = 2;
- const assetData = _.times(numTransfers, () => encodedAssetData);
- const fromAddresses = _.times(numTransfers, () => makerAddress);
- const toAddresses = _.times(numTransfers, () => takerAddress);
- const amounts = _.times(numTransfers, () => amount);
-
- return expectRevertReasonOrAlwaysFailingTransactionAsync(
- erc20Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, {
- from: notAuthorized,
- }),
- RevertReason.SenderNotAuthorized,
- );
- });
- });
-
it('should have an id of 0xf47261b0', async () => {
const proxyId = await erc20Proxy.getProxyId.callAsync();
const expectedProxyId = '0xf47261b0';
@@ -351,7 +295,7 @@ describe('Asset Transfer Proxies', () => {
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(1);
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
encodedAssetData,
makerAddress,
@@ -359,6 +303,7 @@ describe('Asset Transfer Proxies', () => {
amount,
{ from: exchangeAddress },
),
+ RevertReason.TransferFailed,
);
});
@@ -440,61 +385,6 @@ describe('Asset Transfer Proxies', () => {
});
});
- describe('batchTransferFrom', () => {
- it('should succesfully make multiple token transfers', async () => {
- const erc721TokensById = await erc721Wrapper.getBalancesAsync();
- const [makerTokenIdA, makerTokenIdB] = erc721TokensById[makerAddress][erc721Token.address];
-
- const numTransfers = 2;
- const assetData = [
- assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdA),
- assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdB),
- ];
- const fromAddresses = _.times(numTransfers, () => makerAddress);
- const toAddresses = _.times(numTransfers, () => takerAddress);
- const amounts = _.times(numTransfers, () => new BigNumber(1));
-
- const txHash = await erc721Proxy.batchTransferFrom.sendTransactionAsync(
- assetData,
- fromAddresses,
- toAddresses,
- amounts,
- { from: exchangeAddress },
- );
- const res = await web3Wrapper.awaitTransactionSuccessAsync(
- txHash,
- constants.AWAIT_TRANSACTION_MINED_MS,
- );
- expect(res.logs.length).to.equal(numTransfers);
-
- const newOwnerMakerAssetA = await erc721Token.ownerOf.callAsync(makerTokenIdA);
- const newOwnerMakerAssetB = await erc721Token.ownerOf.callAsync(makerTokenIdB);
- expect(newOwnerMakerAssetA).to.be.bignumber.equal(takerAddress);
- expect(newOwnerMakerAssetB).to.be.bignumber.equal(takerAddress);
- });
-
- it('should throw if not called by an authorized address', async () => {
- const erc721TokensById = await erc721Wrapper.getBalancesAsync();
- const [makerTokenIdA, makerTokenIdB] = erc721TokensById[makerAddress][erc721Token.address];
-
- const numTransfers = 2;
- const assetData = [
- assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdA).slice(0, -2),
- assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdB).slice(0, -2),
- ];
- const fromAddresses = _.times(numTransfers, () => makerAddress);
- const toAddresses = _.times(numTransfers, () => takerAddress);
- const amounts = _.times(numTransfers, () => new BigNumber(1));
-
- return expectRevertReasonOrAlwaysFailingTransactionAsync(
- erc721Proxy.batchTransferFrom.sendTransactionAsync(assetData, fromAddresses, toAddresses, amounts, {
- from: notAuthorized,
- }),
- RevertReason.SenderNotAuthorized,
- );
- });
- });
-
it('should have an id of 0x08e937fa', async () => {
const proxyId = await erc721Proxy.getProxyId.callAsync();
const expectedProxyId = '0x08e937fa';
diff --git a/packages/contracts/test/exchange/core.ts b/packages/contracts/test/exchange/core.ts
index 99d2bc157..36f6fa8d3 100644
--- a/packages/contracts/test/exchange/core.ts
+++ b/packages/contracts/test/exchange/core.ts
@@ -17,10 +17,7 @@ import {
FillContractEventArgs,
} from '../../src/generated_contract_wrappers/exchange';
import { artifacts } from '../../src/utils/artifacts';
-import {
- expectRevertOrAlwaysFailingTransactionAsync,
- expectRevertReasonOrAlwaysFailingTransactionAsync,
-} from '../../src/utils/assertions';
+import { expectRevertReasonOrAlwaysFailingTransactionAsync } from '../../src/utils/assertions';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
import { ERC20Wrapper } from '../../src/utils/erc20_wrapper';
@@ -771,8 +768,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
+ RevertReason.TransferFailed,
);
});
@@ -793,8 +791,9 @@ describe('Exchange core', () => {
expect(initialOwnerTakerAsset).to.be.bignumber.not.equal(takerAddress);
// Call Exchange
const takerAssetFillAmount = signedOrder.takerAssetAmount;
- return expectRevertOrAlwaysFailingTransactionAsync(
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
+ RevertReason.TransferFailed,
);
});
@@ -817,7 +816,7 @@ describe('Exchange core', () => {
const takerAssetFillAmount = signedOrder.takerAssetAmount;
return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- RevertReason.TransferFailed,
+ RevertReason.InvalidAmount,
);
});
@@ -840,7 +839,7 @@ describe('Exchange core', () => {
const takerAssetFillAmount = signedOrder.takerAssetAmount;
return expectRevertReasonOrAlwaysFailingTransactionAsync(
exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
- RevertReason.TransferFailed,
+ RevertReason.InvalidAmount,
);
});
@@ -861,6 +860,32 @@ describe('Exchange core', () => {
);
});
+ it('should throw if assetData has a length < 132', async () => {
+ // Construct Exchange parameters
+ const makerAssetId = erc721MakerAssetIds[0];
+ const takerAssetId = erc721TakerAssetIds[0];
+ const makerAssetData = assetProxyUtils
+ .encodeERC721AssetData(erc721Token.address, makerAssetId)
+ .slice(0, -2);
+ signedOrder = orderFactory.newSignedOrder({
+ makerAssetAmount: new BigNumber(1),
+ takerAssetAmount: new BigNumber(1),
+ makerAssetData,
+ takerAssetData: assetProxyUtils.encodeERC721AssetData(erc721Token.address, takerAssetId),
+ });
+ // Verify pre-conditions
+ const initialOwnerMakerAsset = await erc721Token.ownerOf.callAsync(makerAssetId);
+ expect(initialOwnerMakerAsset).to.be.bignumber.equal(makerAddress);
+ const initialOwnerTakerAsset = await erc721Token.ownerOf.callAsync(takerAssetId);
+ expect(initialOwnerTakerAsset).to.be.bignumber.equal(takerAddress);
+ // Call Exchange
+ const takerAssetFillAmount = signedOrder.takerAssetAmount;
+ return expectRevertReasonOrAlwaysFailingTransactionAsync(
+ exchangeWrapper.fillOrderAsync(signedOrder, takerAddress, { takerAssetFillAmount }),
+ RevertReason.LengthGreaterThan131Required,
+ );
+ });
+
it('should successfully fill order when makerAsset is ERC721 and takerAsset is ERC20', async () => {
// Construct Exchange parameters
const makerAssetId = erc721MakerAssetIds[0];