1234567891011121314151617import {Pallets, requirePalletsOrSkip} from '@unique/test-utils/util.js';18import {expect, itEth, usingEthPlaygrounds} from '@unique/test-utils/eth/util.js';19import type {IKeyringPair} from '@polkadot/types/types';20import {CreateCollectionData} from '@unique/test-utils/eth/types.js';2122[23 {mode: 'ft' as const, requiredPallets: []},24 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},25].map(testCase => {26 describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {27 let donor: IKeyringPair;2829 before(async function() {30 await usingEthPlaygrounds(async (helper, privateKey) => {31 requirePalletsOrSkip(this, helper, testCase.requiredPallets);32 donor = await privateKey({url: import.meta.url});33 });34 });3536 itEth('totalSupply', async ({helper}) => {37 const caller = await helper.eth.createAccountWithBalance(donor);38 const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];3940 const {collection, collectionId} = await helper.eth.createCollection(caller, new CreateCollectionData('TotalSupply', '6', '6', testCase.mode)).send();41 if(testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});4243 44 const contract = testCase.mode === 'ft'45 ? collection46 : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);4748 49 testCase.mode === 'ft'50 ? await contract.methods.mint(...mintingParams).send({from: caller})51 : await contract.methods.repartition(200).send({from: caller});5253 const totalSupply = await contract.methods.totalSupply().call();54 expect(totalSupply).to.equal('200');55 });5657 itEth('balanceOf', async ({helper}) => {58 const caller = await helper.eth.createAccountWithBalance(donor);59 const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];6061 const {collection, collectionId} = await helper.eth.createCollection(caller, new CreateCollectionData('BalanceOf', 'Descroption', 'Prefix', testCase.mode)).send();62 if(testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});6364 65 const contract = testCase.mode === 'ft'66 ? collection67 : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);6869 70 testCase.mode === 'ft'71 ? await contract.methods.mint(...mintingParams).send({from: caller})72 : await contract.methods.repartition(200).send({from: caller});7374 const balance = await contract.methods.balanceOf(caller).call();75 expect(balance).to.equal('200');76 });7778 itEth('decimals', async ({helper}) => {79 const caller = await helper.eth.createAccountWithBalance(donor);80 const {collection, collectionId} = await helper.eth.createCollection(caller, new CreateCollectionData('BalanceOf', 'Descroption', 'Prefix', testCase.mode)).send();81 if(testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});8283 84 const contract = testCase.mode === 'ft'85 ? collection86 : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);8788 const decimals = await contract.methods.decimals().call();89 expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');90 });91 });92});