difftreelog
feat add crossBalanceOf
in: master
11 files changed
pallets/nonfungible/src/erc.rsdiffbeforeafterboth755 .map_err(|_| Error::Revert("token not found".into()))755 .map_err(|_| Error::Revert("token not found".into()))756 }756 }757758 /// @notice Count all NFTs assigned to an owner759 /// @dev NFTs assigned to the zero address are considered invalid, and this760 /// function throws for queries about the zero address.761 /// @param owner An cross address for whom to query the balance762 /// @return The number of NFTs owned by `owner`, possibly zero763 fn cross_balance_of(&self, owner: eth::CrossAddress) -> Result<U256> {764 self.consume_store_reads(1)?;765 let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));766 Ok(balance.into())767 }757768758 /// Returns the token properties.769 /// Returns the token properties.759 ///770 ///pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth774}774}775775776/// @title Unique extensions for ERC721.776/// @title Unique extensions for ERC721.777/// @dev the ERC-165 identifier for this interface is 0x16de3152777/// @dev the ERC-165 identifier for this interface is 0x323b1db8778contract ERC721UniqueExtensions is Dummy, ERC165 {778contract ERC721UniqueExtensions is Dummy, ERC165 {779 /// @notice A descriptive name for a collection of NFTs in this contract779 /// @notice A descriptive name for a collection of NFTs in this contract780 /// @dev EVM selector for this function is: 0x06fdde03,780 /// @dev EVM selector for this function is: 0x06fdde03,815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);816 }816 }817818 /// @notice Count all NFTs assigned to an owner819 /// @dev NFTs assigned to the zero address are considered invalid, and this820 /// function throws for queries about the zero address.821 /// @param owner An cross address for whom to query the balance822 /// @return The number of NFTs owned by `owner`, possibly zero823 /// @dev EVM selector for this function is: 0x24e52cea,824 /// or in textual repr: crossBalanceOf((address,uint256))825 function crossBalanceOf(CrossAddress memory owner) public view returns (uint256) {826 require(false, stub_error);827 owner;828 dummy;829 return 0;830 }817831818 /// Returns the token properties.832 /// Returns the token properties.819 ///833 ///pallets/refungible/src/erc.rsdiffbeforeafterboth794 })794 })795 }795 }796797 /// @notice Count all RFTs assigned to an owner798 /// @dev RFTs assigned to the zero address are considered invalid, and this799 /// function throws for queries about the zero address.800 /// @param owner An cross address for whom to query the balance801 /// @return The number of RFTs owned by `owner`, possibly zero802 fn cross_balance_of(&self, owner: eth::CrossAddress) -> Result<U256> {803 self.consume_store_reads(1)?;804 let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));805 Ok(balance.into())806 }796807797 /// Returns the token properties.808 /// Returns the token properties.798 ///809 ///pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth774}774}775775776/// @title Unique extensions for ERC721.776/// @title Unique extensions for ERC721.777/// @dev the ERC-165 identifier for this interface is 0xb365c124777/// @dev the ERC-165 identifier for this interface is 0x9780edce778contract ERC721UniqueExtensions is Dummy, ERC165 {778contract ERC721UniqueExtensions is Dummy, ERC165 {779 /// @notice A descriptive name for a collection of NFTs in this contract779 /// @notice A descriptive name for a collection of NFTs in this contract780 /// @dev EVM selector for this function is: 0x06fdde03,780 /// @dev EVM selector for this function is: 0x06fdde03,815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);815 return CrossAddress(0x0000000000000000000000000000000000000000, 0);816 }816 }817818 /// @notice Count all RFTs assigned to an owner819 /// @dev RFTs assigned to the zero address are considered invalid, and this820 /// function throws for queries about the zero address.821 /// @param owner An cross address for whom to query the balance822 /// @return The number of RFTs owned by `owner`, possibly zero823 /// @dev EVM selector for this function is: 0x24e52cea,824 /// or in textual repr: crossBalanceOf((address,uint256))825 function crossBalanceOf(CrossAddress memory owner) public view returns (uint256) {826 require(false, stub_error);827 owner;828 dummy;829 return 0;830 }817831818 /// Returns the token properties.832 /// Returns the token properties.819 ///833 ///runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth227 | Symbol227 | Symbol228 | Description228 | Description229 | CrossOwnerOf { .. }229 | CrossOwnerOf { .. }230 | CrossBalanceOf { .. }230 | Properties { .. }231 | Properties { .. }231 | NextTokenId232 | NextTokenId232 | TokenContractAddress { .. }233 | TokenContractAddress { .. }tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth384 "stateMutability": "view",384 "stateMutability": "view",385 "type": "function"385 "type": "function"386 },386 },387 {388 "inputs": [389 {390 "components": [391 { "internalType": "address", "name": "eth", "type": "address" },392 { "internalType": "uint256", "name": "sub", "type": "uint256" }393 ],394 "internalType": "struct CrossAddress",395 "name": "owner",396 "type": "tuple"397 }398 ],399 "name": "crossBalanceOf",400 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],401 "stateMutability": "view",402 "type": "function"403 },387 {404 {388 "inputs": [405 "inputs": [389 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }406 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth533}533}534534535/// @title Unique extensions for ERC721.535/// @title Unique extensions for ERC721.536/// @dev the ERC-165 identifier for this interface is 0x16de3152536/// @dev the ERC-165 identifier for this interface is 0x323b1db8537interface ERC721UniqueExtensions is Dummy, ERC165 {537interface ERC721UniqueExtensions is Dummy, ERC165 {538 /// @notice A descriptive name for a collection of NFTs in this contract538 /// @notice A descriptive name for a collection of NFTs in this contract539 /// @dev EVM selector for this function is: 0x06fdde03,539 /// @dev EVM selector for this function is: 0x06fdde03,557 /// or in textual repr: crossOwnerOf(uint256)557 /// or in textual repr: crossOwnerOf(uint256)558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);559560 /// @notice Count all NFTs assigned to an owner561 /// @dev NFTs assigned to the zero address are considered invalid, and this562 /// function throws for queries about the zero address.563 /// @param owner An cross address for whom to query the balance564 /// @return The number of NFTs owned by `owner`, possibly zero565 /// @dev EVM selector for this function is: 0x24e52cea,566 /// or in textual repr: crossBalanceOf((address,uint256))567 function crossBalanceOf(CrossAddress memory owner) external view returns (uint256);559568560 /// Returns the token properties.569 /// Returns the token properties.561 ///570 ///tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth533}533}534534535/// @title Unique extensions for ERC721.535/// @title Unique extensions for ERC721.536/// @dev the ERC-165 identifier for this interface is 0xb365c124536/// @dev the ERC-165 identifier for this interface is 0x9780edce537interface ERC721UniqueExtensions is Dummy, ERC165 {537interface ERC721UniqueExtensions is Dummy, ERC165 {538 /// @notice A descriptive name for a collection of NFTs in this contract538 /// @notice A descriptive name for a collection of NFTs in this contract539 /// @dev EVM selector for this function is: 0x06fdde03,539 /// @dev EVM selector for this function is: 0x06fdde03,557 /// or in textual repr: crossOwnerOf(uint256)557 /// or in textual repr: crossOwnerOf(uint256)558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);558 function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);559560 /// @notice Count all RFTs assigned to an owner561 /// @dev RFTs assigned to the zero address are considered invalid, and this562 /// function throws for queries about the zero address.563 /// @param owner An cross address for whom to query the balance564 /// @return The number of RFTs owned by `owner`, possibly zero565 /// @dev EVM selector for this function is: 0x24e52cea,566 /// or in textual repr: crossBalanceOf((address,uint256))567 function crossBalanceOf(CrossAddress memory owner) external view returns (uint256);559568560 /// Returns the token properties.569 /// Returns the token properties.561 ///570 ///tests/src/eth/nonFungible.test.tsdiffbeforeafterboth663 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;663 await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;664 }));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 });665});697});666698667describe('NFT: Fees', () => {699describe('NFT: Fees', () => {tests/src/eth/reFungible.test.tsdiffbeforeafterboth585 expect(event.returnValues.tokenId).to.equal(tokenId.toString());585 expect(event.returnValues.tokenId).to.equal(tokenId.toString());586 });586 });587588 itEth('Check crossBalanceOf()', async ({helper}) => {589 const collection = await helper.rft.mintCollection(minter, {});590 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);591 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);592 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);593594 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === 0n).to.be.true;595596 for (let i = 1n; i < 100n; i++) {597 await collection.mintToken(minter, 100n, {Ethereum: owner.eth});598 expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === i).to.be.true;599 }600 });601602 itEth.only('Check crossOwnerOf()', async ({helper}) => {603 const collection = await helper.rft.mintCollection(minter, {});604 let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);605 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);606 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);607 const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});608609 for (let i = 1n; i < 100n; i++) {610 const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});611 expect(ownerCross.eth).to.be.eq(owner.eth);612 expect(ownerCross.sub).to.be.eq(owner.sub);613614 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);615 await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});616 owner = newOwner;617 }618619 const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);620 const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);621 const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);622 await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});623 const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});624 expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');625 expect(ownerCross.sub).to.be.eq('0');626 });587});627});588628589describe('RFT: Fees', () => {629describe('RFT: Fees', () => {