1234567891011121314151617import type {IKeyringPair} from '@polkadot/types/types';18import {Pallets} from '@unique/test-utils/util.js';19import {expect, itEth, usingEthPlaygrounds} from '@unique/test-utils/eth/util.js';20import {CreateCollectionData} from '@unique/test-utils/eth/types.js';212223describe('Minting tokens', () => {24 let donor: IKeyringPair;25 let alice: IKeyringPair;2627 before(async function() {28 await usingEthPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({url: import.meta.url});30 [alice] = await helper.arrange.createAccounts([30n, 20n], donor);31 });32 });3334 [35 {mode: 'nft' as const, requiredPallets: []},36 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},37 {mode: 'ft' as const, requiredPallets: []},38 ].map(testCase => {39 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {40 const owner = await helper.eth.createAccountWithBalance(donor);41 const receiver = helper.eth.createAccount();42 const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];4344 const collection = await helper[testCase.mode].mintCollection(alice);45 await collection.addAdmin(alice, {Ethereum: owner});4647 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);48 const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);4950 const result = await contract.methods.mint(...mintingParams).send({from: owner});5152 53 const event = result.events.Transfer;54 expect(event.address).to.equal(collectionAddress);55 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');56 expect(event.returnValues.to).to.equal(receiver);57 if(testCase.mode === 'ft')58 expect(event.returnValues.value).to.equal('100');5960 61 if(testCase.mode === 'ft') {62 expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);63 } else {64 const tokenId = event.returnValues.tokenId;65 expect(tokenId).to.be.equal('1');66 expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);67 expect(await contract.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);68 }69 });70 });7172 [73 {mode: 'nft' as const, requiredPallets: []},74 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},75 {mode: 'ft' as const, requiredPallets: []},76 ].map(testCase => {77 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {78 const owner = await helper.eth.createAccountWithBalance(donor);79 const receiver = helper.eth.createAccount();80 const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];8182 const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(owner, new CreateCollectionData('Name', 'Desc', 'Prefix', testCase.mode)).send();8384 const result = await collection.methods.mint(...mintingParams).send({from: owner});8586 87 const event = result.events.Transfer;88 expect(event.address).to.equal(collectionAddress);89 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');90 expect(event.returnValues.to).to.equal(receiver);91 if(testCase.mode === 'ft')92 expect(event.returnValues.value).to.equal('100');9394 95 if(testCase.mode === 'ft') {96 expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);97 } else {98 const tokenId = event.returnValues.tokenId;99 expect(tokenId).to.be.equal('1');100 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);101 expect(await collection.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);102 }103 });104 });105106 [107 {mode: 'nft' as const, requiredPallets: []},108 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},109 {mode: 'ft' as const, requiredPallets: []},110 ].map(testCase => {111 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {112 const owner = await helper.eth.createAccountWithBalance(donor);113 const receiver = helper.eth.createAccount();114 const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];115116 const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(owner, new CreateCollectionData('Name', 'Desc', 'Prefix', testCase.mode)).send();117118 const result = await collection.methods.mint(...mintingParams).send({from: owner});119120 121 const event = result.events.Transfer;122 expect(event.address).to.equal(collectionAddress);123 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');124 expect(event.returnValues.to).to.equal(receiver);125 if(testCase.mode === 'ft')126 expect(event.returnValues.value).to.equal('100');127128 129 if(testCase.mode === 'ft') {130 expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);131 } else {132 const tokenId = event.returnValues.tokenId;133 expect(tokenId).to.be.equal('1');134 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);135 expect(await collection.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);136 }137 });138 });139140 [141 {mode: 'nft' as const, requiredPallets: []},142 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},143 ].map(testCase => {144 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {145 const owner = await helper.eth.createAccountWithBalance(donor);146 const receiver = helper.eth.createAccount();147148 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');149 const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);150151 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();152 const tokenId = result.events.Transfer.returnValues.tokenId;153 expect(tokenId).to.be.equal('1');154155 const event = result.events.Transfer;156 expect(event.address).to.be.equal(collectionAddress);157 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');158 expect(event.returnValues.to).to.be.equal(receiver);159160 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');161 expect(await contract.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);162 163 164 165 166 });167 });168});