-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
221 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use cfg_traits::ethereum::EthereumTransactor; | ||
use frame_support::pallet_prelude::*; | ||
use mock_builder::{execute_call, register_call}; | ||
use sp_core::{H160, U256}; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config {} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn mock_call( | ||
func: impl Fn(H160, H160, &[u8], U256, U256, U256) -> DispatchResult + 'static, | ||
) { | ||
register_call!(move |(a, b, c, d, e, f)| func(a, b, c, d, e, f)); | ||
} | ||
} | ||
|
||
impl<T: Config> EthereumTransactor for Pallet<T> { | ||
fn call( | ||
a: H160, | ||
b: H160, | ||
c: &[u8], | ||
d: U256, | ||
e: U256, | ||
f: U256, | ||
) -> DispatchResultWithPostInfo { | ||
execute_call!((a, b, c, d, e, f)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#[frame_support::pallet(dev_mode)] | ||
pub mod pallet { | ||
use cfg_traits::liquidity_pools::MessageReceiver; | ||
use frame_support::pallet_prelude::*; | ||
use mock_builder::{execute_call, register_call}; | ||
|
||
#[pallet::config] | ||
pub trait Config: frame_system::Config { | ||
type Middleware; | ||
type Origin; | ||
} | ||
|
||
#[pallet::pallet] | ||
pub struct Pallet<T>(_); | ||
|
||
#[pallet::storage] | ||
type CallIds<T: Config> = StorageMap<_, _, String, mock_builder::CallId>; | ||
|
||
impl<T: Config> Pallet<T> { | ||
pub fn mock_receive( | ||
f: impl Fn(T::Middleware, T::Origin, Vec<u8>) -> DispatchResult + 'static, | ||
) { | ||
register_call!(move |(a, b, c)| f(a, b, c)); | ||
} | ||
} | ||
|
||
impl<T: Config> MessageReceiver for Pallet<T> { | ||
type Middleware = T::Middleware; | ||
type Origin = T::Origin; | ||
|
||
fn receive(a: Self::Middleware, b: Self::Origin, c: Vec<u8>) -> DispatchResult { | ||
execute_call!((a, b, c)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use cfg_types::domain_address::DomainAddress; | ||
use frame_support::{derive_impl, traits::EitherOfDiverse}; | ||
use frame_system::{EnsureRoot, EnsureSigned}; | ||
use sp_core::{H160, H256}; | ||
use sp_io::TestExternalities; | ||
|
||
use crate::{pallet as pallet_axelar_router, AxelarId}; | ||
|
||
type AccountId = u64; | ||
|
||
pub struct Middleware(AxelarId); | ||
|
||
impl From<AxelarId> for Middleware { | ||
fn from(id: AxelarId) -> Self { | ||
Middleware(id) | ||
} | ||
} | ||
|
||
frame_support::construct_runtime!( | ||
pub enum Runtime { | ||
System: frame_system, | ||
Receiver: cfg_mocks::message_receiver::pallet, | ||
Transactor: cfg_mocks::ethereum_transactor::pallet, | ||
AccountCodeChecker: cfg_mocks::pre_conditions::pallet, | ||
AxelarRouter: pallet_axelar_router, | ||
} | ||
); | ||
|
||
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] | ||
impl frame_system::Config for Runtime { | ||
type Block = frame_system::mocking::MockBlock<Runtime>; | ||
} | ||
|
||
impl cfg_mocks::message_receiver::pallet::Config for Runtime { | ||
type Middleware = Middleware; | ||
type Origin = DomainAddress; | ||
} | ||
|
||
impl cfg_mocks::ethereum_transactor::pallet::Config for Runtime {} | ||
|
||
impl cfg_mocks::pre_conditions::pallet::Config for Runtime { | ||
type Conditions = (H160, H256); | ||
type Result = bool; | ||
} | ||
|
||
impl pallet_axelar_router::Config for Runtime { | ||
type AdminOrigin = EitherOfDiverse<EnsureRoot<AccountId>, EnsureSigned<AccountId>>; | ||
type EvmAccountCodeChecker = AccountCodeChecker; | ||
type Middleware = Middleware; | ||
type Receiver = Receiver; | ||
type RuntimeEvent = RuntimeEvent; | ||
type Transactor = Transactor; | ||
} | ||
|
||
pub fn new_test_ext() -> TestExternalities { | ||
System::externalities() | ||
} |
Oops, something went wrong.