git.delta.rocks / unique-network / refs/commits / ab8fc135746e

difftreelog

Change prefixed names to postfixed

Trubnikov Sergey2023-04-17parent: #b77279f.patch.diff
in: master

14 files changed

modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -749,18 +749,24 @@
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
+	#[solidity(hide)]
 	fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {
+		Self::owner_of_cross(&self, token_id)
+	}
+
+	/// Returns the owner (in cross format) of the token.
+	///
+	/// @param tokenId Id for the token.
+	fn owner_of_cross(&self, token_id: U256) -> Result<eth::CrossAddress> {
 		Self::token_owner(&self, token_id.try_into()?)
 			.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
 			.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> {
+	fn balance_of_cross(&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())
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/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 0x323b1db8
+/// @dev the ERC-165 identifier for this interface is 0x307b061a
 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,
@@ -803,12 +803,24 @@
 		return "";
 	}
 
+	// /// Returns the owner (in cross format) of the token.
+	// ///
+	// /// @param tokenId Id for the token.
+	// /// @dev EVM selector for this function is: 0x2b29dace,
+	// ///  or in textual repr: crossOwnerOf(uint256)
+	// function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+	// 	require(false, stub_error);
+	// 	tokenId;
+	// 	dummy;
+	// 	return CrossAddress(0x0000000000000000000000000000000000000000,0);
+	// }
+
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
-	/// @dev EVM selector for this function is: 0x2b29dace,
-	///  or in textual repr: crossOwnerOf(uint256)
-	function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+	/// @dev EVM selector for this function is: 0xcaa3a4d0,
+	///  or in textual repr: ownerOfCross(uint256)
+	function ownerOfCross(uint256 tokenId) public view returns (CrossAddress memory) {
 		require(false, stub_error);
 		tokenId;
 		dummy;
@@ -816,13 +828,11 @@
 	}
 
 	/// @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) {
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
 		require(false, stub_error);
 		owner;
 		dummy;
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -783,7 +783,15 @@
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
+	#[solidity(hide)]
 	fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {
+		Self::owner_of_cross(&self, token_id)
+	}
+
+	/// Returns the owner (in cross format) of the token.
+	///
+	/// @param tokenId Id for the token.
+	fn owner_of_cross(&self, token_id: U256) -> Result<eth::CrossAddress> {
 		Self::token_owner(&self, token_id.try_into()?)
 			.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
 			.or_else(|err| match err {
@@ -795,11 +803,9 @@
 	}
 
 	/// @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> {
+	fn balance_of_cross(&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())
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/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 0x9780edce
+/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
 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,
@@ -803,12 +803,24 @@
 		return "";
 	}
 
+	// /// Returns the owner (in cross format) of the token.
+	// ///
+	// /// @param tokenId Id for the token.
+	// /// @dev EVM selector for this function is: 0x2b29dace,
+	// ///  or in textual repr: crossOwnerOf(uint256)
+	// function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+	// 	require(false, stub_error);
+	// 	tokenId;
+	// 	dummy;
+	// 	return CrossAddress(0x0000000000000000000000000000000000000000,0);
+	// }
+
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
-	/// @dev EVM selector for this function is: 0x2b29dace,
-	///  or in textual repr: crossOwnerOf(uint256)
-	function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+	/// @dev EVM selector for this function is: 0xcaa3a4d0,
+	///  or in textual repr: ownerOfCross(uint256)
+	function ownerOfCross(uint256 tokenId) public view returns (CrossAddress memory) {
 		require(false, stub_error);
 		tokenId;
 		dummy;
@@ -816,13 +828,11 @@
 	}
 
 	/// @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) {
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
 		require(false, stub_error);
 		owner;
 		dummy;
modifiedruntime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth
--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -227,7 +227,8 @@
 			| Symbol
 			| Description
 			| CrossOwnerOf { .. }
-			| CrossBalanceOf { .. }
+			| OwnerOfCross { .. }
+			| BalanceOfCross { .. }
 			| Properties { .. }
 			| NextTokenId
 			| TokenContractAddress { .. }
modifiedtests/src/eth/abi/nonFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -177,6 +177,23 @@
   },
   {
     "inputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "owner",
+        "type": "tuple"
+      }
+    ],
+    "name": "balanceOfCross",
+    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
     ],
     "name": "burn",
@@ -381,42 +398,6 @@
     "inputs": [],
     "name": "contractAddress",
     "outputs": [{ "internalType": "address", "name": "", "type": "address" }],
