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
511 bytes value;511 bytes value;
512}512}
513513
514/// @dev the ERC-165 identifier for this interface is 0x85d7dea6514/// @dev the ERC-165 identifier for this interface is 0x69d14d3e
515contract ERC20UniqueExtensions is Dummy, ERC165 {515contract ERC20UniqueExtensions is Dummy, ERC165 {
516 /// @dev Function to check the amount of tokens that an owner allowed to a spender.516 /// @dev Function to check the amount of tokens that an owner allowed to a spender.
517 /// @param owner crossAddress The address which owns the funds.517 /// @param owner crossAddress The address which owns the funds.
631 return 0x0000000000000000000000000000000000000000;631 return 0x0000000000000000000000000000000000000000;
632 }632 }
633
634 /// @notice Balance of account
635 /// @param owner An cross address for whom to query the balance
636 /// @return The number of fingibles owned by `owner`, possibly zero
637 /// @dev EVM selector for this function is: 0xec069398,
638 /// or in textual repr: balanceOfCross((address,uint256))
639 function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
640 require(false, stub_error);
641 owner;
642 dummy;
643 return 0;
644 }
633}645}
634646
635struct AmountForAddress {647struct AmountForAddress {
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
173 "stateMutability": "view",173 "stateMutability": "view",
174 "type": "function"174 "type": "function"
175 },175 },
176 {
177 "inputs": [
178 {
179 "components": [
180 { "internalType": "address", "name": "eth", "type": "address" },
181 { "internalType": "uint256", "name": "sub", "type": "uint256" }
182 ],
183 "internalType": "struct CrossAddress",
184 "name": "owner",
185 "type": "tuple"
186 }
187 ],
188 "name": "balanceOfCross",
189 "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
190 "stateMutability": "view",
191 "type": "function"
192 },
176 {193 {
177 "inputs": [194 "inputs": [
178 {195 {
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
353 bytes value;353 bytes value;
354}354}
355355
356/// @dev the ERC-165 identifier for this interface is 0x85d7dea6356/// @dev the ERC-165 identifier for this interface is 0x69d14d3e
357interface ERC20UniqueExtensions is Dummy, ERC165 {357interface ERC20UniqueExtensions is Dummy, ERC165 {
358 /// @dev Function to check the amount of tokens that an owner allowed to a spender.358 /// @dev Function to check the amount of tokens that an owner allowed to a spender.
359 /// @param owner crossAddress The address which owns the funds.359 /// @param owner crossAddress The address which owns the funds.
417 /// or in textual repr: collectionHelperAddress()417 /// or in textual repr: collectionHelperAddress()
418 function collectionHelperAddress() external view returns (address);418 function collectionHelperAddress() external view returns (address);
419
420 /// @notice Balance of account
421 /// @param owner An cross address for whom to query the balance
422 /// @return The number of fingibles owned by `owner`, possibly zero
423 /// @dev EVM selector for this function is: 0xec069398,
424 /// or in textual repr: balanceOfCross((address,uint256))
425 function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
419}426}
420427
421struct AmountForAddress {428struct AmountForAddress {
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
428 expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);428 expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);
429 });429 });
430
431 itEth('Check balanceOfCross()', async ({helper}) => {
432 const collection = await helper.ft.mintCollection(alice, {});
433 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
434 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
435 const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner.eth);
436
437 expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === 0n).to.be.true;
438
439 let sum = 0n;
440 for (let i = 1n; i < 100n; i++) {
441 await collection.mint(alice, 100n, {Ethereum: owner.eth});
442 sum += 100n;
443 expect(BigInt(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})) === sum).to.be.true;
444 }
445 });
430});446});
431447
432describe('Fungible: Fees', () => {448describe('Fungible: Fees', () => {
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
585 expect(event.returnValues.tokenId).to.equal(tokenId.toString());585 expect(event.returnValues.tokenId).to.equal(tokenId.toString());
586 });586 });
587587
588 itEth('Check crossBalanceOf()', async ({helper}) => {588 itEth('Check balanceOfCross()', async ({helper}) => {
589 const collection = await helper.rft.mintCollection(minter, {});589 const collection = await helper.rft.mintCollection(minter, {});
590 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);590 const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
591 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);591 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
modifiedtests/src/eth/tokens/minting.test.tsdiffbeforeafterboth
19import {expect, itEth, usingEthPlaygrounds} from '../util';19import {expect, itEth, usingEthPlaygrounds} from '../util';
2020
2121
22describe.only('Minting tokens', () => {22describe('Minting tokens', () => {
23 let donor: IKeyringPair;23 let donor: IKeyringPair;
24 let alice: IKeyringPair;24 let alice: IKeyringPair;
2525