1234567891011121314151617import {Pallets, requirePalletsOrSkip} from '../util';18import {expect, itEth, usingEthPlaygrounds} from './util';19import {IKeyringPair} from '@polkadot/types/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Refungible: Plain calls', () => {23 let donor: IKeyringPair;24 let minter: IKeyringPair;25 let bob: IKeyringPair;26 let charlie: IKeyringPair;2728 before(async function() {29 await usingEthPlaygrounds(async (helper, privateKey) => {30 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3132 donor = await privateKey({filename: __filename});33 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);34 });35 });3637 [38 'substrate' as const,39 'ethereum' as const,40 ].map(testCase => {41 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {42 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);4344 const receiverEth = helper.eth.createAccount();45 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);46 const receiverSub = bob;47 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);4849 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });50 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {51 tokenOwner: false,52 collectionAdmin: true,53 mutable: false}};54 });555657 const collection = await helper.rft.mintCollection(minter, {58 tokenPrefix: 'ethp',59 tokenPropertyPermissions: permissions,60 });61 await collection.addAdmin(minter, {Ethereum: collectionAdmin});6263 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);64 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', collectionAdmin, true);65 let expectedTokenId = await contract.methods.nextTokenId().call();66 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();67 let tokenId = result.events.Transfer.returnValues.tokenId;68 expect(tokenId).to.be.equal(expectedTokenId);6970 let event = result.events.Transfer;71 expect(event.address).to.be.equal(collectionAddress);72 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');73 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));74 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);7576 expectedTokenId = await contract.methods.nextTokenId().call();77 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();78 event = result.events.Transfer;79 expect(event.address).to.be.equal(collectionAddress);80 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');81 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));82 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);8384 tokenId = result.events.Transfer.returnValues.tokenId;8586 expect(tokenId).to.be.equal(expectedTokenId);8788 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties89 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));9091 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))92 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});93 });94 });9596 itEth.skip('Can perform mintBulk()', async ({helper}) => {97 const owner = await helper.eth.createAccountWithBalance(donor);98 const receiver = helper.eth.createAccount();99 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');100 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);101102 {103 const nextTokenId = await contract.methods.nextTokenId().call();104 expect(nextTokenId).to.be.equal('1');105 const result = await contract.methods.mintBulkWithTokenURI(106 receiver,107 [108 [nextTokenId, 'Test URI 0'],109 [+nextTokenId + 1, 'Test URI 1'],110 [+nextTokenId + 2, 'Test URI 2'],111 ],112 ).send();113114 const events = result.events.Transfer;115 for (let i = 0; i < 2; i++) {116 const event = events[i];117 expect(event.address).to.equal(collectionAddress);118 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');119 expect(event.returnValues.to).to.equal(receiver);120 expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));121 }122123 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');124 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');125 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');126 }127 });128129 itEth('Can perform setApprovalForAll()', async ({helper}) => {130 const owner = await helper.eth.createAccountWithBalance(donor);131 const operator = helper.eth.createAccount();132133 const collection = await helper.rft.mintCollection(minter, {});134135 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);136 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);137138 const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();139 expect(approvedBefore).to.be.equal(false);140141 {142 const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});143144 expect(result.events.ApprovalForAll).to.be.like({145 address: collectionAddress,146 event: 'ApprovalForAll',147 returnValues: {148 owner,149 operator,150 approved: true,151 },152 });153154 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();155 expect(approvedAfter).to.be.equal(true);156 }157158 {159 const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});160161 expect(result.events.ApprovalForAll).to.be.like({162 address: collectionAddress,163 event: 'ApprovalForAll',164 returnValues: {165 owner,166 operator,167 approved: false,168 },169 });170171 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();172 expect(approvedAfter).to.be.equal(false);173 }174 });175176 itEth('Can perform burn with ApprovalForAll', async ({helper}) => {177 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});178179 const owner = await helper.eth.createAccountWithBalance(donor);180 const operator = await helper.eth.createAccountWithBalance(donor, 100n);181182 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});183184 const address = helper.ethAddress.fromCollectionId(collection.collectionId);185 const contract = await helper.ethNativeContract.collection(address, 'rft');186187 {188 await contract.methods.setApprovalForAll(operator, true).send({from: owner});189 const ownerCross = helper.ethCrossAccount.fromAddress(owner);190 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});191 const events = result.events.Transfer;192193 expect(events).to.be.like({194 address,195 event: 'Transfer',196 returnValues: {197 from: owner,198 to: '0x0000000000000000000000000000000000000000',199 tokenId: token.tokenId.toString(),200 },201 });202 }203 });204205 itEth('Can perform burn with approve and approvalForAll', async ({helper}) => {206 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});207208 const owner = await helper.eth.createAccountWithBalance(donor);209 const operator = await helper.eth.createAccountWithBalance(donor, 100n);210211 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});212213 const address = helper.ethAddress.fromCollectionId(collection.collectionId);214 const contract = await helper.ethNativeContract.collection(address, 'rft');215216 const rftToken = await helper.ethNativeContract.rftTokenById(token.collectionId, token.tokenId, owner, true);217218 {219 await rftToken.methods.approve(operator, 15n).send({from: owner});220 await contract.methods.setApprovalForAll(operator, true).send({from: owner});221 await rftToken.methods.burnFrom(owner, 10n).send({from: operator});222 const allowance = await rftToken.methods.allowance(owner, operator).call();223 expect(allowance).to.be.equal('5');224 }225 });226227 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {228 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});229230 const owner = await helper.eth.createAccountWithBalance(donor);231 const operator = await helper.eth.createAccountWithBalance(donor);232 const receiver = charlie;233234 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});235236 const address = helper.ethAddress.fromCollectionId(collection.collectionId);237 const contract = await helper.ethNativeContract.collection(address, 'rft');238239 {240 await contract.methods.setApprovalForAll(operator, true).send({from: owner});241 const ownerCross = helper.ethCrossAccount.fromAddress(owner);242 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);243 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});244 const event = result.events.Transfer;245 expect(event).to.be.like({246 address: helper.ethAddress.fromCollectionId(collection.collectionId),247 event: 'Transfer',248 returnValues: {249 from: owner,250 to: helper.address.substrateToEth(receiver.address),251 tokenId: token.tokenId.toString(),252 },253 });254 }255256 expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);257 });258259 itEth('Can perform burn()', async ({helper}) => {260 const caller = await helper.eth.createAccountWithBalance(donor);261 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');262 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);263264 const result = await contract.methods.mint(caller).send();265 const tokenId = result.events.Transfer.returnValues.tokenId;266 {267 const result = await contract.methods.burn(tokenId).send();268 const event = result.events.Transfer;269 expect(event.address).to.equal(collectionAddress);270 expect(event.returnValues.from).to.equal(caller);271 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');272 expect(event.returnValues.tokenId).to.equal(tokenId.toString());273 }274 });275276 itEth('Can perform transferFrom()', async ({helper}) => {277 const caller = await helper.eth.createAccountWithBalance(donor);278 const receiver = helper.eth.createAccount();279 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');280 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);281282 const result = await contract.methods.mint(caller).send();283 const tokenId = result.events.Transfer.returnValues.tokenId;284285 const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);286287 const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, caller);288 await tokenContract.methods.repartition(15).send();289290 {291 const tokenEvents: any = [];292 tokenContract.events.allEvents((_: any, event: any) => {293 tokenEvents.push(event);294 });295 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();296 if (tokenEvents.length == 0) await helper.wait.newBlocks(1);297298 let event = result.events.Transfer;299 expect(event.address).to.equal(collectionAddress);300 expect(event.returnValues.from).to.equal(caller);301 expect(event.returnValues.to).to.equal(receiver);302 expect(event.returnValues.tokenId).to.equal(tokenId.toString());303304 event = tokenEvents[0];305 expect(event.address).to.equal(tokenAddress);306 expect(event.returnValues.from).to.equal(caller);307 expect(event.returnValues.to).to.equal(receiver);308 expect(event.returnValues.value).to.equal('15');309 }310311 {312 const balance = await contract.methods.balanceOf(receiver).call();313 expect(+balance).to.equal(1);314 }315316 {317 const balance = await contract.methods.balanceOf(caller).call();318 expect(+balance).to.equal(0);319 }320 });321322 323 itEth('Can perform burnFrom()', async ({helper}) => {324 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});325326 const owner = await helper.eth.createAccountWithBalance(donor, 100n);327 const spender = await helper.eth.createAccountWithBalance(donor, 100n);328329 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});330331 const address = helper.ethAddress.fromCollectionId(collection.collectionId);332 const contract = await helper.ethNativeContract.collection(address, 'rft', spender, true);333334 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);335 const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner);336 await tokenContract.methods.repartition(15).send();337 await tokenContract.methods.approve(spender, 15).send();338339 {340 const result = await contract.methods.burnFrom(owner, token.tokenId).send();341 const event = result.events.Transfer;342 expect(event).to.be.like({343 address: helper.ethAddress.fromCollectionId(collection.collectionId),344 event: 'Transfer',345 returnValues: {346 from: owner,347 to: '0x0000000000000000000000000000000000000000',348 tokenId: token.tokenId.toString(),349 },350 });351 }352353 expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);354 });355356 itEth('Can perform burnFromCross()', async ({helper}) => {357 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});358359 const owner = bob;360 const spender = await helper.eth.createAccountWithBalance(donor, 100n);361362 const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});363364 const address = helper.ethAddress.fromCollectionId(collection.collectionId);365 const contract = await helper.ethNativeContract.collection(address, 'rft');366367 await token.repartition(owner, 15n);368 await token.approve(owner, {Ethereum: spender}, 15n);369370 {371 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);372 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});373 const event = result.events.Transfer;374 expect(event).to.be.like({375 address: helper.ethAddress.fromCollectionId(collection.collectionId),376 event: 'Transfer',377 returnValues: {378 from: helper.address.substrateToEth(owner.address),379 to: '0x0000000000000000000000000000000000000000',380 tokenId: token.tokenId.toString(),381 },382 });383 }384385 expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);386 });387388 itEth('Can perform transferFromCross()', async ({helper}) => {389 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});390391 const owner = bob;392 const spender = await helper.eth.createAccountWithBalance(donor, 100n);393 const receiver = charlie;394395 const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});396397 const address = helper.ethAddress.fromCollectionId(collection.collectionId);398 const contract = await helper.ethNativeContract.collection(address, 'rft');399400 await token.repartition(owner, 15n);401 await token.approve(owner, {Ethereum: spender}, 15n);402403 {404 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);405 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);406 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});407 const event = result.events.Transfer;408 expect(event).to.be.like({409 address: helper.ethAddress.fromCollectionId(collection.collectionId),410 event: 'Transfer',411 returnValues: {412 from: helper.address.substrateToEth(owner.address),413 to: helper.address.substrateToEth(receiver.address),414 tokenId: token.tokenId.toString(),415 },416 });417 }418419 expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);420 });421422 itEth('Can perform transfer()', async ({helper}) => {423 const caller = await helper.eth.createAccountWithBalance(donor);424 const receiver = helper.eth.createAccount();425 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');426 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);427428 const result = await contract.methods.mint(caller).send();429 const tokenId = result.events.Transfer.returnValues.tokenId;430431 {432 const result = await contract.methods.transfer(receiver, tokenId).send();433434 const event = result.events.Transfer;435 expect(event.address).to.equal(collectionAddress);436 expect(event.returnValues.from).to.equal(caller);437 expect(event.returnValues.to).to.equal(receiver);438 expect(event.returnValues.tokenId).to.equal(tokenId.toString());439 }440441 {442 const balance = await contract.methods.balanceOf(caller).call();443 expect(+balance).to.equal(0);444 }445446 {447 const balance = await contract.methods.balanceOf(receiver).call();448 expect(+balance).to.equal(1);449 }450 });451452 itEth('Can perform transferCross()', async ({helper}) => {453 const sender = await helper.eth.createAccountWithBalance(donor);454 const receiverEth = await helper.eth.createAccountWithBalance(donor);455 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);456 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);457458 const collection = await helper.rft.mintCollection(minter, {});459 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);460 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);461462 const token = await collection.mintToken(minter, 50n, {Ethereum: sender});463464 {465 466 const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});467 468 const event = result.events.Transfer;469 expect(event.address).to.equal(collectionAddress);470 expect(event.returnValues.from).to.equal(sender);471 expect(event.returnValues.to).to.equal(receiverEth);472 expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());473 474 const senderBalance = await collectionEvm.methods.balanceOf(sender).call();475 expect(+senderBalance).to.equal(0);476 expect(await token.getBalance({Ethereum: sender})).to.eq(0n);477 478 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();479 expect(+receiverBalance).to.equal(1);480 expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);481 }482483 {484 485 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});486 487 const event = substrateResult.events.Transfer;488 expect(event.address).to.be.equal(collectionAddress);489 expect(event.returnValues.from).to.be.equal(receiverEth);490 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));491 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);492 493 const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();494 expect(+senderBalance).to.equal(0);495 expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);496 497 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});498 expect(receiverBalance).to.contain(token.tokenId);499 expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);500 }501 });502503 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {504 const sender = await helper.eth.createAccountWithBalance(donor);505 const tokenOwner = await helper.eth.createAccountWithBalance(donor);506 const receiverSub = minter;507 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);508509 const collection = await helper.rft.mintCollection(minter, {});510 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);511 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'rft', sender);512513 await collection.mintToken(minter, 50n, {Ethereum: sender});514 const nonSendersToken = await collection.mintToken(minter, 50n, {Ethereum: tokenOwner});515516 517 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;518 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;519 520 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;521 }));522523 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {524 const caller = await helper.eth.createAccountWithBalance(donor);525 const receiver = helper.eth.createAccount();526 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');527 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);528529 const result = await contract.methods.mint(caller).send();530 const tokenId = result.events.Transfer.returnValues.tokenId;531532 const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);533534 await tokenContract.methods.repartition(2).send();535 await tokenContract.methods.transfer(receiver, 1).send();536537 const events: any = [];538 contract.events.allEvents((_: any, event: any) => {539 events.push(event);540 });541542 await tokenContract.methods.transfer(receiver, 1).send();543 if (events.length == 0) await helper.wait.newBlocks(1);544 const event = events[0];545546 expect(event.address).to.equal(collectionAddress);547 expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');548 expect(event.returnValues.to).to.equal(receiver);549 expect(event.returnValues.tokenId).to.equal(tokenId.toString());550 });551552 itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {553 const caller = await helper.eth.createAccountWithBalance(donor);554 const receiver = helper.eth.createAccount();555 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');556 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);557558 const result = await contract.methods.mint(caller).send();559 const tokenId = result.events.Transfer.returnValues.tokenId;560561 const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);562563 await tokenContract.methods.repartition(2).send();564565 const events: any = [];566 contract.events.allEvents((_: any, event: any) => {567 events.push(event);568 });569570 await tokenContract.methods.transfer(receiver, 1).send();571 if (events.length == 0) await helper.wait.newBlocks(1);572 const event = events[0];573574 expect(event.address).to.equal(collectionAddress);575 expect(event.returnValues.from).to.equal(caller);576 expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');577 expect(event.returnValues.tokenId).to.equal(tokenId.toString());578 });579});580581describe('RFT: Fees', () => {582 let donor: IKeyringPair;583584 before(async function() {585 await usingEthPlaygrounds(async (helper, privateKey) => {586 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);587588 donor = await privateKey({filename: __filename});589 });590 });591592 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {593 const caller = await helper.eth.createAccountWithBalance(donor);594 const receiver = helper.eth.createAccount();595 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');596 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);597598 const result = await contract.methods.mint(caller).send();599 const tokenId = result.events.Transfer.returnValues.tokenId;600601 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());602 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));603 expect(cost > 0n);604 });605606 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {607 const caller = await helper.eth.createAccountWithBalance(donor);608 const receiver = helper.eth.createAccount();609 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');610 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);611612 const result = await contract.methods.mint(caller).send();613 const tokenId = result.events.Transfer.returnValues.tokenId;614615 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());616 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));617 expect(cost > 0n);618 });619});620621describe('Common metadata', () => {622 let donor: IKeyringPair;623 let alice: IKeyringPair;624625 before(async function() {626 await usingEthPlaygrounds(async (helper, privateKey) => {627 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);628629 donor = await privateKey({filename: __filename});630 [alice] = await helper.arrange.createAccounts([20n], donor);631 });632 });633634 itEth('Returns collection name', async ({helper}) => {635 const caller = helper.eth.createAccount();636 const tokenPropertyPermissions = [{637 key: 'URI',638 permission: {639 mutable: true,640 collectionAdmin: true,641 tokenOwner: false,642 },643 }];644 const collection = await helper.rft.mintCollection(645 alice,646 {647 name: 'Leviathan',648 tokenPrefix: '11',649 properties: [{key: 'ERC721Metadata', value: '1'}],650 tokenPropertyPermissions,651 },652 );653654 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);655 const name = await contract.methods.name().call();656 expect(name).to.equal('Leviathan');657 });658659 itEth('Returns symbol name', async ({helper}) => {660 const caller = await helper.eth.createAccountWithBalance(donor);661 const tokenPropertyPermissions = [{662 key: 'URI',663 permission: {664 mutable: true,665 collectionAdmin: true,666 tokenOwner: false,667 },668 }];669 const {collectionId} = await helper.rft.mintCollection(670 alice,671 {672 name: 'Leviathan',673 tokenPrefix: '12',674 properties: [{key: 'ERC721Metadata', value: '1'}],675 tokenPropertyPermissions,676 },677 );678679 const contract = await helper.ethNativeContract.collectionById(collectionId, 'rft', caller);680 const symbol = await contract.methods.symbol().call();681 expect(symbol).to.equal('12');682 });683});684685describe('Negative tests', () => {686 let donor: IKeyringPair;687 let minter: IKeyringPair;688 let alice: IKeyringPair;689690 before(async function() {691 await usingEthPlaygrounds(async (helper, privateKey) => {692 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);693694 donor = await privateKey({filename: __filename});695 [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);696 });697 });698699 itEth('[negative] Cant perform burn without approval', async ({helper}) => {700 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});701702 const owner = await helper.eth.createAccountWithBalance(donor, 100n);703 const spender = await helper.eth.createAccountWithBalance(donor, 100n);704705 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});706707 const address = helper.ethAddress.fromCollectionId(collection.collectionId);708 const contract = await helper.ethNativeContract.collection(address, 'rft');709710 const ownerCross = helper.ethCrossAccount.fromAddress(owner);711712 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;713714 await contract.methods.setApprovalForAll(spender, true).send({from: owner});715 await contract.methods.setApprovalForAll(spender, false).send({from: owner});716717 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;718 });719720 itEth('[negative] Cant perform transfer without approval', async ({helper}) => {721 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});722 const owner = await helper.eth.createAccountWithBalance(donor, 100n);723 const receiver = alice;724725 const spender = await helper.eth.createAccountWithBalance(donor, 100n);726727 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});728729 const address = helper.ethAddress.fromCollectionId(collection.collectionId);730 const contract = await helper.ethNativeContract.collection(address, 'rft');731732 const ownerCross = helper.ethCrossAccount.fromAddress(owner);733 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);734735 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;736737 await contract.methods.setApprovalForAll(spender, true).send({from: owner});738 await contract.methods.setApprovalForAll(spender, false).send({from: owner});739740 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;741 });742});