Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Mar 1, 2024
1 parent c1fba21 commit 26e121f
Show file tree
Hide file tree
Showing 6 changed files with 1,631 additions and 1,416 deletions.
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-executor/src/traits/on_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl VersionChangeNotifier for () {
}

/// The possible state of an XCM query response.
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
#[derive(Debug, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub enum QueryResponseStatus<BlockNumber> {
/// The response has arrived, and includes the inner Response and the block number it arrived
/// at.
Expand Down
15 changes: 9 additions & 6 deletions substrate/frame/contracts/fixtures/contracts/xcm_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
#![no_main]

use common::input;
use uapi::{HostFn, HostFnImpl as api};
use uapi::{
HostFn,
HostFnImpl as api,
};

#[no_mangle]
#[polkavm_derive::polkavm_export]
Expand All @@ -28,10 +31,10 @@ pub extern "C" fn deploy() {}
#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
input!(512, timeout: [u8; 8], match_querier: [u8],);
let mut query_id = [0u8; 8];
input!(512, timeout: [u8; 4], match_querier: [u8],);
let mut query_id = [0u8; 8];

#[allow(deprecated)]
api::xcm_query(timeout, match_querier, &mut query_id).unwrap();
api::return_value(uapi::ReturnFlags::empty(), &query_id);
#[allow(deprecated)]
api::xcm_query(timeout, match_querier, &mut query_id).unwrap();
api::return_value(uapi::ReturnFlags::empty(), &query_id);
}
202 changes: 114 additions & 88 deletions substrate/frame/contracts/mock-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ pub mod relay_chain;
#[cfg(test)]
mod tests;

use crate::primitives::{AccountId, UNITS};
use crate::primitives::{
AccountId,
UNITS,
};
use sp_runtime::BuildStorage;
use xcm::latest::prelude::*;
pub use xcm_executor;
use xcm_executor::traits::ConvertLocation;
pub use xcm_simulator::TestExt;
use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain};
use xcm_simulator::{
decl_test_network,
decl_test_parachain,
decl_test_relay_chain,
};

// Accounts
pub const ADMIN: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([0u8; 32]);
Expand All @@ -38,114 +46,132 @@ pub const BOB: sp_runtime::AccountId32 = sp_runtime::AccountId32::new([2u8; 32])
pub const INITIAL_BALANCE: u128 = 1_000_000_000 * UNITS;

decl_test_parachain! {
pub struct ParaA {
Runtime = parachain::Runtime,
XcmpMessageHandler = parachain::MsgQueue,
DmpMessageHandler = parachain::MsgQueue,
new_ext = para_ext(1),
}
pub struct ParaA {
Runtime = parachain::Runtime,
XcmpMessageHandler = parachain::MsgQueue,
DmpMessageHandler = parachain::MsgQueue,
new_ext = para_ext(1),
}
}

decl_test_relay_chain! {
pub struct Relay {
Runtime = relay_chain::Runtime,
RuntimeCall = relay_chain::RuntimeCall,
RuntimeEvent = relay_chain::RuntimeEvent,
XcmConfig = relay_chain::XcmConfig,
MessageQueue = relay_chain::MessageQueue,
System = relay_chain::System,
new_ext = relay_ext(),
}
pub struct Relay {
Runtime = relay_chain::Runtime,
RuntimeCall = relay_chain::RuntimeCall,
RuntimeEvent = relay_chain::RuntimeEvent,
XcmConfig = relay_chain::XcmConfig,
MessageQueue = relay_chain::MessageQueue,
System = relay_chain::System,
new_ext = relay_ext(),
}
}

decl_test_network! {
pub struct MockNet {
relay_chain = Relay,
parachains = vec![
(1, ParaA),
],
}
pub struct MockNet {
relay_chain = Relay,
parachains = vec![
(1, ParaA),
],
}
}

pub fn relay_sovereign_account_id() -> AccountId {
let location: Location = (Parent,).into();
parachain::SovereignAccountOf::convert_location(&location).unwrap()
let location: Location = (Parent,).into();
parachain::SovereignAccountOf::convert_location(&location).unwrap()
}

pub fn parachain_sovereign_account_id(para: u32) -> AccountId {
let location: Location = (Parachain(para),).into();
relay_chain::SovereignAccountOf::convert_location(&location).unwrap()
let location: Location = (Parachain(para),).into();
relay_chain::SovereignAccountOf::convert_location(&location).unwrap()
}

pub fn parachain_account_sovereign_account_id(
para: u32,
who: sp_runtime::AccountId32,
para: u32,
who: sp_runtime::AccountId32,
) -> AccountId {
let location: Location = (
Parachain(para),
AccountId32 { network: Some(relay_chain::RelayNetwork::get()), id: who.into() },
)
.into();
relay_chain::SovereignAccountOf::convert_location(&location).unwrap()
let location: Location = (
Parachain(para),
AccountId32 {
network: Some(relay_chain::RelayNetwork::get()),
id: who.into(),
},
)
.into();
relay_chain::SovereignAccountOf::convert_location(&location).unwrap()
}

pub fn para_ext(para_id: u32) -> sp_io::TestExternalities {
use parachain::{MsgQueue, Runtime, System};

let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(ALICE, INITIAL_BALANCE),
(relay_sovereign_account_id(), INITIAL_BALANCE),
(BOB, INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();

pallet_assets::GenesisConfig::<Runtime> {
assets: vec![
(0u128, ADMIN, false, 1u128), // Create derivative asset for relay's native token
],
metadata: Default::default(),
accounts: vec![
(0u128, ALICE, INITIAL_BALANCE),
(0u128, relay_sovereign_account_id(), INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
sp_tracing::try_init_simple();
System::set_block_number(1);
MsgQueue::set_para_id(para_id.into());
});
ext
use parachain::{
MsgQueue,
Runtime,
System,
};

let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(ALICE, INITIAL_BALANCE),
(relay_sovereign_account_id(), INITIAL_BALANCE),
(BOB, INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();

pallet_assets::GenesisConfig::<Runtime> {
assets: vec![
(0u128, ADMIN, false, 1u128), /* Create derivative asset for relay's
* native token */
],
metadata: Default::default(),
accounts: vec![
(0u128, ALICE, INITIAL_BALANCE),
(0u128, relay_sovereign_account_id(), INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
sp_tracing::try_init_simple();
System::set_block_number(1);
MsgQueue::set_para_id(para_id.into());
});
ext
}

pub fn relay_ext() -> sp_io::TestExternalities {
use relay_chain::{Runtime, System};

let mut t = frame_system::GenesisConfig::<Runtime>::default().build_storage().unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(ALICE, INITIAL_BALANCE),
(parachain_sovereign_account_id(1), INITIAL_BALANCE),
(parachain_account_sovereign_account_id(1, ALICE), INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
ext
use relay_chain::{
Runtime,
System,
};

let mut t = frame_system::GenesisConfig::<Runtime>::default()
.build_storage()
.unwrap();

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(ALICE, INITIAL_BALANCE),
(parachain_sovereign_account_id(1), INITIAL_BALANCE),
(
parachain_account_sovereign_account_id(1, ALICE),
INITIAL_BALANCE,
),
],
}
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| {
System::set_block_number(1);
});
ext
}

pub type ParachainPalletXcm = pallet_xcm::Pallet<parachain::Runtime>;
Expand Down
Loading

0 comments on commit 26e121f

Please sign in to comment.