Skip to content

Commit 07bc859

Browse files
dharjeezyWizdave97
andauthored
bring back asset hub integration (#576)
Co-authored-by: David Salami <[email protected]>
1 parent 88c7558 commit 07bc859

File tree

20 files changed

+1201
-247
lines changed

20 files changed

+1201
-247
lines changed

Cargo.lock

Lines changed: 40 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/ismp/state-machines/evm/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ pub fn verify_state_proof<H: Keccak256 + Send + Sync>(
116116
entry.push((key, slot_hash));
117117
}
118118

119+
// Ensure there is a proof for all contract addresses
120+
let result = contract_to_keys
121+
.clone()
122+
.into_keys()
123+
.all(|contract| evm_state_proof.storage_proof.contains_key(&contract));
124+
if !result {
125+
Err(Error::Custom(
126+
"The storage proof is incomplete, missing some contract proofs".to_string(),
127+
))?
128+
}
129+
119130
for (contract_address, storage_proof) in evm_state_proof.storage_proof {
120131
let contract_root = get_contract_account::<H>(
121132
evm_state_proof.contract_proof.clone(),

modules/pallets/collator-manager/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
extern crate alloc;
2323

2424
use pallet_messaging_fees::IncentivesManager;
25-
use polkadot_sdk::{
26-
sp_runtime::{DispatchError, Weight},
27-
*,
28-
};
25+
use polkadot_sdk::{sp_runtime::Weight, *};
2926

3027
pub use pallet::*;
3128

@@ -36,7 +33,7 @@ pub mod pallet {
3633
use core::fmt::Debug;
3734
use frame_support::{
3835
PalletId,
39-
dispatch::{DispatchClass, DispatchResult},
36+
dispatch::DispatchResult,
4037
pallet_prelude::*,
4138
traits::{
4239
Currency, ExistenceRequirement, Get, LockIdentifier, LockableCurrency,

modules/pallets/messaging-fees/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ use frame_support::{
3131
traits::Get,
3232
};
3333
use frame_system::pallet_prelude::*;
34-
use polkadot_sdk::{
35-
sp_runtime::{traits::OpaqueKeys, KeyTypeId},
36-
*,
37-
};
34+
use polkadot_sdk::*;
3835

3936
use ismp::{
4037
dispatcher::IsmpDispatcher,

modules/pallets/testsuite/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ evm-state-machine = { workspace = true, default-features = true }
5353
subxt-utils = { workspace = true, default-features = true }
5454
ismp-grandpa = { workspace = true, default-features = true }
5555
rs_merkle = { version = "1.5.0"}
56+
log = { workspace = true }
5657

5758
[dependencies.polkadot-sdk]
5859
workspace = true
@@ -89,9 +90,11 @@ features = [
8990
"pallet-session",
9091
"pallet-assets-holder",
9192
"pallet-authorship",
92-
"cumulus-primitives-parachain-inherent"
93+
"cumulus-primitives-parachain-inherent",
94+
"xcm-emulator"
9395
]
9496

97+
9598
[dev-dependencies]
9699
hex = "0.4.3"
97100
zstd-safe = { version = "7.1.0" }
@@ -101,6 +104,7 @@ tokio = { workspace = true }
101104
dotenv = "0.15.0"
102105
futures = "0.3.28"
103106
pallet-ismp-rpc = { workspace = true }
107+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
104108

105109
[features]
106110
runtime-benchmarks = [
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright (c) 2025 Polytope Labs.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
#![allow(missing_docs, dead_code)]
16+
17+
extern crate alloc;
18+
use polkadot_sdk::{frame_support::traits::WithdrawReasons, sp_runtime::traits::ConvertInto, *};
19+
20+
use cumulus_pallet_parachain_system::ParachainSetCode;
21+
use frame_support::{
22+
derive_impl, parameter_types,
23+
traits::{ConstU32, ConstU64, Get},
24+
PalletId,
25+
};
26+
use frame_system::{EnsureRoot, EnsureSigned, EventRecord};
27+
use polkadot_sdk::{
28+
pallet_session::{disabling::UpToLimitDisablingStrategy, SessionHandler},
29+
sp_runtime::{app_crypto::AppCrypto, traits::OpaqueKeys},
30+
xcm_simulator::{GeneralIndex, Junctions::X3, Location, PalletInstance, Parachain},
31+
};
32+
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
33+
use sp_core::{
34+
offchain::{testing::TestOffchainExt, OffchainDbExt, OffchainWorkerExt},
35+
H160, H256, U256,
36+
};
37+
use sp_runtime::{
38+
traits::{IdentityLookup, Keccak256},
39+
AccountId32, BuildStorage,
40+
};
41+
42+
use crate::asset_hub_runtime::sp_runtime::DispatchError;
43+
use pallet_xcm_gateway::xcm_utilities::ASSET_HUB_PARA_ID;
44+
use xcm_simulator::mock_message_queue;
45+
pub const ALICE: AccountId32 = AccountId32::new([1; 32]);
46+
pub const BOB: AccountId32 = AccountId32::new([2; 32]);
47+
pub const CHARLIE: AccountId32 = AccountId32::new([3; 32]);
48+
pub const DAVE: AccountId32 = AccountId32::new([4; 32]);
49+
50+
pub const INITIAL_BALANCE: u128 = 1_000_000_000_000_000_000;
51+
52+
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<AssetHubTest>;
53+
type Block = frame_system::mocking::MockBlock<AssetHubTest>;
54+
55+
frame_support::construct_runtime!(
56+
pub enum AssetHubTest {
57+
System: frame_system,
58+
ParachainSystem: cumulus_pallet_parachain_system,
59+
ParachainInfo: staging_parachain_info,
60+
Balances: pallet_balances,
61+
XcmpQueue: cumulus_pallet_xcmp_queue,
62+
MessageQueue: pallet_message_queue,
63+
PalletXcm: pallet_xcm,
64+
Assets: pallet_assets,
65+
MsgQueue: mock_message_queue
66+
}
67+
);
68+
69+
/// Verify the the last event emitted
70+
pub fn assert_last_event<T: frame_system::Config>(generic_event: T::RuntimeEvent) {
71+
assert_eq!(last_event::<T>(), generic_event);
72+
}
73+
74+
/// Verify the the last event emitted
75+
pub fn last_event<T: frame_system::Config>() -> T::RuntimeEvent {
76+
let events = frame_system::Pallet::<T>::events();
77+
let EventRecord { event, .. } = &events[events.len() - 1];
78+
event.clone()
79+
}
80+
81+
/// Balance of an account.
82+
pub type Balance = u128;
83+
// Unit = the base number of indivisible units for balances
84+
pub const UNIT: Balance = 1_000_000_000_000;
85+
pub const MILLIUNIT: Balance = 1_000_000_000;
86+
pub const MICROUNIT: Balance = 1_000_000;
87+
88+
/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
89+
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
90+
91+
parameter_types! {
92+
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
93+
}
94+
95+
impl pallet_balances::Config for AssetHubTest {
96+
/// The ubiquitous event type.
97+
type RuntimeEvent = RuntimeEvent;
98+
type RuntimeHoldReason = RuntimeHoldReason;
99+
type RuntimeFreezeReason = RuntimeFreezeReason;
100+
type WeightInfo = pallet_balances::weights::SubstrateWeight<AssetHubTest>;
101+
/// The type for recording an account's balance.
102+
type Balance = Balance;
103+
type DustRemoval = ();
104+
type ExistentialDeposit = ExistentialDeposit;
105+
type AccountStore = System;
106+
type ReserveIdentifier = [u8; 8];
107+
type FreezeIdentifier = ();
108+
type MaxLocks = ConstU32<50>;
109+
type MaxReserves = ConstU32<50>;
110+
type MaxFreezes = ();
111+
type DoneSlashHandler = ();
112+
}
113+
114+
#[derive_impl(frame_system::config_preludes::ParaChainDefaultConfig as frame_system::DefaultConfig)]
115+
impl frame_system::Config for AssetHubTest {
116+
type BaseCallFilter = frame_support::traits::Everything;
117+
type RuntimeOrigin = RuntimeOrigin;
118+
type RuntimeCall = RuntimeCall;
119+
type Hash = H256;
120+
type Hashing = Keccak256;
121+
type AccountId = AccountId32;
122+
type Lookup = IdentityLookup<Self::AccountId>;
123+
type RuntimeEvent = RuntimeEvent;
124+
type BlockHashCount = ConstU64<250>;
125+
type DbWeight = ();
126+
type BlockWeights = ();
127+
type RuntimeTask = ();
128+
type BlockLength = ();
129+
type Version = ();
130+
type Nonce = u64;
131+
type Block = Block;
132+
type PalletInfo = PalletInfo;
133+
type AccountData = pallet_balances::AccountData<Balance>;
134+
type OnNewAccount = ();
135+
type OnKilledAccount = ();
136+
type SystemWeightInfo = ();
137+
type SS58Prefix = ();
138+
type OnSetCode = ParachainSetCode<AssetHubTest>;
139+
type MaxConsumers = ConstU32<16>;
140+
}
141+
142+
parameter_types! {
143+
pub const Decimals: u8 = 10;
144+
}
145+
146+
pub struct NativeAssetId;
147+
148+
impl Get<H256> for NativeAssetId {
149+
fn get() -> H256 {
150+
sp_io::hashing::keccak_256(b"BRIDGE").into()
151+
}
152+
}
153+
154+
sp_runtime::impl_opaque_keys! {
155+
pub struct SessionKeys {
156+
pub aura: AuraId,
157+
}
158+
}
159+
160+
pub fn register_offchain_ext(ext: &mut sp_io::TestExternalities) {
161+
let (offchain, _offchain_state) = TestOffchainExt::with_offchain_db(ext.offchain_db());
162+
ext.register_extension(OffchainDbExt::new(offchain.clone()));
163+
ext.register_extension(OffchainWorkerExt::new(offchain));
164+
}

0 commit comments

Comments
 (0)