1234567891011121314151617import {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 46 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 50 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 107 ].map(testCase => {108 itEth(`${testCase.mode.toUpperCase()}: ownerOf after burn`, 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('RFT: ownerOf for partial ownership', 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});