git.delta.rocks / unique-network / refs/commits / 470ffd5ce9b5

difftreelog

source

js-packages/tests/eth/tokens/callMethodsERC20.test.ts4.1 KiBsourcehistory
1// 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 {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      // Use collection contract for FT or token contract for RFT:44      const contract = testCase.mode === 'ft'45        ? collection46        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);4748      // Mint tokens: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      // Use collection contract for FT or token contract for RFT:65      const contract = testCase.mode === 'ft'66        ? collection67        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);6869      // Mint tokens: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      // Use collection contract for FT or token contract for RFT: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});