Rename internal functions in LibAssetDataTransfer and fix tests

This commit is contained in:
Amir
2020-01-15 10:52:00 -08:00
parent 62b06cd204
commit 2275e27b87
2 changed files with 35 additions and 39 deletions

View File

@@ -58,25 +58,25 @@ library LibAssetDataTransfer {
proxyId == IAssetData(address(0)).ERC20Token.selector || proxyId == IAssetData(address(0)).ERC20Token.selector ||
proxyId == IAssetData(address(0)).ERC20Bridge.selector proxyId == IAssetData(address(0)).ERC20Bridge.selector
) { ) {
assetData._transferERC20Token( assetData.transferERC20Token(
from, from,
to, to,
amount amount
); );
} else if (proxyId == IAssetData(address(0)).ERC721Token.selector) { } else if (proxyId == IAssetData(address(0)).ERC721Token.selector) {
assetData._transferERC721Token( assetData.transferERC721Token(
from, from,
to, to,
amount amount
); );
} else if (proxyId == IAssetData(address(0)).ERC1155Assets.selector) { } else if (proxyId == IAssetData(address(0)).ERC1155Assets.selector) {
assetData._transferERC1155Assets( assetData.transferERC1155Assets(
from, from,
to, to,
amount amount
); );
} else if (proxyId == IAssetData(address(0)).MultiAsset.selector) { } else if (proxyId == IAssetData(address(0)).MultiAsset.selector) {
assetData._transferMultiAsset( assetData.transferMultiAsset(
from, from,
to, to,
amount amount
@@ -125,7 +125,7 @@ library LibAssetDataTransfer {
/// @param from Address to transfer asset from. /// @param from Address to transfer asset from.
/// @param to Address to transfer asset to. /// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer to sender. /// @param amount Amount of asset to transfer to sender.
function _transferERC20Token( function transferERC20Token(
bytes memory assetData, bytes memory assetData,
address from, address from,
address to, address to,
@@ -156,7 +156,7 @@ library LibAssetDataTransfer {
/// @param from Address to transfer asset from. /// @param from Address to transfer asset from.
/// @param to Address to transfer asset to. /// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer to sender. /// @param amount Amount of asset to transfer to sender.
function _transferERC721Token( function transferERC721Token(
bytes memory assetData, bytes memory assetData,
address from, address from,
address to, address to,
@@ -186,7 +186,7 @@ library LibAssetDataTransfer {
/// @param from Address to transfer asset from. /// @param from Address to transfer asset from.
/// @param to Address to transfer asset to. /// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer to sender. /// @param amount Amount of asset to transfer to sender.
function _transferERC1155Assets( function transferERC1155Assets(
bytes memory assetData, bytes memory assetData,
address from, address from,
address to, address to,
@@ -230,7 +230,7 @@ library LibAssetDataTransfer {
/// @param from Address to transfer asset from. /// @param from Address to transfer asset from.
/// @param to Address to transfer asset to. /// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer to sender. /// @param amount Amount of asset to transfer to sender.
function _transferMultiAsset( function transferMultiAsset(
bytes memory assetData, bytes memory assetData,
address from, address from,
address to, address to,

View File

@@ -1,6 +1,7 @@
import { IAssetDataContract } from '@0x/contracts-asset-proxy'; import { IAssetDataContract } from '@0x/contracts-asset-proxy';
import { import {
artifacts as ERC1155Artifacts, artifacts as ERC1155Artifacts,
ERC1155Events,
ERC1155MintableContract, ERC1155MintableContract,
ERC1155TransferBatchEventArgs, ERC1155TransferBatchEventArgs,
Erc1155Wrapper, Erc1155Wrapper,
@@ -247,12 +248,11 @@ blockchainTests.resets('Supported asset type unit tests', env => {
const txReceipt = await forwarder const txReceipt = await forwarder
.transferOut(assetData, amount) .transferOut(assetData, amount)
.awaitTransactionSuccessAsync({ from: receiver }); .awaitTransactionSuccessAsync({ from: receiver });
const logArgs = (txReceipt.logs[0] as LogWithDecodedArgs<ERC1155TransferBatchEventArgs>).args; verifyEventsFromLogs<ERC1155TransferBatchEventArgs>(
expect(logArgs.operator).to.eq(forwarder.address); txReceipt.logs,
expect(logArgs.from).to.eq(forwarder.address); [{ operator: forwarder.address, from: forwarder.address, to: receiver, ids, values }],
expect(logArgs.to).to.eq(receiver); ERC1155Events.TransferBatch,
logArgs.ids.forEach((id, i) => expect(new BigNumber(id)).to.bignumber.eq(ids[i])); );
logArgs.values.forEach((value, i) => expect(new BigNumber(value)).to.bignumber.eq(values[i]));
}); });
it('transfers multiple ids of an ERC1155 token', async () => { it('transfers multiple ids of an ERC1155 token', async () => {
const amount = new BigNumber(1); const amount = new BigNumber(1);
@@ -265,33 +265,29 @@ blockchainTests.resets('Supported asset type unit tests', env => {
.ERC1155Assets(erc1155Token.address, ids, values, constants.NULL_BYTES) .ERC1155Assets(erc1155Token.address, ids, values, constants.NULL_BYTES)
.getABIEncodedTransactionData(); .getABIEncodedTransactionData();
const txReceipt = await forwarder.transferOut(assetData, amount).awaitTransactionSuccessAsync(); const txReceipt = await forwarder.transferOut(assetData, amount).awaitTransactionSuccessAsync();
const logArgs = (txReceipt.logs[0] as LogWithDecodedArgs<ERC1155TransferBatchEventArgs>).args; verifyEventsFromLogs<ERC1155TransferBatchEventArgs>(
expect(logArgs.operator).to.eq(forwarder.address); txReceipt.logs,
expect(logArgs.from).to.eq(forwarder.address); [{ operator: forwarder.address, from: forwarder.address, to: receiver, ids, values }],
expect(logArgs.to).to.eq(receiver); ERC1155Events.TransferBatch,
logArgs.ids.forEach((id, i) => expect(new BigNumber(id)).to.bignumber.eq(ids[i])); );
logArgs.values.forEach((value, i) => expect(new BigNumber(value)).to.bignumber.eq(values[i]));
}); });
it('scales up values when transfering ERC1155 tokens', async () => { it('scales up values when transfering ERC1155 tokens', async () => {
it('transfers multiple ids of an ERC1155 token', async () => { const amount = new BigNumber(2);
const amount = new BigNumber(2); const values = [new BigNumber(1), new BigNumber(2)];
const ids = [ const scaledValues = values.map(value => value.times(amount));
await erc1155Wrapper.mintFungibleTokensAsync([forwarder.address], [amount]), const ids = [
await erc1155Wrapper.mintFungibleTokensAsync([forwarder.address], [amount]), await erc1155Wrapper.mintFungibleTokensAsync([forwarder.address], [scaledValues[0]]),
]; await erc1155Wrapper.mintFungibleTokensAsync([forwarder.address], [scaledValues[1]]),
const values = [new BigNumber(1), new BigNumber(2)]; ];
const assetData = assetDataEncoder const assetData = assetDataEncoder
.ERC1155Assets(erc1155Token.address, ids, values, constants.NULL_BYTES) .ERC1155Assets(erc1155Token.address, ids, values, constants.NULL_BYTES)
.getABIEncodedTransactionData(); .getABIEncodedTransactionData();
const txReceipt = await forwarder.transferOut(assetData, amount).awaitTransactionSuccessAsync(); const txReceipt = await forwarder.transferOut(assetData, amount).awaitTransactionSuccessAsync();
const scaledValues = values.map(value => value.times(amount)); verifyEventsFromLogs<ERC1155TransferBatchEventArgs>(
const logArgs = (txReceipt.logs[0] as LogWithDecodedArgs<ERC1155TransferBatchEventArgs>).args; txReceipt.logs,
expect(logArgs.operator).to.eq(forwarder.address); [{ operator: forwarder.address, from: forwarder.address, to: receiver, ids, values: scaledValues }],
expect(logArgs.from).to.eq(forwarder.address); ERC1155Events.TransferBatch,
expect(logArgs.to).to.eq(receiver); );
logArgs.ids.forEach((id, i) => expect(new BigNumber(id)).to.bignumber.eq(ids[i]));
logArgs.values.forEach((value, i) => expect(new BigNumber(value)).to.bignumber.eq(scaledValues[i]));
});
}); });
it('transfers a single ERC20 token wrapped as MultiAsset', async () => { it('transfers a single ERC20 token wrapped as MultiAsset', async () => {
const nestedAmount = new BigNumber(1337); const nestedAmount = new BigNumber(1337);