difftreelog
Mint tests generalization
in: master
8 files changed
tests/src/eth/collections/callMethodsERC20.test.tsdiffbeforeafterboth--- a/tests/src/eth/collections/callMethodsERC20.test.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {Pallets, requirePalletsOrSkip} from '../../util';
-import {expect, itEth, usingEthPlaygrounds} from '../util';
-import {IKeyringPair} from '@polkadot/types/types';
-
-[
- {mode: 'ft' as const, requiredPallets: []},
- {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
-].map(testCase => {
- describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, testCase.requiredPallets);
- donor = await privateKey({filename: __filename});
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
-
- const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
- if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
-
- // Use collection contract for FT or token contract for RFT:
- const contract = testCase.mode === 'ft'
- ? collection
- : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
-
- // Mint tokens:
- testCase.mode === 'ft'
- ? await contract.methods.mint(...mintingParams).send({from: caller})
- : await contract.methods.repartition(200).send({from: caller});
-
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('200');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
-
- const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
- if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
-
- // Use collection contract for FT or token contract for RFT:
- const contract = testCase.mode === 'ft'
- ? collection
- : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
-
- // Mint tokens:
- testCase.mode === 'ft'
- ? await contract.methods.mint(...mintingParams).send({from: caller})
- : await contract.methods.repartition(200).send({from: caller});
-
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('200');
- });
-
- itEth('decimals', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
- if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
-
- // Use collection contract for FT or token contract for RFT:
- const contract = testCase.mode === 'ft'
- ? collection
- : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
-
- const decimals = await contract.methods.decimals().call();
- expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');
- });
- });
-});
\ No newline at end of file
tests/src/eth/collections/callMethodsERC721.test.tsdiffbeforeafterboth--- a/tests/src/eth/collections/callMethodsERC721.test.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {Pallets, requirePalletsOrSkip} from '../../util';
-import {expect, itEth, usingEthPlaygrounds} from '../util';
-import {IKeyringPair} from '@polkadot/types/types';
-
-[
- {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
- {mode: 'nft' as const, requiredPallets: []},
-].map(testCase => {
- describe(`${testCase.mode.toUpperCase()}: ERC-721 call methods`, () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, testCase.requiredPallets);
-
- donor = await privateKey({filename: __filename});
- });
- });
-
- itEth('name/symbol/description', async ({helper}) => {
- const callerEth = await helper.eth.createAccountWithBalance(donor);
- const [callerSub] = await helper.arrange.createAccounts([100n], donor);
- const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];
-
- const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);
- await collectionEth.methods.mint(callerEth).send({from: callerEth});
- const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});
- const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);
-
- // Can get name/symbol/description for Eth collection
- expect(await collectionEth.methods.name().call()).to.eq(name);
- expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);
- expect(await collectionEth.methods.description().call()).to.eq(description);
- // Can get name/symbol/description for Sub collection
- expect(await collectionSub.methods.name().call()).to.eq(name);
- expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);
- expect(await collectionSub.methods.description().call()).to.eq(description);
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
- await collection.methods.mint(caller).send({from: caller});
-
- const totalSupply = await collection.methods.totalSupply().call();
- expect(totalSupply).to.equal('1');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
- await collection.methods.mint(caller).send({from: caller});
- await collection.methods.mint(caller).send({from: caller});
- await collection.methods.mint(caller).send({from: caller});
-
- const balance = await collection.methods.balanceOf(caller).call();
- expect(balance).to.equal('3');
- });
-
- itEth('ownerOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');
-
- const result = await collection.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
-
- const owner = await collection.methods.ownerOf(tokenId).call();
- expect(owner).to.equal(caller);
- });
-
- // TODO move to rft tests:
- // itEth('ownerOf after burn', async ({helper}) => {
- // const caller = await helper.eth.createAccountWithBalance(donor);
- // const receiver = helper.eth.createAccount();
- // const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');
- // const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- // const result = await contract.methods.mint(caller).send();
- // const tokenId = result.events.Transfer.returnValues.tokenId;
- // const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
-
- // await tokenContract.methods.repartition(2).send();
- // await tokenContract.methods.transfer(receiver, 1).send();
-
- // await tokenContract.methods.burnFrom(caller, 1).send();
-
- // const owner = await contract.methods.ownerOf(tokenId).call();
- // expect(owner).to.equal(receiver);
- // });
-
- // TODO move to rft tests:
- // itEth('ownerOf for partial ownership', async ({helper}) => {
- // const caller = await helper.eth.createAccountWithBalance(donor);
- // const receiver = helper.eth.createAccount();
- // const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
- // const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- // const result = await contract.methods.mint(caller).send();
- // const tokenId = result.events.Transfer.returnValues.tokenId;
- // const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
-
- // await tokenContract.methods.repartition(2).send();
- // await tokenContract.methods.transfer(receiver, 1).send();
-
- // const owner = await contract.methods.ownerOf(tokenId).call();
- // expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
- // });
- });
-});
tests/src/eth/fungible.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 {expect, itEth, usingEthPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';1920describe('Fungible: Plain calls', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;23 let owner: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (helper, privateKey) => {27 donor = await privateKey({filename: __filename});28 [alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);29 });30 });3132 itEth('Can perform mint()', async ({helper}) => {33 const owner = await helper.eth.createAccountWithBalance(donor);34 const receiver = helper.eth.createAccount();35 const collection = await helper.ft.mintCollection(alice);36 await collection.addAdmin(alice, {Ethereum: owner});3738 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);39 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);4041 const result = await contract.methods.mint(receiver, 100).send();4243 const event = result.events.Transfer;44 expect(event.address).to.equal(collectionAddress);45 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');46 expect(event.returnValues.to).to.equal(receiver);47 expect(event.returnValues.value).to.equal('100');48 });4950 [51 'substrate' as const,52 'ethereum' as const,53 ].map(testCase => {54 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {55 // 1. Create receiver depending on the test case:56 const receiverEth = helper.eth.createAccount();57 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);58 const receiverSub = owner;59 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(owner);6061 const ethOwner = await helper.eth.createAccountWithBalance(donor);62 const collection = await helper.ft.mintCollection(alice);63 await collection.addAdmin(alice, {Ethereum: ethOwner});6465 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);66 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', ethOwner);6768 // 2. Mint tokens:69 const result = await collectionEvm.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, 100).send();7071 const event = result.events.Transfer;72 expect(event.address).to.equal(collectionAddress);73 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');74 expect(event.returnValues.to).to.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(receiverSub.address));75 expect(event.returnValues.value).to.equal('100');7677 // 3. Get balance depending on the test case:78 let balance;79 if (testCase === 'ethereum') balance = await collection.getBalance({Ethereum: receiverEth});80 else if (testCase === 'substrate') balance = await collection.getBalance({Substrate: receiverSub.address});81 // 3.1 Check balance:82 expect(balance).to.eq(100n);83 });84 });8586 itEth('Can perform mintBulk()', async ({helper}) => {87 const owner = await helper.eth.createAccountWithBalance(donor);88 const bulkSize = 3;89 const receivers = [...new Array(bulkSize)].map(() => helper.eth.createAccount());90 const collection = await helper.ft.mintCollection(alice);91 await collection.addAdmin(alice, {Ethereum: owner});9293 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);94 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);9596 const result = await contract.methods.mintBulk(Array.from({length: bulkSize}, (_, i) => (97 [receivers[i], (i + 1) * 10]98 ))).send();99 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.value - b.returnValues.value);100 for (let i = 0; i < bulkSize; i++) {101 const event = events[i];102 expect(event.address).to.equal(collectionAddress);103 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');104 expect(event.returnValues.to).to.equal(receivers[i]);105 expect(event.returnValues.value).to.equal(String(10 * (i + 1)));106 }107 });108109 // Soft-deprecated110 itEth('Can perform burn()', async ({helper}) => {111 const owner = await helper.eth.createAccountWithBalance(donor);112 const receiver = await helper.eth.createAccountWithBalance(donor);113 const collection = await helper.ft.mintCollection(alice);114 await collection.addAdmin(alice, {Ethereum: owner});115116 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);117 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner, true);118 await contract.methods.mint(receiver, 100).send();119120 const result = await contract.methods.burnFrom(receiver, 49).send({from: receiver});121122 const event = result.events.Transfer;123 expect(event.address).to.equal(collectionAddress);124 expect(event.returnValues.from).to.equal(receiver);125 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');126 expect(event.returnValues.value).to.equal('49');127128 const balance = await contract.methods.balanceOf(receiver).call();129 expect(balance).to.equal('51');130 });131132 itEth('Can perform approve()', async ({helper}) => {133 const owner = await helper.eth.createAccountWithBalance(donor);134 const spender = helper.eth.createAccount();135 const collection = await helper.ft.mintCollection(alice);136 await collection.mint(alice, 200n, {Ethereum: owner});137138 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);139 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);140141 {142 const result = await contract.methods.approve(spender, 100).send({from: owner});143144 const event = result.events.Approval;145 expect(event.address).to.be.equal(collectionAddress);146 expect(event.returnValues.owner).to.be.equal(owner);147 expect(event.returnValues.spender).to.be.equal(spender);148 expect(event.returnValues.value).to.be.equal('100');149 }150151 {152 const allowance = await contract.methods.allowance(owner, spender).call();153 expect(+allowance).to.equal(100);154 }155 });156157 itEth('Can perform approveCross()', async ({helper}) => {158 const owner = await helper.eth.createAccountWithBalance(donor);159 const spender = helper.eth.createAccount();160 const spenderSub = (await helper.arrange.createAccounts([1n], donor))[0];161 const spenderCrossEth = helper.ethCrossAccount.fromAddress(spender);162 const spenderCrossSub = helper.ethCrossAccount.fromKeyringPair(spenderSub);163164165 const collection = await helper.ft.mintCollection(alice);166 await collection.mint(alice, 200n, {Ethereum: owner});167168 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);169 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);170171 {172 const result = await contract.methods.approveCross(spenderCrossEth, 100).send({from: owner});173 const event = result.events.Approval;174 expect(event.address).to.be.equal(collectionAddress);175 expect(event.returnValues.owner).to.be.equal(owner);176 expect(event.returnValues.spender).to.be.equal(spender);177 expect(event.returnValues.value).to.be.equal('100');178 }179180 {181 const allowance = await contract.methods.allowance(owner, spender).call();182 expect(+allowance).to.equal(100);183 }184185186 {187 const result = await contract.methods.approveCross(spenderCrossSub, 100).send({from: owner});188 const event = result.events.Approval;189 expect(event.address).to.be.equal(collectionAddress);190 expect(event.returnValues.owner).to.be.equal(owner);191 expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(spenderSub.address));192 expect(event.returnValues.value).to.be.equal('100');193 }194195 {196 const allowance = await collection.getApprovedTokens({Ethereum: owner}, {Substrate: spenderSub.address});197 expect(allowance).to.equal(100n);198 }199200 {201 //TO-DO expect with future allowanceCross(owner, spenderCrossEth).call()202 }203 });204205 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {206 const nonOwner = await helper.eth.createAccountWithBalance(donor);207 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);208 const owner = await helper.eth.createAccountWithBalance(donor);209 const collection = await helper.ft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});210 await collection.mint(alice, 100n, {Ethereum: owner});211212 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);213 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);214215 await expect(collectionEvm.methods.approveCross(nonOwnerCross, 20).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');216 });217218219 itEth('Can perform burnFromCross()', async ({helper}) => {220 const sender = await helper.eth.createAccountWithBalance(donor, 100n);221222 const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);223224 await collection.mint(owner, 200n, {Substrate: owner.address});225 await collection.approveTokens(owner, {Ethereum: sender}, 100n);226227 const address = helper.ethAddress.fromCollectionId(collection.collectionId);228 const contract = await helper.ethNativeContract.collection(address, 'ft');229230 const fromBalanceBefore = await collection.getBalance({Substrate: owner.address});231232 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);233 const result = await contract.methods.burnFromCross(ownerCross, 49).send({from: sender});234 const events = result.events;235236 expect(events).to.be.like({237 Transfer: {238 address: helper.ethAddress.fromCollectionId(collection.collectionId),239 event: 'Transfer',240 returnValues: {241 from: helper.address.substrateToEth(owner.address),242 to: '0x0000000000000000000000000000000000000000',243 value: '49',244 },245 },246 Approval: {247 address: helper.ethAddress.fromCollectionId(collection.collectionId),248 returnValues: {249 owner: helper.address.substrateToEth(owner.address),250 spender: sender,251 value: '51',252 },253 event: 'Approval',254 },255 });256257 const fromBalanceAfter = await collection.getBalance({Substrate: owner.address});258 expect(fromBalanceBefore - fromBalanceAfter).to.be.eq(49n);259 });260261 itEth('Can perform transferFrom()', async ({helper}) => {262 const owner = await helper.eth.createAccountWithBalance(donor);263 const spender = await helper.eth.createAccountWithBalance(donor);264 const receiver = helper.eth.createAccount();265 const collection = await helper.ft.mintCollection(alice);266 await collection.mint(alice, 200n, {Ethereum: owner});267268 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);269 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);270271 await contract.methods.approve(spender, 100).send();272273 {274 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});275276 let event = result.events.Transfer;277 expect(event.address).to.be.equal(collectionAddress);278 expect(event.returnValues.from).to.be.equal(owner);279 expect(event.returnValues.to).to.be.equal(receiver);280 expect(event.returnValues.value).to.be.equal('49');281282 event = result.events.Approval;283 expect(event.address).to.be.equal(collectionAddress);284 expect(event.returnValues.owner).to.be.equal(owner);285 expect(event.returnValues.spender).to.be.equal(spender);286 expect(event.returnValues.value).to.be.equal('51');287 }288289 {290 const balance = await contract.methods.balanceOf(receiver).call();291 expect(+balance).to.equal(49);292 }293294 {295 const balance = await contract.methods.balanceOf(owner).call();296 expect(+balance).to.equal(151);297 }298 });299300 itEth('Can perform transferCross()', async ({helper}) => {301 const sender = await helper.eth.createAccountWithBalance(donor);302 const receiverEth = await helper.eth.createAccountWithBalance(donor);303 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);304 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);305 const collection = await helper.ft.mintCollection(alice);306 await collection.mint(alice, 200n, {Ethereum: sender});307308 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);309 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', sender);310311 {312 // Can transferCross to ethereum address:313 const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});314 // Check events:315 const event = result.events.Transfer;316 expect(event.address).to.be.equal(collectionAddress);317 expect(event.returnValues.from).to.be.equal(sender);318 expect(event.returnValues.to).to.be.equal(receiverEth);319 expect(event.returnValues.value).to.be.equal('50');320 // Sender's balance decreased:321 const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();322 expect(+ownerBalance).to.equal(150);323 // Receiver's balance increased:324 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();325 expect(+receiverBalance).to.equal(50);326 }327328 {329 // Can transferCross to substrate address:330 const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});331 // Check events:332 const event = result.events.Transfer;333 expect(event.address).to.be.equal(collectionAddress);334 expect(event.returnValues.from).to.be.equal(sender);335 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));336 expect(event.returnValues.value).to.be.equal('50');337 // Sender's balance decreased:338 const senderBalance = await collection.getBalance({Ethereum: sender});339 expect(senderBalance).to.equal(100n);340 // Receiver's balance increased:341 const balance = await collection.getBalance({Substrate: donor.address});342 expect(balance).to.equal(50n);343 }344 });345346 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} incorrect amount`, async ({helper}) => {347 const sender = await helper.eth.createAccountWithBalance(donor);348 const receiverEth = await helper.eth.createAccountWithBalance(donor);349 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);350 const BALANCE = 200n;351 const BALANCE_TO_TRANSFER = BALANCE + 100n;352353 const collection = await helper.ft.mintCollection(alice);354 await collection.mint(alice, BALANCE, {Ethereum: sender});355 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);356 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', sender);357358 // 1. Cannot transfer more than have359 const receiver = testCase === 'transfer' ? receiverEth : receiverCrossEth;360 await expect(collectionEvm.methods[testCase](receiver, BALANCE_TO_TRANSFER).send({from: sender})).to.be.rejected;361 // 2. Zero transfer allowed (EIP-20):362 await collectionEvm.methods[testCase](receiver, 0n).send({from: sender});363 }));364365366 itEth('Can perform transfer()', async ({helper}) => {367 const owner = await helper.eth.createAccountWithBalance(donor);368 const receiver = await helper.eth.createAccountWithBalance(donor);369 const collection = await helper.ft.mintCollection(alice);370 await collection.mint(alice, 200n, {Ethereum: owner});371372 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);373 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);374375 {376 const result = await contract.methods.transfer(receiver, 50).send({from: owner});377378 const event = result.events.Transfer;379 expect(event.address).to.be.equal(collectionAddress);380 expect(event.returnValues.from).to.be.equal(owner);381 expect(event.returnValues.to).to.be.equal(receiver);382 expect(event.returnValues.value).to.be.equal('50');383 }384385 {386 const balance = await contract.methods.balanceOf(owner).call();387 expect(+balance).to.equal(150);388 }389390 {391 const balance = await contract.methods.balanceOf(receiver).call();392 expect(+balance).to.equal(50);393 }394 });395396 itEth('Can perform transferFromCross()', async ({helper}) => {397 const sender = await helper.eth.createAccountWithBalance(donor, 100n);398399 const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);400401 const receiver = helper.eth.createAccount();402403 await collection.mint(owner, 200n, {Substrate: owner.address});404 await collection.approveTokens(owner, {Ethereum: sender}, 100n);405406 const address = helper.ethAddress.fromCollectionId(collection.collectionId);407 const contract = await helper.ethNativeContract.collection(address, 'ft');408409 const from = helper.ethCrossAccount.fromKeyringPair(owner);410 const to = helper.ethCrossAccount.fromAddress(receiver);411412 const fromBalanceBefore = await collection.getBalance({Substrate: owner.address});413 const toBalanceBefore = await collection.getBalance({Ethereum: receiver});414415 const result = await contract.methods.transferFromCross(from, to, 51).send({from: sender});416417 expect(result.events).to.be.like({418 Transfer: {419 address,420 event: 'Transfer',421 returnValues: {422 from: helper.address.substrateToEth(owner.address),423 to: receiver,424 value: '51',425 },426 },427 Approval: {428 address,429 event: 'Approval',430 returnValues: {431 owner: helper.address.substrateToEth(owner.address),432 spender: sender,433 value: '49',434 },435 }});436437 const fromBalanceAfter = await collection.getBalance({Substrate: owner.address});438 expect(fromBalanceBefore - fromBalanceAfter).to.be.eq(51n);439 const toBalanceAfter = await collection.getBalance({Ethereum: receiver});440 expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);441 });442});443444describe('Fungible: Fees', () => {445 let donor: IKeyringPair;446 let alice: IKeyringPair;447448 before(async function() {449 await usingEthPlaygrounds(async (helper, privateKey) => {450 donor = await privateKey({filename: __filename});451 [alice] = await helper.arrange.createAccounts([20n], donor);452 });453 });454455 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {456 const owner = await helper.eth.createAccountWithBalance(donor);457 const spender = helper.eth.createAccount();458 const collection = await helper.ft.mintCollection(alice);459 await collection.mint(alice, 200n, {Ethereum: owner});460461 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);462 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);463464 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));465 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));466 });467468 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {469 const owner = await helper.eth.createAccountWithBalance(donor);470 const spender = await helper.eth.createAccountWithBalance(donor);471 const collection = await helper.ft.mintCollection(alice);472 await collection.mint(alice, 200n, {Ethereum: owner});473474 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);475 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);476477 await contract.methods.approve(spender, 100).send({from: owner});478479 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));480 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));481 });482483 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {484 const owner = await helper.eth.createAccountWithBalance(donor);485 const receiver = helper.eth.createAccount();486 const collection = await helper.ft.mintCollection(alice);487 await collection.mint(alice, 200n, {Ethereum: owner});488489 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);490 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);491492 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));493 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));494 });495});496497describe('Fungible: Substrate calls', () => {498 let donor: IKeyringPair;499 let alice: IKeyringPair;500 let owner: IKeyringPair;501502 before(async function() {503 await usingEthPlaygrounds(async (helper, privateKey) => {504 donor = await privateKey({filename: __filename});505 [alice, owner] = await helper.arrange.createAccounts([20n, 20n], donor);506 });507 });508509 itEth('Events emitted for approve()', async ({helper}) => {510 const receiver = helper.eth.createAccount();511 const collection = await helper.ft.mintCollection(alice);512 await collection.mint(alice, 200n);513514 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);515 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft');516517 const events: any = [];518 contract.events.allEvents((_: any, event: any) => {519 events.push(event);520 });521522 await collection.approveTokens(alice, {Ethereum: receiver}, 100n);523 if (events.length == 0) await helper.wait.newBlocks(1);524 const event = events[0];525526 expect(event.event).to.be.equal('Approval');527 expect(event.address).to.be.equal(collectionAddress);528 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));529 expect(event.returnValues.spender).to.be.equal(receiver);530 expect(event.returnValues.value).to.be.equal('100');531 });532533 itEth('Events emitted for transferFrom()', async ({helper}) => {534 const [bob] = await helper.arrange.createAccounts([10n], donor);535 const receiver = helper.eth.createAccount();536 const collection = await helper.ft.mintCollection(alice);537 await collection.mint(alice, 200n);538 await collection.approveTokens(alice, {Substrate: bob.address}, 100n);539540 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);541 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft');542543 const events: any = [];544 contract.events.allEvents((_: any, event: any) => {545 events.push(event);546 });547548 await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);549 if (events.length == 0) await helper.wait.newBlocks(1);550 let event = events[0];551552 expect(event.event).to.be.equal('Transfer');553 expect(event.address).to.be.equal(collectionAddress);554 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));555 expect(event.returnValues.to).to.be.equal(receiver);556 expect(event.returnValues.value).to.be.equal('51');557558 event = events[1];559 expect(event.event).to.be.equal('Approval');560 expect(event.address).to.be.equal(collectionAddress);561 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));562 expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));563 expect(event.returnValues.value).to.be.equal('49');564 });565566 itEth('Events emitted for transfer()', async ({helper}) => {567 const receiver = helper.eth.createAccount();568 const collection = await helper.ft.mintCollection(alice);569 await collection.mint(alice, 200n);570571 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);572 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft');573574 const events: any = [];575 contract.events.allEvents((_: any, event: any) => {576 events.push(event);577 });578579 await collection.transfer(alice, {Ethereum:receiver}, 51n);580 if (events.length == 0) await helper.wait.newBlocks(1);581 const event = events[0];582583 expect(event.event).to.be.equal('Transfer');584 expect(event.address).to.be.equal(collectionAddress);585 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));586 expect(event.returnValues.to).to.be.equal(receiver);587 expect(event.returnValues.value).to.be.equal('51');588 });589590 itEth('Events emitted for transferFromCross()', async ({helper}) => {591 const sender = await helper.eth.createAccountWithBalance(donor, 100n);592593 const collection = await helper.ft.mintCollection(owner, {name: 'A', description: 'B', tokenPrefix: 'C'}, 0);594595 const receiver = helper.eth.createAccount();596597 await collection.mint(owner, 200n, {Substrate: owner.address});598 await collection.approveTokens(owner, {Ethereum: sender}, 100n);599600 const address = helper.ethAddress.fromCollectionId(collection.collectionId);601 const contract = await helper.ethNativeContract.collection(address, 'ft');602603 const from = helper.ethCrossAccount.fromKeyringPair(owner);604 const to = helper.ethCrossAccount.fromAddress(receiver);605606 const result = await contract.methods.transferFromCross(from, to, 51).send({from: sender});607608 expect(result.events).to.be.like({609 Transfer: {610 address,611 event: 'Transfer',612 returnValues: {613 from: helper.address.substrateToEth(owner.address),614 to: receiver,615 value: '51',616 },617 },618 Approval: {619 address,620 event: 'Approval',621 returnValues: {622 owner: helper.address.substrateToEth(owner.address),623 spender: sender,624 value: '49',625 },626 }});627 });628});tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -88,30 +88,6 @@
});
});
- itEth('Can perform mint() & get crossOwner()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
-
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
-
- const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal('1');
-
- const event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(receiver);
-
- expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
- // TODO: this wont work right now, need release 919000 first
- // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
- // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
- // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
- });
-
// TODO combine all minting tests in one place
[
'substrate' as const,
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -34,25 +34,6 @@
});
});
- itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-
- const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(receiver);
- const tokenId = event.returnValues.tokenId;
- expect(tokenId).to.be.equal('1');
-
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
- expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
- });
-
[
'substrate' as const,
'ethereum' as const,
tests/src/eth/tokens/callMethodsERC20.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC20.test.ts
@@ -0,0 +1,91 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {Pallets, requirePalletsOrSkip} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+[
+ {mode: 'ft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+].map(testCase => {
+ describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, testCase.requiredPallets);
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ itEth('totalSupply', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ // Mint tokens:
+ testCase.mode === 'ft'
+ ? await contract.methods.mint(...mintingParams).send({from: caller})
+ : await contract.methods.repartition(200).send({from: caller});
+
+ const totalSupply = await contract.methods.totalSupply().call();
+ expect(totalSupply).to.equal('200');
+ });
+
+ itEth('balanceOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ // Mint tokens:
+ testCase.mode === 'ft'
+ ? await contract.methods.mint(...mintingParams).send({from: caller})
+ : await contract.methods.repartition(200).send({from: caller});
+
+ const balance = await contract.methods.balanceOf(caller).call();
+ expect(balance).to.equal('200');
+ });
+
+ itEth('decimals', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ const decimals = await contract.methods.decimals().call();
+ expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');
+ });
+ });
+});
\ No newline at end of file
tests/src/eth/tokens/callMethodsERC721.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC721.test.ts
@@ -0,0 +1,143 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+
+describe('ERC-721 call methods', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: name/symbol/description`, testCase.requiredPallets, async ({helper}) => {
+ const callerEth = await helper.eth.createAccountWithBalance(donor);
+ const [callerSub] = await helper.arrange.createAccounts([100n], donor);
+ const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];
+
+ const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);
+ await collectionEth.methods.mint(callerEth).send({from: callerEth});
+ const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});
+ const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);
+
+ // Can get name/symbol/description for Eth collection
+ expect(await collectionEth.methods.name().call()).to.eq(name);
+ expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);
+ expect(await collectionEth.methods.description().call()).to.eq(description);
+ // Can get name/symbol/description for Sub collection
+ expect(await collectionSub.methods.name().call()).to.eq(name);
+ expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);
+ expect(await collectionSub.methods.description().call()).to.eq(description);
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: totalSupply`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+ await collection.methods.mint(caller).send({from: caller});
+
+ const totalSupply = await collection.methods.totalSupply().call();
+ expect(totalSupply).to.equal('1');
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: balanceOf`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ await collection.methods.mint(caller).send({from: caller});
+ await collection.methods.mint(caller).send({from: caller});
+ await collection.methods.mint(caller).send({from: caller});
+
+ const balance = await collection.methods.balanceOf(caller).call();
+ expect(balance).to.equal('3');
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');
+
+ const result = await collection.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const owner = await collection.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal(caller);
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ // TODO {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth(`${testCase.mode.toUpperCase()}: ownerOf after burn`, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf-AfterBurn', '6', '6');
+
+ const result = await collection.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
+
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ await tokenContract.methods.burnFrom(caller, 1).send();
+
+ const owner = await collection.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal(receiver);
+ });
+ });
+
+ itEth('RFT: ownerOf for partial ownership', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+
+ const result = await contract.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
+
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ const owner = await contract.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ });
+});
tests/src/eth/tokens/minting.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/minting.test.ts
@@ -0,0 +1,167 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+
+
+describe('Minting tokens', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([30n, 20n], donor);
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const collection = await helper[testCase.mode].mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ const result = await contract.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);
+ expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+ const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+ expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+ const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+ expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase => {
+ itEth(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
+ const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(receiver);
+
+ expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
+ expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ // TODO: this wont work right now, need release 919000 first
+ // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
+ // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
+ // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
+ });
+ });
+});
\ No newline at end of file