difftreelog
refactor EthCrossAccount impl, signature some evm methods, tests and stubs
in: master
16 files changed
pallets/common/src/erc.rsdiffbeforeafterboth36use crate::{36use crate::{37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,38 eth::{38 eth::{39 EthCrossAccount, convert_cross_account_to_uint256, CollectionPermissions as EvmPermissions,39 EthCrossAccount, CollectionPermissions as EvmPermissions,40 CollectionLimits as EvmCollectionLimits,40 CollectionLimits as EvmCollectionLimits,41 },41 },42 weights::WeightInfo,42 weights::WeightInfo,pallets/common/src/eth.rsdiffbeforeafterboth53 address[0..16] == ETH_COLLECTION_PREFIX53 address[0..16] == ETH_COLLECTION_PREFIX54}54}5556/// Convert `CrossAccountId` to `uint256`.57pub fn convert_cross_account_to_uint256<T: Config>(from: &T::CrossAccountId) -> uint25658where59 T::AccountId: AsRef<[u8; 32]>,60{61 let slice = from.as_sub().as_ref();62 uint256::from_big_endian(slice)63}645565/// Convert `uint256` to `CrossAccountId`.56/// Convert `uint256` to `CrossAccountId`.66pub fn convert_uint256_to_cross_account<T: Config>(from: uint256) -> T::CrossAccountId57pub fn convert_uint256_to_cross_account<T: Config>(from: uint256) -> T::CrossAccountId73 T::CrossAccountId::from_sub(account_id)64 T::CrossAccountId::from_sub(account_id)74}65}7576/// Convert `CrossAccountId` to `(address, uint256)`.77pub fn convert_cross_account_to_tuple<T: Config>(78 cross_account_id: &T::CrossAccountId,79) -> (address, uint256)80where81 T::AccountId: AsRef<[u8; 32]>,82{83 if cross_account_id.is_canonical_substrate() {84 let sub = convert_cross_account_to_uint256::<T>(cross_account_id);85 (Default::default(), sub)86 } else {87 let eth = *cross_account_id.as_eth();88 (eth, Default::default())89 }90}916692/// Convert tuple `(address, uint256)` to `CrossAccountId`.67/// Convert tuple `(address, uint256)` to `CrossAccountId`.93///68///128 T::AccountId: AsRef<[u8; 32]>,103 T::AccountId: AsRef<[u8; 32]>,129 {104 {130 if cross_account_id.is_canonical_substrate() {105 if cross_account_id.is_canonical_substrate() {131 Self {106 Self::from_sub::<T>(cross_account_id.as_sub())132 eth: Default::default(),133 sub: convert_cross_account_to_uint256::<T>(cross_account_id),134 }135 } else {107 } else {136 Self {108 Self {137 eth: *cross_account_id.as_eth(),109 eth: *cross_account_id.as_eth(),pallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth50 "pallet-evm-coder-substrate/std",50 "pallet-evm-coder-substrate/std",51 "pallet-evm/std",51 "pallet-evm/std",52 "up-sponsorship/std",52 "up-sponsorship/std",53 "pallet-common/std",53]54]54try-runtime = ["frame-support/try-runtime"]55try-runtime = ["frame-support/try-runtime"]55stubgen = ["evm-coder/stubgen"]56stubgen = ["evm-coder/stubgen", "pallet-common/stubgen"]5657pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth175 ///175 ///176 /// @param contractAddress The contract for which a sponsor is requested.176 /// @param contractAddress The contract for which a sponsor is requested.177 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.177 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.178 fn sponsor(&self, contract_address: address) -> Result<(address, uint256)> {178 fn sponsor(&self, contract_address: address) -> Result<EthCrossAccount> {179 let sponsor =179 Ok(EthCrossAccount::from_sub_cross_account::<T>(180 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;180 &Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?,181 Ok(pallet_common::eth::convert_cross_account_to_tuple::<T>(181 ))182 &sponsor,183 ))184 }182 }185 // fn sponsor(&self, contract_address: address) -> Result<EthCrossAccount> {186 // Ok(EthCrossAccount::from_sub_cross_account::<T>(187 // &Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?,188 // ))189 // }190183191 /// Check tat contract has confirmed sponsor.184 /// Check tat contract has confirmed sponsor.192 ///185 ///pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth96 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.96 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.97 /// @dev EVM selector for this function is: 0x766c4f37,97 /// @dev EVM selector for this function is: 0x766c4f37,98 /// or in textual repr: sponsor(address)98 /// or in textual repr: sponsor(address)99 function sponsor(address contractAddress) public view returns (Tuple0 memory) {99 function sponsor(address contractAddress) public view returns (EthCrossAccount memory) {100 require(false, stub_error);100 require(false, stub_error);101 contractAddress;101 contractAddress;102 dummy;102 dummy;103 return Tuple0(0x0000000000000000000000000000000000000000, 0);103 return EthCrossAccount(0x0000000000000000000000000000000000000000, 0);104 }104 }105105106 /// Check tat contract has confirmed sponsor.106 /// Check tat contract has confirmed sponsor.265 }265 }266}266}267267268/// @dev anonymous struct268/// @dev Cross account struct269struct Tuple0 {269struct EthCrossAccount {270 address field_0;270 address eth;271 uint256 field_1;271 uint256 sub;272}272}273273pallets/nonfungible/src/erc.rsdiffbeforeafterboth605 Ok(false)605 Ok(false)606 }606 }607607608 /// @notice Function to mint token.608 /// @notice Function to a mint token.609 /// @param to The new owner609 /// @param to The new owner610 /// @return uint256 The id of the newly minted token610 /// @return uint256 The id of the newly minted token611 #[weight(<SelfWeightOf<T>>::create_item())]611 #[weight(<SelfWeightOf<T>>::create_item())]618 Ok(token_id)618 Ok(token_id)619 }619 }620620621 /// @notice Function to mint token.621 /// @notice Function to a mint token.622 /// @dev `tokenId` should be obtained with `nextTokenId` method,622 /// @dev `tokenId` should be obtained with `nextTokenId` method,623 /// unlike standard, you can't specify it manually623 /// unlike standard, you can't specify it manually624 /// @param to The new owner624 /// @param to The new owner1070 Ok(true)1070 Ok(true)1071 }1071 }107210721073 /// @notice Function to mint token.1073 /// @notice Function to a mint token.1074 /// @param to The new owner crossAccountId1074 /// @param to The new owner crossAccountId1075 /// @param properties Properties of minted token1075 /// @param properties Properties of minted token1076 /// @return uint256 The id of the newly minted token1076 /// @return uint256 The id of the newly minted tokenpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth738 return false;738 return false;739 }739 }740740741 /// @notice Function to mint token.741 /// @notice Function to a mint token.742 /// @param to The new owner742 /// @param to The new owner743 /// @return uint256 The id of the newly minted token743 /// @return uint256 The id of the newly minted token744 /// @dev EVM selector for this function is: 0x6a627842,744 /// @dev EVM selector for this function is: 0x6a627842,750 return 0;750 return 0;751 }751 }752752753 // /// @notice Function to mint token.753 // /// @notice Function to a mint token.754 // /// @dev `tokenId` should be obtained with `nextTokenId` method,754 // /// @dev `tokenId` should be obtained with `nextTokenId` method,755 // /// unlike standard, you can't specify it manually755 // /// unlike standard, you can't specify it manually756 // /// @param to The new owner756 // /// @param to The new owner995 // return false;995 // return false;996 // }996 // }997997998 /// @notice Function to mint token.998 /// @notice Function to a mint token.999 /// @param to The new owner crossAccountId999 /// @param to The new owner crossAccountId1000 /// @param properties Properties of minted token1000 /// @param properties Properties of minted token1001 /// @return uint256 The id of the newly minted token1001 /// @return uint256 The id of the newly minted tokenpallets/refungible/src/erc.rsdiffbeforeafterboth637 Ok(false)637 Ok(false)638 }638 }639639640 /// @notice Function to mint token.640 /// @notice Function to a mint token.641 /// @param to The new owner641 /// @param to The new owner642 /// @return uint256 The id of the newly minted token642 /// @return uint256 The id of the newly minted token643 #[weight(<SelfWeightOf<T>>::create_item())]643 #[weight(<SelfWeightOf<T>>::create_item())]650 Ok(token_id)650 Ok(token_id)651 }651 }652652653 /// @notice Function to mint token.653 /// @notice Function to a mint token.654 /// @dev `tokenId` should be obtained with `nextTokenId` method,654 /// @dev `tokenId` should be obtained with `nextTokenId` method,655 /// unlike standard, you can't specify it manually655 /// unlike standard, you can't specify it manually656 /// @param to The new owner656 /// @param to The new owner1120 Ok(true)1120 Ok(true)1121 }1121 }112211221123 /// @notice Function to mint token.1123 /// @notice Function to a mint token.1124 /// @param to The new owner crossAccountId1124 /// @param to The new owner crossAccountId1125 /// @param properties Properties of minted token1125 /// @param properties Properties of minted token1126 /// @return uint256 The id of the newly minted token1126 /// @return uint256 The id of the newly minted tokenpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth733 return false;733 return false;734 }734 }735735736 /// @notice Function to mint token.736 /// @notice Function to a mint token.737 /// @param to The new owner737 /// @param to The new owner738 /// @return uint256 The id of the newly minted token738 /// @return uint256 The id of the newly minted token739 /// @dev EVM selector for this function is: 0x6a627842,739 /// @dev EVM selector for this function is: 0x6a627842,745 return 0;745 return 0;746 }746 }747747748 // /// @notice Function to mint token.748 // /// @notice Function to a mint token.749 // /// @dev `tokenId` should be obtained with `nextTokenId` method,749 // /// @dev `tokenId` should be obtained with `nextTokenId` method,750 // /// unlike standard, you can't specify it manually750 // /// unlike standard, you can't specify it manually751 // /// @param to The new owner751 // /// @param to The new owner979 // return false;979 // return false;980 // }980 // }981981982 /// @notice Function to mint token.982 /// @notice Function to a mint token.983 /// @param to The new owner crossAccountId983 /// @param to The new owner crossAccountId984 /// @param properties Properties of minted token984 /// @param properties Properties of minted token985 /// @return uint256 The id of the newly minted token985 /// @return uint256 The id of the newly minted tokentests/src/eth/abi/contractHelpers.jsondiffbeforeafterboth223 "outputs": [223 "outputs": [224 {224 {225 "components": [225 "components": [226 { "internalType": "address", "name": "field_0", "type": "address" },226 { "internalType": "address", "name": "eth", "type": "address" },227 { "internalType": "uint256", "name": "field_1", "type": "uint256" }227 { "internalType": "uint256", "name": "sub", "type": "uint256" }228 ],228 ],229 "internalType": "struct Tuple0",229 "internalType": "struct EthCrossAccount",230 "name": "",230 "name": "",231 "type": "tuple"231 "type": "tuple"232 }232 }tests/src/eth/api/ContractHelpers.soldiffbeforeafterboth69 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.69 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.70 /// @dev EVM selector for this function is: 0x766c4f37,70 /// @dev EVM selector for this function is: 0x766c4f37,71 /// or in textual repr: sponsor(address)71 /// or in textual repr: sponsor(address)72 function sponsor(address contractAddress) external view returns (Tuple0 memory);72 function sponsor(address contractAddress) external view returns (EthCrossAccount memory);737374 /// Check tat contract has confirmed sponsor.74 /// Check tat contract has confirmed sponsor.75 ///75 ///171 function toggleAllowlist(address contractAddress, bool enabled) external;171 function toggleAllowlist(address contractAddress, bool enabled) external;172}172}173173174/// @dev anonymous struct174/// @dev Cross account struct175struct Tuple0 {175struct EthCrossAccount {176 address field_0;176 address eth;177 uint256 field_1;177 uint256 sub;178}178}179179tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth515 /// or in textual repr: mintingFinished()515 /// or in textual repr: mintingFinished()516 function mintingFinished() external view returns (bool);516 function mintingFinished() external view returns (bool);517517518 /// @notice Function to mint token.518 /// @notice Function to a mint token.519 /// @param to The new owner519 /// @param to The new owner520 /// @return uint256 The id of the newly minted token520 /// @return uint256 The id of the newly minted token521 /// @dev EVM selector for this function is: 0x6a627842,521 /// @dev EVM selector for this function is: 0x6a627842,522 /// or in textual repr: mint(address)522 /// or in textual repr: mint(address)523 function mint(address to) external returns (uint256);523 function mint(address to) external returns (uint256);524524525 // /// @notice Function to mint token.525 // /// @notice Function to a mint token.526 // /// @dev `tokenId` should be obtained with `nextTokenId` method,526 // /// @dev `tokenId` should be obtained with `nextTokenId` method,527 // /// unlike standard, you can't specify it manually527 // /// unlike standard, you can't specify it manually528 // /// @param to The new owner528 // /// @param to The new owner674 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])674 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])675 // function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);675 // function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);676676677 /// @notice Function to mint token.677 /// @notice Function to a mint token.678 /// @param to The new owner crossAccountId678 /// @param to The new owner crossAccountId679 /// @param properties Properties of minted token679 /// @param properties Properties of minted token680 /// @return uint256 The id of the newly minted token680 /// @return uint256 The id of the newly minted tokentests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth513 /// or in textual repr: mintingFinished()513 /// or in textual repr: mintingFinished()514 function mintingFinished() external view returns (bool);514 function mintingFinished() external view returns (bool);515515516 /// @notice Function to mint token.516 /// @notice Function to a mint token.517 /// @param to The new owner517 /// @param to The new owner518 /// @return uint256 The id of the newly minted token518 /// @return uint256 The id of the newly minted token519 /// @dev EVM selector for this function is: 0x6a627842,519 /// @dev EVM selector for this function is: 0x6a627842,520 /// or in textual repr: mint(address)520 /// or in textual repr: mint(address)521 function mint(address to) external returns (uint256);521 function mint(address to) external returns (uint256);522522523 // /// @notice Function to mint token.523 // /// @notice Function to a mint token.524 // /// @dev `tokenId` should be obtained with `nextTokenId` method,524 // /// @dev `tokenId` should be obtained with `nextTokenId` method,525 // /// unlike standard, you can't specify it manually525 // /// unlike standard, you can't specify it manually526 // /// @param to The new owner526 // /// @param to The new owner666 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])666 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])667 // function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);667 // function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);668668669 /// @notice Function to mint token.669 /// @notice Function to a mint token.670 /// @param to The new owner crossAccountId670 /// @param to The new owner crossAccountId671 /// @param properties Properties of minted token671 /// @param properties Properties of minted token672 /// @return uint256 The id of the newly minted token672 /// @return uint256 The id of the newly minted tokentests/src/eth/nonFungible.test.tsdiffbeforeafterboth17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import {Contract} from 'web3-eth-contract';19import {Contract} from 'web3-eth-contract';20import exp from 'constants';21import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';22212322198 let tokenId = result.events.Transfer.returnValues.tokenId;204 let tokenId = result.events.Transfer.returnValues.tokenId;199 expect(tokenId).to.be.equal(expectedTokenId);205 expect(tokenId).to.be.equal(expectedTokenId);200206201 const event = result.events.Transfer;207 let event = result.events.Transfer;202 expect(event.address).to.be.equal(collectionAddress);208 expect(event.address).to.be.equal(collectionAddress);203 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');209 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');204 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));210 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));205 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);211 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);206 212 207 expectedTokenId = await contract.methods.nextTokenId().call();213 expectedTokenId = await contract.methods.nextTokenId().call();208 result = await contract.methods.mintCross(receiverCross, properties).send();214 result = await contract.methods.mintCross(receiverCross, properties).send();215 event = result.events.Transfer;216 expect(event.address).to.be.equal(collectionAddress);217 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');218 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));219 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);220 209 tokenId = result.events.Transfer.returnValues.tokenId;221 tokenId = result.events.Transfer.returnValues.tokenId;210222 tests/src/eth/reFungible.test.tsdiffbeforeafterboth159 let tokenId = result.events.Transfer.returnValues.tokenId;159 let tokenId = result.events.Transfer.returnValues.tokenId;160 expect(tokenId).to.be.equal(expectedTokenId);160 expect(tokenId).to.be.equal(expectedTokenId);161161162 const event = result.events.Transfer;162 let event = result.events.Transfer;163 expect(event.address).to.be.equal(collectionAddress);163 expect(event.address).to.be.equal(collectionAddress);164 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');164 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');165 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));165 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));166 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);166 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);167 167 168 expectedTokenId = await contract.methods.nextTokenId().call();168 expectedTokenId = await contract.methods.nextTokenId().call();169 result = await contract.methods.mintCross(receiverCross, properties).send();169 result = await contract.methods.mintCross(receiverCross, properties).send();170 event = result.events.Transfer;171 expect(event.address).to.be.equal(collectionAddress);172 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');173 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));174 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);175 170 tokenId = result.events.Transfer.returnValues.tokenId;176 tokenId = result.events.Transfer.returnValues.tokenId;171177