difftreelog
refactor EthCrossAccount impl, signature some evm methods, tests and stubs
in: master
16 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -36,7 +36,7 @@
use crate::{
Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
eth::{
- EthCrossAccount, convert_cross_account_to_uint256, CollectionPermissions as EvmPermissions,
+ EthCrossAccount, CollectionPermissions as EvmPermissions,
CollectionLimits as EvmCollectionLimits,
},
weights::WeightInfo,
pallets/common/src/eth.rsdiffbeforeafterboth--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -53,15 +53,6 @@
address[0..16] == ETH_COLLECTION_PREFIX
}
-/// Convert `CrossAccountId` to `uint256`.
-pub fn convert_cross_account_to_uint256<T: Config>(from: &T::CrossAccountId) -> uint256
-where
- T::AccountId: AsRef<[u8; 32]>,
-{
- let slice = from.as_sub().as_ref();
- uint256::from_big_endian(slice)
-}
-
/// Convert `uint256` to `CrossAccountId`.
pub fn convert_uint256_to_cross_account<T: Config>(from: uint256) -> T::CrossAccountId
where
@@ -71,22 +62,6 @@
from.to_big_endian(&mut new_admin_arr);
let account_id = T::AccountId::from(new_admin_arr);
T::CrossAccountId::from_sub(account_id)
-}
-
-/// Convert `CrossAccountId` to `(address, uint256)`.
-pub fn convert_cross_account_to_tuple<T: Config>(
- cross_account_id: &T::CrossAccountId,
-) -> (address, uint256)
-where
- T::AccountId: AsRef<[u8; 32]>,
-{
- if cross_account_id.is_canonical_substrate() {
- let sub = convert_cross_account_to_uint256::<T>(cross_account_id);
- (Default::default(), sub)
- } else {
- let eth = *cross_account_id.as_eth();
- (eth, Default::default())
- }
}
/// Convert tuple `(address, uint256)` to `CrossAccountId`.
@@ -128,10 +103,7 @@
T::AccountId: AsRef<[u8; 32]>,
{
if cross_account_id.is_canonical_substrate() {
- Self {
- eth: Default::default(),
- sub: convert_cross_account_to_uint256::<T>(cross_account_id),
- }
+ Self::from_sub::<T>(cross_account_id.as_sub())
} else {
Self {
eth: *cross_account_id.as_eth(),
pallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -50,6 +50,7 @@
"pallet-evm-coder-substrate/std",
"pallet-evm/std",
"up-sponsorship/std",
+ "pallet-common/std",
]
try-runtime = ["frame-support/try-runtime"]
-stubgen = ["evm-coder/stubgen"]
+stubgen = ["evm-coder/stubgen", "pallet-common/stubgen"]
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth1// 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/>.1617//! Implementation of magic contract1819extern crate alloc;20use core::marker::PhantomData;21use evm_coder::{22 abi::{AbiWriter, AbiType},23 execution::Result,24 generate_stubgen, solidity_interface,25 types::*,26 ToLog,27};28use pallet_common::eth::EthCrossAccount;29use pallet_evm::{30 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,31 account::CrossAccountId,32};33use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder, dispatch_to_evm};34use pallet_evm_transaction_payment::CallContext;35use sp_core::{H160, U256};36use up_data_structs::SponsorshipState;37use crate::{38 AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringFeeLimit,39 SponsoringRateLimit, SponsoringModeT, Sponsoring,40};41use frame_support::traits::Get;42use up_sponsorship::SponsorshipHandler;43use sp_std::vec::Vec;4445/// Pallet events.46#[derive(ToLog)]47pub enum ContractHelpersEvents {48 /// Contract sponsor was set.49 ContractSponsorSet {50 /// Contract address of the affected collection.51 #[indexed]52 contract_address: address,53 /// New sponsor address.54 sponsor: address,55 },5657 /// New sponsor was confirm.58 ContractSponsorshipConfirmed {59 /// Contract address of the affected collection.60 #[indexed]61 contract_address: address,62 /// New sponsor address.63 sponsor: address,64 },6566 /// Collection sponsor was removed.67 ContractSponsorRemoved {68 /// Contract address of the affected collection.69 #[indexed]70 contract_address: address,71 },72}7374/// See [`ContractHelpersCall`]75pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);76impl<T: Config> WithRecorder<T> for ContractHelpers<T> {77 fn recorder(&self) -> &SubstrateRecorder<T> {78 &self.079 }8081 fn into_recorder(self) -> SubstrateRecorder<T> {82 self.083 }84}8586/// @title Magic contract, which allows users to reconfigure other contracts87#[solidity_interface(name = ContractHelpers, events(ContractHelpersEvents))]88impl<T: Config> ContractHelpers<T>89where90 T::AccountId: AsRef<[u8; 32]>,91{92 /// Get user, which deployed specified contract93 /// @dev May return zero address in case if contract is deployed94 /// using uniquenetwork evm-migration pallet, or using other terms not95 /// intended by pallet-evm96 /// @dev Returns zero address if contract does not exists97 /// @param contractAddress Contract to get owner of98 /// @return address Owner of contract99 fn contract_owner(&self, contract_address: address) -> Result<address> {100 Ok(<Owner<T>>::get(contract_address))101 }102103 /// Set sponsor.104 /// @param contractAddress Contract for which a sponsor is being established.105 /// @param sponsor User address who set as pending sponsor.106 fn set_sponsor(107 &mut self,108 caller: caller,109 contract_address: address,110 sponsor: address,111 ) -> Result<void> {112 self.recorder().consume_sload()?;113 self.recorder().consume_sstore()?;114115 Pallet::<T>::set_sponsor(116 &T::CrossAccountId::from_eth(caller),117 contract_address,118 &T::CrossAccountId::from_eth(sponsor),119 )120 .map_err(dispatch_to_evm::<T>)?;121122 Ok(())123 }124125 /// Set contract as self sponsored.126 ///127 /// @param contractAddress Contract for which a self sponsoring is being enabled.128 fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {129 self.recorder().consume_sload()?;130 self.recorder().consume_sstore()?;131132 let caller = T::CrossAccountId::from_eth(caller);133134 Pallet::<T>::ensure_owner(contract_address, *caller.as_eth())135 .map_err(dispatch_to_evm::<T>)?;136137 Pallet::<T>::force_set_sponsor(138 contract_address,139 &T::CrossAccountId::from_eth(contract_address),140 )141 .map_err(dispatch_to_evm::<T>)?;142143 Ok(())144 }145146 /// Remove sponsor.147 ///148 /// @param contractAddress Contract for which a sponsorship is being removed.149 fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {150 self.recorder().consume_sload()?;151 self.recorder().consume_sstore()?;152153 Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)154 .map_err(dispatch_to_evm::<T>)?;155156 Ok(())157 }158159 /// Confirm sponsorship.160 ///161 /// @dev Caller must be same that set via [`setSponsor`].162 ///163 /// @param contractAddress Сontract for which need to confirm sponsorship.164 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {165 self.recorder().consume_sload()?;166 self.recorder().consume_sstore()?;167168 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)169 .map_err(dispatch_to_evm::<T>)?;170171 Ok(())172 }173174 /// Get current sponsor.175 ///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.178 fn sponsor(&self, contract_address: address) -> Result<(address, uint256)> {179 let 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>(182 &sponsor,183 ))184 }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 // }190191 /// Check tat contract has confirmed sponsor.192 ///193 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.194 /// @return **true** if contract has confirmed sponsor.195 fn has_sponsor(&self, contract_address: address) -> Result<bool> {196 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())197 }198199 /// Check tat contract has pending sponsor.200 ///201 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.202 /// @return **true** if contract has pending sponsor.203 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {204 Ok(match Sponsoring::<T>::get(contract_address) {205 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,206 SponsorshipState::Unconfirmed(_) => true,207 })208 }209210 fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {211 Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)212 }213214 fn set_sponsoring_mode(215 &mut self,216 caller: caller,217 contract_address: address,218 // TODO: implement support for enums in evm-coder219 mode: uint8,220 ) -> Result<void> {221 self.recorder().consume_sload()?;222 self.recorder().consume_sstore()?;223224 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;225 let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;226 <Pallet<T>>::set_sponsoring_mode(contract_address, mode);227228 Ok(())229 }230231 /// Get current contract sponsoring rate limit232 /// @param contractAddress Contract to get sponsoring rate limit of233 /// @return uint32 Amount of blocks between two sponsored transactions234 fn sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {235 self.recorder().consume_sload()?;236237 Ok(<SponsoringRateLimit<T>>::get(contract_address)238 .try_into()239 .map_err(|_| "rate limit > u32::MAX")?)240 }241242 /// Set contract sponsoring rate limit243 /// @dev Sponsoring rate limit - is a minimum amount of blocks that should244 /// pass between two sponsored transactions245 /// @param contractAddress Contract to change sponsoring rate limit of246 /// @param rateLimit Target rate limit247 /// @dev Only contract owner can change this setting248 fn set_sponsoring_rate_limit(249 &mut self,250 caller: caller,251 contract_address: address,252 rate_limit: uint32,253 ) -> Result<void> {254 self.recorder().consume_sload()?;255 self.recorder().consume_sstore()?;256257 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;258 <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());259 Ok(())260 }261262 /// Set contract sponsoring fee limit263 /// @dev Sponsoring fee limit - is maximum fee that could be spent by264 /// single transaction265 /// @param contractAddress Contract to change sponsoring fee limit of266 /// @param feeLimit Fee limit267 /// @dev Only contract owner can change this setting268 fn set_sponsoring_fee_limit(269 &mut self,270 caller: caller,271 contract_address: address,272 fee_limit: uint256,273 ) -> Result<void> {274 self.recorder().consume_sload()?;275 self.recorder().consume_sstore()?;276277 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;278 <Pallet<T>>::set_sponsoring_fee_limit(contract_address, fee_limit.into())279 .map_err(dispatch_to_evm::<T>)?;280 Ok(())281 }282283 /// Get current contract sponsoring fee limit284 /// @param contractAddress Contract to get sponsoring fee limit of285 /// @return uint256 Maximum amount of fee that could be spent by single286 /// transaction287 fn sponsoring_fee_limit(&self, contract_address: address) -> Result<uint256> {288 self.recorder().consume_sload()?;289290 Ok(get_sponsoring_fee_limit::<T>(contract_address))291 }292293 /// Is specified user present in contract allow list294 /// @dev Contract owner always implicitly included295 /// @param contractAddress Contract to check allowlist of296 /// @param user User to check297 /// @return bool Is specified users exists in contract allowlist298 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {299 self.0.consume_sload()?;300 Ok(<Pallet<T>>::allowed(contract_address, user))301 }302303 /// Toggle user presence in contract allowlist304 /// @param contractAddress Contract to change allowlist of305 /// @param user Which user presence should be toggled306 /// @param isAllowed `true` if user should be allowed to be sponsored307 /// or call this contract, `false` otherwise308 /// @dev Only contract owner can change this setting309 fn toggle_allowed(310 &mut self,311 caller: caller,312 contract_address: address,313 user: address,314 is_allowed: bool,315 ) -> Result<void> {316 self.recorder().consume_sload()?;317 self.recorder().consume_sstore()?;318319 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;320 <Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);321322 Ok(())323 }324325 /// Is this contract has allowlist access enabled326 /// @dev Allowlist always can have users, and it is used for two purposes:327 /// in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist328 /// in case of allowlist access enabled, only users from allowlist may call this contract329 /// @param contractAddress Contract to get allowlist access of330 /// @return bool Is specified contract has allowlist access enabled331 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {332 Ok(<AllowlistEnabled<T>>::get(contract_address))333 }334335 /// Toggle contract allowlist access336 /// @param contractAddress Contract to change allowlist access of337 /// @param enabled Should allowlist access to be enabled?338 fn toggle_allowlist(339 &mut self,340 caller: caller,341 contract_address: address,342 enabled: bool,343 ) -> Result<void> {344 self.recorder().consume_sload()?;345 self.recorder().consume_sstore()?;346347 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;348 <Pallet<T>>::toggle_allowlist(contract_address, enabled);349 Ok(())350 }351}352353/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]354pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);355impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>356where357 T::AccountId: AsRef<[u8; 32]>,358{359 fn is_reserved(contract: &sp_core::H160) -> bool {360 contract == &T::ContractAddress::get()361 }362363 fn is_used(contract: &sp_core::H160) -> bool {364 contract == &T::ContractAddress::get()365 }366367 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {368 // TODO: Extract to another OnMethodCall handler369 if <AllowlistEnabled<T>>::get(handle.code_address())370 && !<Pallet<T>>::allowed(handle.code_address(), handle.context().caller)371 {372 return Some(Err(PrecompileFailure::Revert {373 exit_status: ExitRevert::Reverted,374 output: {375 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));376 writer.string("Target contract is allowlisted");377 writer.finish()378 },379 }));380 }381382 if handle.code_address() != T::ContractAddress::get() {383 return None;384 }385386 let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));387 pallet_evm_coder_substrate::call(handle, helpers)388 }389390 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {391 (contract == &T::ContractAddress::get())392 .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())393 }394}395396/// Hooks into contract creation, storing owner of newly deployed contract397pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);398impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {399 fn on_create(owner: H160, contract: H160) {400 <Owner<T>>::insert(contract, owner);401 }402}403404/// Bridge to pallet-sponsoring405pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);406impl<T: Config> SponsorshipHandler<T::CrossAccountId, CallContext>407 for HelpersContractSponsoring<T>408{409 fn get_sponsor(410 who: &T::CrossAccountId,411 call_context: &CallContext,412 ) -> Option<T::CrossAccountId> {413 let contract_address = call_context.contract_address;414 let mode = <Pallet<T>>::sponsoring_mode(contract_address);415 if mode == SponsoringModeT::Disabled {416 return None;417 }418419 let sponsor = match <Pallet<T>>::get_sponsor(contract_address) {420 Some(sponsor) => sponsor,421 None => return None,422 };423424 if mode == SponsoringModeT::Allowlisted425 && !<Pallet<T>>::allowed(contract_address, *who.as_eth())426 {427 return None;428 }429 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;430431 if let Some(last_tx_block) = <SponsorBasket<T>>::get(contract_address, who.as_eth()) {432 let limit = <SponsoringRateLimit<T>>::get(contract_address);433434 let timeout = last_tx_block + limit;435 if block_number < timeout {436 return None;437 }438 }439440 let sponsored_fee_limit = get_sponsoring_fee_limit::<T>(contract_address);441442 if call_context.max_fee > sponsored_fee_limit {443 return None;444 }445446 <SponsorBasket<T>>::insert(contract_address, who.as_eth(), block_number);447448 Some(sponsor)449 }450}451452fn get_sponsoring_fee_limit<T: Config>(contract_address: address) -> uint256 {453 <SponsoringFeeLimit<T>>::get(contract_address)454 .get(&0xffffffff)455 .cloned()456 .unwrap_or(U256::MAX)457}458459generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);460generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);pallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterbothbinary blob — no preview
pallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -96,11 +96,11 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x766c4f37,
/// or in textual repr: sponsor(address)
- function sponsor(address contractAddress) public view returns (Tuple0 memory) {
+ function sponsor(address contractAddress) public view returns (EthCrossAccount memory) {
require(false, stub_error);
contractAddress;
dummy;
- return Tuple0(0x0000000000000000000000000000000000000000, 0);
+ return EthCrossAccount(0x0000000000000000000000000000000000000000, 0);
}
/// Check tat contract has confirmed sponsor.
@@ -265,8 +265,8 @@
}
}
-/// @dev anonymous struct
-struct Tuple0 {
- address field_0;
- uint256 field_1;
+/// @dev Cross account struct
+struct EthCrossAccount {
+ address eth;
+ uint256 sub;
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -605,7 +605,7 @@
Ok(false)
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
#[weight(<SelfWeightOf<T>>::create_item())]
@@ -618,7 +618,7 @@
Ok(token_id)
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @dev `tokenId` should be obtained with `nextTokenId` method,
/// unlike standard, you can't specify it manually
/// @param to The new owner
@@ -1070,7 +1070,7 @@
Ok(true)
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -738,7 +738,7 @@
return false;
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
/// @dev EVM selector for this function is: 0x6a627842,
@@ -750,7 +750,7 @@
return 0;
}
- // /// @notice Function to mint token.
+ // /// @notice Function to a mint token.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
// /// @param to The new owner
@@ -995,7 +995,7 @@
// return false;
// }
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -637,7 +637,7 @@
Ok(false)
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
#[weight(<SelfWeightOf<T>>::create_item())]
@@ -650,7 +650,7 @@
Ok(token_id)
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @dev `tokenId` should be obtained with `nextTokenId` method,
/// unlike standard, you can't specify it manually
/// @param to The new owner
@@ -1120,7 +1120,7 @@
Ok(true)
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -733,7 +733,7 @@
return false;
}
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
/// @dev EVM selector for this function is: 0x6a627842,
@@ -745,7 +745,7 @@
return 0;
}
- // /// @notice Function to mint token.
+ // /// @notice Function to a mint token.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
// /// @param to The new owner
@@ -979,7 +979,7 @@
// return false;
// }
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
tests/src/eth/abi/contractHelpers.jsondiffbeforeafterboth--- a/tests/src/eth/abi/contractHelpers.json
+++ b/tests/src/eth/abi/contractHelpers.json
@@ -223,10 +223,10 @@
"outputs": [
{
"components": [
- { "internalType": "address", "name": "field_0", "type": "address" },
- { "internalType": "uint256", "name": "field_1", "type": "uint256" }
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
],
- "internalType": "struct Tuple0",
+ "internalType": "struct EthCrossAccount",
"name": "",
"type": "tuple"
}
tests/src/eth/api/ContractHelpers.soldiffbeforeafterboth--- a/tests/src/eth/api/ContractHelpers.sol
+++ b/tests/src/eth/api/ContractHelpers.sol
@@ -69,7 +69,7 @@
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
/// @dev EVM selector for this function is: 0x766c4f37,
/// or in textual repr: sponsor(address)
- function sponsor(address contractAddress) external view returns (Tuple0 memory);
+ function sponsor(address contractAddress) external view returns (EthCrossAccount memory);
/// Check tat contract has confirmed sponsor.
///
@@ -171,8 +171,8 @@
function toggleAllowlist(address contractAddress, bool enabled) external;
}
-/// @dev anonymous struct
-struct Tuple0 {
- address field_0;
- uint256 field_1;
+/// @dev Cross account struct
+struct EthCrossAccount {
+ address eth;
+ uint256 sub;
}
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -515,14 +515,14 @@
/// or in textual repr: mintingFinished()
function mintingFinished() external view returns (bool);
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
/// @dev EVM selector for this function is: 0x6a627842,
/// or in textual repr: mint(address)
function mint(address to) external returns (uint256);
- // /// @notice Function to mint token.
+ // /// @notice Function to a mint token.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
// /// @param to The new owner
@@ -674,7 +674,7 @@
// /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
// function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -513,14 +513,14 @@
/// or in textual repr: mintingFinished()
function mintingFinished() external view returns (bool);
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner
/// @return uint256 The id of the newly minted token
/// @dev EVM selector for this function is: 0x6a627842,
/// or in textual repr: mint(address)
function mint(address to) external returns (uint256);
- // /// @notice Function to mint token.
+ // /// @notice Function to a mint token.
// /// @dev `tokenId` should be obtained with `nextTokenId` method,
// /// unlike standard, you can't specify it manually
// /// @param to The new owner
@@ -666,7 +666,7 @@
// /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
// function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);
- /// @notice Function to mint token.
+ /// @notice Function to a mint token.
/// @param to The new owner crossAccountId
/// @param properties Properties of minted token
/// @return uint256 The id of the newly minted token
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -17,7 +17,6 @@
import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-import exp from 'constants';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
@@ -180,9 +179,16 @@
const caller = await helper.eth.createAccountWithBalance(donor);
const receiverCross = helper.ethCrossAccount.fromKeyringPair(bob);
const properties = Array(5).fill(0).map((_, i) => { return {key: `key_${i}`, value: Buffer.from(`value_${i}`)}; });
- const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.key, permission: {tokenOwner: true,
- collectionAdmin: true,
- mutable: true}}; });
+ const permissions: ITokenPropertyPermission[] = properties
+ .map(p => {
+ return {
+ key: p.key, permission: {
+ tokenOwner: true,
+ collectionAdmin: true,
+ mutable: true,
+ },
+ };
+ });
const collection = await helper.nft.mintCollection(minter, {
@@ -198,7 +204,7 @@
let tokenId = result.events.Transfer.returnValues.tokenId;
expect(tokenId).to.be.equal(expectedTokenId);
- const event = result.events.Transfer;
+ let event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
@@ -206,10 +212,16 @@
expectedTokenId = await contract.methods.nextTokenId().call();
result = await contract.methods.mintCross(receiverCross, properties).send();
+ event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+
tokenId = result.events.Transfer.returnValues.tokenId;
-
+
expect(tokenId).to.be.equal(expectedTokenId);
-
+
expect(await contract.methods.properties(tokenId, []).call()).to.be.like(properties
.map(p => { return helper.ethProperty.property(p.key, p.value.toString()); }));
});
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -17,7 +17,7 @@
import {Pallets, requirePalletsOrSkip} from '../util';
import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-import { ITokenPropertyPermission } from '../util/playgrounds/types';
+import {ITokenPropertyPermission} from '../util/playgrounds/types';
describe('Refungible: Information getting', () => {
let donor: IKeyringPair;
@@ -159,7 +159,7 @@
let tokenId = result.events.Transfer.returnValues.tokenId;
expect(tokenId).to.be.equal(expectedTokenId);
- const event = result.events.Transfer;
+ let event = result.events.Transfer;
expect(event.address).to.be.equal(collectionAddress);
expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
@@ -167,6 +167,12 @@
expectedTokenId = await contract.methods.nextTokenId().call();
result = await contract.methods.mintCross(receiverCross, properties).send();
+ event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
+ expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
+
tokenId = result.events.Transfer.returnValues.tokenId;
expect(tokenId).to.be.equal(expectedTokenId);