difftreelog
feat add crossBalanceOf
in: master
11 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -755,6 +755,17 @@
.map_err(|_| Error::Revert("token not found".into()))
}
+ /// @notice Count all NFTs assigned to an owner
+ /// @dev NFTs assigned to the zero address are considered invalid, and this
+ /// function throws for queries about the zero address.
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of NFTs owned by `owner`, possibly zero
+ fn cross_balance_of(&self, owner: eth::CrossAddress) -> Result<U256> {
+ self.consume_store_reads(1)?;
+ let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
+ Ok(balance.into())
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -774,7 +774,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x16de3152
+/// @dev the ERC-165 identifier for this interface is 0x323b1db8
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -815,6 +815,20 @@
return CrossAddress(0x0000000000000000000000000000000000000000, 0);
}
+ /// @notice Count all NFTs assigned to an owner
+ /// @dev NFTs assigned to the zero address are considered invalid, and this
+ /// function throws for queries about the zero address.
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of NFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0x24e52cea,
+ /// or in textual repr: crossBalanceOf((address,uint256))
+ function crossBalanceOf(CrossAddress memory owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -794,6 +794,17 @@
})
}
+ /// @notice Count all RFTs assigned to an owner
+ /// @dev RFTs assigned to the zero address are considered invalid, and this
+ /// function throws for queries about the zero address.
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of RFTs owned by `owner`, possibly zero
+ fn cross_balance_of(&self, owner: eth::CrossAddress) -> Result<U256> {
+ self.consume_store_reads(1)?;
+ let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
+ Ok(balance.into())
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -774,7 +774,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xb365c124
+/// @dev the ERC-165 identifier for this interface is 0x9780edce
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -815,6 +815,20 @@
return CrossAddress(0x0000000000000000000000000000000000000000, 0);
}
+ /// @notice Count all RFTs assigned to an owner
+ /// @dev RFTs assigned to the zero address are considered invalid, and this
+ /// function throws for queries about the zero address.
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of RFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0x24e52cea,
+ /// or in textual repr: crossBalanceOf((address,uint256))
+ function crossBalanceOf(CrossAddress memory owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -227,6 +227,7 @@
| Symbol
| Description
| CrossOwnerOf { .. }
+ | CrossBalanceOf { .. }
| Properties { .. }
| NextTokenId
| TokenContractAddress { .. }
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -386,6 +386,23 @@
},
{
"inputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ }
+ ],
+ "name": "crossBalanceOf",
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "crossOwnerOf",
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -533,7 +533,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x16de3152
+/// @dev the ERC-165 identifier for this interface is 0x323b1db8
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -557,6 +557,15 @@
/// or in textual repr: crossOwnerOf(uint256)
function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+ /// @notice Count all NFTs assigned to an owner
+ /// @dev NFTs assigned to the zero address are considered invalid, and this
+ /// function throws for queries about the zero address.
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of NFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0x24e52cea,
+ /// or in textual repr: crossBalanceOf((address,uint256))
+ function crossBalanceOf(CrossAddress memory owner) external view returns (uint256);
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -533,7 +533,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xb365c124
+/// @dev the ERC-165 identifier for this interface is 0x9780edce
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -557,6 +557,15 @@
/// or in textual repr: crossOwnerOf(uint256)
function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+ /// @notice Count all RFTs assigned to an owner
+ /// @dev RFTs assigned to the zero address are considered invalid, and this
+ /// function throws for queries about the zero address.
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of RFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0x24e52cea,
+ /// or in textual repr: crossBalanceOf((address,uint256))
+ function crossBalanceOf(CrossAddress memory owner) external view returns (uint256);
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
tests/src/eth/nonFungible.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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Check ERC721 token URI for NFT', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (_helper, privateKey) => {27 donor = await privateKey({url: import.meta.url});28 });29 });3031 async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {32 const owner = await helper.eth.createAccountWithBalance(donor);33 const receiver = helper.eth.createAccount();3435 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);36 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);3738 const result = await contract.methods.mint(receiver).send();39 const tokenId = result.events.Transfer.returnValues.tokenId;40 expect(tokenId).to.be.equal('1');4142 if (propertyKey && propertyValue) {43 // Set URL or suffix44 await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();45 }4647 const event = result.events.Transfer;48 expect(event.address).to.be.equal(collectionAddress);49 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');50 expect(event.returnValues.to).to.be.equal(receiver);51 expect(event.returnValues.tokenId).to.be.equal(tokenId);5253 return {contract, nextTokenId: tokenId};54 }5556 itEth('Empty tokenURI', async ({helper}) => {57 const {contract, nextTokenId} = await setup(helper, '');58 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');59 });6061 itEth('TokenURI from url', async ({helper}) => {62 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');63 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');64 });6566 itEth('TokenURI from baseURI', async ({helper}) => {67 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');68 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');69 });7071 itEth('TokenURI from baseURI + suffix', async ({helper}) => {72 const suffix = '/some/suffix';73 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);74 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);75 });76});7778describe('NFT: Plain calls', () => {79 let donor: IKeyringPair;80 let minter: IKeyringPair;81 let bob: IKeyringPair;82 let charlie: IKeyringPair;8384 before(async function() {85 await usingEthPlaygrounds(async (helper, privateKey) => {86 donor = await privateKey({url: import.meta.url});87 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);88 });89 });9091 // TODO combine all minting tests in one place92 [93 'substrate' as const,94 'ethereum' as const,95 ].map(testCase => {96 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {97 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);9899 const receiverEth = helper.eth.createAccount();100 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);101 const receiverSub = bob;102 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);103104 // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);105 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });106 const permissions: ITokenPropertyPermission[] = properties107 .map(p => {108 return {109 key: p.key, permission: {110 tokenOwner: false,111 collectionAdmin: true,112 mutable: false,113 },114 };115 });116117 const collection = await helper.nft.mintCollection(minter, {118 tokenPrefix: 'ethp',119 tokenPropertyPermissions: permissions,120 });121 await collection.addAdmin(minter, {Ethereum: collectionAdmin});122123 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);124 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);125 let expectedTokenId = await contract.methods.nextTokenId().call();126 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();127 let tokenId = result.events.Transfer.returnValues.tokenId;128 expect(tokenId).to.be.equal(expectedTokenId);129130 let event = result.events.Transfer;131 expect(event.address).to.be.equal(collectionAddress);132 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');133 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));134 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);135136 expectedTokenId = await contract.methods.nextTokenId().call();137 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();138 event = result.events.Transfer;139 expect(event.address).to.be.equal(collectionAddress);140 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');141 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));142 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);143144 tokenId = result.events.Transfer.returnValues.tokenId;145146 expect(tokenId).to.be.equal(expectedTokenId);147148 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties149 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));150151 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))152 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});153 });154 });155156 itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {157 const nonOwner = await helper.eth.createAccountWithBalance(donor);158 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);159160 const collection = await helper.nft.mintCollection(minter);161 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);162 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');163164 await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))165 .to.be.rejectedWith('PublicMintingNotAllowed');166 });167168 //TODO: CORE-302 add eth methods169 itEth.skip('Can perform mintBulk()', async ({helper}) => {170 const caller = await helper.eth.createAccountWithBalance(donor);171 const receiver = helper.eth.createAccount();172173 const collection = await helper.nft.mintCollection(minter);174 await collection.addAdmin(minter, {Ethereum: caller});175176 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);177 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);178 {179 const bulkSize = 3;180 const nextTokenId = await contract.methods.nextTokenId().call();181 expect(nextTokenId).to.be.equal('1');182 const result = await contract.methods.mintBulkWithTokenURI(183 receiver,184 Array.from({length: bulkSize}, (_, i) => (185 [+nextTokenId + i, `Test URI ${i}`]186 )),187 ).send({from: caller});188189 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);190 for (let i = 0; i < bulkSize; i++) {191 const event = events[i];192 expect(event.address).to.equal(collectionAddress);193 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');194 expect(event.returnValues.to).to.equal(receiver);195 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);196197 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);198 }199 }200 });201202 itEth('Can perform burn()', async ({helper}) => {203 const caller = await helper.eth.createAccountWithBalance(donor);204205 const collection = await helper.nft.mintCollection(minter, {});206 const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});207208 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);209 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);210211 {212 const result = await contract.methods.burn(tokenId).send({from: caller});213214 const event = result.events.Transfer;215 expect(event.address).to.be.equal(collectionAddress);216 expect(event.returnValues.from).to.be.equal(caller);217 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');218 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);219 }220 });221222 itEth('Can perform approve()', async ({helper}) => {223 const owner = await helper.eth.createAccountWithBalance(donor);224 const spender = helper.eth.createAccount();225226 const collection = await helper.nft.mintCollection(minter, {});227 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});228229 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);230 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);231232 {233 const badTokenId = await contract.methods.nextTokenId().call() + 1;234 await expect(contract.methods.getApproved(badTokenId).call()).to.be.rejectedWith('revert TokenNotFound');235 }236 {237 const approved = await contract.methods.getApproved(tokenId).call();238 expect(approved).to.be.equal('0x0000000000000000000000000000000000000000');239 }240 {241 const result = await contract.methods.approve(spender, tokenId).send({from: owner});242243 const event = result.events.Approval;244 expect(event.address).to.be.equal(collectionAddress);245 expect(event.returnValues.owner).to.be.equal(owner);246 expect(event.returnValues.approved).to.be.equal(spender);247 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);248 }249 {250 const approved = await contract.methods.getApproved(tokenId).call();251 expect(approved).to.be.equal(spender);252 }253 });254255 itEth('Can perform setApprovalForAll()', async ({helper}) => {256 const owner = await helper.eth.createAccountWithBalance(donor);257 const operator = helper.eth.createAccount();258259 const collection = await helper.nft.mintCollection(minter, {});260261 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);262 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);263264 const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();265 expect(approvedBefore).to.be.equal(false);266267 {268 const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});269270 expect(result.events.ApprovalForAll).to.be.like({271 address: collectionAddress,272 event: 'ApprovalForAll',273 returnValues: {274 owner,275 operator,276 approved: true,277 },278 });279280 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();281 expect(approvedAfter).to.be.equal(true);282 }283284 {285 const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});286287 expect(result.events.ApprovalForAll).to.be.like({288 address: collectionAddress,289 event: 'ApprovalForAll',290 returnValues: {291 owner,292 operator,293 approved: false,294 },295 });296297 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();298 expect(approvedAfter).to.be.equal(false);299 }300 });301302 itEth('Can perform burn with ApprovalForAll', async ({helper}) => {303 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});304305 const owner = await helper.eth.createAccountWithBalance(donor);306 const operator = await helper.eth.createAccountWithBalance(donor, 100n);307308 const token = await collection.mintToken(minter, {Ethereum: owner});309310 const address = helper.ethAddress.fromCollectionId(collection.collectionId);311 const contract = await helper.ethNativeContract.collection(address, 'nft');312313 {314 await contract.methods.setApprovalForAll(operator, true).send({from: owner});315 const ownerCross = helper.ethCrossAccount.fromAddress(owner);316 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});317 const events = result.events.Transfer;318319 expect(events).to.be.like({320 address,321 event: 'Transfer',322 returnValues: {323 from: owner,324 to: '0x0000000000000000000000000000000000000000',325 tokenId: token.tokenId.toString(),326 },327 });328 }329330 expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;331 });332333 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {334 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});335336 const owner = await helper.eth.createAccountWithBalance(donor);337 const operator = await helper.eth.createAccountWithBalance(donor);338 const receiver = charlie;339340 const token = await collection.mintToken(minter, {Ethereum: owner});341342 const address = helper.ethAddress.fromCollectionId(collection.collectionId);343 const contract = await helper.ethNativeContract.collection(address, 'nft');344345 {346 await contract.methods.setApprovalForAll(operator, true).send({from: owner});347 const ownerCross = helper.ethCrossAccount.fromAddress(owner);348 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);349 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});350 const event = result.events.Transfer;351 expect(event).to.be.like({352 address: helper.ethAddress.fromCollectionId(collection.collectionId),353 event: 'Transfer',354 returnValues: {355 from: owner,356 to: helper.address.substrateToEth(receiver.address),357 tokenId: token.tokenId.toString(),358 },359 });360 }361362 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});363 });364365 itEth('Can perform burnFromCross()', async ({helper}) => {366 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});367 const ownerSub = bob;368 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);369 const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);370 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);371372 const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);373 const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);374375 const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});376 const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});377378 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);379 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');380381 // Approve tokens from substrate and ethereum:382 await token1.approve(ownerSub, {Ethereum: burnerEth});383 await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});384385 // can burnFromCross:386 const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});387 const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});388 const events1 = result1.events.Transfer;389 const events2 = result2.events.Transfer;390391 // Check events for burnFromCross (substrate and ethereum):392 [393 [events1, token1, helper.address.substrateToEth(ownerSub.address)],394 [events2, token2, ownerEth],395 ].map(burnData => {396 expect(burnData[0]).to.be.like({397 address: collectionAddress,398 event: 'Transfer',399 returnValues: {400 from: burnData[2],401 to: '0x0000000000000000000000000000000000000000',402 tokenId: burnData[1].tokenId.toString(),403 },404 });405 });406407 expect(await token1.doesExist()).to.be.false;408 expect(await token2.doesExist()).to.be.false;409 });410411 // TODO combine all approve tests in one place412 itEth('Can perform approveCross()', async ({helper}) => {413 // arrange: create accounts414 const owner = await helper.eth.createAccountWithBalance(donor, 100n);415 const ownerCross = helper.ethCrossAccount.fromAddress(owner);416 const receiverSub = charlie;417 const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);418 const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);419 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);420421 // arrange: create collection and tokens:422 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});423 const token1 = await collection.mintToken(minter, {Ethereum: owner});424 const token2 = await collection.mintToken(minter, {Ethereum: owner});425426 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');427428 // Can approveCross substrate and ethereum address:429 const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});430 const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});431 const eventSub = resultSub.events.Approval;432 const eventEth = resultEth.events.Approval;433 expect(eventSub).to.be.like({434 address: helper.ethAddress.fromCollectionId(collection.collectionId),435 event: 'Approval',436 returnValues: {437 owner,438 approved: helper.address.substrateToEth(receiverSub.address),439 tokenId: token1.tokenId.toString(),440 },441 });442 expect(eventEth).to.be.like({443 address: helper.ethAddress.fromCollectionId(collection.collectionId),444 event: 'Approval',445 returnValues: {446 owner,447 approved: receiverEth,448 tokenId: token2.tokenId.toString(),449 },450 });451452 // Substrate address can transferFrom approved tokens:453 await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});454 expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});455 // Ethereum address can transferFromCross approved tokens:456 await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});457 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});458 });459460 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {461 const nonOwner = await helper.eth.createAccountWithBalance(donor);462 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);463 const owner = await helper.eth.createAccountWithBalance(donor);464 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});465 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');466 const token = await collection.mintToken(minter, {Ethereum: owner});467468 await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');469 });470471 itEth('Can reaffirm approved address', async ({helper}) => {472 const owner = await helper.eth.createAccountWithBalance(donor, 100n);473 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);474 const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);475 const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);476 const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);477 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});478 const token1 = await collection.mintToken(minter, {Ethereum: owner});479 const token2 = await collection.mintToken(minter, {Ethereum: owner});480 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');481482 // Can approve and reaffirm approved address:483 await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});484 await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});485486 // receiver1 cannot transferFrom:487 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;488 // receiver2 can transferFrom:489 await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});490491 // can set approved address to self address to remove approval:492 await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});493 await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});494495 // receiver1 cannot transfer token anymore:496 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;497 });498499 itEth('Can perform transferFrom()', async ({helper}) => {500 const owner = await helper.eth.createAccountWithBalance(donor);501 const spender = await helper.eth.createAccountWithBalance(donor);502 const receiver = helper.eth.createAccount();503504 const collection = await helper.nft.mintCollection(minter, {});505 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});506507 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);508 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);509510 await contract.methods.approve(spender, tokenId).send({from: owner});511512 {513 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});514515 const event = result.events.Transfer;516 expect(event.address).to.be.equal(collectionAddress);517 expect(event.returnValues.from).to.be.equal(owner);518 expect(event.returnValues.to).to.be.equal(receiver);519 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);520 }521522 {523 const balance = await contract.methods.balanceOf(receiver).call();524 expect(+balance).to.equal(1);525 }526527 {528 const balance = await contract.methods.balanceOf(owner).call();529 expect(+balance).to.equal(0);530 }531 });532533 itEth('Can perform transferFromCross()', async ({helper}) => {534 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});535536 const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);537 const spender = await helper.eth.createAccountWithBalance(donor);538539 const token = await collection.mintToken(minter, {Substrate: owner.address});540541 const address = helper.ethAddress.fromCollectionId(collection.collectionId);542 const contract = await helper.ethNativeContract.collection(address, 'nft');543544 await token.approve(owner, {Ethereum: spender});545546 {547 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);548 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);549 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});550 const event = result.events.Transfer;551 expect(event).to.be.like({552 address: helper.ethAddress.fromCollectionId(collection.collectionId),553 event: 'Transfer',554 returnValues: {555 from: helper.address.substrateToEth(owner.address),556 to: helper.address.substrateToEth(receiver.address),557 tokenId: token.tokenId.toString(),558 },559 });560 }561562 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});563 });564565 itEth('Can perform transfer()', async ({helper}) => {566 const collection = await helper.nft.mintCollection(minter, {});567 const owner = await helper.eth.createAccountWithBalance(donor);568 const receiver = helper.eth.createAccount();569570 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});571572 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);573 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);574575 {576 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});577578 const event = result.events.Transfer;579 expect(event.address).to.be.equal(collectionAddress);580 expect(event.returnValues.from).to.be.equal(owner);581 expect(event.returnValues.to).to.be.equal(receiver);582 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);583 }584585 {586 const balance = await contract.methods.balanceOf(owner).call();587 expect(+balance).to.equal(0);588 }589590 {591 const balance = await contract.methods.balanceOf(receiver).call();592 expect(+balance).to.equal(1);593 }594 });595596 itEth('Can perform transferCross()', async ({helper}) => {597 const collection = await helper.nft.mintCollection(minter, {});598 const owner = await helper.eth.createAccountWithBalance(donor);599 const receiverEth = await helper.eth.createAccountWithBalance(donor);600 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);601 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);602603 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});604605 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);606 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);607608 {609 // Can transferCross to ethereum address:610 const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});611 // Check events:612 const event = result.events.Transfer;613 expect(event.address).to.be.equal(collectionAddress);614 expect(event.returnValues.from).to.be.equal(owner);615 expect(event.returnValues.to).to.be.equal(receiverEth);616 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);617618 // owner has balance = 0:619 const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();620 expect(+ownerBalance).to.equal(0);621 // receiver owns token:622 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();623 expect(+receiverBalance).to.equal(1);624 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});625 }626627 {628 // Can transferCross to substrate address:629 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});630 // Check events:631 const event = substrateResult.events.Transfer;632 expect(event.address).to.be.equal(collectionAddress);633 expect(event.returnValues.from).to.be.equal(receiverEth);634 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));635 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);636637 // owner has balance = 0:638 const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();639 expect(+ownerBalance).to.equal(0);640 // receiver owns token:641 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});642 expect(receiverBalance).to.contain(tokenId);643 }644 });645646 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {647 const sender = await helper.eth.createAccountWithBalance(donor);648 const tokenOwner = await helper.eth.createAccountWithBalance(donor);649 const receiverSub = minter;650 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);651652 const collection = await helper.nft.mintCollection(minter, {});653 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);654 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', sender);655656 await collection.mintToken(minter, {Ethereum: sender});657 const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});658659 // Cannot transferCross someone else's token:660 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;661 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;662 // Cannot transfer token if it does not exist:663 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;664 }));665});666667describe('NFT: Fees', () => {668 let donor: IKeyringPair;669 let alice: IKeyringPair;670 let bob: IKeyringPair;671 let charlie: IKeyringPair;672673 before(async function() {674 await usingEthPlaygrounds(async (helper, privateKey) => {675 donor = await privateKey({url: import.meta.url});676 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);677 });678 });679680 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {681 const owner = await helper.eth.createAccountWithBalance(donor);682 const spender = helper.eth.createAccount();683684 const collection = await helper.nft.mintCollection(alice, {});685 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});686687 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);688689 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));690 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));691 });692693 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {694 const owner = await helper.eth.createAccountWithBalance(donor);695 const spender = await helper.eth.createAccountWithBalance(donor);696697 const collection = await helper.nft.mintCollection(alice, {});698 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});699700 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);701702 await contract.methods.approve(spender, tokenId).send({from: owner});703704 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));705 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));706 });707708 itEth('Can perform transferFromCross()', async ({helper}) => {709 const collectionMinter = alice;710 const owner = bob;711 const receiver = charlie;712 const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});713714 const spender = await helper.eth.createAccountWithBalance(donor, 100n);715716 const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});717718 const address = helper.ethAddress.fromCollectionId(collection.collectionId);719 const contract = await helper.ethNativeContract.collection(address, 'nft');720721 await token.approve(owner, {Ethereum: spender});722723 {724 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);725 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);726 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});727 const event = result.events.Transfer;728 expect(event).to.be.like({729 address: helper.ethAddress.fromCollectionId(collection.collectionId),730 event: 'Transfer',731 returnValues: {732 from: helper.address.substrateToEth(owner.address),733 to: helper.address.substrateToEth(receiver.address),734 tokenId: token.tokenId.toString(),735 },736 });737 }738739 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});740 });741742 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {743 const owner = await helper.eth.createAccountWithBalance(donor);744 const receiver = helper.eth.createAccount();745746 const collection = await helper.nft.mintCollection(alice, {});747 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});748749 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);750751 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));752 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));753 });754});755756describe('NFT: Substrate calls', () => {757 let donor: IKeyringPair;758 let alice: IKeyringPair;759760 before(async function() {761 await usingEthPlaygrounds(async (helper, privateKey) => {762 donor = await privateKey({url: import.meta.url});763 [alice] = await helper.arrange.createAccounts([20n], donor);764 });765 });766767 itEth('Events emitted for mint()', async ({helper}) => {768 const collection = await helper.nft.mintCollection(alice, {});769 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);770 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');771772 const events: any = [];773 contract.events.allEvents((_: any, event: any) => {774 events.push(event);775 });776777 const {tokenId} = await collection.mintToken(alice);778 if (events.length == 0) await helper.wait.newBlocks(1);779 const event = events[0];780781 expect(event.event).to.be.equal('Transfer');782 expect(event.address).to.be.equal(collectionAddress);783 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');784 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));785 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());786 });787788 itEth('Events emitted for burn()', async ({helper}) => {789 const collection = await helper.nft.mintCollection(alice, {});790 const token = await collection.mintToken(alice);791792 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);793 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');794795 const events: any = [];796 contract.events.allEvents((_: any, event: any) => {797 events.push(event);798 });799800 await token.burn(alice);801 if (events.length == 0) await helper.wait.newBlocks(1);802 const event = events[0];803804 expect(event.event).to.be.equal('Transfer');805 expect(event.address).to.be.equal(collectionAddress);806 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));807 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');808 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());809 });810811 itEth('Events emitted for approve()', async ({helper}) => {812 const receiver = helper.eth.createAccount();813814 const collection = await helper.nft.mintCollection(alice, {});815 const token = await collection.mintToken(alice);816817 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);818 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');819820 const events: any = [];821 contract.events.allEvents((_: any, event: any) => {822 events.push(event);823 });824825 await token.approve(alice, {Ethereum: receiver});826 if (events.length == 0) await helper.wait.newBlocks(1);827 const event = events[0];828829 expect(event.event).to.be.equal('Approval');830 expect(event.address).to.be.equal(collectionAddress);831 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));832 expect(event.returnValues.approved).to.be.equal(receiver);833 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());834 });835836 itEth('Events emitted for transferFrom()', async ({helper}) => {837 const [bob] = await helper.arrange.createAccounts([10n], donor);838 const receiver = helper.eth.createAccount();839840 const collection = await helper.nft.mintCollection(alice, {});841 const token = await collection.mintToken(alice);842 await token.approve(alice, {Substrate: bob.address});843844 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);845 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');846847 const events: any = [];848 contract.events.allEvents((_: any, event: any) => {849 events.push(event);850 });851852 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});853854 if (events.length == 0) await helper.wait.newBlocks(1);855 const event = events[0];856857 expect(event.address).to.be.equal(collectionAddress);858 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));859 expect(event.returnValues.to).to.be.equal(receiver);860 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);861 });862863 itEth('Events emitted for transfer()', async ({helper}) => {864 const receiver = helper.eth.createAccount();865866 const collection = await helper.nft.mintCollection(alice, {});867 const token = await collection.mintToken(alice);868869 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);870 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');871872 const events: any = [];873 contract.events.allEvents((_: any, event: any) => {874 events.push(event);875 });876877 await token.transfer(alice, {Ethereum: receiver});878879 if (events.length == 0) await helper.wait.newBlocks(1);880 const event = events[0];881882 expect(event.address).to.be.equal(collectionAddress);883 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));884 expect(event.returnValues.to).to.be.equal(receiver);885 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);886 });887});888889describe('Common metadata', () => {890 let donor: IKeyringPair;891 let alice: IKeyringPair;892893 before(async function() {894 await usingEthPlaygrounds(async (helper, privateKey) => {895 donor = await privateKey({url: import.meta.url});896 [alice] = await helper.arrange.createAccounts([20n], donor);897 });898 });899900 itEth('Returns collection name', async ({helper}) => {901 const caller = await helper.eth.createAccountWithBalance(donor);902 const tokenPropertyPermissions = [{903 key: 'URI',904 permission: {905 mutable: true,906 collectionAdmin: true,907 tokenOwner: false,908 },909 }];910 const collection = await helper.nft.mintCollection(911 alice,912 {913 name: 'oh River',914 tokenPrefix: 'CHANGE',915 properties: [{key: 'ERC721Metadata', value: '1'}],916 tokenPropertyPermissions,917 },918 );919920 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);921 const name = await contract.methods.name().call();922 expect(name).to.equal('oh River');923 });924925 itEth('Returns symbol name', async ({helper}) => {926 const caller = await helper.eth.createAccountWithBalance(donor);927 const tokenPropertyPermissions = [{928 key: 'URI',929 permission: {930 mutable: true,931 collectionAdmin: true,932 tokenOwner: false,933 },934 }];935 const collection = await helper.nft.mintCollection(936 alice,937 {938 name: 'oh River',939 tokenPrefix: 'CHANGE',940 properties: [{key: 'ERC721Metadata', value: '1'}],941 tokenPropertyPermissions,942 },943 );944945 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);946 const symbol = await contract.methods.symbol().call();947 expect(symbol).to.equal('CHANGE');948 });949});950951describe('Negative tests', () => {952 let donor: IKeyringPair;953 let minter: IKeyringPair;954 let alice: IKeyringPair;955956 before(async function() {957 await usingEthPlaygrounds(async (helper, privateKey) => {958 donor = await privateKey({url: import.meta.url});959 [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);960 });961 });962963 itEth('[negative] Cant perform burn without approval', async ({helper}) => {964 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});965966 const owner = await helper.eth.createAccountWithBalance(donor, 100n);967 const spender = await helper.eth.createAccountWithBalance(donor, 100n);968969 const token = await collection.mintToken(minter, {Ethereum: owner});970971 const address = helper.ethAddress.fromCollectionId(collection.collectionId);972 const contract = await helper.ethNativeContract.collection(address, 'nft');973974 const ownerCross = helper.ethCrossAccount.fromAddress(owner);975 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;976977 await contract.methods.setApprovalForAll(spender, true).send({from: owner});978 await contract.methods.setApprovalForAll(spender, false).send({from: owner});979980 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;981 });982983 itEth('[negative] Cant perform transfer without approval', async ({helper}) => {984 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});985 const receiver = alice;986987 const owner = await helper.eth.createAccountWithBalance(donor, 100n);988 const spender = await helper.eth.createAccountWithBalance(donor, 100n);989990 const token = await collection.mintToken(minter, {Ethereum: owner});991992 const address = helper.ethAddress.fromCollectionId(collection.collectionId);993 const contract = await helper.ethNativeContract.collection(address, 'nft');994995 const ownerCross = helper.ethCrossAccount.fromAddress(owner);996 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);997998 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;9991000 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1001 await contract.methods.setApprovalForAll(spender, false).send({from: owner});10021003 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1004 });1005});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 {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Check ERC721 token URI for NFT', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (_helper, privateKey) => {27 donor = await privateKey({url: import.meta.url});28 });29 });3031 async function setup(helper: EthUniqueHelper, baseUri: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {32 const owner = await helper.eth.createAccountWithBalance(donor);33 const receiver = helper.eth.createAccount();3435 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', 'a', 'b', baseUri);36 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);3738 const result = await contract.methods.mint(receiver).send();39 const tokenId = result.events.Transfer.returnValues.tokenId;40 expect(tokenId).to.be.equal('1');4142 if (propertyKey && propertyValue) {43 // Set URL or suffix44 await contract.methods.setProperties(tokenId, [{key: propertyKey, value: Buffer.from(propertyValue)}]).send();45 }4647 const event = result.events.Transfer;48 expect(event.address).to.be.equal(collectionAddress);49 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');50 expect(event.returnValues.to).to.be.equal(receiver);51 expect(event.returnValues.tokenId).to.be.equal(tokenId);5253 return {contract, nextTokenId: tokenId};54 }5556 itEth('Empty tokenURI', async ({helper}) => {57 const {contract, nextTokenId} = await setup(helper, '');58 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');59 });6061 itEth('TokenURI from url', async ({helper}) => {62 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URI', 'Token URI');63 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');64 });6566 itEth('TokenURI from baseURI', async ({helper}) => {67 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');68 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_');69 });7071 itEth('TokenURI from baseURI + suffix', async ({helper}) => {72 const suffix = '/some/suffix';73 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'URISuffix', suffix);74 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);75 });76});7778describe('NFT: Plain calls', () => {79 let donor: IKeyringPair;80 let minter: IKeyringPair;81 let bob: IKeyringPair;82 let charlie: IKeyringPair;8384 before(async function() {85 await usingEthPlaygrounds(async (helper, privateKey) => {86 donor = await privateKey({url: import.meta.url});87 [minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);88 });89 });9091 // TODO combine all minting tests in one place92 [93 'substrate' as const,94 'ethereum' as const,95 ].map(testCase => {96 itEth(`Can perform mintCross() for ${testCase} address`, async ({helper}) => {97 const collectionAdmin = await helper.eth.createAccountWithBalance(donor);9899 const receiverEth = helper.eth.createAccount();100 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);101 const receiverSub = bob;102 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);103104 // const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);105 const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });106 const permissions: ITokenPropertyPermission[] = properties107 .map(p => {108 return {109 key: p.key, permission: {110 tokenOwner: false,111 collectionAdmin: true,112 mutable: false,113 },114 };115 });116117 const collection = await helper.nft.mintCollection(minter, {118 tokenPrefix: 'ethp',119 tokenPropertyPermissions: permissions,120 });121 await collection.addAdmin(minter, {Ethereum: collectionAdmin});122123 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);124 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', collectionAdmin, true);125 let expectedTokenId = await contract.methods.nextTokenId().call();126 let result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, []).send();127 let tokenId = result.events.Transfer.returnValues.tokenId;128 expect(tokenId).to.be.equal(expectedTokenId);129130 let event = result.events.Transfer;131 expect(event.address).to.be.equal(collectionAddress);132 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');133 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));134 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);135136 expectedTokenId = await contract.methods.nextTokenId().call();137 result = await contract.methods.mintCross(testCase === 'ethereum' ? receiverCrossEth : receiverCrossSub, properties).send();138 event = result.events.Transfer;139 expect(event.address).to.be.equal(collectionAddress);140 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');141 expect(event.returnValues.to).to.be.equal(testCase === 'ethereum' ? receiverEth : helper.address.substrateToEth(bob.address));142 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);143144 tokenId = result.events.Transfer.returnValues.tokenId;145146 expect(tokenId).to.be.equal(expectedTokenId);147148 expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties149 .map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));150151 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId))152 .to.deep.eq(testCase === 'ethereum' ? {Ethereum: receiverEth.toLowerCase()} : {Substrate: receiverSub.address});153 });154 });155156 itEth('Non-owner and non admin cannot mintCross', async ({helper}) => {157 const nonOwner = await helper.eth.createAccountWithBalance(donor);158 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);159160 const collection = await helper.nft.mintCollection(minter);161 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);162 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');163164 await expect(collectionEvm.methods.mintCross(nonOwnerCross, []).call({from: nonOwner}))165 .to.be.rejectedWith('PublicMintingNotAllowed');166 });167168 //TODO: CORE-302 add eth methods169 itEth.skip('Can perform mintBulk()', async ({helper}) => {170 const caller = await helper.eth.createAccountWithBalance(donor);171 const receiver = helper.eth.createAccount();172173 const collection = await helper.nft.mintCollection(minter);174 await collection.addAdmin(minter, {Ethereum: caller});175176 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);177 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);178 {179 const bulkSize = 3;180 const nextTokenId = await contract.methods.nextTokenId().call();181 expect(nextTokenId).to.be.equal('1');182 const result = await contract.methods.mintBulkWithTokenURI(183 receiver,184 Array.from({length: bulkSize}, (_, i) => (185 [+nextTokenId + i, `Test URI ${i}`]186 )),187 ).send({from: caller});188189 const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.tokenId - b.returnValues.tokenId);190 for (let i = 0; i < bulkSize; i++) {191 const event = events[i];192 expect(event.address).to.equal(collectionAddress);193 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');194 expect(event.returnValues.to).to.equal(receiver);195 expect(event.returnValues.tokenId).to.equal(`${+nextTokenId+i}`);196197 expect(await contract.methods.tokenURI(+nextTokenId + i).call()).to.be.equal(`Test URI ${i}`);198 }199 }200 });201202 itEth('Can perform burn()', async ({helper}) => {203 const caller = await helper.eth.createAccountWithBalance(donor);204205 const collection = await helper.nft.mintCollection(minter, {});206 const {tokenId} = await collection.mintToken(minter, {Ethereum: caller});207208 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);209 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', caller);210211 {212 const result = await contract.methods.burn(tokenId).send({from: caller});213214 const event = result.events.Transfer;215 expect(event.address).to.be.equal(collectionAddress);216 expect(event.returnValues.from).to.be.equal(caller);217 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');218 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);219 }220 });221222 itEth('Can perform approve()', async ({helper}) => {223 const owner = await helper.eth.createAccountWithBalance(donor);224 const spender = helper.eth.createAccount();225226 const collection = await helper.nft.mintCollection(minter, {});227 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});228229 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);230 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);231232 {233 const badTokenId = await contract.methods.nextTokenId().call() + 1;234 await expect(contract.methods.getApproved(badTokenId).call()).to.be.rejectedWith('revert TokenNotFound');235 }236 {237 const approved = await contract.methods.getApproved(tokenId).call();238 expect(approved).to.be.equal('0x0000000000000000000000000000000000000000');239 }240 {241 const result = await contract.methods.approve(spender, tokenId).send({from: owner});242243 const event = result.events.Approval;244 expect(event.address).to.be.equal(collectionAddress);245 expect(event.returnValues.owner).to.be.equal(owner);246 expect(event.returnValues.approved).to.be.equal(spender);247 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);248 }249 {250 const approved = await contract.methods.getApproved(tokenId).call();251 expect(approved).to.be.equal(spender);252 }253 });254255 itEth('Can perform setApprovalForAll()', async ({helper}) => {256 const owner = await helper.eth.createAccountWithBalance(donor);257 const operator = helper.eth.createAccount();258259 const collection = await helper.nft.mintCollection(minter, {});260261 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);262 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);263264 const approvedBefore = await contract.methods.isApprovedForAll(owner, operator).call();265 expect(approvedBefore).to.be.equal(false);266267 {268 const result = await contract.methods.setApprovalForAll(operator, true).send({from: owner});269270 expect(result.events.ApprovalForAll).to.be.like({271 address: collectionAddress,272 event: 'ApprovalForAll',273 returnValues: {274 owner,275 operator,276 approved: true,277 },278 });279280 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();281 expect(approvedAfter).to.be.equal(true);282 }283284 {285 const result = await contract.methods.setApprovalForAll(operator, false).send({from: owner});286287 expect(result.events.ApprovalForAll).to.be.like({288 address: collectionAddress,289 event: 'ApprovalForAll',290 returnValues: {291 owner,292 operator,293 approved: false,294 },295 });296297 const approvedAfter = await contract.methods.isApprovedForAll(owner, operator).call();298 expect(approvedAfter).to.be.equal(false);299 }300 });301302 itEth('Can perform burn with ApprovalForAll', async ({helper}) => {303 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});304305 const owner = await helper.eth.createAccountWithBalance(donor);306 const operator = await helper.eth.createAccountWithBalance(donor, 100n);307308 const token = await collection.mintToken(minter, {Ethereum: owner});309310 const address = helper.ethAddress.fromCollectionId(collection.collectionId);311 const contract = await helper.ethNativeContract.collection(address, 'nft');312313 {314 await contract.methods.setApprovalForAll(operator, true).send({from: owner});315 const ownerCross = helper.ethCrossAccount.fromAddress(owner);316 const result = await contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: operator});317 const events = result.events.Transfer;318319 expect(events).to.be.like({320 address,321 event: 'Transfer',322 returnValues: {323 from: owner,324 to: '0x0000000000000000000000000000000000000000',325 tokenId: token.tokenId.toString(),326 },327 });328 }329330 expect(await helper.nft.doesTokenExist(collection.collectionId, token.tokenId)).to.be.false;331 });332333 itEth('Can perform transfer with ApprovalForAll', async ({helper}) => {334 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});335336 const owner = await helper.eth.createAccountWithBalance(donor);337 const operator = await helper.eth.createAccountWithBalance(donor);338 const receiver = charlie;339340 const token = await collection.mintToken(minter, {Ethereum: owner});341342 const address = helper.ethAddress.fromCollectionId(collection.collectionId);343 const contract = await helper.ethNativeContract.collection(address, 'nft');344345 {346 await contract.methods.setApprovalForAll(operator, true).send({from: owner});347 const ownerCross = helper.ethCrossAccount.fromAddress(owner);348 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);349 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: operator});350 const event = result.events.Transfer;351 expect(event).to.be.like({352 address: helper.ethAddress.fromCollectionId(collection.collectionId),353 event: 'Transfer',354 returnValues: {355 from: owner,356 to: helper.address.substrateToEth(receiver.address),357 tokenId: token.tokenId.toString(),358 },359 });360 }361362 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});363 });364365 itEth('Can perform burnFromCross()', async ({helper}) => {366 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});367 const ownerSub = bob;368 const ownerCrossSub = helper.ethCrossAccount.fromKeyringPair(ownerSub);369 const ownerEth = await helper.eth.createAccountWithBalance(donor, 100n);370 const ownerCrossEth = helper.ethCrossAccount.fromAddress(ownerEth);371372 const burnerEth = await helper.eth.createAccountWithBalance(donor, 100n);373 const burnerCrossEth = helper.ethCrossAccount.fromAddress(burnerEth);374375 const token1 = await collection.mintToken(minter, {Substrate: ownerSub.address});376 const token2 = await collection.mintToken(minter, {Ethereum: ownerEth});377378 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);379 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft');380381 // Approve tokens from substrate and ethereum:382 await token1.approve(ownerSub, {Ethereum: burnerEth});383 await collectionEvm.methods.approveCross(burnerCrossEth, token2.tokenId).send({from: ownerEth});384385 // can burnFromCross:386 const result1 = await collectionEvm.methods.burnFromCross(ownerCrossSub, token1.tokenId).send({from: burnerEth});387 const result2 = await collectionEvm.methods.burnFromCross(ownerCrossEth, token2.tokenId).send({from: burnerEth});388 const events1 = result1.events.Transfer;389 const events2 = result2.events.Transfer;390391 // Check events for burnFromCross (substrate and ethereum):392 [393 [events1, token1, helper.address.substrateToEth(ownerSub.address)],394 [events2, token2, ownerEth],395 ].map(burnData => {396 expect(burnData[0]).to.be.like({397 address: collectionAddress,398 event: 'Transfer',399 returnValues: {400 from: burnData[2],401 to: '0x0000000000000000000000000000000000000000',402 tokenId: burnData[1].tokenId.toString(),403 },404 });405 });406407 expect(await token1.doesExist()).to.be.false;408 expect(await token2.doesExist()).to.be.false;409 });410411 // TODO combine all approve tests in one place412 itEth('Can perform approveCross()', async ({helper}) => {413 // arrange: create accounts414 const owner = await helper.eth.createAccountWithBalance(donor, 100n);415 const ownerCross = helper.ethCrossAccount.fromAddress(owner);416 const receiverSub = charlie;417 const recieverCrossSub = helper.ethCrossAccount.fromKeyringPair(receiverSub);418 const receiverEth = await helper.eth.createAccountWithBalance(donor, 100n);419 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);420421 // arrange: create collection and tokens:422 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});423 const token1 = await collection.mintToken(minter, {Ethereum: owner});424 const token2 = await collection.mintToken(minter, {Ethereum: owner});425426 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');427428 // Can approveCross substrate and ethereum address:429 const resultSub = await collectionEvm.methods.approveCross(recieverCrossSub, token1.tokenId).send({from: owner});430 const resultEth = await collectionEvm.methods.approveCross(receiverCrossEth, token2.tokenId).send({from: owner});431 const eventSub = resultSub.events.Approval;432 const eventEth = resultEth.events.Approval;433 expect(eventSub).to.be.like({434 address: helper.ethAddress.fromCollectionId(collection.collectionId),435 event: 'Approval',436 returnValues: {437 owner,438 approved: helper.address.substrateToEth(receiverSub.address),439 tokenId: token1.tokenId.toString(),440 },441 });442 expect(eventEth).to.be.like({443 address: helper.ethAddress.fromCollectionId(collection.collectionId),444 event: 'Approval',445 returnValues: {446 owner,447 approved: receiverEth,448 tokenId: token2.tokenId.toString(),449 },450 });451452 // Substrate address can transferFrom approved tokens:453 await helper.nft.transferTokenFrom(receiverSub, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiverSub.address});454 expect(await helper.nft.getTokenOwner(collection.collectionId, token1.tokenId)).to.deep.eq({Substrate: receiverSub.address});455 // Ethereum address can transferFromCross approved tokens:456 await collectionEvm.methods.transferFromCross(ownerCross, receiverCrossEth, token2.tokenId).send({from: receiverEth});457 expect(await helper.nft.getTokenOwner(collection.collectionId, token2.tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});458 });459460 itEth('Non-owner and non admin cannot approveCross', async ({helper}) => {461 const nonOwner = await helper.eth.createAccountWithBalance(donor);462 const nonOwnerCross = helper.ethCrossAccount.fromAddress(nonOwner);463 const owner = await helper.eth.createAccountWithBalance(donor);464 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});465 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');466 const token = await collection.mintToken(minter, {Ethereum: owner});467468 await expect(collectionEvm.methods.approveCross(nonOwnerCross, token.tokenId).call({from: nonOwner})).to.be.rejectedWith('CantApproveMoreThanOwned');469 });470471 itEth('Can reaffirm approved address', async ({helper}) => {472 const owner = await helper.eth.createAccountWithBalance(donor, 100n);473 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);474 const [receiver1, receiver2] = await helper.arrange.createAccounts([100n, 100n], donor);475 const receiver1Cross = helper.ethCrossAccount.fromKeyringPair(receiver1);476 const receiver2Cross = helper.ethCrossAccount.fromKeyringPair(receiver2);477 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});478 const token1 = await collection.mintToken(minter, {Ethereum: owner});479 const token2 = await collection.mintToken(minter, {Ethereum: owner});480 const collectionEvm = await helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');481482 // Can approve and reaffirm approved address:483 await collectionEvm.methods.approveCross(receiver1Cross, token1.tokenId).send({from: owner});484 await collectionEvm.methods.approveCross(receiver2Cross, token1.tokenId).send({from: owner});485486 // receiver1 cannot transferFrom:487 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;488 // receiver2 can transferFrom:489 await helper.nft.transferTokenFrom(receiver2, collection.collectionId, token1.tokenId, {Ethereum: owner}, {Substrate: receiver2.address});490491 // can set approved address to self address to remove approval:492 await collectionEvm.methods.approveCross(receiver1Cross, token2.tokenId).send({from: owner});493 await collectionEvm.methods.approveCross(ownerCrossEth, token2.tokenId).send({from: owner});494495 // receiver1 cannot transfer token anymore:496 await expect(helper.nft.transferTokenFrom(receiver1, collection.collectionId, token2.tokenId, {Ethereum: owner}, {Substrate: receiver1.address})).to.be.rejected;497 });498499 itEth('Can perform transferFrom()', async ({helper}) => {500 const owner = await helper.eth.createAccountWithBalance(donor);501 const spender = await helper.eth.createAccountWithBalance(donor);502 const receiver = helper.eth.createAccount();503504 const collection = await helper.nft.mintCollection(minter, {});505 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});506507 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);508 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);509510 await contract.methods.approve(spender, tokenId).send({from: owner});511512 {513 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});514515 const event = result.events.Transfer;516 expect(event.address).to.be.equal(collectionAddress);517 expect(event.returnValues.from).to.be.equal(owner);518 expect(event.returnValues.to).to.be.equal(receiver);519 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);520 }521522 {523 const balance = await contract.methods.balanceOf(receiver).call();524 expect(+balance).to.equal(1);525 }526527 {528 const balance = await contract.methods.balanceOf(owner).call();529 expect(+balance).to.equal(0);530 }531 });532533 itEth('Can perform transferFromCross()', async ({helper}) => {534 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});535536 const [owner, receiver] = await helper.arrange.createAccounts([100n, 100n], donor);537 const spender = await helper.eth.createAccountWithBalance(donor);538539 const token = await collection.mintToken(minter, {Substrate: owner.address});540541 const address = helper.ethAddress.fromCollectionId(collection.collectionId);542 const contract = await helper.ethNativeContract.collection(address, 'nft');543544 await token.approve(owner, {Ethereum: spender});545546 {547 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);548 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);549 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});550 const event = result.events.Transfer;551 expect(event).to.be.like({552 address: helper.ethAddress.fromCollectionId(collection.collectionId),553 event: 'Transfer',554 returnValues: {555 from: helper.address.substrateToEth(owner.address),556 to: helper.address.substrateToEth(receiver.address),557 tokenId: token.tokenId.toString(),558 },559 });560 }561562 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});563 });564565 itEth('Can perform transfer()', async ({helper}) => {566 const collection = await helper.nft.mintCollection(minter, {});567 const owner = await helper.eth.createAccountWithBalance(donor);568 const receiver = helper.eth.createAccount();569570 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});571572 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);573 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);574575 {576 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});577578 const event = result.events.Transfer;579 expect(event.address).to.be.equal(collectionAddress);580 expect(event.returnValues.from).to.be.equal(owner);581 expect(event.returnValues.to).to.be.equal(receiver);582 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);583 }584585 {586 const balance = await contract.methods.balanceOf(owner).call();587 expect(+balance).to.equal(0);588 }589590 {591 const balance = await contract.methods.balanceOf(receiver).call();592 expect(+balance).to.equal(1);593 }594 });595596 itEth('Can perform transferCross()', async ({helper}) => {597 const collection = await helper.nft.mintCollection(minter, {});598 const owner = await helper.eth.createAccountWithBalance(donor);599 const receiverEth = await helper.eth.createAccountWithBalance(donor);600 const receiverCrossEth = helper.ethCrossAccount.fromAddress(receiverEth);601 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);602603 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner});604605 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);606 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);607608 {609 // Can transferCross to ethereum address:610 const result = await collectionEvm.methods.transferCross(receiverCrossEth, tokenId).send({from: owner});611 // Check events:612 const event = result.events.Transfer;613 expect(event.address).to.be.equal(collectionAddress);614 expect(event.returnValues.from).to.be.equal(owner);615 expect(event.returnValues.to).to.be.equal(receiverEth);616 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);617618 // owner has balance = 0:619 const ownerBalance = await collectionEvm.methods.balanceOf(owner).call();620 expect(+ownerBalance).to.equal(0);621 // receiver owns token:622 const receiverBalance = await collectionEvm.methods.balanceOf(receiverEth).call();623 expect(+receiverBalance).to.equal(1);624 expect(await helper.nft.getTokenOwner(collection.collectionId, tokenId)).to.deep.eq({Ethereum: receiverEth.toLowerCase()});625 }626627 {628 // Can transferCross to substrate address:629 const substrateResult = await collectionEvm.methods.transferCross(receiverCrossSub, tokenId).send({from: receiverEth});630 // Check events:631 const event = substrateResult.events.Transfer;632 expect(event.address).to.be.equal(collectionAddress);633 expect(event.returnValues.from).to.be.equal(receiverEth);634 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(minter.address));635 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);636637 // owner has balance = 0:638 const ownerBalance = await collectionEvm.methods.balanceOf(receiverEth).call();639 expect(+ownerBalance).to.equal(0);640 // receiver owns token:641 const receiverBalance = await helper.nft.getTokensByAddress(collection.collectionId, {Substrate: minter.address});642 expect(receiverBalance).to.contain(tokenId);643 }644 });645646 ['transfer', 'transferCross'].map(testCase => itEth(`Cannot ${testCase} non-owned token`, async ({helper}) => {647 const sender = await helper.eth.createAccountWithBalance(donor);648 const tokenOwner = await helper.eth.createAccountWithBalance(donor);649 const receiverSub = minter;650 const receiverCrossSub = helper.ethCrossAccount.fromKeyringPair(minter);651652 const collection = await helper.nft.mintCollection(minter, {});653 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);654 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', sender);655656 await collection.mintToken(minter, {Ethereum: sender});657 const nonSendersToken = await collection.mintToken(minter, {Ethereum: tokenOwner});658659 // Cannot transferCross someone else's token:660 const receiver = testCase === 'transfer' ? helper.address.substrateToEth(receiverSub.address) : receiverCrossSub;661 await expect(collectionEvm.methods[testCase](receiver, nonSendersToken.tokenId).send({from: sender})).to.be.rejected;662 // Cannot transfer token if it does not exist:663 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;664 }));665666 itEth('Check crossBalanceOf()', async ({helper}) => {667 const collection = await helper.nft.mintCollection(minter, {});668 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);669 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);670 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);671672 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === 0n).to.be.true;673674 for (let i = 1n; i < 100n; i++) {675 await collection.mintToken(minter, {Ethereum: owner.eth});676 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === i).to.be.true;677 }678 });679680 itEth('Check crossOwnerOf()', async ({helper}) => {681 const collection = await helper.nft.mintCollection(minter, {});682 let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);683 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);684 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);685 const {tokenId} = await collection.mintToken(minter, {Ethereum: owner.eth});686687 for (let i = 1n; i < 100n; i++) {688 const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});689 expect(ownerCross.eth).to.be.eq(owner.eth);690 expect(ownerCross.sub).to.be.eq(owner.sub);691692 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);693 await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});694 owner = newOwner;695 }696 });697});698699describe('NFT: Fees', () => {700 let donor: IKeyringPair;701 let alice: IKeyringPair;702 let bob: IKeyringPair;703 let charlie: IKeyringPair;704705 before(async function() {706 await usingEthPlaygrounds(async (helper, privateKey) => {707 donor = await privateKey({url: import.meta.url});708 [alice, bob, charlie] = await helper.arrange.createAccounts([10n, 10n, 10n], donor);709 });710 });711712 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {713 const owner = await helper.eth.createAccountWithBalance(donor);714 const spender = helper.eth.createAccount();715716 const collection = await helper.nft.mintCollection(alice, {});717 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});718719 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);720721 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));722 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));723 });724725 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {726 const owner = await helper.eth.createAccountWithBalance(donor);727 const spender = await helper.eth.createAccountWithBalance(donor);728729 const collection = await helper.nft.mintCollection(alice, {});730 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});731732 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);733734 await contract.methods.approve(spender, tokenId).send({from: owner});735736 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));737 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));738 });739740 itEth('Can perform transferFromCross()', async ({helper}) => {741 const collectionMinter = alice;742 const owner = bob;743 const receiver = charlie;744 const collection = await helper.nft.mintCollection(collectionMinter, {name: 'A', description: 'B', tokenPrefix: 'C'});745746 const spender = await helper.eth.createAccountWithBalance(donor, 100n);747748 const token = await collection.mintToken(collectionMinter, {Substrate: owner.address});749750 const address = helper.ethAddress.fromCollectionId(collection.collectionId);751 const contract = await helper.ethNativeContract.collection(address, 'nft');752753 await token.approve(owner, {Ethereum: spender});754755 {756 const ownerCross = helper.ethCrossAccount.fromKeyringPair(owner);757 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);758 const result = await contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender});759 const event = result.events.Transfer;760 expect(event).to.be.like({761 address: helper.ethAddress.fromCollectionId(collection.collectionId),762 event: 'Transfer',763 returnValues: {764 from: helper.address.substrateToEth(owner.address),765 to: helper.address.substrateToEth(receiver.address),766 tokenId: token.tokenId.toString(),767 },768 });769 }770771 expect(await token.getOwner()).to.be.like({Substrate: receiver.address});772 });773774 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {775 const owner = await helper.eth.createAccountWithBalance(donor);776 const receiver = helper.eth.createAccount();777778 const collection = await helper.nft.mintCollection(alice, {});779 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});780781 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);782783 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));784 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));785 });786});787788describe('NFT: Substrate calls', () => {789 let donor: IKeyringPair;790 let alice: IKeyringPair;791792 before(async function() {793 await usingEthPlaygrounds(async (helper, privateKey) => {794 donor = await privateKey({url: import.meta.url});795 [alice] = await helper.arrange.createAccounts([20n], donor);796 });797 });798799 itEth('Events emitted for mint()', async ({helper}) => {800 const collection = await helper.nft.mintCollection(alice, {});801 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);802 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');803804 const events: any = [];805 contract.events.allEvents((_: any, event: any) => {806 events.push(event);807 });808809 const {tokenId} = await collection.mintToken(alice);810 if (events.length == 0) await helper.wait.newBlocks(1);811 const event = events[0];812813 expect(event.event).to.be.equal('Transfer');814 expect(event.address).to.be.equal(collectionAddress);815 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');816 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));817 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());818 });819820 itEth('Events emitted for burn()', async ({helper}) => {821 const collection = await helper.nft.mintCollection(alice, {});822 const token = await collection.mintToken(alice);823824 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);825 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');826827 const events: any = [];828 contract.events.allEvents((_: any, event: any) => {829 events.push(event);830 });831832 await token.burn(alice);833 if (events.length == 0) await helper.wait.newBlocks(1);834 const event = events[0];835836 expect(event.event).to.be.equal('Transfer');837 expect(event.address).to.be.equal(collectionAddress);838 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));839 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');840 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());841 });842843 itEth('Events emitted for approve()', async ({helper}) => {844 const receiver = helper.eth.createAccount();845846 const collection = await helper.nft.mintCollection(alice, {});847 const token = await collection.mintToken(alice);848849 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);850 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');851852 const events: any = [];853 contract.events.allEvents((_: any, event: any) => {854 events.push(event);855 });856857 await token.approve(alice, {Ethereum: receiver});858 if (events.length == 0) await helper.wait.newBlocks(1);859 const event = events[0];860861 expect(event.event).to.be.equal('Approval');862 expect(event.address).to.be.equal(collectionAddress);863 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));864 expect(event.returnValues.approved).to.be.equal(receiver);865 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());866 });867868 itEth('Events emitted for transferFrom()', async ({helper}) => {869 const [bob] = await helper.arrange.createAccounts([10n], donor);870 const receiver = helper.eth.createAccount();871872 const collection = await helper.nft.mintCollection(alice, {});873 const token = await collection.mintToken(alice);874 await token.approve(alice, {Substrate: bob.address});875876 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);877 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');878879 const events: any = [];880 contract.events.allEvents((_: any, event: any) => {881 events.push(event);882 });883884 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});885886 if (events.length == 0) await helper.wait.newBlocks(1);887 const event = events[0];888889 expect(event.address).to.be.equal(collectionAddress);890 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));891 expect(event.returnValues.to).to.be.equal(receiver);892 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);893 });894895 itEth('Events emitted for transfer()', async ({helper}) => {896 const receiver = helper.eth.createAccount();897898 const collection = await helper.nft.mintCollection(alice, {});899 const token = await collection.mintToken(alice);900901 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);902 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft');903904 const events: any = [];905 contract.events.allEvents((_: any, event: any) => {906 events.push(event);907 });908909 await token.transfer(alice, {Ethereum: receiver});910911 if (events.length == 0) await helper.wait.newBlocks(1);912 const event = events[0];913914 expect(event.address).to.be.equal(collectionAddress);915 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));916 expect(event.returnValues.to).to.be.equal(receiver);917 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);918 });919});920921describe('Common metadata', () => {922 let donor: IKeyringPair;923 let alice: IKeyringPair;924925 before(async function() {926 await usingEthPlaygrounds(async (helper, privateKey) => {927 donor = await privateKey({url: import.meta.url});928 [alice] = await helper.arrange.createAccounts([20n], donor);929 });930 });931932 itEth('Returns collection name', async ({helper}) => {933 const caller = await helper.eth.createAccountWithBalance(donor);934 const tokenPropertyPermissions = [{935 key: 'URI',936 permission: {937 mutable: true,938 collectionAdmin: true,939 tokenOwner: false,940 },941 }];942 const collection = await helper.nft.mintCollection(943 alice,944 {945 name: 'oh River',946 tokenPrefix: 'CHANGE',947 properties: [{key: 'ERC721Metadata', value: '1'}],948 tokenPropertyPermissions,949 },950 );951952 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);953 const name = await contract.methods.name().call();954 expect(name).to.equal('oh River');955 });956957 itEth('Returns symbol name', async ({helper}) => {958 const caller = await helper.eth.createAccountWithBalance(donor);959 const tokenPropertyPermissions = [{960 key: 'URI',961 permission: {962 mutable: true,963 collectionAdmin: true,964 tokenOwner: false,965 },966 }];967 const collection = await helper.nft.mintCollection(968 alice,969 {970 name: 'oh River',971 tokenPrefix: 'CHANGE',972 properties: [{key: 'ERC721Metadata', value: '1'}],973 tokenPropertyPermissions,974 },975 );976977 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);978 const symbol = await contract.methods.symbol().call();979 expect(symbol).to.equal('CHANGE');980 });981});982983describe('Negative tests', () => {984 let donor: IKeyringPair;985 let minter: IKeyringPair;986 let alice: IKeyringPair;987988 before(async function() {989 await usingEthPlaygrounds(async (helper, privateKey) => {990 donor = await privateKey({url: import.meta.url});991 [minter, alice] = await helper.arrange.createAccounts([100n, 100n], donor);992 });993 });994995 itEth('[negative] Cant perform burn without approval', async ({helper}) => {996 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});997998 const owner = await helper.eth.createAccountWithBalance(donor, 100n);999 const spender = await helper.eth.createAccountWithBalance(donor, 100n);10001001 const token = await collection.mintToken(minter, {Ethereum: owner});10021003 const address = helper.ethAddress.fromCollectionId(collection.collectionId);1004 const contract = await helper.ethNativeContract.collection(address, 'nft');10051006 const ownerCross = helper.ethCrossAccount.fromAddress(owner);1007 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;10081009 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1010 await contract.methods.setApprovalForAll(spender, false).send({from: owner});10111012 await expect(contract.methods.burnFromCross(ownerCross, token.tokenId).send({from: spender})).to.be.rejected;1013 });10141015 itEth('[negative] Cant perform transfer without approval', async ({helper}) => {1016 const collection = await helper.nft.mintCollection(minter, {name: 'A', description: 'B', tokenPrefix: 'C'});1017 const receiver = alice;10181019 const owner = await helper.eth.createAccountWithBalance(donor, 100n);1020 const spender = await helper.eth.createAccountWithBalance(donor, 100n);10211022 const token = await collection.mintToken(minter, {Ethereum: owner});10231024 const address = helper.ethAddress.fromCollectionId(collection.collectionId);1025 const contract = await helper.ethNativeContract.collection(address, 'nft');10261027 const ownerCross = helper.ethCrossAccount.fromAddress(owner);1028 const recieverCross = helper.ethCrossAccount.fromKeyringPair(receiver);10291030 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;10311032 await contract.methods.setApprovalForAll(spender, true).send({from: owner});1033 await contract.methods.setApprovalForAll(spender, false).send({from: owner});10341035 await expect(contract.methods.transferFromCross(ownerCross, recieverCross, token.tokenId).send({from: spender})).to.be.rejected;1036 });1037});tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -584,6 +584,46 @@
expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
expect(event.returnValues.tokenId).to.equal(tokenId.toString());
});
+
+ itEth('Check crossBalanceOf()', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(minter, {});
+ const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
+
+ expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === 0n).to.be.true;
+
+ for (let i = 1n; i < 100n; i++) {
+ await collection.mintToken(minter, 100n, {Ethereum: owner.eth});
+ expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === i).to.be.true;
+ }
+ });
+
+ itEth.only('Check crossOwnerOf()', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(minter, {});
+ let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
+ const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});
+
+ for (let i = 1n; i < 100n; i++) {
+ const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});
+ expect(ownerCross.eth).to.be.eq(owner.eth);
+ expect(ownerCross.sub).to.be.eq(owner.sub);
+
+ const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});
+ owner = newOwner;
+ }
+
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);
+ const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});
+ const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});
+ expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
+ expect(ownerCross.sub).to.be.eq('0');
+ });
});
describe('RFT: Fees', () => {