Skip to content

Commit

Permalink
wip: Connectors mock.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoAlexandre committed Sep 14, 2022
1 parent b90cbb8 commit f60e0b8
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 9 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pallets/connectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ pallet-ethereum = { git = "https://github.com/NunoAlexandre/frontier", branch =
[dev-dependencies]
hex = "0.4.3"

# Our pallets
pallet-pools = { path = "../pools", default-features = false}
pallet-loans = { path = "../loans", default-features = false}
pallet-interest-accrual = { path = "../interest-accrual", default-features = false}
pallet-permissions = { path = "../permissions", default-features = false}

# Substrate crates & pallets
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.26" }
sp-io = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.26" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.26" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.26" }
pallet-uniques = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "polkadot-v0.9.26" }

# Orml crates
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", default-features = true, branch = "polkadot-v0.9.26" }
Expand Down Expand Up @@ -87,4 +95,9 @@ std = [
'pallet-ethereum/std',
'xcm-primitives/std',
'ethabi/std',
'pallet-interest-accrual/std',
'pallet-permissions/std',
'pallet-loans/std',
'pallet-pools/std',
'pallet-uniques/std'
]
17 changes: 11 additions & 6 deletions pallets/connectors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub use message::*;
mod routers;
pub use routers::*;

#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;

#[derive(Encode, Decode, Clone, PartialEq, TypeInfo)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum Domain {
Expand Down Expand Up @@ -484,7 +489,7 @@ pub mod pallet {
/// where this `ethereum_xcm` call is to be executed
/// * `contract_call` - The encoded EVM call calling ConnectorsXcmRouter::handle(msg)
pub fn encoded_ethereum_xcm_call(
domain_info: XcmDomainInfo,
domain_info: XcmDomain,
evm_call: Vec<u8>,
) -> Result<Vec<u8>, ()> {
let eth_tx =
Expand All @@ -500,7 +505,7 @@ pub fn encoded_ethereum_xcm_call(
// The complete encoded call payload to be sent in a `Transact` XCM instruction,
// encoding an ethereum_xcm::transact call.
let mut encoded: Vec<u8> = Vec::new();
encoded.append(&mut domain_info.ethereum_xcm_transact_prefix.clone());
encoded.append(&mut domain_info.ethereum_xcm_transact_call_index.clone());
encoded.append(&mut eth_tx.encode());

Ok(encoded)
Expand Down Expand Up @@ -552,7 +557,7 @@ pub fn xcm_router_contract() -> Contract {
}

#[cfg(test)]
mod tests {
mod unit_tests {
use crate::*;
use codec::Encode;
use hex::FromHex;
Expand All @@ -578,14 +583,14 @@ mod tests {
interior: X1(Parachain(1000)),
};
// 38 is the pallet index, 0 is the `transact` extrinsic index.
let ethereum_xcm_transact_prefix = vec![38, 0];
let ethereum_xcm_transact_call_index = vec![38, 0];
let contract_address = H160::from(
<[u8; 20]>::from_hex("cE0Cb9BB900dfD0D378393A041f3abAb6B182882")
.expect("Decoding failed"),
);
let domain_info = XcmDomainInfo {
let domain_info = XcmDomain {
location: VersionedMultiLocation::V1(moonbase_location.clone()),
ethereum_xcm_transact_prefix,
ethereum_xcm_transact_call_index,
contract_address,
};

Expand Down
Loading

0 comments on commit f60e0b8

Please sign in to comment.