git.delta.rocks / unique-network / refs/commits / 9f4fc065e116

difftreelog

source

tests/src/eth/tokens/callMethodsERC721.test.ts6.6 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';202122describe('ERC-721 call methods', () => {23  let donor: IKeyringPair;2425  before(async function() {26    await usingEthPlaygrounds(async (helper, privateKey) => {27      donor = await privateKey({filename: __filename});28    });29  });3031  [32    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},33    {mode: 'nft' as const, requiredPallets: []},34  ].map(testCase => {35    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: name/symbol/description`, testCase.requiredPallets, async ({helper}) => {36      const callerEth = await helper.eth.createAccountWithBalance(donor);37      const [callerSub] = await helper.arrange.createAccounts([100n], donor);38      const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];3940      const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);41      await collectionEth.methods.mint(callerEth).send({from: callerEth});42      const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});43      const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);4445      // Can get name/symbol/description for Eth collection46      expect(await collectionEth.methods.name().call()).to.eq(name);47      expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);48      expect(await collectionEth.methods.description().call()).to.eq(description);49      // Can get name/symbol/description for Sub collection50      expect(await collectionSub.methods.name().call()).to.eq(name);51      expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);52      expect(await collectionSub.methods.description().call()).to.eq(description);53    });54  });5556  [57    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},58    {mode: 'nft' as const, requiredPallets: []},59  ].map(testCase => {60    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: totalSupply`, testCase.requiredPallets, async ({helper}) => {61      const caller = await helper.eth.createAccountWithBalance(donor);6263      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');64      await collection.methods.mint(caller).send({from: caller});6566      const totalSupply = await collection.methods.totalSupply().call();67      expect(totalSupply).to.equal('1');68    });69  });7071  [72    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},73    {mode: 'nft' as const, requiredPallets: []},74  ].map(testCase => {75    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: balanceOf`, testCase.requiredPallets, async ({helper}) => {76      const caller = await helper.eth.createAccountWithBalance(donor);7778      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');79      await collection.methods.mint(caller).send({from: caller});80      await collection.methods.mint(caller).send({from: caller});81      await collection.methods.mint(caller).send({from: caller});8283      const balance = await collection.methods.balanceOf(caller).call();84      expect(balance).to.equal('3');85    });86  });8788  [89    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},90    {mode: 'nft' as const, requiredPallets: []},91  ].map(testCase => {92    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf`, testCase.requiredPallets, async ({helper}) => {93      const caller = await helper.eth.createAccountWithBalance(donor);94      const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');9596      const result = await collection.methods.mint(caller).send();97      const tokenId = result.events.Transfer.returnValues.tokenId;9899      const owner = await collection.methods.ownerOf(tokenId).call();100      expect(owner).to.equal(caller);101    });102  });103104  [105    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},106    // TODO {mode: 'nft' as const, requiredPallets: []},107  ].map(testCase => {108    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf after burn`, testCase.requiredPallets, async ({helper}) => {109      const caller = await helper.eth.createAccountWithBalance(donor);110      const receiver = helper.eth.createAccount();111      const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf-AfterBurn', '6', '6');112113      const result = await collection.methods.mint(caller).send();114      const tokenId = result.events.Transfer.returnValues.tokenId;115      const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);116117      await tokenContract.methods.repartition(2).send();118      await tokenContract.methods.transfer(receiver, 1).send();119120      await tokenContract.methods.burnFrom(caller, 1).send();121122      const owner = await collection.methods.ownerOf(tokenId).call();123      expect(owner).to.equal(receiver);124    });125  });126127  itEth.ifWithPallets('RFT: ownerOf for partial ownership', [Pallets.ReFungible], async ({helper}) => {128    const caller = await helper.eth.createAccountWithBalance(donor);129    const receiver = helper.eth.createAccount();130    const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');131    const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);132133    const result = await contract.methods.mint(caller).send();134    const tokenId = result.events.Transfer.returnValues.tokenId;135    const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);136137    await tokenContract.methods.repartition(2).send();138    await tokenContract.methods.transfer(receiver, 1).send();139140    const owner = await contract.methods.ownerOf(tokenId).call();141    expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');142  });143});