git.delta.rocks / unique-network / refs/commits / 8a76dd7aa345

difftreelog

source

tests/src/eth/collections/callMethodsERC721.test.ts6.0 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: 'rft' as const, requiredPallets: [Pallets.ReFungible]},23  {mode: 'nft' as const, requiredPallets: []},24].map(testCase => {25  describe(`${testCase.mode.toUpperCase()}: ERC-721 call methods`, () => {26    let donor: IKeyringPair;2728    before(async function() {29      await usingEthPlaygrounds(async (helper, privateKey) => {30        requirePalletsOrSkip(this, helper, testCase.requiredPallets);3132        donor = await privateKey({filename: __filename});33      });34    });3536    itEth('name/symbol/description', async ({helper}) => {37      const callerEth = await helper.eth.createAccountWithBalance(donor);38      const [callerSub] = await helper.arrange.createAccounts([100n], donor);39      const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];4041      const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);42      await collectionEth.methods.mint(callerEth).send({from: callerEth});43      const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});44      const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);4546      // Can get name/symbol/description for Eth collection47      expect(await collectionEth.methods.name().call()).to.eq(name);48      expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);49      expect(await collectionEth.methods.description().call()).to.eq(description);50      // Can get name/symbol/description for Sub collection51      expect(await collectionSub.methods.name().call()).to.eq(name);52      expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);53      expect(await collectionSub.methods.description().call()).to.eq(description);54    });5556    itEth('totalSupply', async ({helper}) => {57      const caller = await helper.eth.createAccountWithBalance(donor);5859      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');60      await collection.methods.mint(caller).send({from: caller});6162      const totalSupply = await collection.methods.totalSupply().call();63      expect(totalSupply).to.equal('1');64    });6566    itEth('balanceOf', async ({helper}) => {67      const caller = await helper.eth.createAccountWithBalance(donor);6869      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');70      await collection.methods.mint(caller).send({from: caller});71      await collection.methods.mint(caller).send({from: caller});72      await collection.methods.mint(caller).send({from: caller});7374      const balance = await collection.methods.balanceOf(caller).call();75      expect(balance).to.equal('3');76    });7778    itEth('ownerOf', async ({helper}) => {79      const caller = await helper.eth.createAccountWithBalance(donor);80      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');8182      const result = await collection.methods.mint(caller).send();83      const tokenId = result.events.Transfer.returnValues.tokenId;8485      const owner = await collection.methods.ownerOf(tokenId).call();86      expect(owner).to.equal(caller);87    });8889    // TODO move to rft tests:90    // itEth('ownerOf after burn', async ({helper}) => {91    //   const caller = await helper.eth.createAccountWithBalance(donor);92    //   const receiver = helper.eth.createAccount();93    //   const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');94    //   const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9596    //   const result = await contract.methods.mint(caller).send();97    //   const tokenId = result.events.Transfer.returnValues.tokenId;98    //   const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);99100    //   await tokenContract.methods.repartition(2).send();101    //   await tokenContract.methods.transfer(receiver, 1).send();102103    //   await tokenContract.methods.burnFrom(caller, 1).send();104105    //   const owner = await contract.methods.ownerOf(tokenId).call();106    //   expect(owner).to.equal(receiver);107    // });108109    // TODO move to rft tests:110    // itEth('ownerOf for partial ownership', async ({helper}) => {111    //   const caller = await helper.eth.createAccountWithBalance(donor);112    //   const receiver = helper.eth.createAccount();113    //   const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');114    //   const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);115116    //   const result = await contract.methods.mint(caller).send();117    //   const tokenId = result.events.Transfer.returnValues.tokenId;118    //   const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);119120    //   await tokenContract.methods.repartition(2).send();121    //   await tokenContract.methods.transfer(receiver, 1).send();122123    //   const owner = await contract.methods.ownerOf(tokenId).call();124    //   expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');125    // });126  });127});