Skip to content

Commit a4678d7

Browse files
authored
Merge pull request #1309 from galacticcouncil/chore/ismp-testnet-config
chore: add Parameters based ismp testnet config
2 parents 5afc54b + 67425d2 commit a4678d7

5 files changed

Lines changed: 65 additions & 18 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fp-rpc = { workspace = true }
8484

8585
# Hyperbridge
8686
ismp = { workspace = true }
87+
pallet-ismp = { workspace = true }
8788
ismp-parachain = { workspace = true }
8889

8990
# Cumulus dependencies

integration-tests/src/parameters.rs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,17 @@
2727

2828
use crate::polkadot_test_net::*;
2929
use codec::Encode;
30+
use ismp::host::StateMachine;
3031
use primitives::constants::time::{HOURS, MINUTES};
3132
use sp_core::{storage::StorageKey, Get};
3233
use xcm_emulator::TestExt;
3334

35+
fn set_parameters_storage_to_testnet() {
36+
let key = StorageKey(frame_support::storage::storage_prefix(b"Parameters", b"IsTestnet").to_vec());
37+
let value = true.encode();
38+
sp_io::storage::set(&key.0, &value);
39+
}
40+
3441
#[test]
3542
fn is_testnet_sets_correct_referenda_params_when_default() {
3643
TestNet::reset();
@@ -54,9 +61,7 @@ fn is_testnet_sets_correct_referenda_params_when_testnet() {
5461
TestNet::reset();
5562
Hydra::execute_with(|| {
5663
// Prepare
57-
let key = StorageKey(frame_support::storage::storage_prefix(b"Parameters", b"IsTestnet").to_vec());
58-
let value = true.encode();
59-
sp_io::storage::set(&key.0, &value);
64+
set_parameters_storage_to_testnet();
6065

6166
// Assert
6267
let tracks = <hydradx_runtime::Runtime as pallet_referenda::Config>::Tracks::get();
@@ -70,3 +75,32 @@ fn is_testnet_sets_correct_referenda_params_when_testnet() {
7075
assert_eq!(root_track.1.min_enactment_period, 1);
7176
});
7277
}
78+
79+
#[test]
80+
fn is_testnet_sets_correct_ismp_params_when_default() {
81+
TestNet::reset();
82+
Hydra::execute_with(|| {
83+
// Assert
84+
let ismp_coprocessor = <hydradx_runtime::Runtime as pallet_ismp::Config>::Coprocessor::get();
85+
let host_state_machine = <hydradx_runtime::Runtime as pallet_ismp::Config>::HostStateMachine::get();
86+
87+
assert_eq!(ismp_coprocessor, Some(StateMachine::Polkadot(3367)));
88+
assert_eq!(host_state_machine, StateMachine::Polkadot(2034));
89+
});
90+
}
91+
92+
#[test]
93+
fn is_testnet_sets_correct_ismp_params_when_testnet() {
94+
TestNet::reset();
95+
Hydra::execute_with(|| {
96+
// Prepare
97+
set_parameters_storage_to_testnet();
98+
99+
// Assert
100+
let ismp_coprocessor = <hydradx_runtime::Runtime as pallet_ismp::Config>::Coprocessor::get();
101+
let host_state_machine = <hydradx_runtime::Runtime as pallet_ismp::Config>::HostStateMachine::get();
102+
103+
assert_eq!(ismp_coprocessor, Some(StateMachine::Kusama(4009)));
104+
assert_eq!(host_state_machine, StateMachine::Kusama(2034));
105+
});
106+
}

runtime/hydradx/src/benchmarking/token_gateway_ismp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ismp::module::IsmpModule;
1414
use ismp::router::{PostRequest, PostResponse, Request, Response, Timeout};
1515
use pallet_token_gateway as tg;
1616
use pallet_token_gateway::types::Body;
17-
use sp_core::H256;
17+
use sp_core::{Get, H256};
1818

1919
// Helper: encode a token-gateway Body and prefix with a selector byte expected by on_accept/on_timeout
2020
fn encode_body(body: Body) -> Vec<u8> {

runtime/hydradx/src/hyperbridge.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::origins::GeneralAdmin;
22
use crate::{
3-
weights, Balances, EVMAccounts, Ismp, IsmpParachain, NativeAssetId, Runtime, RuntimeEvent,
3+
weights, Balances, EVMAccounts, Ismp, IsmpParachain, NativeAssetId, Parameters, Runtime, RuntimeEvent,
44
TechCommitteeSuperMajority, Timestamp, TokenGateway, TreasuryAccount,
55
};
66
use frame_support::parameter_types;
@@ -18,6 +18,7 @@ use pallet_token_gateway::types::EvmToSubstrate;
1818
use primitive_types::H160;
1919
use primitives::constants::currency::NATIVE_DECIMALS;
2020
use primitives::{AccountId, AssetId, Balance};
21+
use sp_core::Get;
2122
use sp_std::{boxed::Box, vec::Vec};
2223

2324
impl pallet_hyperbridge::Config for Runtime {
@@ -27,19 +28,29 @@ impl pallet_hyperbridge::Config for Runtime {
2728
}
2829

2930
parameter_types! {
30-
// The hyperbridge parachain on Polkadot
31-
pub const Coprocessor: Option<StateMachine> = Some(StateMachine::Polkadot(3367));
32-
33-
// The host state machine of this pallet on Polkadot
34-
pub const HostStateMachine: StateMachine = StateMachine::Polkadot(2034);
35-
36-
// The hyperbridge parachain on Paseo
37-
// pub const Coprocessor: Option<StateMachine> = Some(StateMachine::Kusama(4009));
31+
pub const USDC: AssetId = 22; // USDC asset id on Hydration
32+
}
3833

39-
// The host state machine of this pallet on Paseo
40-
// pub const HostStateMachine: StateMachine = StateMachine::Kusama(2034);
34+
pub struct IsmpCoprocessor;
35+
impl Get<Option<StateMachine>> for IsmpCoprocessor {
36+
fn get() -> Option<StateMachine> {
37+
if Parameters::is_testnet() {
38+
Some(StateMachine::Kusama(4009))
39+
} else {
40+
Some(StateMachine::Polkadot(3367))
41+
}
42+
}
43+
}
4144

42-
pub const USDC: AssetId = 22; // USDC asset id on Hydration
45+
pub struct IsmpHostStateMachine;
46+
impl Get<StateMachine> for IsmpHostStateMachine {
47+
fn get() -> StateMachine {
48+
if Parameters::is_testnet() {
49+
StateMachine::Kusama(2034)
50+
} else {
51+
StateMachine::Polkadot(2034)
52+
}
53+
}
4354
}
4455

4556
impl pallet_ismp::Config for Runtime {
@@ -51,9 +62,9 @@ impl pallet_ismp::Config for Runtime {
5162
// The token used to collect fees, only stablecoins are supported
5263
type Currency = ItemOf<FungibleCurrencies<Runtime>, USDC, AccountId>;
5364
// The state machine identifier of the chain -- parachain id
54-
type HostStateMachine = HostStateMachine;
65+
type HostStateMachine = IsmpHostStateMachine;
5566
// Co-processor
56-
type Coprocessor = Coprocessor;
67+
type Coprocessor = IsmpCoprocessor;
5768
// The router provides the implementation for the IsmpModule as the module id.
5869
type Router = IsmpRouterStruct;
5970
// A tuple of types implementing the ConsensusClient interface, which defines all consensus algorithms supported by this protocol deployment

0 commit comments

Comments
 (0)