git.delta.rocks / unique-network / refs/commits / 1d2d3c81f701

difftreelog

source

tests/src/eth/tokens/callMethodsERC721.test.ts6.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} from '../../util';18import {expect, itEth, usingEthPlaygrounds} from '../util';19import {IKeyringPair} from '@polkadot/types/types';20import {CreateCollectionData} from '../util/playgrounds/types';212223describe('ERC-721 call methods', () => {24  let donor: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({url: import.meta.url});29    });30  });3132  [33    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},34    {mode: 'nft' as const, requiredPallets: []},35  ].map(testCase => {36    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: name/symbol/description`, testCase.requiredPallets, 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(callerEth, new CreateCollectionData(name, description, tokenPrefix, testCase.mode)).send();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    });55  });5657  [58    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},59    {mode: 'nft' as const, requiredPallets: []},60  ].map(testCase => {61    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: totalSupply`, testCase.requiredPallets, async ({helper}) => {62      const caller = await helper.eth.createAccountWithBalance(donor);6364      const {collection} = await helper.eth.createCollection(caller, new CreateCollectionData('TotalSupply', '6', '6', testCase.mode)).send();65      await collection.methods.mint(caller).send({from: caller});6667      const totalSupply = await collection.methods.totalSupply().call();68      expect(totalSupply).to.equal('1');69    });70  });7172  [73    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},74    {mode: 'nft' as const, requiredPallets: []},75  ].map(testCase => {76    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: balanceOf`, testCase.requiredPallets, async ({helper}) => {77      const caller = await helper.eth.createAccountWithBalance(donor);7879      const {collection} = await helper.eth.createCollection(caller, new CreateCollectionData('BalanceOf', 'Descroption', 'Prefix', testCase.mode)).send();80      await collection.methods.mint(caller).send({from: caller});81      await collection.methods.mint(caller).send({from: caller});82      await collection.methods.mint(caller).send({from: caller});8384      const balance = await collection.methods.balanceOf(caller).call();85      expect(balance).to.equal('3');86    });87  });8889  [90    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},91    {mode: 'nft' as const, requiredPallets: []},92  ].map(testCase => {93    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf`, testCase.requiredPallets, async ({helper}) => {94      const caller = await helper.eth.createAccountWithBalance(donor);95      const {collection} = await helper.eth.createCollection(caller, new CreateCollectionData('OwnerOf', '6', '6', testCase.mode)).send();9697      const result = await collection.methods.mint(caller).send();98      const tokenId = result.events.Transfer.returnValues.tokenId;99100      const owner = await collection.methods.ownerOf(tokenId).call();101      expect(owner).to.equal(caller);102    });103  });104105  [106    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},107    // TODO {mode: 'nft' as const, requiredPallets: []},108  ].map(testCase => {109    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf after burn`, testCase.requiredPallets, async ({helper}) => {110      const caller = await helper.eth.createAccountWithBalance(donor);111      const receiver = helper.eth.createAccount();112      const {collection, collectionId} = await helper.eth.createCollection(caller, new CreateCollectionData('OwnerOf-AfterBurn', '6', '6', testCase.mode)).send();113114      const result = await collection.methods.mint(caller).send();115      const tokenId = result.events.Transfer.returnValues.tokenId;116      const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);117118      await tokenContract.methods.repartition(2).send();119      await tokenContract.methods.transfer(receiver, 1).send();120121      await tokenContract.methods.burnFrom(caller, 1).send();122123      const owner = await collection.methods.ownerOf(tokenId).call();124      expect(owner).to.equal(receiver);125    });126  });127128  itEth.ifWithPallets('RFT: ownerOf for partial ownership', [Pallets.ReFungible], async ({helper}) => {129    const caller = await helper.eth.createAccountWithBalance(donor);130    const receiver = helper.eth.createAccount();131    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');132    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);133134    const result = await contract.methods.mint(caller).send();135    const tokenId = result.events.Transfer.returnValues.tokenId;136    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);137138    await tokenContract.methods.repartition(2).send();139    await tokenContract.methods.transfer(receiver, 1).send();140141    const owner = await contract.methods.ownerOf(tokenId).call();142    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');143  });144});