difftreelog
Add transferCross tests
in: master
3 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -232,56 +232,49 @@
});
itEth('Can perform transferCross()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(donor);
+ const sender = await helper.eth.createAccountWithBalance(donor);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(donor);
const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n, {Ethereum: owner});
+ await collection.mint(alice, 200n, {Ethereum: sender});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', sender);
{
- const result = await contract.methods.transferCross(to, 50).send({from: owner});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, 50).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(owner);
- expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(sender);
+ expect(event.returnValues.to).to.be.equal(receiverEth);
expect(event.returnValues.value).to.be.equal('50');
- }
-
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(150);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(50);
+ // Sender's balance decreased:
+ const ownerBalance = await collectionEvm.methods.balanceOf(sender).call();
+ expect(+ownerBalance).to.equal(150);
+ // Receiver's balance increased:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(50);
}
{
- const result = await contract.methods.transferCross(toSubstrate, 50).send({from: owner});
-
+ // Can transferCross to substrate address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossSub, 50).send({from: sender});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.from).to.be.equal(sender);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(donor.address));
expect(event.returnValues.value).to.be.equal('50');
- }
-
- {
- const balance = await collection.getBalance({Ethereum: owner});
- expect(balance).to.equal(100n);
- }
-
- {
+ // Sender's balance decreased:
+ const senderBalance = await collection.getBalance({Ethereum: sender});
+ expect(senderBalance).to.equal(100n);
+ // Receiver's balance increased:
const balance = await collection.getBalance({Substrate: donor.address});
expect(balance).to.equal(50n);
}
-
});
itEth('Can perform transfer()', async ({helper}) => {
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -252,8 +252,9 @@
itEth('Can perform burnFromCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});
const ownerSub = bob;
- const ownerCross = helper.ethCrossAccount.fromKeyringPair(ownerSub);
+ const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);
const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);
const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);
const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);
@@ -269,20 +270,23 @@
await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});
// can burnFromCross:
- const result1 = await collectionEvm.methods.burnFromCross(ownerCross, token1.tokenId).send({from: burnerEth});
- // FIXME Error No Permission?:
- const result2 = await collectionEvm.methods.burnFromCross(ownerCross, token2.tokenId).send({from: burnerEth});
+ const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});
+ const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});
const events1 = result1.events.Transfer;
const events2 = result2.events.Transfer;
- [[events1, token1], [events2, token2]].map(burnEvents => {
- expect(burnEvents[0]).to.be.like({
+ // Check events for burnFromCross (substrate and ethereum):
+ [
+ [events1, token1, helper.address.substrateToEth(ownerSub.address)],
+ [events2, token2, ownerEth],
+ ].map(burnData => {
+ expect(burnData[0]).to.be.like({
address: collectionAddress,
event: 'Transfer',
returnValues: {
- from: helper.address.substrateToEth(ownerSub.address),
+ from: burnData[2],
to: '0x0000000000000000000000000000000000000000',
- tokenId: burnEvents[1].tokenId.toString(),
+ tokenId: burnData[1].tokenId.toString(),
},
});
});
@@ -341,6 +345,7 @@
itEth('Can reaffirm approved address', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor, 100n);
+ const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);
const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);
const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);
@@ -358,12 +363,9 @@
// receiver2 can transferFrom:
await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});
- // can set approved address to zero address:
+ // can set approved address to self address to remove approval:
await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});
-
- // FIXME how to remove approval?:
- await collectionEvm.methods.approveCross({eth: '0x0000000000000000000000000000000000000000', sub: '0'}, token2.tokenId).call({from: owner});
- await collectionEvm.methods.approve('0x0000000000000000000000000000000000000000', token2.tokenId).call({from: owner});
+ await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});
// receiver1 cannot transfer token anymore:
await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;
@@ -469,54 +471,50 @@
itEth('Can perform transferCross()', async ({helper}) => {
const collection = await helper.nft.mintCollection(minter, {});
const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = await helper.eth.createAccountWithBalance(donor);
- const to = helper.ethCrossAccount.fromAddress(receiver);
- const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);
+ const receiverEth = await helper.eth.createAccountWithBalance(donor);
+ const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);
+ const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);
const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});
const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+ const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
{
- const result = await contract.methods.transferCross(to, tokenId).send({from: owner});
-
+ // Can transferCross to ethereum address:
+ const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});
+ // Check events:
const event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal(owner);
- expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.to).to.be.equal(receiverEth);
expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
- }
-
- {
- const balance = await contract.methods.balanceOf(owner).call();
- expect(+balance).to.equal(0);
+
+ // owner has balance = 0:
+ const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();
+ expect(+ownerBalance).to.equal(0);
+ // receiver owns token:
+ const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+receiverBalance).to.equal(1);
+ expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});
}
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(1);
- }
{
- const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});
-
-
+ // Can transferCross to substrate address:
+ const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});
+ // Check events:
const event = substrateResult.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal(receiver);
+ expect(event.returnValues.from).to.be.equal(receiverEth);
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));
expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);
- }
-
- {
- const balance = await contract.methods.balanceOf(receiver).call();
- expect(+balance).to.equal(0);
- }
-
- {
- const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
- expect(balance).to.be.contain(tokenId);
+
+ // owner has balance = 0:
+ const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();
+ expect(+ownerBalance).to.equal(0);
+ // receiver owns token:
+ const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});
+ expect(receiverBalance).to.contain(tokenId);
}
});
});
tests/src/eth/reFungible.test.tsdiffbeforeafterboth1// 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';2021describe('Refungible: Information getting', () => {22 let donor: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728 donor = await privateKey({filename: __filename});29 });30 });3132 itEth('totalSupply', async ({helper}) => {33 const caller = await helper.eth.createAccountWithBalance(donor);34 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');35 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);3637 await contract.methods.mint(caller).send();3839 const totalSupply = await contract.methods.totalSupply().call();40 expect(totalSupply).to.equal('1');41 });4243 itEth('balanceOf', async ({helper}) => {44 const caller = await helper.eth.createAccountWithBalance(donor);45 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');46 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4748 await contract.methods.mint(caller).send();49 await contract.methods.mint(caller).send();50 await contract.methods.mint(caller).send();5152 const balance = await contract.methods.balanceOf(caller).call();53 expect(balance).to.equal('3');54 });5556 itEth('ownerOf', async ({helper}) => {57 const caller = await helper.eth.createAccountWithBalance(donor);58 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');59 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6061 const result = await contract.methods.mint(caller).send();62 const tokenId = result.events.Transfer.returnValues.tokenId;6364 const owner = await contract.methods.ownerOf(tokenId).call();65 expect(owner).to.equal(caller);66 });6768 itEth('ownerOf after burn', async ({helper}) => {69 const caller = await helper.eth.createAccountWithBalance(donor);70 const receiver = helper.eth.createAccount();71 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');72 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);7374 const result = await contract.methods.mint(caller).send();75 const tokenId = result.events.Transfer.returnValues.tokenId;76 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);7778 await tokenContract.methods.repartition(2).send();79 await tokenContract.methods.transfer(receiver, 1).send();8081 await tokenContract.methods.burnFrom(caller, 1).send();8283 const owner = await contract.methods.ownerOf(tokenId).call();84 expect(owner).to.equal(receiver);85 });8687 itEth('ownerOf for partial ownership', async ({helper}) => {88 const caller = await helper.eth.createAccountWithBalance(donor);89 const receiver = helper.eth.createAccount();90 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');91 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9293 const result = await contract.methods.mint(caller).send();94 const tokenId = result.events.Transfer.returnValues.tokenId;95 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);9697 await tokenContract.methods.repartition(2).send();98 await tokenContract.methods.transfer(receiver, 1).send();99100 const owner = await contract.methods.ownerOf(tokenId).call();101 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');102 });103});104105describe('Refungible: Plain calls', () => {106 let donor: IKeyringPair;107 let minter: IKeyringPair;108 let bob: IKeyringPair;109 let charlie: IKeyringPair;110111 before(async function() {112 await usingEthPlaygrounds(async (helper, privateKey) => {113 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);114115 donor = await privateKey({filename: __filename});116 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);117 });118 });119120 itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {121 const owner = await helper.eth.createAccountWithBalance(donor);122 const receiver = helper.eth.createAccount();123 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');124 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);125126 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();127128 const event = result.events.Transfer;129 expect(event.address).to.equal(collectionAddress);130 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');131 expect(event.returnValues.to).to.equal(receiver);132 const tokenId = event.returnValues.tokenId;133 expect(tokenId).to.be.equal('1');134135 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);136 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');137 });138139 itEth.skip('Can perform mintBulk()', async ({helper}) => {140 const owner = await helper.eth.createAccountWithBalance(donor);141 const receiver = helper.eth.createAccount();142 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');143 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);144145 {146 const nextTokenId = await contract.methods.nextTokenId().call();147 expect(nextTokenId).to.be.equal('1');148 const result = await contract.methods.mintBulkWithTokenURI(149 receiver,150 [151 [nextTokenId, 'Test URI 0'],152 [+nextTokenId + 1, 'Test URI 1'],153 [+nextTokenId + 2, 'Test URI 2'],154 ],155 ).send();156157 const events = result.events.Transfer;158 for (let i = 0; i < 2; i++) {159 const event = events[i];160 expect(event.address).to.equal(collectionAddress);161 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');162 expect(event.returnValues.to).to.equal(receiver);163 expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));164 }165166 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');167 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');168 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');169 }170 });171172 itEth('Can perform burn()', async ({helper}) => {173 const caller = await helper.eth.createAccountWithBalance(donor);174 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');175 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);176177 const result = await contract.methods.mint(caller).send();178 const tokenId = result.events.Transfer.returnValues.tokenId;179 {180 const result = await contract.methods.burn(tokenId).send();181 const event = result.events.Transfer;182 expect(event.address).to.equal(collectionAddress);183 expect(event.returnValues.from).to.equal(caller);184 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');185 expect(event.returnValues.tokenId).to.equal(tokenId.toString());186 }187 });188189 itEth('Can perform transferFrom()', async ({helper}) => {190 const caller = await helper.eth.createAccountWithBalance(donor);191 const receiver = helper.eth.createAccount();192 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');193 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);194195 const result = await contract.methods.mint(caller).send();196 const tokenId = result.events.Transfer.returnValues.tokenId;197198 const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);199200 const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);201 await tokenContract.methods.repartition(15).send();202203 {204 const tokenEvents: any = [];205 tokenContract.events.allEvents((_: any, event: any) => {206 tokenEvents.push(event);207 });208 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();209 if (tokenEvents.length == 0) await helper.wait.newBlocks(1);210211 let event = result.events.Transfer;212 expect(event.address).to.equal(collectionAddress);213 expect(event.returnValues.from).to.equal(caller);214 expect(event.returnValues.to).to.equal(receiver);215 expect(event.returnValues.tokenId).to.equal(tokenId.toString());216217 event = tokenEvents[0];218 expect(event.address).to.equal(tokenAddress);219 expect(event.returnValues.from).to.equal(caller);220 expect(event.returnValues.to).to.equal(receiver);221 expect(event.returnValues.value).to.equal('15');222 }223224 {225 const balance = await contract.methods.balanceOf(receiver).call();226 expect(+balance).to.equal(1);227 }228229 {230 const balance = await contract.methods.balanceOf(caller).call();231 expect(+balance).to.equal(0);232 }233 });234235 // Soft-deprecated236 itEth('Can perform burnFrom()', async ({helper}) => {237 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});238239 const owner = await helper.eth.createAccountWithBalance(donor, 100n);240 const spender = await helper.eth.createAccountWithBalance(donor, 100n);241242 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});243244 const address = helper.ethAddress.fromCollectionId(collection.collectionId);245 const contract = helper.ethNativeContract.collection(address, 'rft', spender, true);246247 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);248 const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);249 await tokenContract.methods.repartition(15).send();250 await tokenContract.methods.approve(spender, 15).send();251252 {253 const result = await contract.methods.burnFrom(owner, token.tokenId).send();254 const event = result.events.Transfer;255 expect(event).to.be.like({256 address: helper.ethAddress.fromCollectionId(collection.collectionId),257 event: 'Transfer',258 returnValues: {259 from: owner,260 to: '0x0000000000000000000000000000000000000000',261 tokenId: token.tokenId.toString(),262 },263 });264 }265266 expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);267 });268269 itEth('Can perform burnFromCross()', async ({helper}) => {270 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});271 272 const owner = bob;273 const spender = await helper.eth.createAccountWithBalance(donor, 100n);274275 const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});276277 const address = helper.ethAddress.fromCollectionId(collection.collectionId);278 const contract = helper.ethNativeContract.collection(address, 'rft');279280 await token.repartition(owner, 15n);281 await token.approve(owner, {Ethereum: spender}, 15n);282283 {284 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);285 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});286 const event = result.events.Transfer;287 expect(event).to.be.like({288 address: helper.ethAddress.fromCollectionId(collection.collectionId),289 event: 'Transfer',290 returnValues: {291 from: helper.address.substrateToEth(owner.address),292 to: '0x0000000000000000000000000000000000000000',293 tokenId: token.tokenId.toString(),294 },295 });296 }297298 expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);299 });300301 itEth('Can perform transferFromCross()', async ({helper}) => {302 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});303304 const owner = bob;305 const spender = await helper.eth.createAccountWithBalance(donor, 100n);306 const receiver = charlie;307308 const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});309310 const address = helper.ethAddress.fromCollectionId(collection.collectionId);311 const contract = helper.ethNativeContract.collection(address, 'rft');312313 await token.repartition(owner, 15n);314 await token.approve(owner, {Ethereum: spender}, 15n);315316 {317 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);318 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);319 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});320 const event = result.events.Transfer;321 expect(event).to.be.like({322 address: helper.ethAddress.fromCollectionId(collection.collectionId),323 event: 'Transfer',324 returnValues: {325 from: helper.address.substrateToEth(owner.address),326 to: helper.address.substrateToEth(receiver.address),327 tokenId: token.tokenId.toString(),328 },329 });330 }331332 expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);333 });334335 itEth('Can perform transfer()', async ({helper}) => {336 const caller = await helper.eth.createAccountWithBalance(donor);337 const receiver = helper.eth.createAccount();338 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');339 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);340341 const result = await contract.methods.mint(caller).send();342 const tokenId = result.events.Transfer.returnValues.tokenId;343344 {345 const result = await contract.methods.transfer(receiver, tokenId).send();346347 const event = result.events.Transfer;348 expect(event.address).to.equal(collectionAddress);349 expect(event.returnValues.from).to.equal(caller);350 expect(event.returnValues.to).to.equal(receiver);351 expect(event.returnValues.tokenId).to.equal(tokenId.toString());352 }353354 {355 const balance = await contract.methods.balanceOf(caller).call();356 expect(+balance).to.equal(0);357 }358359 {360 const balance = await contract.methods.balanceOf(receiver).call();361 expect(+balance).to.equal(1);362 }363 });364 365 itEth('Can perform transferCross()', async ({helper}) => {366 const caller = await helper.eth.createAccountWithBalance(donor);367 const receiver = await helper.eth.createAccountWithBalance(donor);368 const to = helper.ethCrossAccount.fromAddress(receiver);369 const toSubstrate = helper.ethCrossAccount.fromKeyringPair(minter);370 const collection = await helper.rft.mintCollection(minter, {});371 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);372 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);373374 const {tokenId} = await collection.mintToken(minter, 1n, {Ethereum: caller});375376 {377 const result = await contract.methods.transferCross(to, tokenId).send({from: caller});378379 const event = result.events.Transfer;380 expect(event.address).to.equal(collectionAddress);381 expect(event.returnValues.from).to.equal(caller);382 expect(event.returnValues.to).to.equal(receiver);383 expect(event.returnValues.tokenId).to.equal(tokenId.toString());384 }385386 {387 const balance = await contract.methods.balanceOf(caller).call();388 expect(+balance).to.equal(0);389 }390391 {392 const balance = await contract.methods.balanceOf(receiver).call();393 expect(+balance).to.equal(1);394 }395 396 {397 const substrateResult = await contract.methods.transferCross(toSubstrate, tokenId).send({from: receiver});398 399400 const event = substrateResult.events.Transfer;401 expect(event.address).to.be.equal(collectionAddress);402 expect(event.returnValues.from).to.be.equal(receiver);403 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));404 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);405 }406407 {408 const balance = await contract.methods.balanceOf(receiver).call();409 expect(+balance).to.equal(0);410 }411412 {413 const balance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});414 expect(balance).to.be.contain(tokenId);415 }416 });417418 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {419 const caller = await helper.eth.createAccountWithBalance(donor);420 const receiver = helper.eth.createAccount();421 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');422 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);423424 const result = await contract.methods.mint(caller).send();425 const tokenId = result.events.Transfer.returnValues.tokenId;426427 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);428429 await tokenContract.methods.repartition(2).send();430 await tokenContract.methods.transfer(receiver, 1).send();431432 const events: any = [];433 contract.events.allEvents((_: any, event: any) => {434 events.push(event);435 });436437 await tokenContract.methods.transfer(receiver, 1).send();438 if (events.length == 0) await helper.wait.newBlocks(1);439 const event = events[0];440441 expect(event.address).to.equal(collectionAddress);442 expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');443 expect(event.returnValues.to).to.equal(receiver);444 expect(event.returnValues.tokenId).to.equal(tokenId.toString());445 });446447 itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {448 const caller = await helper.eth.createAccountWithBalance(donor);449 const receiver = helper.eth.createAccount();450 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');451 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);452453 const result = await contract.methods.mint(caller).send();454 const tokenId = result.events.Transfer.returnValues.tokenId;455456 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);457458 await tokenContract.methods.repartition(2).send();459460 const events: any = [];461 contract.events.allEvents((_: any, event: any) => {462 events.push(event);463 });464465 await tokenContract.methods.transfer(receiver, 1).send();466 if (events.length == 0) await helper.wait.newBlocks(1);467 const event = events[0];468469 expect(event.address).to.equal(collectionAddress);470 expect(event.returnValues.from).to.equal(caller);471 expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');472 expect(event.returnValues.tokenId).to.equal(tokenId.toString());473 });474});475476describe('RFT: Fees', () => {477 let donor: IKeyringPair;478479 before(async function() {480 await usingEthPlaygrounds(async (helper, privateKey) => {481 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);482483 donor = await privateKey({filename: __filename});484 });485 });486487 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {488 const caller = await helper.eth.createAccountWithBalance(donor);489 const receiver = helper.eth.createAccount();490 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');491 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);492493 const result = await contract.methods.mint(caller).send();494 const tokenId = result.events.Transfer.returnValues.tokenId;495496 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());497 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));498 expect(cost > 0n);499 });500501 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {502 const caller = await helper.eth.createAccountWithBalance(donor);503 const receiver = helper.eth.createAccount();504 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');505 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);506507 const result = await contract.methods.mint(caller).send();508 const tokenId = result.events.Transfer.returnValues.tokenId;509510 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());511 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));512 expect(cost > 0n);513 });514});515516describe('Common metadata', () => {517 let donor: IKeyringPair;518 let alice: IKeyringPair;519520 before(async function() {521 await usingEthPlaygrounds(async (helper, privateKey) => {522 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);523524 donor = await privateKey({filename: __filename});525 [alice] = await helper.arrange.createAccounts([20n], donor);526 });527 });528529 itEth('Returns collection name', async ({helper}) => {530 const caller = helper.eth.createAccount();531 const tokenPropertyPermissions = [{532 key: 'URI',533 permission: {534 mutable: true,535 collectionAdmin: true,536 tokenOwner: false,537 },538 }];539 const collection = await helper.rft.mintCollection(540 alice,541 {542 name: 'Leviathan',543 tokenPrefix: '11',544 properties: [{key: 'ERC721Metadata', value: '1'}],545 tokenPropertyPermissions,546 },547 );548549 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);550 const name = await contract.methods.name().call();551 expect(name).to.equal('Leviathan');552 });553554 itEth('Returns symbol name', async ({helper}) => {555 const caller = await helper.eth.createAccountWithBalance(donor);556 const tokenPropertyPermissions = [{557 key: 'URI',558 permission: {559 mutable: true,560 collectionAdmin: true,561 tokenOwner: false,562 },563 }];564 const {collectionId} = await helper.rft.mintCollection(565 alice,566 {567 name: 'Leviathan',568 tokenPrefix: '12',569 properties: [{key: 'ERC721Metadata', value: '1'}],570 tokenPropertyPermissions,571 },572 );573574 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);575 const symbol = await contract.methods.symbol().call();576 expect(symbol).to.equal('12');577 });578});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';2021describe('Refungible: Information getting', () => {22 let donor: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2728 donor = await privateKey({filename: __filename});29 });30 });3132 itEth('totalSupply', async ({helper}) => {33 const caller = await helper.eth.createAccountWithBalance(donor);34 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');35 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);3637 await contract.methods.mint(caller).send();3839 const totalSupply = await contract.methods.totalSupply().call();40 expect(totalSupply).to.equal('1');41 });4243 itEth('balanceOf', async ({helper}) => {44 const caller = await helper.eth.createAccountWithBalance(donor);45 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');46 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4748 await contract.methods.mint(caller).send();49 await contract.methods.mint(caller).send();50 await contract.methods.mint(caller).send();5152 const balance = await contract.methods.balanceOf(caller).call();53 expect(balance).to.equal('3');54 });5556 itEth('ownerOf', async ({helper}) => {57 const caller = await helper.eth.createAccountWithBalance(donor);58 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');59 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6061 const result = await contract.methods.mint(caller).send();62 const tokenId = result.events.Transfer.returnValues.tokenId;6364 const owner = await contract.methods.ownerOf(tokenId).call();65 expect(owner).to.equal(caller);66 });6768 itEth('ownerOf after burn', async ({helper}) => {69 const caller = await helper.eth.createAccountWithBalance(donor);70 const receiver = helper.eth.createAccount();71 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');72 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);7374 const result = await contract.methods.mint(caller).send();75 const tokenId = result.events.Transfer.returnValues.tokenId;76 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);7778 await tokenContract.methods.repartition(2).send();79 await tokenContract.methods.transfer(receiver, 1).send();8081 await tokenContract.methods.burnFrom(caller, 1).send();8283 const owner = await contract.methods.ownerOf(tokenId).call();84 expect(owner).to.equal(receiver);85 });8687 itEth('ownerOf for partial ownership', async ({helper}) => {88 const caller = await helper.eth.createAccountWithBalance(donor);89 const receiver = helper.eth.createAccount();90 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');91 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9293 const result = await contract.methods.mint(caller).send();94 const tokenId = result.events.Transfer.returnValues.tokenId;95 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);9697 await tokenContract.methods.repartition(2).send();98 await tokenContract.methods.transfer(receiver, 1).send();99100 const owner = await contract.methods.ownerOf(tokenId).call();101 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');102 });103});104105describe('Refungible: Plain calls', () => {106 let donor: IKeyringPair;107 let minter: IKeyringPair;108 let bob: IKeyringPair;109 let charlie: IKeyringPair;110111 before(async function() {112 await usingEthPlaygrounds(async (helper, privateKey) => {113 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);114115 donor = await privateKey({filename: __filename});116 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);117 });118 });119120 itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {121 const owner = await helper.eth.createAccountWithBalance(donor);122 const receiver = helper.eth.createAccount();123 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');124 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);125126 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();127128 const event = result.events.Transfer;129 expect(event.address).to.equal(collectionAddress);130 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');131 expect(event.returnValues.to).to.equal(receiver);132 const tokenId = event.returnValues.tokenId;133 expect(tokenId).to.be.equal('1');134135 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);136 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');137 });138139 itEth.skip('Can perform mintBulk()', async ({helper}) => {140 const owner = await helper.eth.createAccountWithBalance(donor);141 const receiver = helper.eth.createAccount();142 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'MintBulky', '6', '6', '');143 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);144145 {146 const nextTokenId = await contract.methods.nextTokenId().call();147 expect(nextTokenId).to.be.equal('1');148 const result = await contract.methods.mintBulkWithTokenURI(149 receiver,150 [151 [nextTokenId, 'Test URI 0'],152 [+nextTokenId + 1, 'Test URI 1'],153 [+nextTokenId + 2, 'Test URI 2'],154 ],155 ).send();156157 const events = result.events.Transfer;158 for (let i = 0; i < 2; i++) {159 const event = events[i];160 expect(event.address).to.equal(collectionAddress);161 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');162 expect(event.returnValues.to).to.equal(receiver);163 expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));164 }165166 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');167 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');168 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');169 }170 });171172 itEth('Can perform burn()', async ({helper}) => {173 const caller = await helper.eth.createAccountWithBalance(donor);174 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Burny', '6', '6');175 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);176177 const result = await contract.methods.mint(caller).send();178 const tokenId = result.events.Transfer.returnValues.tokenId;179 {180 const result = await contract.methods.burn(tokenId).send();181 const event = result.events.Transfer;182 expect(event.address).to.equal(collectionAddress);183 expect(event.returnValues.from).to.equal(caller);184 expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');185 expect(event.returnValues.tokenId).to.equal(tokenId.toString());186 }187 });188189 itEth('Can perform transferFrom()', async ({helper}) => {190 const caller = await helper.eth.createAccountWithBalance(donor);191 const receiver = helper.eth.createAccount();192 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'TransferFromy', '6', '6');193 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);194195 const result = await contract.methods.mint(caller).send();196 const tokenId = result.events.Transfer.returnValues.tokenId;197198 const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);199200 const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);201 await tokenContract.methods.repartition(15).send();202203 {204 const tokenEvents: any = [];205 tokenContract.events.allEvents((_: any, event: any) => {206 tokenEvents.push(event);207 });208 const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();209 if (tokenEvents.length == 0) await helper.wait.newBlocks(1);210211 let event = result.events.Transfer;212 expect(event.address).to.equal(collectionAddress);213 expect(event.returnValues.from).to.equal(caller);214 expect(event.returnValues.to).to.equal(receiver);215 expect(event.returnValues.tokenId).to.equal(tokenId.toString());216217 event = tokenEvents[0];218 expect(event.address).to.equal(tokenAddress);219 expect(event.returnValues.from).to.equal(caller);220 expect(event.returnValues.to).to.equal(receiver);221 expect(event.returnValues.value).to.equal('15');222 }223224 {225 const balance = await contract.methods.balanceOf(receiver).call();226 expect(+balance).to.equal(1);227 }228229 {230 const balance = await contract.methods.balanceOf(caller).call();231 expect(+balance).to.equal(0);232 }233 });234235 // Soft-deprecated236 itEth('Can perform burnFrom()', async ({helper}) => {237 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});238239 const owner = await helper.eth.createAccountWithBalance(donor, 100n);240 const spender = await helper.eth.createAccountWithBalance(donor, 100n);241242 const token = await collection.mintToken(minter, 100n, {Ethereum: owner});243244 const address = helper.ethAddress.fromCollectionId(collection.collectionId);245 const contract = helper.ethNativeContract.collection(address, 'rft', spender, true);246247 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);248 const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);249 await tokenContract.methods.repartition(15).send();250 await tokenContract.methods.approve(spender, 15).send();251252 {253 const result = await contract.methods.burnFrom(owner, token.tokenId).send();254 const event = result.events.Transfer;255 expect(event).to.be.like({256 address: helper.ethAddress.fromCollectionId(collection.collectionId),257 event: 'Transfer',258 returnValues: {259 from: owner,260 to: '0x0000000000000000000000000000000000000000',261 tokenId: token.tokenId.toString(),262 },263 });264 }265266 expect(await collection.getTokenBalance(token.tokenId, {Ethereum: owner})).to.be.eq(0n);267 });268269 itEth('Can perform burnFromCross()', async ({helper}) => {270 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});271 272 const owner = bob;273 const spender = await helper.eth.createAccountWithBalance(donor, 100n);274275 const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});276277 const address = helper.ethAddress.fromCollectionId(collection.collectionId);278 const contract = helper.ethNativeContract.collection(address, 'rft');279280 await token.repartition(owner, 15n);281 await token.approve(owner, {Ethereum: spender}, 15n);282283 {284 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);285 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender});286 const event = result.events.Transfer;287 expect(event).to.be.like({288 address: helper.ethAddress.fromCollectionId(collection.collectionId),289 event: 'Transfer',290 returnValues: {291 from: helper.address.substrateToEth(owner.address),292 to: '0x0000000000000000000000000000000000000000',293 tokenId: token.tokenId.toString(),294 },295 });296 }297298 expect(await collection.getTokenBalance(token.tokenId, {Substrate: owner.address})).to.be.eq(0n);299 });300301 itEth('Can perform transferFromCross()', async ({helper}) => {302 const collection = await helper.rft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});303304 const owner = bob;305 const spender = await helper.eth.createAccountWithBalance(donor, 100n);306 const receiver = charlie;307308 const token = await collection.mintToken(minter, 100n, {Substrate: owner.address});309310 const address = helper.ethAddress.fromCollectionId(collection.collectionId);311 const contract = helper.ethNativeContract.collection(address, 'rft');312313 await token.repartition(owner, 15n);314 await token.approve(owner, {Ethereum: spender}, 15n);315316 {317 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);318 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);319 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});320 const event = result.events.Transfer;321 expect(event).to.be.like({322 address: helper.ethAddress.fromCollectionId(collection.collectionId),323 event: 'Transfer',324 returnValues: {325 from: helper.address.substrateToEth(owner.address),326 to: helper.address.substrateToEth(receiver.address),327 tokenId: token.tokenId.toString(),328 },329 });330 }331332 expect(await token.getTop10Owners()).to.be.like([{Substrate: receiver.address}]);333 });334335 itEth('Can perform transfer()', async ({helper}) => {336 const caller = await helper.eth.createAccountWithBalance(donor);337 const receiver = helper.eth.createAccount();338 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry', '6', '6');339 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);340341 const result = await contract.methods.mint(caller).send();342 const tokenId = result.events.Transfer.returnValues.tokenId;343344 {345 const result = await contract.methods.transfer(receiver, tokenId).send();346347 const event = result.events.Transfer;348 expect(event.address).to.equal(collectionAddress);349 expect(event.returnValues.from).to.equal(caller);350 expect(event.returnValues.to).to.equal(receiver);351 expect(event.returnValues.tokenId).to.equal(tokenId.toString());352 }353354 {355 const balance = await contract.methods.balanceOf(caller).call();356 expect(+balance).to.equal(0);357 }358359 {360 const balance = await contract.methods.balanceOf(receiver).call();361 expect(+balance).to.equal(1);362 }363 });364 365 itEth('Can perform transferCross()', async ({helper}) => {366 const sender = await helper.eth.createAccountWithBalance(donor);367 const receiverEth = await helper.eth.createAccountWithBalance(donor);368 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);369 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);370371 const collection = await helper.rft.mintCollection(minter, {});372 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);373 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);374375 const token = await collection.mintToken(minter, 50n, {Ethereum: sender});376377 {378 // Can transferCross to ethereum address:379 const result = await collectionEvm.methods.transferCross(receiverCrossEth, token.tokenId).send({from: sender});380 // Check events:381 const event = result.events.Transfer;382 expect(event.address).to.equal(collectionAddress);383 expect(event.returnValues.from).to.equal(sender);384 expect(event.returnValues.to).to.equal(receiverEth);385 expect(event.returnValues.tokenId).to.equal(token.tokenId.toString());386 // Sender's balance decreased:387 const senderBalance = await collectionEvm.methods.balanceOf(sender).call();388 expect(+senderBalance).to.equal(0);389 expect(await token.getBalance({Ethereum: sender})).to.eq(0n);390 // Receiver's balance increased:391 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();392 expect(+receiverBalance).to.equal(1);393 expect(await token.getBalance({Ethereum: receiverEth})).to.eq(50n);394 }395 396 {397 // Can transferCross to substrate address:398 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, token.tokenId).send({from: receiverEth});399 // Check events:400 const event = substrateResult.events.Transfer;401 expect(event.address).to.be.equal(collectionAddress);402 expect(event.returnValues.from).to.be.equal(receiverEth);403 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));404 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);405 // Sender's balance decreased:406 const senderBalance = await collectionEvm.methods.balanceOf(receiverEth).call();407 expect(+senderBalance).to.equal(0);408 expect(await token.getBalance({Ethereum: receiverEth})).to.eq(0n);409 // Receiver's balance increased:410 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});411 expect(receiverBalance).to.contain(token.tokenId);412 expect(await token.getBalance({Substrate: minter.address})).to.eq(50n);413 }414 });415416 itEth('Cannot transferCross with invalid params', async ({helper}) => {417 const sender = await helper.eth.createAccountWithBalance(donor);418 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);419420 const collection = await helper.rft.mintCollection(minter, {});421 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);422 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', sender);423424 const {tokenId} = await collection.mintToken(minter, 50n, {Ethereum: sender});425 // FIXME (transaction successful): Cannot transfer token if it does not exist:426 await expect(collectionEvm.methods.transferCross(receiverCrossSub, tokenId + 1).send({from: sender})).to.be.rejected;427 });428429 itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {430 const caller = await helper.eth.createAccountWithBalance(donor);431 const receiver = helper.eth.createAccount();432 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Partial-to-Full', '6', '6');433 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);434435 const result = await contract.methods.mint(caller).send();436 const tokenId = result.events.Transfer.returnValues.tokenId;437438 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);439440 await tokenContract.methods.repartition(2).send();441 await tokenContract.methods.transfer(receiver, 1).send();442443 const events: any = [];444 contract.events.allEvents((_: any, event: any) => {445 events.push(event);446 });447448 await tokenContract.methods.transfer(receiver, 1).send();449 if (events.length == 0) await helper.wait.newBlocks(1);450 const event = events[0];451452 expect(event.address).to.equal(collectionAddress);453 expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');454 expect(event.returnValues.to).to.equal(receiver);455 expect(event.returnValues.tokenId).to.equal(tokenId.toString());456 });457458 itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {459 const caller = await helper.eth.createAccountWithBalance(donor);460 const receiver = helper.eth.createAccount();461 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Transferry-Full-to-Partial', '6', '6');462 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);463464 const result = await contract.methods.mint(caller).send();465 const tokenId = result.events.Transfer.returnValues.tokenId;466467 const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);468469 await tokenContract.methods.repartition(2).send();470471 const events: any = [];472 contract.events.allEvents((_: any, event: any) => {473 events.push(event);474 });475476 await tokenContract.methods.transfer(receiver, 1).send();477 if (events.length == 0) await helper.wait.newBlocks(1);478 const event = events[0];479480 expect(event.address).to.equal(collectionAddress);481 expect(event.returnValues.from).to.equal(caller);482 expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');483 expect(event.returnValues.tokenId).to.equal(tokenId.toString());484 });485});486487describe('RFT: Fees', () => {488 let donor: IKeyringPair;489490 before(async function() {491 await usingEthPlaygrounds(async (helper, privateKey) => {492 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);493494 donor = await privateKey({filename: __filename});495 });496 });497498 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {499 const caller = await helper.eth.createAccountWithBalance(donor);500 const receiver = helper.eth.createAccount();501 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer-From', '6', '6');502 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);503504 const result = await contract.methods.mint(caller).send();505 const tokenId = result.events.Transfer.returnValues.tokenId;506507 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());508 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));509 expect(cost > 0n);510 });511512 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {513 const caller = await helper.eth.createAccountWithBalance(donor);514 const receiver = helper.eth.createAccount();515 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'Feeful-Transfer', '6', '6');516 const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);517518 const result = await contract.methods.mint(caller).send();519 const tokenId = result.events.Transfer.returnValues.tokenId;520521 const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());522 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));523 expect(cost > 0n);524 });525});526527describe('Common metadata', () => {528 let donor: IKeyringPair;529 let alice: IKeyringPair;530531 before(async function() {532 await usingEthPlaygrounds(async (helper, privateKey) => {533 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);534535 donor = await privateKey({filename: __filename});536 [alice] = await helper.arrange.createAccounts([20n], donor);537 });538 });539540 itEth('Returns collection name', async ({helper}) => {541 const caller = helper.eth.createAccount();542 const tokenPropertyPermissions = [{543 key: 'URI',544 permission: {545 mutable: true,546 collectionAdmin: true,547 tokenOwner: false,548 },549 }];550 const collection = await helper.rft.mintCollection(551 alice,552 {553 name: 'Leviathan',554 tokenPrefix: '11',555 properties: [{key: 'ERC721Metadata', value: '1'}],556 tokenPropertyPermissions,557 },558 );559560 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);561 const name = await contract.methods.name().call();562 expect(name).to.equal('Leviathan');563 });564565 itEth('Returns symbol name', async ({helper}) => {566 const caller = await helper.eth.createAccountWithBalance(donor);567 const tokenPropertyPermissions = [{568 key: 'URI',569 permission: {570 mutable: true,571 collectionAdmin: true,572 tokenOwner: false,573 },574 }];575 const {collectionId} = await helper.rft.mintCollection(576 alice,577 {578 name: 'Leviathan',579 tokenPrefix: '12',580 properties: [{key: 'ERC721Metadata', value: '1'}],581 tokenPropertyPermissions,582 },583 );584585 const contract = helper.ethNativeContract.collectionById(collectionId, 'rft', caller);586 const symbol = await contract.methods.symbol().call();587 expect(symbol).to.equal('12');588 });589});