Skip to content

Commit

Permalink
add claim test to coretime westend
Browse files Browse the repository at this point in the history
  • Loading branch information
Zihan Zhao authored and programskillforverification committed Jul 15, 2024
1 parent ae44cd3 commit 9d5ff40
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 22 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ console = { version = "0.15.8" }
contracts-rococo-runtime = { path = "cumulus/parachains/runtimes/contracts/contracts-rococo" }
coretime-rococo-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo" }
coretime-rococo-runtime = { path = "cumulus/parachains/runtimes/coretime/coretime-rococo" }
coretime-westend-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend" }
coretime-westend-runtime = { path = "cumulus/parachains/runtimes/coretime/coretime-westend" }
cpu-time = { version = "1.0.0" }
criterion = { version = "0.5.1", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ workspace = true

[dependencies]

# Substrate
sp-core = { workspace = true }
frame-support = { workspace = true }

# Cumulus
parachains-common = { workspace = true, default-features = true }
cumulus-primitives-core = { workspace = true }
coretime-westend-runtime = { workspace = true, default-features = true }
emulated-integration-tests-common = { workspace = true }
testnet-parachains-constants = { features = ["westend"], workspace = true, default-features = true }
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Substrate
use sp_core::storage::Storage;

// Cumulus
use emulated_integration_tests_common::{
accounts, build_genesis_storage, collators, SAFE_XCM_VERSION,
};
use parachains_common::Balance;

pub const PARA_ID: u32 = 1005;
pub const ED: Balance = testnet_parachains_constants::westend::currency::EXISTENTIAL_DEPOSIT;

pub fn genesis() -> Storage {
let genesis_config = coretime_westend_runtime::RuntimeGenesisConfig {
system: coretime_westend_runtime::SystemConfig::default(),
balances: coretime_westend_runtime::BalancesConfig {
balances: accounts::init_balances().iter().cloned().map(|k| (k, ED * 4096)).collect(),
},
parachain_info: coretime_westend_runtime::ParachainInfoConfig {
parachain_id: PARA_ID.into(),
..Default::default()
},
collator_selection: coretime_westend_runtime::CollatorSelectionConfig {
invulnerables: collators::invulnerables().iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: ED * 16,
..Default::default()
},
session: coretime_westend_runtime::SessionConfig {
keys: collators::invulnerables()
.into_iter()
.map(|(acc, aura)| {
(
acc.clone(), // account id
acc, // validator id
coretime_westend_runtime::SessionKeys { aura }, // session keys
)
})
.collect(),
},
polkadot_xcm: coretime_westend_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
..Default::default()
};

build_genesis_storage(
&genesis_config,
coretime_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
pub use coretime_westend_runtime;

pub mod genesis;

#[cfg(test)]
mod tests {
use super::*;
// Substrate
use frame_support::traits::OnInitialize;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
// Cumulus
use emulated_integration_tests_common::{
impl_accounts_helpers_for_parachain, impl_assert_events_helpers_for_parachain,
impls::Parachain, xcm_emulator::decl_test_parachains,
};

// CoretimeWestend Parachain declaration
decl_test_parachains! {
pub struct CoretimeWestend {
genesis = genesis::genesis(),
on_init = {
coretime_westend_runtime::AuraExt::on_initialize(1);
},
runtime = coretime_westend_runtime,
core = {
XcmpMessageHandler: coretime_westend_runtime::XcmpQueue,
LocationToAccountId: coretime_westend_runtime::xcm_config::LocationToAccountId,
ParachainInfo: coretime_westend_runtime::ParachainInfo,
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
},
pallets = {
PolkadotXcm: coretime_westend_runtime::PolkadotXcm,
Balances: coretime_westend_runtime::Balances,
Broker: coretime_westend_runtime::Broker,
}
},
}

// CoretimeWestend implementation
impl_accounts_helpers_for_parachain!(CoretimeWestend);
impl_assert_events_helpers_for_parachain!(CoretimeWestend);
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ bridge-hub-westend-emulated-chain = { workspace = true }
collectives-westend-emulated-chain = { workspace = true }
penpal-emulated-chain = { workspace = true }
people-westend-emulated-chain = { workspace = true }
coretime-westend-emulated-chain = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
pub use asset_hub_westend_emulated_chain;
pub use bridge_hub_westend_emulated_chain;
pub use collectives_westend_emulated_chain;
pub use coretime_westend_emulated_chain;
pub use penpal_emulated_chain;
pub use people_westend_emulated_chain;
pub use westend_emulated_chain;

use asset_hub_westend_emulated_chain::AssetHubWestend;
use bridge_hub_westend_emulated_chain::BridgeHubWestend;
use collectives_westend_emulated_chain::CollectivesWestend;
use coretime_westend_emulated_chain::CoretimeWestend;
use penpal_emulated_chain::{PenpalA, PenpalB};
use people_westend_emulated_chain::PeopleWestend;
use westend_emulated_chain::Westend;
Expand All @@ -40,6 +42,7 @@ decl_test_networks! {
AssetHubWestend,
BridgeHubWestend,
CollectivesWestend,
CoretimeWestend,
PeopleWestend,
PenpalA,
PenpalB,
Expand All @@ -53,6 +56,7 @@ decl_test_sender_receiver_accounts_parameter_types! {
AssetHubWestendPara { sender: ALICE, receiver: BOB },
BridgeHubWestendPara { sender: ALICE, receiver: BOB },
CollectivesWestendPara { sender: ALICE, receiver: BOB },
CoretimeWestendPara { sender: ALICE, receiver: BOB },
PeopleWestendPara { sender: ALICE, receiver: BOB },
PenpalAPara { sender: ALICE, receiver: BOB },
PenpalBPara { sender: ALICE, receiver: BOB }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@ publish = false

[dependencies]

# Substrate
frame-support = { workspace = true }
pallet-balances = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-identity = { workspace = true }
sp-runtime = { workspace = true }

# Polkadot
polkadot-runtime-common = { workspace = true, default-features = true }
westend-runtime-constants = { workspace = true, default-features = true }
xcm = { workspace = true }
xcm-executor = { workspace = true }

# Cumulus
emulated-integration-tests-common = { workspace = true }
westend-system-emulated-network = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
mod imports {

// Substrate
pub use frame_support::assert_ok;

// Polkadot
pub use xcm::prelude::*;

// Cumulus
pub use emulated_integration_tests_common::xcm_emulator::{
assert_expected_events, bx, TestExt,
};
pub use westend_system_emulated_network::{
coretime_westend_emulated_chain::{
coretime_westend_runtime::ExistentialDeposit as CoretimeWestendExistentialDeposit,
CoretimeWestendParaPallet as CoretimeWestendPallet,
},
CoretimeWestendPara as CoretimeWestend,
CoretimeWestendParaReceiver as CoretimeWestendReceiver,
CoretimeWestendParaSender as CoretimeWestendSender,
};
}

#[cfg(test)]
mod tests;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Tests related to claiming assets trapped during XCM execution.
use crate::imports::*;

use emulated_integration_tests_common::test_chain_can_claim_assets;
use xcm_executor::traits::DropAssets;

#[test]
fn assets_can_be_claimed() {
let amount = CoretimeWestendExistentialDeposit::get();
let assets: Assets = (Parent, amount).into();

test_chain_can_claim_assets!(CoretimeWestend, RuntimeCall, NetworkId::Westend, assets, amount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

mod claim_assets;

0 comments on commit 9d5ff40

Please sign in to comment.