-    "stateMutability": "view",
-    "type": "function"
-  },
-  {
-    "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",
-    "outputs": [
-      {
-        "components": [
-          { "internalType": "address", "name": "eth", "type": "address" },
-          { "internalType": "uint256", "name": "sub", "type": "uint256" }
-        ],
-        "internalType": "struct CrossAddress",
-        "name": "",
-        "type": "tuple"
-      }
-    ],
     "stateMutability": "view",
     "type": "function"
   },
@@ -557,6 +538,25 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
+    ],
+    "name": "ownerOfCross",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "",
+        "type": "tuple"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
       { "internalType": "string[]", "name": "keys", "type": "string[]" }
     ],
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -159,6 +159,23 @@
   },
   {
     "inputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "owner",
+        "type": "tuple"
+      }
+    ],
+    "name": "balanceOfCross",
+    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
     ],
     "name": "burn",
@@ -368,25 +385,6 @@
   },
   {
     "inputs": [
-      { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
-    ],
-    "name": "crossOwnerOf",
-    "outputs": [
-      {
-        "components": [
-          { "internalType": "address", "name": "eth", "type": "address" },
-          { "internalType": "uint256", "name": "sub", "type": "uint256" }
-        ],
-        "internalType": "struct CrossAddress",
-        "name": "",
-        "type": "tuple"
-      }
-    ],
-    "stateMutability": "view",
-    "type": "function"
-  },
-  {
-    "inputs": [
       { "internalType": "string[]", "name": "keys", "type": "string[]" }
     ],
     "name": "deleteCollectionProperties",
@@ -522,6 +520,25 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
+    ],
+    "name": "ownerOfCross",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "",
+        "type": "tuple"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" },
       { "internalType": "string[]", "name": "keys", "type": "string[]" }
     ],
modifiedtests/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 0x323b1db8
+/// @dev the ERC-165 identifier for this interface is 0x307b061a
 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,
@@ -550,21 +550,26 @@
 	///  or in textual repr: description()
 	function description() external view returns (string memory);
 
+	// /// Returns the owner (in cross format) of the token.
+	// ///
+	// /// @param tokenId Id for the token.
+	// /// @dev EVM selector for this function is: 0x2b29dace,
+	// ///  or in textual repr: crossOwnerOf(uint256)
+	// function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
-	/// @dev EVM selector for this function is: 0x2b29dace,
-	///  or in textual repr: crossOwnerOf(uint256)
-	function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+	/// @dev EVM selector for this function is: 0xcaa3a4d0,
+	///  or in textual repr: ownerOfCross(uint256)
+	function ownerOfCross(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);
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
 
 	/// Returns the token properties.
 	///
modifiedtests/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 0x9780edce
+/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
 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,
@@ -550,21 +550,26 @@
 	///  or in textual repr: description()
 	function description() external view returns (string memory);
 
+	// /// Returns the owner (in cross format) of the token.
+	// ///
+	// /// @param tokenId Id for the token.
+	// /// @dev EVM selector for this function is: 0x2b29dace,
+	// ///  or in textual repr: crossOwnerOf(uint256)
+	// function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+
 	/// Returns the owner (in cross format) of the token.
 	///
 	/// @param tokenId Id for the token.
-	/// @dev EVM selector for this function is: 0x2b29dace,
-	///  or in textual repr: crossOwnerOf(uint256)
-	function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+	/// @dev EVM selector for this function is: 0xcaa3a4d0,
+	///  or in textual repr: ownerOfCross(uint256)
+	function ownerOfCross(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);
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
 
 	/// Returns the token properties.
 	///
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -663,21 +663,21 @@
     await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;
   }));
 
-  itEth('Check crossBalanceOf()', async ({helper}) => {
+  itEth('Check balanceOfCross()', async ({helper}) => {
     const collection = await helper.nft.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;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
 
     for (let i = 1n; i < 100n; i++) {
       await collection.mintToken(minter, {Ethereum: owner.eth});
-      expect(BigInt(await collectionEvm.methods.crossBalanceOf(owner).call({from: owner.eth})) === i).to.be.true;
+      expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === i).to.be.true;
     }
   });
 
-  itEth('Check crossOwnerOf()', async ({helper}) => {
+  itEth('Check ownerOfCross()', async ({helper}) => {
     const collection = await helper.nft.mintCollection(minter, {});
     let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
     const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
@@ -685,7 +685,7 @@
     const {tokenId} = await collection.mintToken(minter, {Ethereum: owner.eth});
 
     for (let i = 1n; i < 100n; i++) {
-      const ownerCross = await collectionEvm.methods.crossOwnerOf(tokenId).call({from: owner.eth});
+      const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});
       expect(ownerCross.eth).to.be.eq(owner.eth);
       expect(ownerCross.sub).to.be.eq(owner.sub);
 
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -591,15 +591,15 @@
     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;
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(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;
+      expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === i).to.be.true;
     }
   });
 
-  itEth.only('Check crossOwnerOf()', async ({helper}) => {
+  itEth('Check ownerOfCross()', async ({helper}) => {
     const collection = await helper.rft.mintCollection(minter, {});
     let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
     const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
@@ -607,7 +607,7 @@
     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});
+      const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});
       expect(ownerCross.eth).to.be.eq(owner.eth);
       expect(ownerCross.sub).to.be.eq(owner.sub);
 
@@ -620,7 +620,7 @@
     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});
