--- a/crates/evm-coder/src/abi.rs +++ b/crates/evm-coder/src/abi.rs @@ -450,7 +450,7 @@ } } -impl AbiWrite for &EthCrossAccount { +impl AbiWrite for EthCrossAccount { fn abi_write(&self, writer: &mut AbiWriter) { self.eth.abi_write(writer); self.sub.abi_write(writer); --- a/crates/evm-coder/src/lib.rs +++ b/crates/evm-coder/src/lib.rs @@ -218,7 +218,7 @@ } } - #[derive(Debug)] + #[derive(Debug, Default)] pub struct EthCrossAccount { pub(crate) eth: address, pub(crate) sub: uint256, --- a/crates/evm-coder/src/solidity.rs +++ b/crates/evm-coder/src/solidity.rs @@ -203,7 +203,7 @@ } fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result { - write!(writer, "{}(", tc.collect_tuple::())?; + write!(writer, "{}(", tc.collect_struct::())?; address::solidity_default(writer, tc)?; write!(writer, ",")?; uint256::solidity_default(writer, tc)?; --- a/pallets/common/src/erc.rs +++ b/pallets/common/src/erc.rs @@ -231,13 +231,13 @@ fn set_collection_sponsor_cross( &mut self, caller: caller, - sponsor: (address, uint256), + sponsor: EthCrossAccount, ) -> Result { self.consume_store_reads_and_writes(1, 1)?; check_is_owner_or_admin(caller, self)?; - let sponsor = convert_tuple_to_cross_account::(sponsor)?; + let sponsor = sponsor.into_sub_cross_account::()?; self.set_sponsor(sponsor.as_sub().clone()) .map_err(dispatch_to_evm::)?; save(self) @@ -388,12 +388,12 @@ fn add_collection_admin_cross( &mut self, caller: caller, - new_admin: (address, uint256), + new_admin: EthCrossAccount, ) -> Result { self.consume_store_writes(2)?; let caller = T::CrossAccountId::from_eth(caller); - let new_admin = convert_tuple_to_cross_account::(new_admin)?; + let new_admin = new_admin.into_sub_cross_account::()?; >::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::)?; Ok(()) } @@ -403,12 +403,12 @@ fn remove_collection_admin_cross( &mut self, caller: caller, - admin: (address, uint256), + admin: EthCrossAccount, ) -> Result { self.consume_store_writes(2)?; let caller = T::CrossAccountId::from_eth(caller); - let admin = convert_tuple_to_cross_account::(admin)?; + let admin = admin.into_sub_cross_account::()?; >::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::)?; Ok(()) } @@ -566,12 +566,12 @@ fn add_to_collection_allow_list_cross( &mut self, caller: caller, - user: (address, uint256), + user: EthCrossAccount, ) -> Result { self.consume_store_writes(1)?; let caller = T::CrossAccountId::from_eth(caller); - let user = convert_tuple_to_cross_account::(user)?; + let user = user.into_sub_cross_account::()?; Pallet::::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::)?; Ok(()) } @@ -594,12 +594,12 @@ fn remove_from_collection_allow_list_cross( &mut self, caller: caller, - user: (address, uint256), + user: EthCrossAccount, ) -> Result { self.consume_store_writes(1)?; let caller = T::CrossAccountId::from_eth(caller); - let user = convert_tuple_to_cross_account::(user)?; + let user = user.into_sub_cross_account::()?; Pallet::::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::)?; Ok(()) } @@ -639,8 +639,8 @@ /// /// @param user User cross account to verify /// @return "true" if account is the owner or admin - fn is_owner_or_admin_cross(&self, user: (address, uint256)) -> Result { - let user = convert_tuple_to_cross_account::(user)?; + fn is_owner_or_admin_cross(&self, user: EthCrossAccount) -> Result { + let user = user.into_sub_cross_account::()?; Ok(self.is_owner_or_admin(&user)) } @@ -660,8 +660,8 @@ /// /// @return Tuble with sponsor address and his substrate mirror. /// If address is canonical then substrate mirror is zero and vice versa. - fn collection_owner(&self) -> Result<(address, uint256)> { - Ok(convert_cross_account_to_tuple::( + fn collection_owner(&self) -> Result { + Ok(EthCrossAccount::from_sub_cross_account::( &T::CrossAccountId::from_sub(self.owner.clone()), )) } @@ -684,9 +684,9 @@ /// /// @return Vector of tuples with admins address and his substrate mirror. /// If address is canonical then substrate mirror is zero and vice versa. - fn collection_admins(&self) -> Result> { + fn collection_admins(&self) -> Result> { let result = crate::IsAdmin::::iter_prefix((self.id,)) - .map(|(admin, _)| crate::eth::convert_cross_account_to_tuple::(&admin)) + .map(|(admin, _)| EthCrossAccount::from_sub_cross_account::(&admin)) .collect(); Ok(result) } @@ -695,11 +695,11 @@ /// /// @dev Owner can be changed only by current owner /// @param newOwner new owner cross account - fn set_owner_cross(&mut self, caller: caller, new_owner: (address, uint256)) -> Result { + fn set_owner_cross(&mut self, caller: caller, new_owner: EthCrossAccount) -> Result { self.consume_store_writes(1)?; let caller = T::CrossAccountId::from_eth(caller); - let new_owner = convert_tuple_to_cross_account::(new_owner)?; + let new_owner = new_owner.into_sub_cross_account::()?; self.set_owner_internal(caller, new_owner) .map_err(dispatch_to_evm::) } --- a/pallets/fungible/src/erc.rs +++ b/pallets/fungible/src/erc.rs @@ -167,11 +167,11 @@ fn approve_cross( &mut self, caller: caller, - spender: (address, uint256), + spender: EthCrossAccount, amount: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - let spender = convert_tuple_to_cross_account::(spender)?; + let spender = spender.into_sub_cross_account::()?; let amount = amount.try_into().map_err(|_| "amount overflow")?; >::set_allowance(self, &caller, &spender, amount) @@ -207,11 +207,11 @@ fn burn_from_cross( &mut self, caller: caller, - from: (address, uint256), + from: EthCrossAccount, amount: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - let from = convert_tuple_to_cross_account::(from)?; + let from = from.into_sub_cross_account::()?; let amount = amount.try_into().map_err(|_| "amount overflow")?; let budget = self .recorder @@ -249,13 +249,13 @@ fn transfer_from_cross( &mut self, caller: caller, - from: (address, uint256), - to: (address, uint256), + from: EthCrossAccount, + to: EthCrossAccount, amount: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - let from = convert_tuple_to_cross_account::(from)?; - let to = convert_tuple_to_cross_account::(to)?; + let from = from.into_sub_cross_account::()?; + let to = to.into_sub_cross_account::()?; let amount = amount.try_into().map_err(|_| "amount overflow")?; let budget = self .recorder --- a/pallets/nonfungible/src/erc.rs +++ b/pallets/nonfungible/src/erc.rs @@ -684,11 +684,11 @@ fn approve_cross( &mut self, caller: caller, - approved: (address, uint256), + approved: EthCrossAccount, token_id: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - let approved = convert_tuple_to_cross_account::(approved)?; + let approved = approved.into_sub_cross_account::()?; let token = token_id.try_into()?; >::set_allowance(self, &caller, token, Some(&approved)) @@ -770,11 +770,11 @@ fn burn_from_cross( &mut self, caller: caller, - from: (address, uint256), + from: EthCrossAccount, token_id: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - let from = convert_tuple_to_cross_account::(from)?; + let from = from.into_sub_cross_account::()?; let token = token_id.try_into()?; let budget = self .recorder --- a/pallets/refungible/src/erc.rs +++ b/pallets/refungible/src/erc.rs @@ -734,23 +734,23 @@ fn transfer_from_cross( &mut self, caller: caller, - from: (address, uint256), - to: (address, uint256), + from: EthCrossAccount, + to: EthCrossAccount, token_id: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - // let from = convert_tuple_to_cross_account::(from)?; - // let to = convert_tuple_to_cross_account::(to)?; - // let token_id = token_id.try_into()?; - // let budget = self - // .recorder - // .weight_calls_budget(>::find_parent()); + let from = from.into_sub_cross_account::()?; + let to = to.into_sub_cross_account::()?; + let token_id = token_id.try_into()?; + let budget = self + .recorder + .weight_calls_budget(>::find_parent()); - // let balance = balance(self, token_id, &from)?; - // ensure_single_owner(self, token_id, balance)?; + let balance = balance(self, token_id, &from)?; + ensure_single_owner(self, token_id, balance)?; - // Pallet::::transfer_from(self, &caller, &from, &to, token_id, balance, &budget) - // .map_err(dispatch_to_evm::)?; + Pallet::::transfer_from(self, &caller, &from, &to, token_id, balance, &budget) + .map_err(dispatch_to_evm::)?; Ok(()) } @@ -789,11 +789,11 @@ fn burn_from_cross( &mut self, caller: caller, - from: (address, uint256), + from: EthCrossAccount, token_id: uint256, ) -> Result { let caller = T::CrossAccountId::from_eth(caller); - let from = convert_tuple_to_cross_account::(from)?; + let from = from.into_sub_cross_account::()?; let token = token_id.try_into()?; let budget = self .recorder --- a/tests/src/eth/collectionAdmin.test.ts +++ b/tests/src/eth/collectionAdmin.test.ts @@ -94,25 +94,6 @@ await collectionEvm.methods.addCollectionAdmin(newAdmin).send(); expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true; }); - - itEth.skip('Check adminlist', async ({helper, privateKey}) => { - const owner = await helper.eth.createAccountWithBalance(donor); - - const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C'); - const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - - const admin1 = helper.eth.createAccount(); - const admin2 = privateKey('admin'); - await collectionEvm.methods.addCollectionAdmin(admin1).send(); - await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send(); - - const adminListRpc = await helper.collection.getAdmins(collectionId); - let adminListEth = await collectionEvm.methods.collectionAdmins().call(); - adminListEth = adminListEth.map((element: IEthCrossAccountId) => { - return helper.address.convertCrossAccountFromEthCrossAcoount(element); - }); - expect(adminListRpc).to.be.like(adminListEth); - }); itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => { const owner = await helper.eth.createAccountWithBalance(donor); --- a/tests/src/eth/nonFungible.test.ts +++ b/tests/src/eth/nonFungible.test.ts @@ -409,7 +409,7 @@ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))); }); - itEth.only('Can perform transferFromCross()', async ({helper, privateKey}) => { + itEth('Can perform transferFromCross()', async ({helper, privateKey}) => { const alice = privateKey('//Alice'); const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'}); --- a/tests/src/util/playgrounds/types.ts +++ b/tests/src/util/playgrounds/types.ts @@ -73,8 +73,8 @@ export interface IEthCrossAccountId { 0: TEthereumAccount; 1: TSubstrateAccount; - field_0: TEthereumAccount; - field_1: TSubstrateAccount; + eth: TEthereumAccount; + sub: TSubstrateAccount; } export interface ICollectionLimits { --- a/tests/src/util/playgrounds/unique.ts +++ b/tests/src/util/playgrounds/unique.ts @@ -2430,11 +2430,11 @@ * @returns substrate cross account id */ convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId { - if (ethCrossAccount.field_1 === '0') { - return {Ethereum: ethCrossAccount.field_0.toLocaleLowerCase()}; + if (ethCrossAccount.sub === '0') { + return {Ethereum: ethCrossAccount.eth.toLocaleLowerCase()}; } - const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.field_1)); + const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.sub)); return {Substrate: ss58}; }