1234567891011121314151617import {Pallets, requirePalletsOrSkip} from '../../util';18import {expect, itEth, usingEthPlaygrounds} from '../util';19import {IKeyringPair} from '@polkadot/types/types';2021[22 {mode: 'ft' as const, requiredPallets: []},23 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},24].map(testCase => {25 describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {26 let donor: IKeyringPair;2728 before(async function() {29 await usingEthPlaygrounds(async (helper, privateKey) => {30 requirePalletsOrSkip(this, helper, testCase.requiredPallets);31 donor = await privateKey({url: import.meta.url});32 });33 });3435 itEth('totalSupply', async ({helper}) => {36 const caller = await helper.eth.createAccountWithBalance(donor);37 const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];3839 const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');40 if(testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});4142 43 const contract = testCase.mode === 'ft'44 ? collection45 : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);4647 48 testCase.mode === 'ft'49 ? await contract.methods.mint(...mintingParams).send({from: caller})50 : await contract.methods.repartition(200).send({from: caller});5152 const totalSupply = await contract.methods.totalSupply().call();53 expect(totalSupply).to.equal('200');54 });5556 itEth('balanceOf', async ({helper}) => {57 const caller = await helper.eth.createAccountWithBalance(donor);58 const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];5960 const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');61 if(testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});6263 64 const contract = testCase.mode === 'ft'65 ? collection66 : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);6768 69 testCase.mode === 'ft'70 ? await contract.methods.mint(...mintingParams).send({from: caller})71 : await contract.methods.repartition(200).send({from: caller});7273 const balance = await contract.methods.balanceOf(caller).call();74 expect(balance).to.equal('200');75 });7677 itEth('decimals', async ({helper}) => {78 const caller = await helper.eth.createAccountWithBalance(donor);79 const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');80 if(testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});8182 83 const contract = testCase.mode === 'ft'84 ? collection85 : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);8687 const decimals = await contract.methods.decimals().call();88 expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');89 });90 });91});