git.delta.rocks / unique-network / refs/commits / d8a93a39e482

difftreelog

source

tests/src/eth/tokens/callMethodsERC20.test.ts3.9 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 '../../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({filename: __filename});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      // Use collection contract for FT or token contract for RFT:43      const contract = testCase.mode === 'ft'44        ? collection45        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);4647      // Mint tokens: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      // Use collection contract for FT or token contract for RFT:64      const contract = testCase.mode === 'ft'65        ? collection66        : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);6768      // Mint tokens: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      // Use collection contract for FT or token contract for RFT: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});