1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {Pallets} from '../../util';19import {expect, itEth, usingEthPlaygrounds} from '../util';202122describe('Minting tokens', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({url: import.meta.url});29 [alice] = await helper.arrange.createAccounts([30n, 20n], donor);30 });31 });3233 [34 {mode: 'nft' as const, requiredPallets: []},35 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},36 {mode: 'ft' as const, requiredPallets: []},37 ].map(testCase => {38 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {39 const owner = await helper.eth.createAccountWithBalance(donor);40 const receiver = helper.eth.createAccount();41 const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];4243 const collection = await helper[testCase.mode].mintCollection(alice);44 await collection.addAdmin(alice, {Ethereum: owner});4546 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);47 const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);4849 const result = await contract.methods.mint(...mintingParams).send({from: owner});5051 52 const event = result.events.Transfer;53 expect(event.address).to.equal(collectionAddress);54 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');55 expect(event.returnValues.to).to.equal(receiver);56 if (testCase.mode === 'ft')57 expect(event.returnValues.value).to.equal('100');5859 60 if(testCase.mode === 'ft') {61 expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);62 } else {63 const tokenId = event.returnValues.tokenId;64 expect(tokenId).to.be.equal('1');65 expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);66 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);67 }68 });69 });7071 [72 {mode: 'nft' as const, requiredPallets: []},73 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},74 {mode: 'ft' as const, requiredPallets: []},75 ].map(testCase => {76 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {77 const owner = await helper.eth.createAccountWithBalance(donor);78 const receiver = helper.eth.createAccount();79 const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];8081 const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');8283 const result = await collection.methods.mint(...mintingParams).send({from: owner});8485 86 const event = result.events.Transfer;87 expect(event.address).to.equal(collectionAddress);88 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');89 expect(event.returnValues.to).to.equal(receiver);90 if (testCase.mode === 'ft')91 expect(event.returnValues.value).to.equal('100');9293 94 if(testCase.mode === 'ft') {95 expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);96 } else {97 const tokenId = event.returnValues.tokenId;98 expect(tokenId).to.be.equal('1');99 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);100 expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);101 }102 });103 });104105 [106 {mode: 'nft' as const, requiredPallets: []},107 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},108 {mode: 'ft' as const, requiredPallets: []},109 ].map(testCase => {110 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {111 const owner = await helper.eth.createAccountWithBalance(donor);112 const receiver = helper.eth.createAccount();113 const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];114115 const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');116117 const result = await collection.methods.mint(...mintingParams).send({from: owner});118119 120 const event = result.events.Transfer;121 expect(event.address).to.equal(collectionAddress);122 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');123 expect(event.returnValues.to).to.equal(receiver);124 if (testCase.mode === 'ft')125 expect(event.returnValues.value).to.equal('100');126127 128 if(testCase.mode === 'ft') {129 expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);130 } else {131 const tokenId = event.returnValues.tokenId;132 expect(tokenId).to.be.equal('1');133 expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);134 expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);135 }136 });137 });138139 [140 {mode: 'nft' as const, requiredPallets: []},141 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},142 ].map(testCase => {143 itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {144 const owner = await helper.eth.createAccountWithBalance(donor);145 const receiver = helper.eth.createAccount();146147 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');148 const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);149150 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();151 const tokenId = result.events.Transfer.returnValues.tokenId;152 expect(tokenId).to.be.equal('1');153154 const event = result.events.Transfer;155 expect(event.address).to.be.equal(collectionAddress);156 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');157 expect(event.returnValues.to).to.be.equal(receiver);158159 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');160 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);161 162 163 164 165 });166 });167});