difftreelog
Merge pull request #745 from UniqueNetwork/tests/eth-helpers
in: master
9 files changed
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -239,19 +239,29 @@
const owner = await helper.eth.createAccountWithBalance(donor);
const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
- const [newAdmin] = await helper.arrange.createAccounts([10n], donor);
- const newAdminCross = helper.ethCrossAccount.fromKeyringPair(newAdmin);
+ const [adminSub] = await helper.arrange.createAccounts([10n], donor);
+ const adminEth = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();
+ const adminCrossSub = helper.ethCrossAccount.fromKeyringPair(adminSub);
+ const adminCrossEth = helper.ethCrossAccount.fromAddress(adminEth);
+
const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
- await collectionEvm.methods.addCollectionAdminCross(newAdminCross).send();
+ await collectionEvm.methods.addCollectionAdminCross(adminCrossSub).send();
+ await collectionEvm.methods.addCollectionAdminCross(adminCrossEth).send();
+
{
- const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
- expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())
- .to.be.eq(newAdmin.address.toLocaleLowerCase());
+ const adminList = await helper.collection.getAdmins(collectionId);
+ expect(adminList).to.deep.include({Substrate: adminSub.address});
+ expect(adminList).to.deep.include({Ethereum: adminEth});
}
- await collectionEvm.methods.removeCollectionAdminCross(newAdminCross).send();
- const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
+ await collectionEvm.methods.removeCollectionAdminCross(adminCrossSub).send();
+ await collectionEvm.methods.removeCollectionAdminCross(adminCrossEth).send();
+ const adminList = await helper.collection.getAdmins(collectionId);
expect(adminList.length).to.be.eq(0);
+
+ // Non admin cannot mint:
+ await expect(helper.nft.mintToken(adminSub, {collectionId, owner: {Substrate: adminSub.address}})).to.be.rejectedWith(/common.PublicMintingNotAllowed/);
+ await expect(collectionEvm.methods.mint(adminEth).send({from: adminEth})).to.be.rejected;
});
// Soft-deprecated
@@ -395,16 +405,27 @@
itEth('Change owner [cross]', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const [newOwner] = await helper.arrange.createAccounts([10n], donor);
- const newOwnerCross = helper.ethCrossAccount.fromKeyringPair(newOwner);
- const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
- const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const ownerEth = await helper.eth.createAccountWithBalance(donor);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);
+ const [ownerSub] = await helper.arrange.createAccounts([10n], donor);
+ const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);
- expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.false;
+ const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
- await collectionEvm.methods.changeCollectionOwnerCross(newOwnerCross).send();
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.false;
- expect(await collectionEvm.methods.isOwnerOrAdminCross(newOwnerCross).call()).to.be.true;
+ // Can set ethereum owner:
+ await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossEth).send({from: owner});
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossEth).call()).to.be.true;
+ expect(await helper.collection.getData(collectionId))
+ .to.have.property('normalizedOwner').that.is.eq(helper.address.ethToSubstrate(ownerEth));
+
+ // Can set Substrate owner:
+ await collectionEvm.methods.changeCollectionOwnerCross(ownerCrossSub).send({from: ownerEth});
+ expect(await collectionEvm.methods.isOwnerOrAdminCross(ownerCrossSub).call()).to.be.true;
+ expect(await helper.collection.getData(collectionId))
+ .to.have.property('normalizedOwner').that.is.eq(helper.address.normalizeSubstrate(ownerSub.address));
});
itEth.skip('change owner call fee', async ({helper}) => {
tests/src/eth/createFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createFTCollection.test.ts
+++ b/tests/src/eth/createFTCollection.test.ts
@@ -144,7 +144,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
+ const {collectionAddress, collectionId} = await helper.eth.createFungibleCollection(owner, 'Exister', DECIMALS, 'absolutely anything', 'WIWT');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
const result = await collectionHelper.methods
@@ -166,6 +166,7 @@
expect(await collectionHelper.methods
.isCollectionExist(collectionAddress)
.call()).to.be.false;
+ expect(await helper.collection.getData(collectionId)).to.be.null;
});
});
@@ -214,12 +215,15 @@
}
});
- itEth('(!negative test!) Create collection (no funds)', async ({helper}) => {
+ itEth('(!negative test!) cannot create collection if value !== 2', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
- await expect(collectionHelper.methods
- .createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
- .call({value: Number(1n * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
+ const expects = [0n, 1n, 30n].map(async value => {
+ await expect(collectionHelper.methods
+ .createFTCollection('Peasantry', DECIMALS, 'absolutely anything', 'TWIW')
+ .call({value: Number(value * nominal)})).to.be.rejectedWith('Sent amount not equals to collection creation price (2000000000000000000)');
+ });
+ await Promise.all(expects);
});
// Soft-deprecated
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -308,7 +308,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
+ const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
@@ -331,5 +331,6 @@
expect(await collectionHelper.methods
.isCollectionExist(collectionAddress)
.call()).to.be.false;
+ expect(await helper.collection.getData(collectionId)).to.be.null;
});
});
\ No newline at end of file
tests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createRFTCollection.test.ts
+++ b/tests/src/eth/createRFTCollection.test.ts
@@ -340,7 +340,7 @@
itEth('destroyCollection', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
+ const {collectionAddress, collectionId} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
await expect(collectionHelper.methods
@@ -349,6 +349,7 @@
expect(await collectionHelper.methods
.isCollectionExist(collectionAddress)
- .call()).to.be.false;
+ .call()).to.be.false;
+ expect(await helper.collection.getData(collectionId)).to.be.null;
});
});
tests/src/eth/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/destroyCollection.test.ts
+++ b/tests/src/eth/destroyCollection.test.ts
@@ -15,62 +15,48 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets, requirePalletsOrSkip} from '../util';
+import {Pallets} from '../util';
import {expect, itEth, usingEthPlaygrounds} from './util';
-
-describe('Destroy Collection from EVM', () => {
+describe('Destroy Collection from EVM', function() {
let donor: IKeyringPair;
+ const testCases = [
+ {method: 'createRFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.ReFungible]},
+ {method: 'createNFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF'], requiredPallets: [Pallets.NFT]},
+ {method: 'createFTCollection' as const, params: ['Limits', 'absolutely anything', 'OLF', 18], requiredPallets: [Pallets.Fungible]},
+ ];
before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible, Pallets.NFT]);
+ await usingEthPlaygrounds(async (_, privateKey) => {
donor = await privateKey({filename: __filename});
});
});
-
- itEth('(!negative test!) RFT', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const signer = await helper.eth.createAccountWithBalance(donor);
-
- const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
-
- const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
- const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);
-
- await expect(collectionHelper.methods
- .destroyCollection(collectionAddress)
- .send({from: signer})).to.be.rejected;
-
- await expect(collectionHelper.methods
- .destroyCollection(unexistedCollection)
- .send({from: signer})).to.be.rejected;
-
- expect(await collectionHelper.methods
- .isCollectionExist(unexistedCollection)
- .call()).to.be.false;
- });
-
- itEth('(!negative test!) NFT', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const signer = await helper.eth.createAccountWithBalance(donor);
-
- const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
-
- const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
- const collectionHelper = helper.ethNativeContract.collectionHelpers(signer);
-
- await expect(collectionHelper.methods
- .destroyCollection(collectionAddress)
- .send({from: signer})).to.be.rejected;
-
- await expect(collectionHelper.methods
- .destroyCollection(unexistedCollection)
- .send({from: signer})).to.be.rejected;
-
- expect(await collectionHelper.methods
- .isCollectionExist(unexistedCollection)
- .call()).to.be.false;
- });
+ testCases.map((testCase) =>
+ itEth.ifWithPallets(`Cannot burn non-owned or non-existing collection ${testCase.method}`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const signer = await helper.eth.createAccountWithBalance(donor);
+
+ const unexistedCollection = helper.ethAddress.fromCollectionId(1000000);
+
+ const collectionHelpers = helper.ethNativeContract.collectionHelpers(signer);
+ const {collectionAddress} = await helper.eth.createCollecion(testCase.method, owner, ...testCase.params as [string, string, string, number?]);
+
+ // cannot burn collec
+ await expect(collectionHelpers.methods
+ .destroyCollection(collectionAddress)
+ .send({from: signer})).to.be.rejected;
+
+ await expect(collectionHelpers.methods
+ .destroyCollection(unexistedCollection)
+ .send({from: signer})).to.be.rejected;
+
+ expect(await collectionHelpers.methods
+ .isCollectionExist(unexistedCollection)
+ .call()).to.be.false;
+
+ expect(await collectionHelpers.methods
+ .isCollectionExist(collectionAddress)
+ .call()).to.be.true;
+ }));
});
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -232,56 +232,64 @@
});
itEth('Can perform transferCross()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(donor);
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);
const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n, {Ethereum: owner});
+ await collection.mint(alice, 200n, {Ethereum: sender});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
{
- const result = await contract.methods.transferCross(to, 50).send({from: owner});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(owner);
- expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(sender);
+ expect(event.returnValues.to).to.be.equal(receiverEth);
expect(event.returnValues.value).to.be.equal('50');
- }
-
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(150);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(50);
+ // Sender's balance decreased:
+ const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();
+ expect(+ownerBalance).to.equal(150);
+ // Receiver's balance increased:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(50);
}
{
- const result = await contract.methods.transferCross(toSubstrate, 50).send({from: owner});
-
+ // Can transferCross to substrate address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.from).to.be.equal(sender);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));
expect(event.returnValues.value).to.be.equal('50');
+ // Sender's balance decreased:
+ const senderBalance = await collection.getBalance({Ethereum: sender});
+ expect(senderBalance).to.equal(100n);
+ // Receiver's balance increased:
+ const balance = await collection.getBalance({Substrate: donor.address});
+ expect(balance).to.equal(50n);
}
+ });
+
+ itEth('Cannot transferCross() more than have', async ({helper}) => {
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const BALANCE = 200n;
+ const BALANCE_TO_TRANSFER = BALANCE + 100n;
- {
- const balance = await collection.getBalance({Ethereum: owner});
- expect(balance).to.equal(100n);
- }
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, BALANCE, {Ethereum: sender});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
- {
- const balance = await collection.getBalance({Substrate: donor.address});
- expect(balance).to.equal(50n);
- }
-
+ await expect(collectionEvm.methods.transferCross(receiverCrossEth, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;
});
itEth('Can perform transfer()', async ({helper}) => {
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';202122describe('NFT: Information getting', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice] = await helper.arrange.createAccounts([10n], donor);30 });31 });3233 itEth('totalSupply', async ({helper}) => {34 const collection = await helper.nft.mintCollection(alice, {});35 await collection.mintToken(alice);3637 const caller = await helper.eth.createAccountWithBalance(donor);3839 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);40 const totalSupply = await contract.methods.totalSupply().call();4142 expect(totalSupply).to.equal('1');43 });4445 itEth('balanceOf', async ({helper}) => {46 const collection = await helper.nft.mintCollection(alice, {});47 const caller = await helper.eth.createAccountWithBalance(donor);4849 await collection.mintToken(alice, {Ethereum: caller});50 await collection.mintToken(alice, {Ethereum: caller});51 await collection.mintToken(alice, {Ethereum: caller});5253 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);54 const balance = await contract.methods.balanceOf(caller).call();5556 expect(balance).to.equal('3');57 });5859 itEth('ownerOf', async ({helper}) => {60 const collection = await helper.nft.mintCollection(alice, {});61 const caller = await helper.eth.createAccountWithBalance(donor);6263 const token = await collection.mintToken(alice, {Ethereum: caller});6465 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6667 const owner = await contract.methods.ownerOf(token.tokenId).call();6869 expect(owner).to.equal(caller);70 });7172 itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {73 const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});74 const caller = helper.eth.createAccount();7576 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7778 expect(await contract.methods.name().call()).to.equal('test');79 expect(await contract.methods.symbol().call()).to.equal('TEST');80 });81});8283describe('Check ERC721 token URI for NFT', () => {84 let donor: IKeyringPair;8586 before(async function() {87 await usingEthPlaygrounds(async (_helper, privateKey) => {88 donor = await privateKey({filename: __filename});89 });90 });9192 async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {93 const owner = await helper.eth.createAccountWithBalance(donor);94 const receiver = helper.eth.createAccount();9596 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);97 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);9899 const result = await contract.methods.mint(receiver).send();100 const tokenId = result.events.Transfer.returnValues.tokenId;101 expect(tokenId).to.be.equal('1');102103 if (propertyKey && propertyValue) {104 // Set URL or suffix105 await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();106 }107108 const event = result.events.Transfer;109 expect(event.address).to.be.equal(collectionAddress);110 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');111 expect(event.returnValues.to).to.be.equal(receiver);112 expect(event.returnValues.tokenId).to.be.equal(tokenId);113114 return {contract, nextTokenId: tokenId};115 }116117 itEth('Empty tokenURI', async ({helper}) => {118 const {contract, nextTokenId} = await setup(helper, '');119 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');120 });121122 itEth('TokenURI from url', async ({helper}) => {123 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');124 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');125 });126127 itEth('TokenURI from baseURI', async ({helper}) => {128 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');129 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');130 });131132 itEth('TokenURI from baseURI + suffix', async ({helper}) => {133 const suffix = '/some/suffix';134 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);135 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);136 });137});138139describe('NFT: Plain calls', () => {140 let donor: IKeyringPair;141 let minter: IKeyringPair;142 let bob: IKeyringPair;143 let charlie: IKeyringPair;144145 before(async function() {146 await usingEthPlaygrounds(async (helper, privateKey) => {147 donor = await privateKey({filename: __filename});148 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);149 });150 });151152 itEth('Can perform mint() & get crossOwner()', async ({helper}) => {153 const owner = await helper.eth.createAccountWithBalance(donor);154 const receiver = helper.eth.createAccount();155156 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');157 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);158159 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();160 const tokenId = result.events.Transfer.returnValues.tokenId;161 expect(tokenId).to.be.equal('1');162163 const event = result.events.Transfer;164 expect(event.address).to.be.equal(collectionAddress);165 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');166 expect(event.returnValues.to).to.be.equal(receiver);167168 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');169 console.log(await contract.methods.crossOwnerOf(tokenId).call());170 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);171 // TODO: this wont work right now, need release 919000 first172 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();173 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();174 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);175 });176177 //TODO: CORE-302 add eth methods178 itEth.skip('Can perform mintBulk()', async ({helper}) => {179 const caller = await helper.eth.createAccountWithBalance(donor);180 const receiver = helper.eth.createAccount();181182 const collection = await helper.nft.mintCollection(minter);183 await collection.addAdmin(minter, {Ethereum: caller});184185 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);186 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);187 {188 const bulkSize = 3;189 const nextTokenId = await contract.methods.nextTokenId().call();190 expect(nextTokenId).to.be.equal('1');191 const result = await contract.methods.mintBulkWithTokenURI(192 receiver,193 Array.from({length: bulkSize}, (_, i) => (194 [+nextTokenId + i, `Test URI ${i}`]195 )),196 ).send({from: caller});197198 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);199 for (let i = 0; i < bulkSize; i++) {200 const event = events[i];201 expect(event.address).to.equal(collectionAddress);202 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');203 expect(event.returnValues.to).to.equal(receiver);204 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);205206 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);207 }208 }209 });210211 itEth('Can perform burn()', async ({helper}) => {212 const caller = await helper.eth.createAccountWithBalance(donor);213214 const collection = await helper.nft.mintCollection(minter, {});215 const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});216217 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);218 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);219220 {221 const result = await contract.methods.burn(tokenId).send({from: caller});222223 const event = result.events.Transfer;224 expect(event.address).to.be.equal(collectionAddress);225 expect(event.returnValues.from).to.be.equal(caller);226 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');227 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);228 }229 });230231 itEth('Can perform approve()', async ({helper}) => {232 const owner = await helper.eth.createAccountWithBalance(donor);233 const spender = helper.eth.createAccount();234235 const collection = await helper.nft.mintCollection(minter, {});236 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});237238 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);239 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);240241 {242 const result = await contract.methods.approve(spender, tokenId).send({from: owner});243244 const event = result.events.Approval;245 expect(event.address).to.be.equal(collectionAddress);246 expect(event.returnValues.owner).to.be.equal(owner);247 expect(event.returnValues.approved).to.be.equal(spender);248 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);249 }250 });251252 itEth('Can perform burnFromCross()', async ({helper}) => {253 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});254255 const owner = bob;256 const spender = await helper.eth.createAccountWithBalance(donor, 100n);257258 const token = await collection.mintToken(minter, {Substrate: owner.address});259260 const address = helper.ethAddress.fromCollectionId(collection.collectionId);261 const contract = helper.ethNativeContract.collection(address, 'nft');262263 {264 await token.approve(owner, {Ethereum: spender});265 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);266 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});267 const events = result.events.Transfer;268269 expect(events).to.be.like({270 address,271 event: 'Transfer',272 returnValues: {273 from: helper.address.substrateToEth(owner.address),274 to: '0x0000000000000000000000000000000000000000',275 tokenId: token.tokenId.toString(),276 },277 });278 }279 });280281 itEth('Can perform approveCross()', async ({helper}) => {282 // arrange: create accounts283 const owner = await helper.eth.createAccountWithBalance(donor, 100n);284 const ownerCross = helper.ethCrossAccount.fromAddress(owner);285 const receiverSub = charlie;286 const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);287 const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);288 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);289290 // arrange: create collection and tokens:291 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});292 const token1 = await collection.mintToken(minter, {Ethereum: owner});293 const token2 = await collection.mintToken(minter, {Ethereum: owner});294295 const collectionEvm = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');296297 // Can approveCross substrate and ethereum address:298 const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});299 const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});300 const eventSub = resultSub.events.Approval;301 const eventEth = resultEth.events.Approval;302 expect(eventSub).to.be.like({303 address: helper.ethAddress.fromCollectionId(collection.collectionId),304 event: 'Approval',305 returnValues: {306 owner,307 approved: helper.address.substrateToEth(receiverSub.address),308 tokenId: token1.tokenId.toString(),309 },310 });311 expect(eventEth).to.be.like({312 address: helper.ethAddress.fromCollectionId(collection.collectionId),313 event: 'Approval',314 returnValues: {315 owner,316 approved: receiverEth,317 tokenId: token2.tokenId.toString(),318 },319 });320321 // Substrate address can transferFrom approved tokens:322 await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});323 expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});324 // Ethereum address can transferFromCross approved tokens:325 await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});326 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});327 });328329 itEth('Can perform transferFrom()', async ({helper}) => {330 const owner = await helper.eth.createAccountWithBalance(donor);331 const spender = await helper.eth.createAccountWithBalance(donor);332 const receiver = helper.eth.createAccount();333334 const collection = await helper.nft.mintCollection(minter, {});335 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});336337 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);338 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);339340 await contract.methods.approve(spender, tokenId).send({from: owner});341342 {343 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});344345 const event = result.events.Transfer;346 expect(event.address).to.be.equal(collectionAddress);347 expect(event.returnValues.from).to.be.equal(owner);348 expect(event.returnValues.to).to.be.equal(receiver);349 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);350 }351352 {353 const balance = await contract.methods.balanceOf(receiver).call();354 expect(+balance).to.equal(1);355 }356357 {358 const balance = await contract.methods.balanceOf(owner).call();359 expect(+balance).to.equal(0);360 }361 });362363 itEth('Can perform transferFromCross()', async ({helper}) => {364 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});365366 const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);367 const spender = await helper.eth.createAccountWithBalance(donor);368369 const token = await collection.mintToken(minter, {Substrate: owner.address});370371 const address = helper.ethAddress.fromCollectionId(collection.collectionId);372 const contract = helper.ethNativeContract.collection(address, 'nft');373374 await token.approve(owner, {Ethereum: spender});375376 {377 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);378 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);379 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});380 const event = result.events.Transfer;381 expect(event).to.be.like({382 address: helper.ethAddress.fromCollectionId(collection.collectionId),383 event: 'Transfer',384 returnValues: {385 from: helper.address.substrateToEth(owner.address),386 to: helper.address.substrateToEth(receiver.address),387 tokenId: token.tokenId.toString(),388 },389 });390 }391392 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});393 });394395 itEth('Can perform transfer()', async ({helper}) => {396 const collection = await helper.nft.mintCollection(minter, {});397 const owner = await helper.eth.createAccountWithBalance(donor);398 const receiver = helper.eth.createAccount();399400 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});401402 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);403 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);404405 {406 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});407408 const event = result.events.Transfer;409 expect(event.address).to.be.equal(collectionAddress);410 expect(event.returnValues.from).to.be.equal(owner);411 expect(event.returnValues.to).to.be.equal(receiver);412 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);413 }414415 {416 const balance = await contract.methods.balanceOf(owner).call();417 expect(+balance).to.equal(0);418 }419420 {421 const balance = await contract.methods.balanceOf(receiver).call();422 expect(+balance).to.equal(1);423 }424 });425 426 itEth('Can perform transferCross()', async ({helper}) => {427 const collection = await helper.nft.mintCollection(minter, {});428 const owner = await helper.eth.createAccountWithBalance(donor);429 const receiver = await helper.eth.createAccountWithBalance(donor);430 const to = helper.ethCrossAccount.fromAddress(receiver);431 const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);432 433 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});434435 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);436 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);437438 {439 const result = await contract.methods.transferCross(to, tokenId).send({from: owner});440441 const event = result.events.Transfer;442 expect(event.address).to.be.equal(collectionAddress);443 expect(event.returnValues.from).to.be.equal(owner);444 expect(event.returnValues.to).to.be.equal(receiver);445 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);446 }447448 {449 const balance = await contract.methods.balanceOf(owner).call();450 expect(+balance).to.equal(0);451 }452453 {454 const balance = await contract.methods.balanceOf(receiver).call();455 expect(+balance).to.equal(1);456 }457 458 {459 const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});460 461462 const event = substrateResult.events.Transfer;463 expect(event.address).to.be.equal(collectionAddress);464 expect(event.returnValues.from).to.be.equal(receiver);465 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));466 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);467 }468469 {470 const balance = await contract.methods.balanceOf(receiver).call();471 expect(+balance).to.equal(0);472 }473474 {475 const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});476 expect(balance).to.be.contain(tokenId);477 }478 });479});480481describe('NFT: Fees', () => {482 let donor: IKeyringPair;483 let alice: IKeyringPair;484 let bob: IKeyringPair;485 let charlie: IKeyringPair;486487 before(async function() {488 await usingEthPlaygrounds(async (helper, privateKey) => {489 donor = await privateKey({filename: __filename});490 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);491 });492 });493494 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {495 const owner = await helper.eth.createAccountWithBalance(donor);496 const spender = helper.eth.createAccount();497498 const collection = await helper.nft.mintCollection(alice, {});499 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});500501 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);502503 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));504 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));505 });506507 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {508 const owner = await helper.eth.createAccountWithBalance(donor);509 const spender = await helper.eth.createAccountWithBalance(donor);510511 const collection = await helper.nft.mintCollection(alice, {});512 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});513514 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);515516 await contract.methods.approve(spender, tokenId).send({from: owner});517518 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));519 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));520 });521522 itEth('Can perform transferFromCross()', async ({helper}) => {523 const collectionMinter = alice;524 const owner = bob;525 const receiver = charlie;526 const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});527528 const spender = await helper.eth.createAccountWithBalance(donor, 100n);529530 const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});531532 const address = helper.ethAddress.fromCollectionId(collection.collectionId);533 const contract = helper.ethNativeContract.collection(address, 'nft');534535 await token.approve(owner, {Ethereum: spender});536537 {538 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);539 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);540 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});541 const event = result.events.Transfer;542 expect(event).to.be.like({543 address: helper.ethAddress.fromCollectionId(collection.collectionId),544 event: 'Transfer',545 returnValues: {546 from: helper.address.substrateToEth(owner.address),547 to: helper.address.substrateToEth(receiver.address),548 tokenId: token.tokenId.toString(),549 },550 });551 }552553 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});554 });555556 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {557 const owner = await helper.eth.createAccountWithBalance(donor);558 const receiver = helper.eth.createAccount();559560 const collection = await helper.nft.mintCollection(alice, {});561 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});562563 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);564565 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));566 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));567 });568});569570describe('NFT: Substrate calls', () => {571 let donor: IKeyringPair;572 let alice: IKeyringPair;573574 before(async function() {575 await usingEthPlaygrounds(async (helper, privateKey) => {576 donor = await privateKey({filename: __filename});577 [alice] = await helper.arrange.createAccounts([20n], donor);578 });579 });580581 itEth('Events emitted for mint()', async ({helper}) => {582 const collection = await helper.nft.mintCollection(alice, {});583 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);584 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');585586 const events: any = [];587 contract.events.allEvents((_: any, event: any) => {588 events.push(event);589 });590591 const {tokenId} = await collection.mintToken(alice);592 if (events.length == 0) await helper.wait.newBlocks(1);593 const event = events[0];594595 expect(event.event).to.be.equal('Transfer');596 expect(event.address).to.be.equal(collectionAddress);597 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');598 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));599 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());600 });601602 itEth('Events emitted for burn()', async ({helper}) => {603 const collection = await helper.nft.mintCollection(alice, {});604 const token = await collection.mintToken(alice);605606 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);607 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');608609 const events: any = [];610 contract.events.allEvents((_: any, event: any) => {611 events.push(event);612 });613614 await token.burn(alice);615 if (events.length == 0) await helper.wait.newBlocks(1);616 const event = events[0];617618 expect(event.event).to.be.equal('Transfer');619 expect(event.address).to.be.equal(collectionAddress);620 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));621 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');622 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());623 });624625 itEth('Events emitted for approve()', async ({helper}) => {626 const receiver = helper.eth.createAccount();627628 const collection = await helper.nft.mintCollection(alice, {});629 const token = await collection.mintToken(alice);630631 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);632 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');633634 const events: any = [];635 contract.events.allEvents((_: any, event: any) => {636 events.push(event);637 });638639 await token.approve(alice, {Ethereum: receiver});640 if (events.length == 0) await helper.wait.newBlocks(1);641 const event = events[0];642643 expect(event.event).to.be.equal('Approval');644 expect(event.address).to.be.equal(collectionAddress);645 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));646 expect(event.returnValues.approved).to.be.equal(receiver);647 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());648 });649650 itEth('Events emitted for transferFrom()', async ({helper}) => {651 const [bob] = await helper.arrange.createAccounts([10n], donor);652 const receiver = helper.eth.createAccount();653654 const collection = await helper.nft.mintCollection(alice, {});655 const token = await collection.mintToken(alice);656 await token.approve(alice, {Substrate: bob.address});657658 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);659 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');660661 const events: any = [];662 contract.events.allEvents((_: any, event: any) => {663 events.push(event);664 });665666 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});667668 if (events.length == 0) await helper.wait.newBlocks(1);669 const event = events[0];670671 expect(event.address).to.be.equal(collectionAddress);672 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));673 expect(event.returnValues.to).to.be.equal(receiver);674 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);675 });676677 itEth('Events emitted for transfer()', async ({helper}) => {678 const receiver = helper.eth.createAccount();679680 const collection = await helper.nft.mintCollection(alice, {});681 const token = await collection.mintToken(alice);682683 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);684 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');685686 const events: any = [];687 contract.events.allEvents((_: any, event: any) => {688 events.push(event);689 });690691 await token.transfer(alice, {Ethereum: receiver});692693 if (events.length == 0) await helper.wait.newBlocks(1);694 const event = events[0];695696 expect(event.address).to.be.equal(collectionAddress);697 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));698 expect(event.returnValues.to).to.be.equal(receiver);699 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);700 });701});702703describe('Common metadata', () => {704 let donor: IKeyringPair;705 let alice: IKeyringPair;706707 before(async function() {708 await usingEthPlaygrounds(async (helper, privateKey) => {709 donor = await privateKey({filename: __filename});710 [alice] = await helper.arrange.createAccounts([20n], donor);711 });712 });713714 itEth('Returns collection name', async ({helper}) => {715 const caller = await helper.eth.createAccountWithBalance(donor);716 const tokenPropertyPermissions = [{717 key: 'URI',718 permission: {719 mutable: true,720 collectionAdmin: true,721 tokenOwner: false,722 },723 }];724 const collection = await helper.nft.mintCollection(725 alice,726 {727 name: 'oh River',728 tokenPrefix: 'CHANGE',729 properties: [{key: 'ERC721Metadata', value: '1'}],730 tokenPropertyPermissions,731 },732 );733734 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);735 const name = await contract.methods.name().call();736 expect(name).to.equal('oh River');737 });738739 itEth('Returns symbol name', async ({helper}) => {740 const caller = await helper.eth.createAccountWithBalance(donor);741 const tokenPropertyPermissions = [{742 key: 'URI',743 permission: {744 mutable: true,745 collectionAdmin: true,746 tokenOwner: false,747 },748 }];749 const collection = await helper.nft.mintCollection(750 alice,751 {752 name: 'oh River',753 tokenPrefix: 'CHANGE',754 properties: [{key: 'ERC721Metadata', value: '1'}],755 tokenPropertyPermissions,756 },757 );758759 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);760 const symbol = await contract.methods.symbol().call();761 expect(symbol).to.equal('CHANGE');762 });763});tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -363,56 +363,71 @@
});
itEth('Can perform transferCross()', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
+
const collection = await helper.rft.mintCollection(minter, {});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
- const {tokenId} = await collection.mintToken(minter, 1n, {Ethereum: caller});
+ const token = await collection.mintToken(minter, 50n, {Ethereum: sender});
{
- const result = await contract.methods.transferCross(to, tokenId).send({from: caller});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal(caller);
- expect(event.returnValues.to).to.equal(receiver);
- expect(event.returnValues.tokenId).to.equal(tokenId.toString());
- }
-
- {
- const balance = await contract.methods.balanceOf(caller).call();
- expect(+balance).to.equal(0);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
+ expect(event.returnValues.from).to.equal(sender);
+ expect(event.returnValues.to).to.equal(receiverEth);
+ expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());
+ // Sender's balance decreased:
+ const senderBalance = await collectionEvm.methods.balanceOf(sender).call();
+ expect(+senderBalance).to.equal(0);
+ expect(await token.getBalance({Ethereum: sender})).to.eq(0n);
+ // Receiver's balance increased:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(1);
+ expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);
}
{
- const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});
-
-
+ // Can transferCross to substrate address:
+ const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});
+ // Check events:
const event = substrateResult.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(receiverEth);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));
- expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
+ expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);
+ // Sender's balance decreased:
+ const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+senderBalance).to.equal(0);
+ expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);
+ // Receiver's balance increased:
+ const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
+ expect(receiverBalance).to.contain(token.tokenId);
+ expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);
}
+ });
+
+ itEth.skip('Cannot transferCross with invalid params', async ({helper}) => {
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const tokenOwner = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(0);
- }
+ const collection = await helper.rft.mintCollection(minter, {});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);
- {
- const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
- expect(balance).to.be.contain(tokenId);
- }
+ await collection.mintToken(minter, 50n, {Ethereum: sender});
+ const notSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});
+ // Cannot transferCross someone else's token:
+ await expect(collectionEvm.methods.transferCross(receiverCrossSub, notSendersToken.tokenId).send({from: sender})).to.be.rejected;
+ // FIXME: (transaction successful): Cannot transfer token if it does not exist:
+ await expect(collectionEvm.methods.transferCross(receiverCrossSub, 999999).send({from: sender})).to.be.rejected;
});
itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -186,11 +186,12 @@
return await this.helper.callRpc('api.rpc.eth.call', [{from: signer, to: contractAddress, data: abi}]);
}
- async createCollecion(functionName: string, signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
+ async createCollecion(functionName: 'createNFTCollection' | 'createRFTCollection' | 'createFTCollection', signer: string, name: string, description: string, tokenPrefix: string, decimals?: number): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
- const result = await collectionHelper.methods[functionName](name, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
+ const functionParams = functionName === 'createFTCollection' ? [name, decimals, description, tokenPrefix] : [name, description, tokenPrefix];
+ const result = await collectionHelper.methods[functionName](...functionParams).send({value: Number(collectionCreationPrice)});
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
@@ -217,17 +218,8 @@
return this.createCollecion('createRFTCollection', signer, name, description, tokenPrefix);
}
- async createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
- const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
- const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
-
- const result = await collectionHelper.methods.createFTCollection(name, decimals, description, tokenPrefix).send({value: Number(collectionCreationPrice)});
- const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
- const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
-
- const events = this.helper.eth.normalizeEvents(result.events);
-
- return {collectionId, collectionAddress, events};
+ createFungibleCollection(signer: string, name: string, decimals: number, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[]}> {
+ return this.createCollecion('createFTCollection', signer, name, description, tokenPrefix, decimals);
}
async createERC721MetadataCompatibleRFTCollection(signer: string, name: string, description: string, tokenPrefix: string, baseUri: string): Promise<{collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {