aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/test/asset_proxy
diff options
context:
space:
mode:
Diffstat (limited to 'packages/contracts/test/asset_proxy')
-rw-r--r--packages/contracts/test/asset_proxy/decoder.ts40
-rw-r--r--packages/contracts/test/asset_proxy/proxies.ts117
2 files changed, 62 insertions, 95 deletions
diff --git a/packages/contracts/test/asset_proxy/decoder.ts b/packages/contracts/test/asset_proxy/decoder.ts
index 0f1413ff1..712ef8656 100644
--- a/packages/contracts/test/asset_proxy/decoder.ts
+++ b/packages/contracts/test/asset_proxy/decoder.ts
@@ -12,7 +12,7 @@ import { artifacts } from '../../src/utils/artifacts';
import { assetProxyUtils } from '../../src/utils/asset_proxy_utils';
import { chaiSetup } from '../../src/utils/chai_setup';
import { constants } from '../../src/utils/constants';
-import { AssetProxyId, ERC20ProxyData, ERC721ProxyData, ProxyData } from '../../src/utils/types';
+import { AssetProxyId, ERC20AssetData, ERC721AssetData, AssetData } from '../../src/utils/types';
import { provider, txDefaults, web3Wrapper } from '../../src/utils/web3_wrapper';
chaiSetup.configure();
@@ -45,21 +45,21 @@ describe('LibAssetProxyDecoder', () => {
describe('LibAssetProxyDecoder', () => {
it('should correctly decode ERC20 proxy data)', async () => {
- const encodedProxyData = assetProxyUtils.encodeERC20ProxyData(testAddress);
- const expectedDecodedProxyData = assetProxyUtils.decodeERC20ProxyData(encodedProxyData);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(testAddress);
+ const expectedDecodedAssetData = assetProxyUtils.decodeERC20AssetData(encodedAssetData);
let decodedAssetProxyId: number;
let decodedTokenAddress: string;
[decodedAssetProxyId, decodedTokenAddress] = await testAssetProxyDecoder.publicDecodeERC20Data.callAsync(
- encodedProxyData,
+ encodedAssetData,
);
- expect(decodedAssetProxyId).to.be.equal(expectedDecodedProxyData.assetProxyId);
- expect(decodedTokenAddress).to.be.equal(expectedDecodedProxyData.tokenAddress);
+ expect(decodedAssetProxyId).to.be.equal(expectedDecodedAssetData.assetProxyId);
+ expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress);
});
it('should correctly decode ERC721 proxy data', async () => {
const tokenId = ZeroEx.generatePseudoRandomSalt();
- const encodedProxyData = assetProxyUtils.encodeERC721ProxyData(testAddress, tokenId);
- const expectedDecodedProxyData = assetProxyUtils.decodeERC721ProxyData(encodedProxyData);
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(testAddress, tokenId);
+ const expectedDecodedAssetData = assetProxyUtils.decodeERC721AssetData(encodedAssetData);
let decodedAssetProxyId: number;
let decodedTokenAddress: string;
let decodedTokenId: BigNumber;
@@ -69,18 +69,18 @@ describe('LibAssetProxyDecoder', () => {
decodedTokenAddress,
decodedTokenId,
decodedData,
- ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedProxyData);
- expect(decodedAssetProxyId).to.be.equal(expectedDecodedProxyData.assetProxyId);
- expect(decodedTokenAddress).to.be.equal(expectedDecodedProxyData.tokenAddress);
- expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedProxyData.tokenId);
- expect(decodedData).to.be.equal(expectedDecodedProxyData.data);
+ ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedAssetData);
+ expect(decodedAssetProxyId).to.be.equal(expectedDecodedAssetData.assetProxyId);
+ expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress);
+ expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedAssetData.tokenId);
+ expect(decodedData).to.be.equal(expectedDecodedAssetData.data);
});
it('should correctly decode ERC721 proxy data with receiver data', async () => {
const tokenId = ZeroEx.generatePseudoRandomSalt();
const data = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(ZeroEx.generatePseudoRandomSalt())) + 'FFFF';
- const encodedProxyData = assetProxyUtils.encodeERC721ProxyData(testAddress, tokenId, data);
- const expectedDecodedProxyData = assetProxyUtils.decodeERC721ProxyData(encodedProxyData);
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(testAddress, tokenId, data);
+ const expectedDecodedAssetData = assetProxyUtils.decodeERC721AssetData(encodedAssetData);
let decodedAssetProxyId: number;
let decodedTokenAddress: string;
let decodedTokenId: BigNumber;
@@ -90,11 +90,11 @@ describe('LibAssetProxyDecoder', () => {
decodedTokenAddress,
decodedTokenId,
decodedData,
- ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedProxyData);
- expect(decodedAssetProxyId).to.be.equal(expectedDecodedProxyData.assetProxyId);
- expect(decodedTokenAddress).to.be.equal(expectedDecodedProxyData.tokenAddress);
- expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedProxyData.tokenId);
- expect(decodedData).to.be.equal(expectedDecodedProxyData.data);
+ ] = await testAssetProxyDecoder.publicDecodeERC721Data.callAsync(encodedAssetData);
+ expect(decodedAssetProxyId).to.be.equal(expectedDecodedAssetData.assetProxyId);
+ expect(decodedTokenAddress).to.be.equal(expectedDecodedAssetData.tokenAddress);
+ expect(decodedTokenId).to.be.bignumber.equal(expectedDecodedAssetData.tokenId);
+ expect(decodedData).to.be.equal(expectedDecodedAssetData.data);
});
});
});
diff --git a/packages/contracts/test/asset_proxy/proxies.ts b/packages/contracts/test/asset_proxy/proxies.ts
index 4995e95a0..d6bc8163b 100644
--- a/packages/contracts/test/asset_proxy/proxies.ts
+++ b/packages/contracts/test/asset_proxy/proxies.ts
@@ -107,13 +107,13 @@ describe('Asset Transfer Proxies', () => {
describe('transferFrom', () => {
it('should successfully transfer tokens', async () => {
// Construct metadata for ERC20 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(10);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
amount,
@@ -133,13 +133,13 @@ describe('Asset Transfer Proxies', () => {
it('should do nothing if transferring 0 amount of a token', async () => {
// Construct metadata for ERC20 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
// Perform a transfer from makerAddress to takerAddress
const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(0);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
amount,
@@ -159,7 +159,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if allowances are too low', async () => {
// Construct metadata for ERC20 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
// Create allowance less than transfer amount. Set allowance on proxy.
const allowance = new BigNumber(0);
const transferAmount = new BigNumber(10);
@@ -172,7 +172,7 @@ describe('Asset Transfer Proxies', () => {
// Perform a transfer; expect this to fail.
return expectRevertOrAlwaysFailingTransactionAsync(
erc20Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
transferAmount,
@@ -183,19 +183,13 @@ describe('Asset Transfer Proxies', () => {
it('should throw if requesting address is not authorized', async () => {
// Construct metadata for ERC20 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(10);
return expectRevertOrAlwaysFailingTransactionAsync(
- erc20Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
- makerAddress,
- takerAddress,
- amount,
- {
- from: notAuthorized,
- },
- ),
+ erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, {
+ from: notAuthorized,
+ }),
);
});
});
@@ -204,16 +198,16 @@ describe('Asset Transfer Proxies', () => {
it('should succesfully make multiple token transfers', async () => {
const erc20Balances = await erc20Wrapper.getBalancesAsync();
- const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
const amount = new BigNumber(10);
const numTransfers = 2;
- const assetMetadata = _.times(numTransfers, () => encodedProxyMetadata);
+ 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(
- assetMetadata,
+ assetData,
fromAddresses,
toAddresses,
amounts,
@@ -235,17 +229,17 @@ describe('Asset Transfer Proxies', () => {
});
it('should throw if not called by an authorized address', async () => {
- const encodedProxyMetadata = assetProxyUtils.encodeERC20ProxyData(zrxToken.address);
+ const encodedAssetData = assetProxyUtils.encodeERC20AssetData(zrxToken.address);
const amount = new BigNumber(10);
const numTransfers = 2;
- const assetMetadata = _.times(numTransfers, () => encodedProxyMetadata);
+ const assetData = _.times(numTransfers, () => encodedAssetData);
const fromAddresses = _.times(numTransfers, () => makerAddress);
const toAddresses = _.times(numTransfers, () => takerAddress);
const amounts = _.times(numTransfers, () => amount);
return expectRevertOrAlwaysFailingTransactionAsync(
erc20Proxy.batchTransferFrom.sendTransactionAsync(
- assetMetadata,
+ encodedAssetData,
fromAddresses,
toAddresses,
amounts,
@@ -265,10 +259,7 @@ describe('Asset Transfer Proxies', () => {
describe('transferFrom', () => {
it('should successfully transfer tokens', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
@@ -276,7 +267,7 @@ describe('Asset Transfer Proxies', () => {
const amount = new BigNumber(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
amount,
@@ -291,10 +282,7 @@ describe('Asset Transfer Proxies', () => {
it('should call onERC721Received when transferring to a smart contract', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
@@ -302,7 +290,7 @@ describe('Asset Transfer Proxies', () => {
const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(1);
const txHash = await erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
erc721Receiver.address,
amount,
@@ -327,7 +315,7 @@ describe('Asset Transfer Proxies', () => {
it('should call onERC721Received when transferring to a smart contract and receive extra data', async () => {
// Construct metadata for ERC721 proxy
const data = ethUtil.bufferToHex(assetProxyUtils.encodeUint256(ZeroEx.generatePseudoRandomSalt()));
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(
erc721Token.address,
erc721MakerTokenId,
data,
@@ -339,7 +327,7 @@ describe('Asset Transfer Proxies', () => {
const erc20Balances = await erc20Wrapper.getBalancesAsync();
const amount = new BigNumber(1);
const txHash = await erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
erc721Receiver.address,
amount,
@@ -363,10 +351,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if receiving contract does not have onERC721Received', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
@@ -375,7 +360,7 @@ describe('Asset Transfer Proxies', () => {
const amount = new BigNumber(1);
return expect(
erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
erc20Proxy.address, // the ERC20 proxy does not have an ERC721 receiver
amount,
@@ -386,10 +371,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if transferring 0 amount of a token', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
@@ -397,7 +379,7 @@ describe('Asset Transfer Proxies', () => {
const amount = new BigNumber(0);
return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
amount,
@@ -408,10 +390,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if transferring > 1 amount of a token', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Verify pre-condition
const ownerMakerAsset = await erc721Token.ownerOf.callAsync(erc721MakerTokenId);
expect(ownerMakerAsset).to.be.bignumber.equal(makerAddress);
@@ -419,7 +398,7 @@ describe('Asset Transfer Proxies', () => {
const amount = new BigNumber(500);
return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
amount,
@@ -430,10 +409,7 @@ describe('Asset Transfer Proxies', () => {
it('should throw if allowances are too low', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Remove transfer approval for makerAddress.
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Token.setApprovalForAll.sendTransactionAsync(erc721Proxy.address, false, {
@@ -444,29 +420,20 @@ describe('Asset Transfer Proxies', () => {
// Perform a transfer; expect this to fail.
const amount = new BigNumber(1);
return expectRevertOrAlwaysFailingTransactionAsync(
- erc20Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
- makerAddress,
- takerAddress,
- amount,
- {
- from: notAuthorized,
- },
- ),
+ erc20Proxy.transferFrom.sendTransactionAsync(encodedAssetData, makerAddress, takerAddress, amount, {
+ from: notAuthorized,
+ }),
);
});
it('should throw if requesting address is not authorized', async () => {
// Construct metadata for ERC721 proxy
- const encodedProxyMetadata = assetProxyUtils.encodeERC721ProxyData(
- erc721Token.address,
- erc721MakerTokenId,
- );
+ const encodedAssetData = assetProxyUtils.encodeERC721AssetData(erc721Token.address, erc721MakerTokenId);
// Perform a transfer from makerAddress to takerAddress
const amount = new BigNumber(1);
return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.transferFrom.sendTransactionAsync(
- encodedProxyMetadata,
+ encodedAssetData,
makerAddress,
takerAddress,
amount,
@@ -482,16 +449,16 @@ describe('Asset Transfer Proxies', () => {
const [makerTokenIdA, makerTokenIdB] = erc721TokensById[makerAddress][erc721Token.address];
const numTransfers = 2;
- const assetMetadata = [
- assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdA),
- assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdB),
+ 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(
- assetMetadata,
+ assetData,
fromAddresses,
toAddresses,
amounts,
@@ -514,9 +481,9 @@ describe('Asset Transfer Proxies', () => {
const [makerTokenIdA, makerTokenIdB] = erc721TokensById[makerAddress][erc721Token.address];
const numTransfers = 2;
- const assetMetadata = [
- assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdA),
- assetProxyUtils.encodeERC721ProxyData(erc721Token.address, makerTokenIdB),
+ const assetData = [
+ assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdA),
+ assetProxyUtils.encodeERC721AssetData(erc721Token.address, makerTokenIdB),
];
const fromAddresses = _.times(numTransfers, () => makerAddress);
const toAddresses = _.times(numTransfers, () => takerAddress);
@@ -524,7 +491,7 @@ describe('Asset Transfer Proxies', () => {
return expectRevertOrAlwaysFailingTransactionAsync(
erc721Proxy.batchTransferFrom.sendTransactionAsync(
- assetMetadata,
+ encodedAssetData,
fromAddresses,
toAddresses,
amounts,