+    const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});
     expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
     expect(ownerCross.sub).to.be.eq('0');
   });
modifiedtests/src/eth/tokens/minting.test.tsdiffbeforeafterboth
before · tests/src/eth/tokens/minting.test.ts
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 {IKeyringPair} from '@polkadot/types/types';18import {Pallets} from '../../util';19import {expect, itEth, usingEthPlaygrounds} from '../util';202122describe('Minting tokens', () => {23  let donor: IKeyringPair;24  let alice: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({url: import.meta.url});29      [alice] = await helper.arrange.createAccounts([30n, 20n], donor);30    });31  });3233  [34    {mode: 'nft' as const, requiredPallets: []},35    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},36    {mode: 'ft' as const, requiredPallets: []},37  ].map(testCase => {38    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {39      const owner = await helper.eth.createAccountWithBalance(donor);40      const receiver = helper.eth.createAccount();41      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];4243      const collection = await helper[testCase.mode].mintCollection(alice);44      await collection.addAdmin(alice, {Ethereum: owner});4546      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);47      const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);4849      const result = await contract.methods.mint(...mintingParams).send({from: owner});5051      // Check events:52      const event = result.events.Transfer;53      expect(event.address).to.equal(collectionAddress);54      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');55      expect(event.returnValues.to).to.equal(receiver);56      if (testCase.mode === 'ft')57        expect(event.returnValues.value).to.equal('100');5859      // Check token exist:60      if(testCase.mode === 'ft') {61        expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);62      } else {63        const tokenId = event.returnValues.tokenId;64        expect(tokenId).to.be.equal('1');65        expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);66        expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);67      }68    });69  });7071  [72    {mode: 'nft' as const, requiredPallets: []},73    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},74    {mode: 'ft' as const, requiredPallets: []},75  ].map(testCase => {76    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {77      const owner = await helper.eth.createAccountWithBalance(donor);78      const receiver = helper.eth.createAccount();79      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];8081      const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');8283      const result = await collection.methods.mint(...mintingParams).send({from: owner});8485      // Check events:86      const event = result.events.Transfer;87      expect(event.address).to.equal(collectionAddress);88      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');89      expect(event.returnValues.to).to.equal(receiver);90      if (testCase.mode === 'ft')91        expect(event.returnValues.value).to.equal('100');9293      // Check token exist:94      if(testCase.mode === 'ft') {95        expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);96      } else {97        const tokenId = event.returnValues.tokenId;98        expect(tokenId).to.be.equal('1');99        expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);100        expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);101      }102    });103  });104105  [106    {mode: 'nft' as const, requiredPallets: []},107    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},108    {mode: 'ft' as const, requiredPallets: []},109  ].map(testCase => {110    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {111      const owner = await helper.eth.createAccountWithBalance(donor);112      const receiver = helper.eth.createAccount();113      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];114115      const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');116117      const result = await collection.methods.mint(...mintingParams).send({from: owner});118119      // Check events:120      const event = result.events.Transfer;121      expect(event.address).to.equal(collectionAddress);122      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');123      expect(event.returnValues.to).to.equal(receiver);124      if (testCase.mode === 'ft')125        expect(event.returnValues.value).to.equal('100');126127      // Check token exist:128      if(testCase.mode === 'ft') {129        expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);130      } else {131        const tokenId = event.returnValues.tokenId;132        expect(tokenId).to.be.equal('1');133        expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);134        expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);135      }136    });137  });138139  [140    {mode: 'nft' as const, requiredPallets: []},141    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},142  ].map(testCase => {143    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {144      const owner = await helper.eth.createAccountWithBalance(donor);145      const receiver = helper.eth.createAccount();146147      const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');148      const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);149150      const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();151      const tokenId = result.events.Transfer.returnValues.tokenId;152      expect(tokenId).to.be.equal('1');153154      const event = result.events.Transfer;155      expect(event.address).to.be.equal(collectionAddress);156      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');157      expect(event.returnValues.to).to.be.equal(receiver);158159      expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');160      expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);161      // TODO: this wont work right now, need release 919000 first162      // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();163      // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();164      // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);165    });166  });167});
after · tests/src/eth/tokens/minting.test.ts
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 {IKeyringPair} from '@polkadot/types/types';18import {Pallets} from '../../util';19import {expect, itEth, usingEthPlaygrounds} from '../util';202122describe.only('Minting tokens', () => {23  let donor: IKeyringPair;24  let alice: IKeyringPair;2526  before(async function() {27    await usingEthPlaygrounds(async (helper, privateKey) => {28      donor = await privateKey({url: import.meta.url});29      [alice] = await helper.arrange.createAccounts([30n, 20n], donor);30    });31  });3233  [34    {mode: 'nft' as const, requiredPallets: []},35    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},36    {mode: 'ft' as const, requiredPallets: []},37  ].map(testCase => {38    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {39      const owner = await helper.eth.createAccountWithBalance(donor);40      const receiver = helper.eth.createAccount();41      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];4243      const collection = await helper[testCase.mode].mintCollection(alice);44      await collection.addAdmin(alice, {Ethereum: owner});4546      const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);47      const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);4849      const result = await contract.methods.mint(...mintingParams).send({from: owner});5051      // Check events:52      const event = result.events.Transfer;53      expect(event.address).to.equal(collectionAddress);54      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');55      expect(event.returnValues.to).to.equal(receiver);56      if (testCase.mode === 'ft')57        expect(event.returnValues.value).to.equal('100');5859      // Check token exist:60      if(testCase.mode === 'ft') {61        expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);62      } else {63        const tokenId = event.returnValues.tokenId;64        expect(tokenId).to.be.equal('1');65        expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);66        expect(await contract.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);67      }68    });69  });7071  [72    {mode: 'nft' as const, requiredPallets: []},73    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},74    {mode: 'ft' as const, requiredPallets: []},75  ].map(testCase => {76    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {77      const owner = await helper.eth.createAccountWithBalance(donor);78      const receiver = helper.eth.createAccount();79      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];8081      const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');8283      const result = await collection.methods.mint(...mintingParams).send({from: owner});8485      // Check events:86      const event = result.events.Transfer;87      expect(event.address).to.equal(collectionAddress);88      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');89      expect(event.returnValues.to).to.equal(receiver);90      if (testCase.mode === 'ft')91        expect(event.returnValues.value).to.equal('100');9293      // Check token exist:94      if(testCase.mode === 'ft') {95        expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);96      } else {97        const tokenId = event.returnValues.tokenId;98        expect(tokenId).to.be.equal('1');99        expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);100        expect(await collection.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);101      }102    });103  });104105  [106    {mode: 'nft' as const, requiredPallets: []},107    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},108    {mode: 'ft' as const, requiredPallets: []},109  ].map(testCase => {110    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {111      const owner = await helper.eth.createAccountWithBalance(donor);112      const receiver = helper.eth.createAccount();113      const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];114115      const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');116117      const result = await collection.methods.mint(...mintingParams).send({from: owner});118119      // Check events:120      const event = result.events.Transfer;121      expect(event.address).to.equal(collectionAddress);122      expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');123      expect(event.returnValues.to).to.equal(receiver);124      if (testCase.mode === 'ft')125        expect(event.returnValues.value).to.equal('100');126127      // Check token exist:128      if(testCase.mode === 'ft') {129        expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);130      } else {131        const tokenId = event.returnValues.tokenId;132        expect(tokenId).to.be.equal('1');133        expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);134        expect(await collection.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);135      }136    });137  });138139  [140    {mode: 'nft' as const, requiredPallets: []},141    {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},142  ].map(testCase => {143    itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {144      const owner = await helper.eth.createAccountWithBalance(donor);145      const receiver = helper.eth.createAccount();146147      const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');148      const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);149150      const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();151      const tokenId = result.events.Transfer.returnValues.tokenId;152      expect(tokenId).to.be.equal('1');153154      const event = result.events.Transfer;155      expect(event.address).to.be.equal(collectionAddress);156      expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');157      expect(event.returnValues.to).to.be.equal(receiver);158159      expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');160      expect(await contract.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);161      // TODO: this wont work right now, need release 919000 first162      // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();163      // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();164      // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);165    });166  });167});