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

difftreelog

feat balanceOfCross for fingible

Trubnikov Sergey2023-04-18parent: #ab8fc13.patch.diff
in: master

8 files changed

modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
328 Ok(T::ContractAddress::get())328 Ok(T::ContractAddress::get())
329 }329 }
330
331 /// @notice Balance of account
332 /// @param owner An cross address for whom to query the balance
333 /// @return The number of fingibles owned by `owner`, possibly zero
334 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
335 self.consume_store_reads(1)?;
336 let balance = <Balance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
337 Ok(balance.into())
338 }
330}339}
331340
332#[solidity_interface(341#[solidity_interface(
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -511,7 +511,7 @@
 	bytes value;
 }
 
-/// @dev the ERC-165 identifier for this interface is 0x85d7dea6
+/// @dev the ERC-165 identifier for this interface is 0x69d14d3e
 contract ERC20UniqueExtensions is Dummy, ERC165 {
 	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
 	/// @param owner crossAddress The address which owns the funds.
@@ -630,6 +630,18 @@
 		dummy;
 		return 0x0000000000000000000000000000000000000000;
 	}
+
+	/// @notice Balance of account
+	/// @param owner An cross address for whom to query the balance
+	/// @return The number of fingibles owned by `owner`, possibly zero
+	/// @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;
+		return 0;
+	}
 }
 
 struct AmountForAddress {
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/fungible.json
+++ b/tests/src/eth/abi/fungible.json
@@ -181,6 +181,23 @@
           { "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": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
         "name": "from",
         "type": "tuple"
       },
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -353,7 +353,7 @@
 	bytes value;
 }
 
-/// @dev the ERC-165 identifier for this interface is 0x85d7dea6
+/// @dev the ERC-165 identifier for this interface is 0x69d14d3e
 interface ERC20UniqueExtensions is Dummy, ERC165 {
 	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
 	/// @param owner crossAddress The address which owns the funds.
@@ -416,6 +416,13 @@
 	/// @dev EVM selector for this function is: 0x1896cce6,
 	///  or in textual repr: collectionHelperAddress()
 	function collectionHelperAddress() external view returns (address);
+
+	/// @notice Balance of account
+	/// @param owner An cross address for whom to query the balance
+	/// @return The number of fingibles owned by `owner`, possibly zero
+	/// @dev EVM selector for this function is: 0xec069398,
+	///  or in textual repr: balanceOfCross((address,uint256))
+	function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
 }
 
 struct AmountForAddress {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -427,6 +427,22 @@
     const toBalanceAfter = await collection.getBalance({Ethereum: receiver});
     expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);
   });
+
+  itEth('Check balanceOfCross()', async ({helper}) => {
+    const collection = await helper.ft.mintCollection(alice, {});
+    const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+    const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+    const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner.eth);
+
+    expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
+
+    let sum = 0n;
+    for (let i = 1n; i < 100n; i++) {
+      await collection.mint(alice, 100n, {Ethereum: owner.eth});
+      sum += 100n;
+      expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === sum).to.be.true;
+    }
+  });
 });
 
 describe('Fungible: Fees', () => {
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -585,7 +585,7 @@
     expect(event.returnValues.tokenId).to.equal(tokenId.toString());
   });
 
-  itEth('Check crossBalanceOf()', async ({helper}) => {
+  itEth('Check balanceOfCross()', async ({helper}) => {
     const collection = await helper.rft.mintCollection(minter, {});
     const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
     const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
modifiedtests/src/eth/tokens/minting.test.tsdiffbeforeafterboth
--- a/tests/src/eth/tokens/minting.test.ts
+++ b/tests/src/eth/tokens/minting.test.ts
@@ -19,7 +19,7 @@
 import {expect, itEth, usingEthPlaygrounds} from '../util';
 
 
-describe.only('Minting tokens', () => {
+describe('Minting tokens', () => {
   let donor: IKeyringPair;
   let alice: IKeyringPair;