Split ERC1155 Asset Proxy from ERC1155 POC implementation - squashed
This commit is contained in:
@@ -34,10 +34,16 @@ import {
|
||||
ERC20Wrapper,
|
||||
ERC721ProxyContract,
|
||||
ERC721Wrapper,
|
||||
ERC1155Wrapper,
|
||||
ERC1155ProxyContract,
|
||||
IAssetDataContract,
|
||||
IAssetProxyContract,
|
||||
MultiAssetProxyContract,
|
||||
ERC1155MintableContract,
|
||||
DummyERC1155ReceiverContract,
|
||||
DummyERC1155ReceiverBatchTokenReceivedEventArgs,
|
||||
} from '../src';
|
||||
import values from 'ramda/es/values';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
@@ -68,15 +74,22 @@ describe('Asset Transfer Proxies', () => {
|
||||
let erc721Receiver: DummyERC721ReceiverContract;
|
||||
let erc20Proxy: ERC20ProxyContract;
|
||||
let erc721Proxy: ERC721ProxyContract;
|
||||
let erc1155Proxy: ERC721ProxyContract;
|
||||
let erc1155Receiver: DummyERC1155ReceiverContract;
|
||||
let noReturnErc20Token: DummyNoReturnERC20TokenContract;
|
||||
let multipleReturnErc20Token: DummyMultipleReturnERC20TokenContract;
|
||||
let multiAssetProxy: MultiAssetProxyContract;
|
||||
|
||||
let erc20Wrapper: ERC20Wrapper;
|
||||
let erc721Wrapper: ERC721Wrapper;
|
||||
let erc1155Wrapper: ERC1155Wrapper;
|
||||
let erc721AFromTokenId: BigNumber;
|
||||
let erc721BFromTokenId: BigNumber;
|
||||
|
||||
let erc1155Token: ERC1155MintableContract;
|
||||
let erc1155FungibleTokenIds: BigNumber[];
|
||||
let erc1155NonFungibleTokenIds: BigNumber[];
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
});
|
||||
@@ -89,10 +102,12 @@ describe('Asset Transfer Proxies', () => {
|
||||
|
||||
erc20Wrapper = new ERC20Wrapper(provider, usedAddresses, owner);
|
||||
erc721Wrapper = new ERC721Wrapper(provider, usedAddresses, owner);
|
||||
erc1155Wrapper = new ERC1155Wrapper(provider, usedAddresses, owner);
|
||||
|
||||
// Deploy AssetProxies
|
||||
erc20Proxy = await erc20Wrapper.deployProxyAsync();
|
||||
erc721Proxy = await erc721Wrapper.deployProxyAsync();
|
||||
erc1155Proxy = await erc1155Wrapper.deployProxyAsync();
|
||||
multiAssetProxy = await MultiAssetProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.MultiAssetProxy,
|
||||
provider,
|
||||
@@ -127,6 +142,20 @@ describe('Asset Transfer Proxies', () => {
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
// Configure ERC1155Proxy
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await erc1155Proxy.addAuthorizedAddress.sendTransactionAsync(authorized, {
|
||||
from: owner,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await erc1155Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, {
|
||||
from: owner,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
// Configure MultiAssetProxy
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await multiAssetProxy.addAuthorizedAddress.sendTransactionAsync(authorized, {
|
||||
@@ -208,11 +237,21 @@ describe('Asset Transfer Proxies', () => {
|
||||
provider,
|
||||
txDefaults,
|
||||
);
|
||||
|
||||
await erc721Wrapper.setBalancesAndAllowancesAsync();
|
||||
const erc721Balances = await erc721Wrapper.getBalancesAsync();
|
||||
erc721AFromTokenId = erc721Balances[fromAddress][erc721TokenA.address][0];
|
||||
erc721BFromTokenId = erc721Balances[fromAddress][erc721TokenB.address][0];
|
||||
|
||||
// Deploy and configure ERC1155 tokens and receiver
|
||||
[erc1155Token] = await erc1155Wrapper.deployDummyTokensAsync();
|
||||
erc1155Receiver = await DummyERC1155ReceiverContract.deployFrom0xArtifactAsync(
|
||||
artifacts.DummyERC1155Receiver,
|
||||
provider,
|
||||
txDefaults,
|
||||
);
|
||||
await erc1155Wrapper.setBalancesAndAllowancesAsync();
|
||||
erc1155FungibleTokenIds = erc1155Wrapper.getFungibleTokenIds();
|
||||
erc1155NonFungibleTokenIds = erc1155Wrapper.getNonFungibleTokenIds();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -477,7 +516,6 @@ describe('Asset Transfer Proxies', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ERC721Proxy', () => {
|
||||
it('should revert if undefined function is called', async () => {
|
||||
const undefinedSelector = '0x01020304';
|
||||
@@ -1286,6 +1324,373 @@ describe('Asset Transfer Proxies', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
describe.only('ERC1155Proxy', () => {
|
||||
it('should revert if undefined function is called', async () => {
|
||||
const undefinedSelector = '0x01020304';
|
||||
await expectTransactionFailedWithoutReasonAsync(
|
||||
web3Wrapper.sendTransactionAsync({
|
||||
from: owner,
|
||||
to: erc1155Proxy.address,
|
||||
value: constants.ZERO_AMOUNT,
|
||||
data: undefinedSelector,
|
||||
}),
|
||||
);
|
||||
});
|
||||
it('should have an id of 0x9645780d', async () => {
|
||||
const proxyId = await erc1155Proxy.getProxyId.callAsync();
|
||||
// proxy computed using -- bytes4(keccak256("ERC1155Token(address,uint256[],uint256[],bytes)"));
|
||||
const expectedProxyId = '0x9645780d';
|
||||
expect(proxyId).to.equal(expectedProxyId);
|
||||
});
|
||||
describe('transferFrom', () => {
|
||||
it('should successfully transfer value for a single token', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const fungibleTokenIdToTransfer = erc1155FungibleTokenIds[0];
|
||||
const tokenIdsToTransfer = [fungibleTokenIdToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(10)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify pre-condition
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const initialSenderBalance = initialHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const initialReceiverBalance = initialHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1000);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
toAddress,
|
||||
perUnitValue,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
// Verify transfer was successful
|
||||
const totalValueTransferred = tokenValuesToTransfer[0].times(perUnitValue);
|
||||
const newHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const newSenderBalance = newHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewSenderBalance = initialSenderBalance.minus(totalValueTransferred);
|
||||
const newReceiverBalance = newHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewReceiverBalance = initialReceiverBalance.plus(totalValueTransferred);
|
||||
expect(newSenderBalance).to.be.bignumber.equal(expectedNewSenderBalance);
|
||||
expect(newReceiverBalance).to.be.bignumber.equal(expectedNewReceiverBalance);
|
||||
});
|
||||
it('should successfully transfer value for a collection of fungible tokens of the same id', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const fungibleTokenIdToTransfer = erc1155FungibleTokenIds[0];
|
||||
const tokenIdsToTransfer = [fungibleTokenIdToTransfer, fungibleTokenIdToTransfer, fungibleTokenIdToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(10), new BigNumber(20), new BigNumber(30)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify pre-condition
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const initialSenderBalance = initialHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const initialReceiverBalance = initialHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1000);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
toAddress,
|
||||
perUnitValue,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
// Verify transfer was successful
|
||||
const totalValueTransferred = _.reduce(tokenValuesToTransfer, (sum: BigNumber, value: BigNumber) => {return sum.plus(value)}, new BigNumber(0)).times(perUnitValue);
|
||||
const newHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const newSenderBalance = newHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewSenderBalance = initialSenderBalance.minus(totalValueTransferred);
|
||||
const newReceiverBalance = newHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewReceiverBalance = initialReceiverBalance.plus(totalValueTransferred);
|
||||
expect(newSenderBalance).to.be.bignumber.equal(expectedNewSenderBalance);
|
||||
expect(newReceiverBalance).to.be.bignumber.equal(expectedNewReceiverBalance);
|
||||
});
|
||||
it('should successfully transfer value for a collection of fungible tokens of different ids', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const tokenIdsToTransfer = erc1155FungibleTokenIds.slice(0, 2);
|
||||
const tokenValuesToTransfer = [new BigNumber(10), new BigNumber(20)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify pre-condition
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const initialSenderBalances: BigNumber[] = [];
|
||||
const initialReceiverBalances: BigNumber[] = [];
|
||||
_.each(tokenIdsToTransfer, (tokenIdToTransfer: BigNumber) => {
|
||||
initialSenderBalances.push(initialHoldingsByOwner.fungible[fromAddress][erc1155Token.address][tokenIdToTransfer.toString()]);
|
||||
initialReceiverBalances.push(initialHoldingsByOwner.fungible[toAddress][erc1155Token.address][tokenIdToTransfer.toString()]);
|
||||
});
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1000);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
toAddress,
|
||||
perUnitValue,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
// Verify transfer was successful
|
||||
const newHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
_.each(tokenIdsToTransfer, (tokenIdToTransfer: BigNumber, i: number) => {
|
||||
const totalValueTransferred = tokenValuesToTransfer[i].times(perUnitValue);
|
||||
const newSenderBalance = newHoldingsByOwner.fungible[fromAddress][erc1155Token.address][tokenIdToTransfer.toString()];
|
||||
const expectedNewSenderBalance = initialSenderBalances[i].minus(totalValueTransferred);
|
||||
const newReceiverBalance = newHoldingsByOwner.fungible[toAddress][erc1155Token.address][tokenIdToTransfer.toString()];
|
||||
const expectedNewReceiverBalance = initialReceiverBalances[i].plus(totalValueTransferred);
|
||||
expect(newSenderBalance).to.be.bignumber.equal(expectedNewSenderBalance);
|
||||
expect(newReceiverBalance).to.be.bignumber.equal(expectedNewReceiverBalance);
|
||||
});
|
||||
});
|
||||
it('should successfully transfer a non-fungible token', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const nonFungibleTokenIdToTransfer = erc1155NonFungibleTokenIds[0];
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const nftToTransfer = initialHoldingsByOwner.nonFungible[fromAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()][0];
|
||||
const tokenIdsToTransfer = [nftToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(1)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify precondition
|
||||
const nftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(nftHolder).to.be.equal(fromAddress);
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
toAddress,
|
||||
perUnitValue,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
// Verify transfer was successful
|
||||
const newNftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(newNftHolder).to.be.equal(toAddress);
|
||||
// Verify balances updated successfully
|
||||
const newHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const newNftsForFromAddress = newHoldingsByOwner.nonFungible[fromAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()];
|
||||
const newNftsForToAddress = newHoldingsByOwner.nonFungible[toAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()];
|
||||
expect(_.find(newNftsForFromAddress, nftToTransfer)).to.be.undefined();
|
||||
expect(_.find(newNftsForToAddress, nftToTransfer)).to.be.not.undefined();
|
||||
});
|
||||
it('should successfully transfer value for a combination of fungible/non-fungible tokens', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const fungibleTokenIdToTransfer = erc1155FungibleTokenIds[0];
|
||||
const nonFungibleTokenIdToTransfer = erc1155NonFungibleTokenIds[0];
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const nftToTransfer = initialHoldingsByOwner.nonFungible[fromAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()][0];
|
||||
const tokenIdsToTransfer = [fungibleTokenIdToTransfer, nftToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(10), new BigNumber(1)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify precondition
|
||||
const initialSenderBalance = initialHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const initialReceiverBalance = initialHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const nftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(nftHolder).to.be.equal(fromAddress);
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
toAddress,
|
||||
perUnitValue,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
// Verify non-fungible transfer was successful
|
||||
const newNftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(newNftHolder).to.be.equal(toAddress);
|
||||
// Verify non-fungible balances updated successfully
|
||||
const newHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const newNftsForFromAddress = newHoldingsByOwner.nonFungible[fromAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()];
|
||||
const newNftsForToAddress = newHoldingsByOwner.nonFungible[toAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()];
|
||||
expect(_.find(newNftsForFromAddress, nftToTransfer)).to.be.undefined();
|
||||
expect(_.find(newNftsForToAddress, nftToTransfer)).to.be.not.undefined();
|
||||
// Verify fungible transfer was successful
|
||||
const totalValueTransferred = tokenValuesToTransfer[0].times(perUnitValue);
|
||||
const newSenderBalance = newHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewSenderBalance = initialSenderBalance.minus(totalValueTransferred);
|
||||
const newReceiverBalance = newHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewReceiverBalance = initialReceiverBalance.plus(totalValueTransferred);
|
||||
expect(newSenderBalance).to.be.bignumber.equal(expectedNewSenderBalance);
|
||||
expect(newReceiverBalance).to.be.bignumber.equal(expectedNewReceiverBalance);
|
||||
});
|
||||
it('should successfully transfer value and ignore extra assetData', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const fungibleTokenIdToTransfer = erc1155FungibleTokenIds[0];
|
||||
const tokenIdsToTransfer = [fungibleTokenIdToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(10)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
const extraData = '0102030405060708';
|
||||
const encodedAssetDataPlusExtraData = `${encodedAssetData}${extraData}`;
|
||||
// Verify pre-condition
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const initialSenderBalance = initialHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const initialReceiverBalance = initialHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1000);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetDataPlusExtraData,
|
||||
fromAddress,
|
||||
toAddress,
|
||||
perUnitValue,
|
||||
);
|
||||
await web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
// Verify transfer was successful
|
||||
const totalValueTransferred = tokenValuesToTransfer[0].times(perUnitValue);
|
||||
const newHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const newSenderBalance = newHoldingsByOwner.fungible[fromAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewSenderBalance = initialSenderBalance.minus(totalValueTransferred);
|
||||
const newReceiverBalance = newHoldingsByOwner.fungible[toAddress][erc1155Token.address][fungibleTokenIdToTransfer.toString()];
|
||||
const expectedNewReceiverBalance = initialReceiverBalance.plus(totalValueTransferred);
|
||||
expect(newSenderBalance).to.be.bignumber.equal(expectedNewSenderBalance);
|
||||
expect(newReceiverBalance).to.be.bignumber.equal(expectedNewReceiverBalance);
|
||||
});
|
||||
it.only('should successfully execute callback when transferring to a smart contract', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x";
|
||||
const nonFungibleTokenIdToTransfer = erc1155NonFungibleTokenIds[0];
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const nftToTransfer = initialHoldingsByOwner.nonFungible[fromAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()][0];
|
||||
const tokenIdsToTransfer = [nftToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(1)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify precondition
|
||||
const nftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(nftHolder).to.be.equal(fromAddress);
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
erc1155Receiver.address,
|
||||
perUnitValue,
|
||||
);
|
||||
const logDecoder = new LogDecoder(web3Wrapper, artifacts);
|
||||
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
})
|
||||
);
|
||||
// Verify logs
|
||||
expect(txReceipt.logs.length).to.be.equal(2);
|
||||
const receiverLog = txReceipt.logs[1] as LogWithDecodedArgs<DummyERC1155ReceiverBatchTokenReceivedEventArgs>;
|
||||
expect(receiverLog.args.operator).to.be.equal(erc1155Proxy.address);
|
||||
expect(receiverLog.args.from).to.be.equal(fromAddress);
|
||||
expect(receiverLog.args.tokenIds.length).to.be.deep.equal(1);
|
||||
expect(receiverLog.args.tokenIds[0]).to.be.bignumber.equal(tokenIdsToTransfer[0]);
|
||||
expect(receiverLog.args.tokenValues.length).to.be.deep.equal(1);
|
||||
expect(receiverLog.args.tokenValues[0]).to.be.bignumber.equal(tokenValuesToTransfer[0]);
|
||||
expect(receiverLog.args.data).to.be.deep.equal(callbackData);
|
||||
// Verify transfer was successful
|
||||
const newNftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(newNftHolder).to.be.equal(erc1155Receiver.address);
|
||||
});
|
||||
it.only('should successfully execute callback when transferring to a smart conract when there is callback data', async () => {
|
||||
// Construct ERC1155 asset data
|
||||
const callbackData = "0x12345678";
|
||||
const nonFungibleTokenIdToTransfer = erc1155NonFungibleTokenIds[0];
|
||||
const initialHoldingsByOwner = await erc1155Wrapper.getBalancesAsync();
|
||||
const nftToTransfer = initialHoldingsByOwner.nonFungible[fromAddress][erc1155Token.address][nonFungibleTokenIdToTransfer.toString()][0];
|
||||
const tokenIdsToTransfer = [nftToTransfer];
|
||||
const tokenValuesToTransfer = [new BigNumber(1)];
|
||||
const encodedAssetData = assetDataUtils.encodeERC1155AssetData(erc1155Token.address, tokenIdsToTransfer, tokenValuesToTransfer, callbackData);
|
||||
// Verify precondition
|
||||
const nftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(nftHolder).to.be.equal(fromAddress);
|
||||
// Perform a transfer from fromAddress to toAddress
|
||||
const perUnitValue = new BigNumber(1);
|
||||
const data = assetProxyInterface.transferFrom.getABIEncodedTransactionData(
|
||||
encodedAssetData,
|
||||
fromAddress,
|
||||
erc1155Receiver.address,
|
||||
perUnitValue,
|
||||
);
|
||||
const logDecoder = new LogDecoder(web3Wrapper, artifacts);
|
||||
const txReceipt = await logDecoder.getTxWithDecodedLogsAsync(
|
||||
await web3Wrapper.sendTransactionAsync({
|
||||
to: erc1155Proxy.address,
|
||||
data,
|
||||
from: authorized,
|
||||
})
|
||||
);
|
||||
// Verify logs
|
||||
expect(txReceipt.logs.length).to.be.equal(2);
|
||||
const receiverLog = txReceipt.logs[1] as LogWithDecodedArgs<DummyERC1155ReceiverBatchTokenReceivedEventArgs>;
|
||||
expect(receiverLog.args.operator).to.be.equal(erc1155Proxy.address);
|
||||
expect(receiverLog.args.from).to.be.equal(fromAddress);
|
||||
expect(receiverLog.args.tokenIds.length).to.be.deep.equal(1);
|
||||
expect(receiverLog.args.tokenIds[0]).to.be.bignumber.equal(tokenIdsToTransfer[0]);
|
||||
expect(receiverLog.args.tokenValues.length).to.be.deep.equal(1);
|
||||
expect(receiverLog.args.tokenValues[0]).to.be.bignumber.equal(tokenValuesToTransfer[0]);
|
||||
expect(receiverLog.args.data).to.be.deep.equal(callbackData);
|
||||
// Verify transfer was successful
|
||||
const newNftHolder = await erc1155Wrapper.ownerOfNonFungibleAsync(erc1155Token.address, nftToTransfer);
|
||||
expect(newNftHolder).to.be.equal(erc1155Receiver.address);
|
||||
});
|
||||
it('should propagate revert reason from erc1155 contract failure', async () => {
|
||||
});
|
||||
it('should revert if transferring the same non-fungible token more than once', async () => {
|
||||
});
|
||||
it('should revert if tansferring 0 amount of any token', async () => {
|
||||
});
|
||||
it('should revert if there is a multiplication overflow', async () => {
|
||||
});
|
||||
it('should revert if there is a multiplication overflow, when transferring multiple tokens', async () => {
|
||||
});
|
||||
it('should revert if transferring > 1 instances of a non-fungible token (amount field >1)', async () => {
|
||||
});
|
||||
it('should revert if transferring > 1 instances of a non-fungible token (value field >1)', async () => {
|
||||
});
|
||||
it('should revert if sender balance is insufficient', async () => {
|
||||
});
|
||||
it('should revert if sender allowance is insufficient', async () => {
|
||||
});
|
||||
it('should revert if caller is not authorized', async () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// tslint:enable:no-unnecessary-type-assertion
|
||||
// tslint:disable:max-file-line-count
|
||||
|
288
contracts/asset-proxy/test/utils/erc1155_wrapper.ts
Normal file
288
contracts/asset-proxy/test/utils/erc1155_wrapper.ts
Normal file
@@ -0,0 +1,288 @@
|
||||
import { constants, ERC1155HoldingsByOwner, ERC1155FungibleHoldingsByOwner, ERC1155NonFungibleHoldingsByOwner, LogDecoder, txDefaults } from '@0x/contracts-test-utils';
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import { Provider } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||
|
||||
import { artifacts, ERC1155MintableContract, ERC1155ProxyContract, ERC1155MintableTransferSingleEventArgs } from '../../src';
|
||||
|
||||
|
||||
export class ERC1155Wrapper {
|
||||
private readonly _tokenOwnerAddresses: string[];
|
||||
private readonly _fungibleTokenIds: string[];
|
||||
private readonly _nonFungibleTokenIds: string[];
|
||||
private readonly _nfts: {id: BigNumber, tokenId: BigNumber}[];
|
||||
private readonly _contractOwnerAddress: string;
|
||||
private readonly _web3Wrapper: Web3Wrapper;
|
||||
private readonly _provider: Provider;
|
||||
private readonly _logDecoder: LogDecoder;
|
||||
private readonly _dummyTokenContracts: ERC1155MintableContract[];
|
||||
private _proxyContract?: ERC1155ProxyContract;
|
||||
private _proxyIdIfExists?: string;
|
||||
private _initialTokenIdsByOwner: ERC1155HoldingsByOwner = {fungible: {}, nonFungible: {}};
|
||||
constructor(provider: Provider, tokenOwnerAddresses: string[], contractOwnerAddress: string) {
|
||||
this._web3Wrapper = new Web3Wrapper(provider);
|
||||
this._provider = provider;
|
||||
this._logDecoder = new LogDecoder(this._web3Wrapper, artifacts);
|
||||
this._dummyTokenContracts = [];
|
||||
this._tokenOwnerAddresses = tokenOwnerAddresses;
|
||||
this._contractOwnerAddress = contractOwnerAddress;
|
||||
this._fungibleTokenIds = [];
|
||||
this._nonFungibleTokenIds = [];
|
||||
this._nfts = [];
|
||||
}
|
||||
public async deployDummyTokensAsync(): Promise<ERC1155MintableContract[]> {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
for (const i of _.times(constants.NUM_DUMMY_ERC1155_TO_DEPLOY)) {
|
||||
this._dummyTokenContracts.push(
|
||||
await ERC1155MintableContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ERC1155Mintable,
|
||||
this._provider,
|
||||
txDefaults,
|
||||
),
|
||||
);
|
||||
}
|
||||
return this._dummyTokenContracts;
|
||||
}
|
||||
public async deployProxyAsync(): Promise<ERC1155ProxyContract> {
|
||||
this._proxyContract = await ERC1155ProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ERC1155Proxy,
|
||||
this._provider,
|
||||
txDefaults,
|
||||
);
|
||||
this._proxyIdIfExists = await this._proxyContract.getProxyId.callAsync();
|
||||
return this._proxyContract;
|
||||
}
|
||||
public getProxyId(): string {
|
||||
this._validateProxyContractExistsOrThrow();
|
||||
return this._proxyIdIfExists as string;
|
||||
}
|
||||
public async setBalancesAndAllowancesAsync(): Promise<ERC1155HoldingsByOwner> {
|
||||
this._validateDummyTokenContractsExistOrThrow();
|
||||
this._validateProxyContractExistsOrThrow();
|
||||
this._initialTokenIdsByOwner = {
|
||||
fungible: {} as ERC1155FungibleHoldingsByOwner,
|
||||
nonFungible: {}
|
||||
};
|
||||
const fungibleHoldingsByOwner: ERC1155FungibleHoldingsByOwner = {};
|
||||
const nonFungibleHoldingsByOwner: ERC1155NonFungibleHoldingsByOwner = {};
|
||||
for (const dummyTokenContract of this._dummyTokenContracts) {
|
||||
// Fungible Tokens
|
||||
for (const i of _.times(constants.NUM_ERC1155_FUNGIBLE_TOKENS_MINT)) {
|
||||
// Create a fungible token
|
||||
const tokenUri = generatePseudoRandomSalt().toString();
|
||||
const tokenIsNonFungible = false;
|
||||
const tokenId = await this.createTokenAsync(dummyTokenContract.address, tokenUri, tokenIsNonFungible);
|
||||
const tokenIdAsString = tokenId.toString();
|
||||
this._fungibleTokenIds.push(tokenIdAsString);
|
||||
// Mint tokens for each owner for this token
|
||||
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
||||
// tslint:disable-next-line:no-unused-variable
|
||||
await this.mintFungibleAsync(dummyTokenContract.address, tokenId, tokenOwnerAddress);
|
||||
if (_.isUndefined(fungibleHoldingsByOwner[tokenOwnerAddress])) {
|
||||
fungibleHoldingsByOwner[tokenOwnerAddress] = {};
|
||||
}
|
||||
if (_.isUndefined(fungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address])) {
|
||||
fungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address] = {};
|
||||
}
|
||||
fungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address][tokenIdAsString] = constants.INITIAL_ERC1155_FUNGIBLE_BALANCE;
|
||||
await this.approveProxyAsync(dummyTokenContract.address, tokenId, tokenOwnerAddress);
|
||||
}
|
||||
}
|
||||
// Non-Fungible Tokens
|
||||
for (const i of _.times(constants.NUM_ERC1155_NONFUNGIBLE_TOKENS_MINT)) {
|
||||
const tokenUri = generatePseudoRandomSalt().toString();
|
||||
const tokenIsNonFungible = true;
|
||||
const tokenId = await this.createTokenAsync(dummyTokenContract.address, tokenUri, tokenIsNonFungible);
|
||||
const tokenIdAsString = tokenId.toString();
|
||||
this._nonFungibleTokenIds.push(tokenIdAsString);
|
||||
await this.mintNonFungibleAsync(dummyTokenContract.address, tokenId, this._tokenOwnerAddresses);
|
||||
let tokenNonce = 0;
|
||||
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
||||
if (_.isUndefined(nonFungibleHoldingsByOwner[tokenOwnerAddress])) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress] = {};
|
||||
}
|
||||
if (_.isUndefined(nonFungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address])) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address] = {};
|
||||
}
|
||||
if (_.isUndefined(nonFungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address][tokenIdAsString])) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address][tokenIdAsString] = [];
|
||||
}
|
||||
const nonFungibleId = tokenId.plus(++tokenNonce);
|
||||
this._nfts.push({id: nonFungibleId, tokenId});
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress][dummyTokenContract.address][tokenIdAsString].push(nonFungibleId);
|
||||
await this.approveProxyAsync(dummyTokenContract.address, tokenId, tokenOwnerAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._initialTokenIdsByOwner = {
|
||||
fungible: fungibleHoldingsByOwner,
|
||||
nonFungible: nonFungibleHoldingsByOwner,
|
||||
}
|
||||
return this._initialTokenIdsByOwner;
|
||||
}
|
||||
public async approveProxyAsync(tokenAddress: string, tokenId: BigNumber, tokenOwner: string): Promise<void> {
|
||||
const proxyAddress = (this._proxyContract as ERC1155ProxyContract).address;
|
||||
await this.approveProxyForAllAsync(proxyAddress, tokenAddress, tokenOwner);
|
||||
}
|
||||
public async approveProxyForAllAsync(to: string, tokenAddress: string, tokenOwner: string): Promise<void> {
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await tokenContract.setApprovalForAll.sendTransactionAsync(to, true, {
|
||||
from: tokenOwner,
|
||||
}),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
}
|
||||
public async createTokenAsync(tokenAddress: string, tokenUri: string, tokenIsNonFungible: boolean): Promise<BigNumber> {
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
const txReceipt = await this._logDecoder.getTxWithDecodedLogsAsync(
|
||||
await tokenContract.create.sendTransactionAsync(tokenUri, tokenIsNonFungible),
|
||||
);
|
||||
const createFungibleTokenLog = txReceipt.logs[0] as LogWithDecodedArgs<ERC1155MintableTransferSingleEventArgs>;
|
||||
const dummyFungibleTokenId = createFungibleTokenLog.args._id;
|
||||
return dummyFungibleTokenId;
|
||||
}
|
||||
public async mintFungibleAsync(tokenAddress: string, tokenId: BigNumber, userAddress: string): Promise<void> {
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await tokenContract.mintFungible.sendTransactionAsync(
|
||||
tokenId,
|
||||
[userAddress],
|
||||
[constants.INITIAL_ERC1155_FUNGIBLE_BALANCE],
|
||||
{ from: this._contractOwnerAddress }
|
||||
),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
}
|
||||
public async mintNonFungibleAsync(tokenAddress: string, tokenId: BigNumber, userAddresses: string[]): Promise<void> {
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await tokenContract.mintNonFungible.sendTransactionAsync(
|
||||
tokenId,
|
||||
userAddresses,
|
||||
{ from: this._contractOwnerAddress }
|
||||
),
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
}
|
||||
public async ownerOfNonFungibleAsync(tokenAddress: string, tokenId: BigNumber): Promise<string> {
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
const owner = await tokenContract.ownerOf.callAsync(tokenId);
|
||||
return owner;
|
||||
}
|
||||
public async isNonFungibleOwnerAsync(userAddress: string, tokenAddress: string, tokenId: BigNumber): Promise<boolean> {
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
const tokenOwner = await tokenContract.ownerOf.callAsync(tokenId);
|
||||
const isOwner = tokenOwner === userAddress;
|
||||
return isOwner;
|
||||
}
|
||||
public async isProxyApprovedForAllAsync(userAddress: string, tokenAddress: string): Promise<boolean> {
|
||||
this._validateProxyContractExistsOrThrow();
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
const operator = (this._proxyContract as ERC1155ProxyContract).address;
|
||||
const didApproveAll = await tokenContract.isApprovedForAll.callAsync(userAddress, operator);
|
||||
return didApproveAll;
|
||||
}
|
||||
public async getBalancesAsync(): Promise<ERC1155HoldingsByOwner> {
|
||||
this._validateDummyTokenContractsExistOrThrow();
|
||||
this._validateBalancesAndAllowancesSetOrThrow();
|
||||
const tokenHoldingsByOwner: ERC1155FungibleHoldingsByOwner = {};
|
||||
const nonFungibleHoldingsByOwner: ERC1155NonFungibleHoldingsByOwner = {};
|
||||
for (const dummyTokenContract of this._dummyTokenContracts) {
|
||||
const tokenAddress = dummyTokenContract.address;
|
||||
const tokenContract = this._getTokenContractFromAssetData(tokenAddress);
|
||||
// Construct batch balance call
|
||||
const tokenOwners: string[] = [];
|
||||
const tokenIds: BigNumber[] = [];
|
||||
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
||||
for (const tokenId of this._fungibleTokenIds) {
|
||||
tokenOwners.push(tokenOwnerAddress);
|
||||
tokenIds.push(new BigNumber(tokenId));
|
||||
}
|
||||
for (const nft of this._nfts) {
|
||||
tokenOwners.push(tokenOwnerAddress);
|
||||
tokenIds.push(nft.id);
|
||||
}
|
||||
}
|
||||
const balances = await tokenContract.balanceOfBatch.callAsync(tokenOwners, tokenIds);
|
||||
// Parse out balances into fungible / non-fungible token holdings
|
||||
let i = 0;
|
||||
for (const tokenOwnerAddress of this._tokenOwnerAddresses) {
|
||||
// Fungible tokens
|
||||
for (const tokenId of this._fungibleTokenIds) {
|
||||
if (_.isUndefined(tokenHoldingsByOwner[tokenOwnerAddress])) {
|
||||
tokenHoldingsByOwner[tokenOwnerAddress] = {};
|
||||
}
|
||||
if (_.isUndefined(tokenHoldingsByOwner[tokenOwnerAddress][tokenAddress])) {
|
||||
tokenHoldingsByOwner[tokenOwnerAddress][tokenAddress] = {};
|
||||
}
|
||||
tokenHoldingsByOwner[tokenOwnerAddress][tokenAddress][tokenId] = balances[i++];
|
||||
}
|
||||
// Non-fungible tokens
|
||||
for (const nft of this._nfts) {
|
||||
if (_.isUndefined(nonFungibleHoldingsByOwner[tokenOwnerAddress])) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress] = {};
|
||||
}
|
||||
if (_.isUndefined(nonFungibleHoldingsByOwner[tokenOwnerAddress][tokenAddress])) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress][tokenAddress] = {};
|
||||
}
|
||||
if (_.isUndefined(nonFungibleHoldingsByOwner[tokenOwnerAddress][tokenAddress][nft.tokenId.toString()])) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress][tokenAddress][nft.tokenId.toString()] = [];
|
||||
}
|
||||
const isOwner = balances[i++];
|
||||
if (isOwner.isEqualTo(1)) {
|
||||
nonFungibleHoldingsByOwner[tokenOwnerAddress][tokenAddress][nft.tokenId.toString()].push(nft.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const holdingsByOwner = {
|
||||
fungible: tokenHoldingsByOwner,
|
||||
nonFungible: nonFungibleHoldingsByOwner,
|
||||
}
|
||||
return holdingsByOwner;
|
||||
}
|
||||
public getFungibleTokenIds(): BigNumber[] {
|
||||
const fungibleTokenIds = _.map(this._fungibleTokenIds, (tokenIdAsString: string) => {return new BigNumber(tokenIdAsString)});
|
||||
return fungibleTokenIds;
|
||||
}
|
||||
public getNonFungibleTokenIds(): BigNumber[] {
|
||||
const nonFungibleTokenIds = _.map(this._nonFungibleTokenIds, (tokenIdAsString: string) => {return new BigNumber(tokenIdAsString)});
|
||||
return nonFungibleTokenIds;
|
||||
}
|
||||
public getTokenOwnerAddresses(): string[] {
|
||||
return this._tokenOwnerAddresses;
|
||||
}
|
||||
public getTokenAddresses(): string[] {
|
||||
const tokenAddresses = _.map(this._dummyTokenContracts, dummyTokenContract => dummyTokenContract.address);
|
||||
return tokenAddresses;
|
||||
}
|
||||
private _getTokenContractFromAssetData(tokenAddress: string): ERC1155MintableContract {
|
||||
const tokenContractIfExists = _.find(this._dummyTokenContracts, c => c.address === tokenAddress);
|
||||
if (_.isUndefined(tokenContractIfExists)) {
|
||||
throw new Error(`Token: ${tokenAddress} was not deployed through ERC1155Wrapper`);
|
||||
}
|
||||
return tokenContractIfExists;
|
||||
}
|
||||
private _validateDummyTokenContractsExistOrThrow(): void {
|
||||
if (_.isUndefined(this._dummyTokenContracts)) {
|
||||
throw new Error('Dummy ERC1155 tokens not yet deployed, please call "deployDummyTokensAsync"');
|
||||
}
|
||||
}
|
||||
private _validateProxyContractExistsOrThrow(): void {
|
||||
if (_.isUndefined(this._proxyContract)) {
|
||||
throw new Error('ERC1155 proxy contract not yet deployed, please call "deployProxyAsync"');
|
||||
}
|
||||
}
|
||||
private _validateBalancesAndAllowancesSetOrThrow(): void {
|
||||
if (_.keys(this._initialTokenIdsByOwner.fungible).length === 0 || _.keys(this._initialTokenIdsByOwner.nonFungible).length === 0) {
|
||||
throw new Error(
|
||||
'Dummy ERC1155 balances and allowances not yet set, please call "setBalancesAndAllowancesAsync"',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,2 +1,3 @@
|
||||
export * from './erc20_wrapper';
|
||||
export * from './erc721_wrapper';
|
||||
export * from './erc1155_wrapper';
|
||||
|
Reference in New Issue
Block a user