From 0f907f33fbd0cf6a913b182e2edc614372f297d1 Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Fri, 8 Sep 2023 23:45:50 +0200 Subject: [PATCH] fix: ethereum transaction pallet must forward to pallet-ethereum::transact (#1536) Using the stumb is the most severe change for Altair. We want the message to succeed for testing, hence we trigger an event. Besides those, the ethereum logic now calls directly into the EVM logic to trigger the same code-path as normal EVM txs. * fix: just forward to ethereum::transact * fix: rebase issues * feat: event for inbound queue * fix: calling into EVM and weights * feat: Stumb-queue, fix tests * fix: use stumb * feat: bumb version, fix taplo * fix: clippy --- Cargo.lock | 1 + pallets/ethereum-transaction/src/lib.rs | 185 +++--------------- pallets/ethereum-transaction/src/mock.rs | 4 +- pallets/ethereum-transaction/src/tests.rs | 13 +- .../routers/src/lib.rs | 9 + .../routers/src/mock.rs | 4 +- .../routers/src/routers/axelar_evm.rs | 5 + pallets/liquidity-pools/src/lib.rs | 19 ++ runtime/altair/Cargo.toml | 2 +- runtime/altair/src/evm.rs | 4 +- runtime/altair/src/lib.rs | 40 +++- runtime/centrifuge/src/evm.rs | 4 +- runtime/centrifuge/src/lib.rs | 5 +- runtime/development/src/evm.rs | 4 +- runtime/development/src/lib.rs | 5 +- runtime/integration-tests/Cargo.toml | 1 + .../src/ethereum_transaction/pallet.rs | 44 ++++- 17 files changed, 161 insertions(+), 188 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afc3c4a5db..e80d47c3dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11052,6 +11052,7 @@ dependencies = [ "pallet-collator-selection", "pallet-collective", "pallet-democracy", + "pallet-ethereum", "pallet-ethereum-transaction", "pallet-evm", "pallet-evm-chain-id", diff --git a/pallets/ethereum-transaction/src/lib.rs b/pallets/ethereum-transaction/src/lib.rs index bb0680dde5..55132e4ae5 100644 --- a/pallets/ethereum-transaction/src/lib.rs +++ b/pallets/ethereum-transaction/src/lib.rs @@ -14,15 +14,12 @@ use cfg_primitives::TRANSACTION_RECOVERY_ID; use cfg_traits::ethereum::EthereumTransactor; use ethereum::{LegacyTransaction, TransactionAction, TransactionSignature, TransactionV2}; -use fp_evm::CallOrCreateInfo; use frame_support::{ dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo}, pallet_prelude::*, }; pub use pallet::*; -use pallet_evm::{ExitError, ExitFatal, ExitReason}; use sp_core::{H160, H256, U256}; -use sp_std::vec::Vec; #[cfg(test)] mod mock; @@ -32,6 +29,8 @@ mod tests; #[frame_support::pallet] pub mod pallet { + use frame_system::pallet_prelude::OriginFor; + use super::*; #[pallet::pallet] @@ -39,99 +38,37 @@ pub mod pallet { pub struct Pallet(_); #[pallet::config] - pub trait Config: frame_system::Config + pallet_ethereum::Config { - /// The event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; + pub trait Config: frame_system::Config + pallet_ethereum::Config + where + OriginFor: + From + Into>>, + { } /// Storage for nonce. #[pallet::storage] + #[pallet::getter(fn nonce)] pub(crate) type Nonce = StorageValue<_, U256, ValueQuery>; - #[pallet::event] - #[pallet::generate_deposit(pub (super) fn deposit_event)] - pub enum Event { - /// A call was executed. - Executed { - from: H160, - to: H160, - exit_reason: ExitReason, - value: Vec, - }, - } - - #[pallet::error] - pub enum Error { - /// Trying to pop from an empty stack. - StackUnderflow, - - /// Trying to push into a stack over stack limit. - StackOverflow, - - /// Jump destination is invalid. - InvalidJump, - - /// An opcode accesses memory region, but the region is invalid. - InvalidRange, - - /// Encountered the designated invalid opcode. - DesignatedInvalid, - - /// Call stack is too deep (runtime). - CallTooDeep, - - /// Create opcode encountered collision (runtime). - CreateCollision, - - /// Create init code exceeds limit (runtime). - CreateContractLimit, - - /// Invalid opcode during execution or starting byte is 0xef. See [EIP-3541](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3541.md). - InvalidCode(u8), - - /// An opcode accesses external information, but the request is off - /// offset limit (runtime). - OutOfOffset, - - /// Execution runs out of gas (runtime). - OutOfGas, - - /// Not enough fund to start the execution (runtime). - OutOfFund, - - /// PC underflowed (unused). - PCUnderflow, - - /// Attempt to create an empty account (runtime, unused). - CreateEmpty, - - /// The operation is not supported. - NotSupported, - /// The trap (interrupt) is unhandled. - UnhandledInterrupt, - - /// Machine encountered an explicit revert. - Reverted, - - /// Unexpected result when executing a transaction. - UnexpectedExecuteResult, - - /// Other normal errors. - Other, - } - - impl Pallet { - fn get_transaction_signature() -> Option { - //TODO(cdamian): Same signature as the one in ethereum-xcm. + impl Pallet + where + OriginFor: + From + Into>>, + { + pub fn get_transaction_signature() -> Option { TransactionSignature::new( TRANSACTION_RECOVERY_ID, - H256::from_low_u64_be(1u64), - H256::from_low_u64_be(1u64), + H256::from_low_u64_be(2u64), + H256::from_low_u64_be(2u64), ) } } - impl EthereumTransactor for Pallet { + impl EthereumTransactor for Pallet + where + OriginFor: + From + Into>>, + { /// This implementation serves as a wrapper around the Ethereum pallet /// execute functionality. It keeps track of the nonce used for each /// call and builds a fake signature for executing the provided call. @@ -170,10 +107,9 @@ pub mod pallet { Nonce::::put(nonce.saturating_add(U256::one())); - let (_target, _value, info) = pallet_ethereum::Pallet::::execute( - from, - &transaction, - Some(T::config().clone()), + pallet_ethereum::Pallet::::transact( + pallet_ethereum::Origin::EthereumTransaction(from).into(), + transaction, ) .map_err(|e| { let weight = e.post_info.actual_weight.map_or(Weight::zero(), |w| w); @@ -185,72 +121,15 @@ pub mod pallet { }, error: e.error, } - })?; - - let dispatch_info = PostDispatchInfo { - actual_weight: Some(read_weight), + }) + .map(|dispatch_info| PostDispatchInfo { pays_fee: Pays::Yes, - }; - - match info { - CallOrCreateInfo::Call(call_info) => { - Self::deposit_event(Event::Executed { - from, - to, - exit_reason: call_info.exit_reason.clone(), - value: call_info.value.clone(), - }); - - match call_info.exit_reason { - ExitReason::Succeed(_) => Ok(dispatch_info), - ExitReason::Error(e) => Err(DispatchErrorWithPostInfo { - post_info: dispatch_info, - error: map_evm_error::(e).into(), - }), - ExitReason::Revert(_) => Err(DispatchErrorWithPostInfo { - post_info: dispatch_info, - error: Error::::Reverted.into(), - }), - ExitReason::Fatal(e) => Err(DispatchErrorWithPostInfo { - post_info: dispatch_info, - error: map_evm_fatal_error::(e).into(), - }), - } - } - CallOrCreateInfo::Create(_) => Err(DispatchErrorWithPostInfo { - post_info: dispatch_info, - error: Error::::UnexpectedExecuteResult.into(), - }), - } - } - } - - fn map_evm_error(e: ExitError) -> Error { - match e { - ExitError::StackUnderflow => Error::StackUnderflow, - ExitError::StackOverflow => Error::StackOverflow, - ExitError::InvalidJump => Error::InvalidJump, - ExitError::InvalidRange => Error::InvalidRange, - ExitError::DesignatedInvalid => Error::DesignatedInvalid, - ExitError::CallTooDeep => Error::CallTooDeep, - ExitError::CreateCollision => Error::CreateCollision, - ExitError::CreateContractLimit => Error::CreateContractLimit, - ExitError::InvalidCode(opcode) => Error::InvalidCode(opcode.0), - ExitError::OutOfOffset => Error::OutOfOffset, - ExitError::OutOfGas => Error::OutOfGas, - ExitError::OutOfFund => Error::OutOfFund, - ExitError::PCUnderflow => Error::PCUnderflow, - ExitError::CreateEmpty => Error::CreateEmpty, - ExitError::Other(_) => Error::Other, - } - } - - fn map_evm_fatal_error(e: ExitFatal) -> Error { - match e { - ExitFatal::NotSupported => Error::NotSupported, - ExitFatal::UnhandledInterrupt => Error::UnhandledInterrupt, - ExitFatal::CallErrorAsFatal(e) => map_evm_error(e), - ExitFatal::Other(_) => Error::Other, + actual_weight: dispatch_info + .actual_weight + .map_or(Some(read_weight), |weight| { + Some(weight.saturating_add(read_weight)) + }), + }) } } } diff --git a/pallets/ethereum-transaction/src/mock.rs b/pallets/ethereum-transaction/src/mock.rs index 5e9fc26cf6..3f4c85bae0 100644 --- a/pallets/ethereum-transaction/src/mock.rs +++ b/pallets/ethereum-transaction/src/mock.rs @@ -183,9 +183,7 @@ impl pallet_ethereum::Config for Runtime { type StateRoot = IntermediateStateRoot; } -impl pallet_ethereum_transaction::Config for Runtime { - type RuntimeEvent = RuntimeEvent; -} +impl pallet_ethereum_transaction::Config for Runtime {} pub fn new_test_ext() -> sp_io::TestExternalities { let storage = frame_system::GenesisConfig::default() diff --git a/pallets/ethereum-transaction/src/tests.rs b/pallets/ethereum-transaction/src/tests.rs index cdfe6b860e..e7752611f3 100644 --- a/pallets/ethereum-transaction/src/tests.rs +++ b/pallets/ethereum-transaction/src/tests.rs @@ -4,7 +4,7 @@ use pallet_evm::{AddressMapping, Error::BalanceLow}; use sp_core::{crypto::AccountId32, H160, U256}; use super::mock::*; -use crate::{pallet::Nonce, Error}; +use crate::pallet::Nonce; mod utils { use super::*; @@ -101,15 +101,20 @@ mod call { assert_eq!(Nonce::::get(), U256::from(0)); - let res = ::call( + // NOTE: We can not check for errors as the internal `pallet-ethereum` logic + // does not transform an EVM error into an Substrate error and return + // `Ok(..)` in theses cases. + // + // We can also not mimic the `pallet-ethereum::Pallet::::transact(..)` + // code path as some needed parts are private. + assert_ok!(::call( sender, to, data.as_slice(), value, gas_price, gas_limit, - ); - assert_eq!(res.err().unwrap().error, Error::::OutOfGas.into()); + )); assert_eq!(Nonce::::get(), U256::from(1)); }); diff --git a/pallets/liquidity-pools-gateway/routers/src/lib.rs b/pallets/liquidity-pools-gateway/routers/src/lib.rs index 6c23d9c39a..481d2b016d 100644 --- a/pallets/liquidity-pools-gateway/routers/src/lib.rs +++ b/pallets/liquidity-pools-gateway/routers/src/lib.rs @@ -34,6 +34,7 @@ use frame_support::{ ensure, traits::OriginTrait, }; +use frame_system::pallet_prelude::OriginFor; use pallet_xcm_transactor::{Currency, CurrencyPayment, TransactWeights}; use scale_info::TypeInfo; use sp_core::{bounded::BoundedVec, ConstU32, H160, H256, U256}; @@ -84,6 +85,8 @@ where + pallet_ethereum_transaction::Config + pallet_evm::Config, T::AccountId: AsRef<[u8; 32]>, + OriginFor: + From + Into>>, { EthereumXCM(EthereumXCMRouter), AxelarEVM(AxelarEVMRouter), @@ -98,6 +101,8 @@ where + pallet_ethereum_transaction::Config + pallet_evm::Config, T::AccountId: AsRef<[u8; 32]>, + OriginFor: + From + Into>>, { type Message = MessageOf; type Sender = AccountIdOf; @@ -124,6 +129,8 @@ where pub struct EVMRouter where T: frame_system::Config + pallet_ethereum_transaction::Config + pallet_evm::Config, + OriginFor: + From + Into>>, { pub evm_domain: EVMDomain, pub _marker: PhantomData, @@ -133,6 +140,8 @@ impl EVMRouter where T: frame_system::Config + pallet_ethereum_transaction::Config + pallet_evm::Config, T::AccountId: AsRef<[u8; 32]>, + OriginFor: + From + Into>>, { /// Performs an extra check to ensure that the actual contract is deployed /// at the provided address and that the contract code hash matches. diff --git a/pallets/liquidity-pools-gateway/routers/src/mock.rs b/pallets/liquidity-pools-gateway/routers/src/mock.rs index 349e3e9732..d94caa1c53 100644 --- a/pallets/liquidity-pools-gateway/routers/src/mock.rs +++ b/pallets/liquidity-pools-gateway/routers/src/mock.rs @@ -114,9 +114,7 @@ impl pallet_mock_liquidity_pools::Config for Runtime { type Message = MessageMock; } -impl pallet_ethereum_transaction::Config for Runtime { - type RuntimeEvent = RuntimeEvent; -} +impl pallet_ethereum_transaction::Config for Runtime {} impl pallet_mock_routers::Config for Runtime {} diff --git a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs index b7ac4f2a49..137160536f 100644 --- a/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs +++ b/pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs @@ -13,6 +13,7 @@ use cfg_traits::liquidity_pools::Codec; use codec::{Decode, Encode, MaxEncodedLen}; use ethabi::{Contract, Function, Param, ParamType, Token}; use frame_support::dispatch::{DispatchError, DispatchResult}; +use frame_system::pallet_prelude::OriginFor; use scale_info::{ prelude::string::{String, ToString}, TypeInfo, @@ -34,6 +35,8 @@ where + pallet_liquidity_pools_gateway::Config + pallet_ethereum_transaction::Config + pallet_evm::Config, + OriginFor: + From + Into>>, { pub router: EVMRouter, pub evm_chain: BoundedVec>, @@ -48,6 +51,8 @@ where + pallet_ethereum_transaction::Config + pallet_evm::Config, T::AccountId: AsRef<[u8; 32]>, + OriginFor: + From + Into>>, { /// Calls the init function on the EVM router. pub fn do_init(&self) -> DispatchResult { diff --git a/pallets/liquidity-pools/src/lib.rs b/pallets/liquidity-pools/src/lib.rs index a2644d19e2..f385770b17 100644 --- a/pallets/liquidity-pools/src/lib.rs +++ b/pallets/liquidity-pools/src/lib.rs @@ -243,6 +243,20 @@ pub mod pallet { #[pallet::constant] type TreasuryAccount: Get; + + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + #[allow(clippy::large_enum_variant)] + pub enum Event { + /// An incoming LP message was + /// detected and is further processed + IncomingMessage { + sender: DomainAddress, + message: MessageOf, + }, } #[pallet::error] @@ -791,6 +805,11 @@ pub mod pallet { #[transactional] fn submit(sender: DomainAddress, msg: MessageOf) -> DispatchResult { + Self::deposit_event(Event::::IncomingMessage { + sender: sender.clone(), + message: msg.clone(), + }); + match msg { Message::Transfer { currency, diff --git a/runtime/altair/Cargo.toml b/runtime/altair/Cargo.toml index 048e1db676..aa6414aa8e 100644 --- a/runtime/altair/Cargo.toml +++ b/runtime/altair/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "altair-runtime" -version = "0.10.31" +version = "0.10.32" authors = ["Centrifuge "] edition = "2021" build = "build.rs" diff --git a/runtime/altair/src/evm.rs b/runtime/altair/src/evm.rs index 148c37f95e..f89fc02221 100644 --- a/runtime/altair/src/evm.rs +++ b/runtime/altair/src/evm.rs @@ -85,9 +85,7 @@ impl pallet_ethereum::Config for Runtime { type StateRoot = pallet_ethereum::IntermediateStateRoot; } -impl pallet_ethereum_transaction::Config for Runtime { - type RuntimeEvent = RuntimeEvent; -} +impl pallet_ethereum_transaction::Config for Runtime {} impl axelar_gateway_precompile::Config for Runtime { type AdminOrigin = EnsureRootOr; diff --git a/runtime/altair/src/lib.rs b/runtime/altair/src/lib.rs index 33aa7d4566..f26008d6c5 100644 --- a/runtime/altair/src/lib.rs +++ b/runtime/altair/src/lib.rs @@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("altair"), impl_name: create_runtime_str!("altair"), authoring_version: 1, - spec_version: 1031, + spec_version: 1032, impl_version: 1, #[cfg(not(feature = "disable-runtime-api"))] apis: RUNTIME_API_VERSIONS, @@ -1401,6 +1401,7 @@ impl pallet_liquidity_pools::Config for Runtime { type Permission = Permissions; type PoolId = PoolId; type PoolInspect = PoolSystem; + type RuntimeEvent = RuntimeEvent; type Time = Timestamp; type Tokens = Tokens; type TrancheCurrency = TrancheCurrency; @@ -1415,9 +1416,37 @@ parameter_types! { pub Sender: AccountId = GatewayAccountProvider::::get_gateway_account(); } +/// A +pub struct StumbInboundQueue; +impl InboundQueue for StumbInboundQueue { + type Message = pallet_liquidity_pools::Message; + type Sender = DomainAddress; + + fn submit(sender: Self::Sender, message: Self::Message) -> DispatchResult { + let event = { + let event = + pallet_liquidity_pools::Event::::IncomingMessage { sender, message }; + + // Mirror deposit_event logic here as it is private + let event = <::RuntimeEvent as From< + pallet_liquidity_pools::Event, + >>::from(event); + + <::RuntimeEvent as Into< + ::RuntimeEvent, + >>::into(event) + }; + + // Triggering only the event for error resolution + System::deposit_event(event); + + Ok(()) + } +} + impl pallet_liquidity_pools_gateway::Config for Runtime { type AdminOrigin = EnsureRootOr; - type InboundQueue = LiquidityPools; + type InboundQueue = StumbInboundQueue; type LocalEVMOrigin = pallet_liquidity_pools_gateway::EnsureLocal; type MaxIncomingMessageSize = MaxIncomingMessageSize; type Message = pallet_liquidity_pools::Message; @@ -1795,7 +1824,7 @@ construct_runtime!( BlockRewards: pallet_block_rewards::{Pallet, Call, Storage, Event, Config} = 105, Keystore: pallet_keystore::{Pallet, Call, Storage, Event} = 106, PriceCollector: pallet_data_collector::{Pallet, Storage} = 107, - LiquidityPools: pallet_liquidity_pools::{Pallet, Call, Storage} = 108, + LiquidityPools: pallet_liquidity_pools::{Pallet, Call, Storage, Event} = 108, LiquidityPoolsGateway: pallet_liquidity_pools_gateway::{Pallet, Call, Storage, Event, Origin } = 109, LiquidityRewardsBase: pallet_rewards::::{Pallet, Storage, Event, Config} = 110, LiquidityRewards: pallet_liquidity_rewards::{Pallet, Call, Storage, Event} = 111, @@ -1821,7 +1850,7 @@ construct_runtime!( EVMChainId: pallet_evm_chain_id::{Pallet, Config, Storage} = 161, BaseFee: pallet_base_fee::{Pallet, Call, Config, Storage, Event} = 162, Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 163, - EthereumTransaction: pallet_ethereum_transaction::{Pallet, Storage, Event} = 164, + EthereumTransaction: pallet_ethereum_transaction::{Pallet, Storage} = 164, LiquidityPoolsAxelarGateway: axelar_gateway_precompile::{Pallet, Call, Storage, Event} = 165, // migration pallet @@ -1976,7 +2005,8 @@ mod __runtime_api_use { #[cfg(not(feature = "disable-runtime-api"))] use __runtime_api_use::*; -use cfg_types::domain_address::Domain; +use cfg_traits::liquidity_pools::InboundQueue; +use cfg_types::domain_address::{Domain, DomainAddress}; use runtime_common::{account_conversion::AccountConverter, xcm::AccountIdToMultiLocation}; #[cfg(not(feature = "disable-runtime-api"))] diff --git a/runtime/centrifuge/src/evm.rs b/runtime/centrifuge/src/evm.rs index 733a319f06..dd772d265a 100644 --- a/runtime/centrifuge/src/evm.rs +++ b/runtime/centrifuge/src/evm.rs @@ -86,9 +86,7 @@ impl pallet_ethereum::Config for crate::Runtime { type StateRoot = pallet_ethereum::IntermediateStateRoot; } -impl pallet_ethereum_transaction::Config for crate::Runtime { - type RuntimeEvent = crate::RuntimeEvent; -} +impl pallet_ethereum_transaction::Config for crate::Runtime {} impl axelar_gateway_precompile::Config for crate::Runtime { type AdminOrigin = EnsureAccountOrRootOr; diff --git a/runtime/centrifuge/src/lib.rs b/runtime/centrifuge/src/lib.rs index 33516c606e..76574a5697 100644 --- a/runtime/centrifuge/src/lib.rs +++ b/runtime/centrifuge/src/lib.rs @@ -448,6 +448,7 @@ impl pallet_liquidity_pools::Config for Runtime { type Permission = Permissions; type PoolId = PoolId; type PoolInspect = PoolSystem; + type RuntimeEvent = RuntimeEvent; type Time = Timestamp; type Tokens = Tokens; type TrancheCurrency = TrancheCurrency; @@ -1960,7 +1961,7 @@ construct_runtime!( BlockRewardsBase: pallet_rewards::::{Pallet, Storage, Event, Config} = 100, BlockRewards: pallet_block_rewards::{Pallet, Call, Storage, Event, Config} = 101, PriceCollector: pallet_data_collector::{Pallet, Storage} = 102, - LiquidityPools: pallet_liquidity_pools::{Pallet, Call, Storage} = 103, + LiquidityPools: pallet_liquidity_pools::{Pallet, Call, Storage, Event} = 103, LiquidityRewardsBase: pallet_rewards::::{Pallet, Storage, Event, Config} = 104, LiquidityRewards: pallet_liquidity_rewards::{Pallet, Call, Storage, Event} = 105, GapRewardMechanism: pallet_rewards::mechanism::gap = 106, @@ -1987,7 +1988,7 @@ construct_runtime!( EVMChainId: pallet_evm_chain_id::{Pallet, Config, Storage} = 161, BaseFee: pallet_base_fee::{Pallet, Call, Config, Storage, Event} = 162, Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 163, - EthereumTransaction: pallet_ethereum_transaction::{Pallet, Storage, Event} = 164, + EthereumTransaction: pallet_ethereum_transaction::{Pallet, Storage} = 164, LiquidityPoolsAxelarGateway: axelar_gateway_precompile::{Pallet, Call, Storage, Event} = 165, // Synced pallets across all runtimes - Range: 180-240 diff --git a/runtime/development/src/evm.rs b/runtime/development/src/evm.rs index 27d300e4f0..2a1c0856f6 100644 --- a/runtime/development/src/evm.rs +++ b/runtime/development/src/evm.rs @@ -86,9 +86,7 @@ impl pallet_ethereum::Config for Runtime { type StateRoot = pallet_ethereum::IntermediateStateRoot; } -impl pallet_ethereum_transaction::Config for Runtime { - type RuntimeEvent = RuntimeEvent; -} +impl pallet_ethereum_transaction::Config for Runtime {} impl axelar_gateway_precompile::Config for Runtime { type AdminOrigin = EnsureRoot; diff --git a/runtime/development/src/lib.rs b/runtime/development/src/lib.rs index 97f2e4c38c..e02df6c836 100644 --- a/runtime/development/src/lib.rs +++ b/runtime/development/src/lib.rs @@ -1561,6 +1561,7 @@ impl pallet_liquidity_pools::Config for Runtime { type Permission = Permissions; type PoolId = PoolId; type PoolInspect = PoolSystem; + type RuntimeEvent = RuntimeEvent; type Time = Timestamp; type Tokens = Tokens; type TrancheCurrency = TrancheCurrency; @@ -1892,7 +1893,7 @@ construct_runtime!( Investments: pallet_investments::{Pallet, Call, Storage, Event} = 105, LiquidityRewardsBase: pallet_rewards::::{Pallet, Storage, Event, Config} = 106, LiquidityRewards: pallet_liquidity_rewards::{Pallet, Call, Storage, Event} = 107, - LiquidityPools: pallet_liquidity_pools::{Pallet, Call, Storage} = 108, + LiquidityPools: pallet_liquidity_pools::{Pallet, Call, Storage, Event} = 108, PoolRegistry: pallet_pool_registry::{Pallet, Call, Storage, Event} = 109, BlockRewardsBase: pallet_rewards::::{Pallet, Storage, Event, Config} = 110, BlockRewards: pallet_block_rewards::{Pallet, Call, Storage, Event, Config} = 111, @@ -1923,7 +1924,7 @@ construct_runtime!( EVMChainId: pallet_evm_chain_id::{Pallet, Config, Storage} = 161, BaseFee: pallet_base_fee::{Pallet, Call, Config, Storage, Event} = 162, Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 163, - EthereumTransaction: pallet_ethereum_transaction::{Pallet, Storage, Event} = 164, + EthereumTransaction: pallet_ethereum_transaction::{Pallet, Storage} = 164, LiquidityPoolsAxelarGateway: axelar_gateway_precompile::{Pallet, Call, Storage, Event} = 165, // migration pallet diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 8cfc8c36b1..c35567d1d3 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -90,6 +90,7 @@ cfg-utils = { path = "../../libs/utils" } ethereum = { version = "0.14.0", default-features = false } +pallet-ethereum = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" } pallet-evm = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" } pallet-evm-chain-id = { git = "https://github.com/PureStake/frontier", default-features = false, branch = "moonbeam-polkadot-v0.9.38" } diff --git a/runtime/integration-tests/src/ethereum_transaction/pallet.rs b/runtime/integration-tests/src/ethereum_transaction/pallet.rs index 1b33f58624..92713adfac 100644 --- a/runtime/integration-tests/src/ethereum_transaction/pallet.rs +++ b/runtime/integration-tests/src/ethereum_transaction/pallet.rs @@ -15,7 +15,7 @@ use cfg_traits::ethereum::EthereumTransactor; use ethereum::{LegacyTransaction, TransactionAction, TransactionSignature, TransactionV2}; use frame_support::{assert_err, dispatch::RawOrigin}; use fudge::primitives::Chain; -use pallet_evm::FeeCalculator; +use pallet_evm::{ExitReason, ExitReason::Succeed, ExitSucceed, FeeCalculator}; use runtime_common::account_conversion::AccountConverter; use sp_core::{Get, H160, U256}; use tokio::runtime::Handle; @@ -80,6 +80,28 @@ async fn call() { }) .unwrap(); + let t_hash = { + let nonce = env + .with_state(Chain::Para(PARA_ID), || { + pallet_ethereum_transaction::Pallet::::nonce() + }) + .unwrap(); + + let signature = + pallet_ethereum_transaction::Pallet::::get_transaction_signature().unwrap(); + + TransactionV2::Legacy(LegacyTransaction { + nonce, + gas_price: U256::from(1), + gas_limit: U256::from(0x100000), + action: TransactionAction::Call(contract_address), + value: U256::zero(), + input: foo.as_slice().into(), + signature, + }) + .hash() + }; + // Executing Foo should be OK and emit an event with the value returned by the // function. env.with_mut_state(Chain::Para(PARA_ID), || { @@ -95,15 +117,24 @@ async fn call() { }) .unwrap(); + let reason = ExitReason::Succeed(ExitSucceed::Returned); + env::evolve_until_event_is_found!( env, Chain::Para(PARA_ID), RuntimeEvent, 5, - RuntimeEvent::EthereumTransaction(pallet_ethereum_transaction::Event::Executed { - value, - .. - }) if [ hex::encode(value) == "0000000000000000000000000000000000000000000000000000000000000001" ], + RuntimeEvent::Ethereum(pallet_ethereum::Event::Executed { + from, + to, + transaction_hash, + exit_reason + }) if [ + from == &sender_address + && to == &contract_address + && transaction_hash == &t_hash + && exit_reason == &reason + ], ); // Executing Bar should error out since the function returns an error. @@ -117,7 +148,8 @@ async fn call() { U256::from(0x100000), ); - assert!(res.is_err()); + // NOTE: WE CAN NOTE CHECK WHETHER THE EVM ERRORS OUT + assert!(res.is_ok()); }) .unwrap(); }