From 28af4b5c3df139b558c857c275df8076f61a9aae Mon Sep 17 00:00:00 2001 From: hqwangningbo <2536935847@qq.com> Date: Mon, 20 Nov 2023 21:25:52 +0800 Subject: [PATCH] Optimising integration tests --- Cargo.lock | 295 +----- Cargo.toml | 1 + integration-tests/bifrost-kusama/Cargo.toml | 6 + .../bifrost-kusama/src/account_id.rs | 12 +- .../bifrost-kusama/src/dollor_tests.rs | 14 +- .../bifrost-kusama/src/general_key.rs | 4 +- .../src/kusama_cross_chain_transact.rs | 134 --- .../src/kusama_integration_tests.rs | 181 ---- .../bifrost-kusama/src/kusama_test_net.rs | 187 ---- integration-tests/bifrost-kusama/src/lib.rs | 95 +- integration-tests/bifrost-kusama/src/slp.rs | 994 ++++++++---------- .../bifrost-kusama/src/total_issuance.rs | 82 +- .../bifrost-kusama/src/transact.rs | 141 +++ .../bifrost-kusama/src/treasury.rs | 141 --- .../bifrost-kusama/src/vtoken_minting.rs | 325 +++--- .../bifrost-kusama/src/vtoken_voting.rs | 412 ++++---- .../bifrost-kusama/src/xcm_interface.rs | 296 +++--- .../{reserve_transfer.rs => xcm_transfer.rs} | 59 +- integration-tests/bifrost-polkadot/Cargo.toml | 3 +- integration-tests/bifrost-polkadot/src/lib.rs | 76 +- .../{reserve_transfer.rs => xcm_transfer.rs} | 69 +- integration-tests/common/Cargo.toml | 18 +- integration-tests/common/src/constants.rs | 581 ++-------- integration-tests/common/src/impls.rs | 136 +-- integration-tests/common/src/lib.rs | 390 +------ 25 files changed, 1422 insertions(+), 3230 deletions(-) delete mode 100644 integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs delete mode 100644 integration-tests/bifrost-kusama/src/kusama_integration_tests.rs delete mode 100644 integration-tests/bifrost-kusama/src/kusama_test_net.rs create mode 100644 integration-tests/bifrost-kusama/src/transact.rs delete mode 100644 integration-tests/bifrost-kusama/src/treasury.rs rename integration-tests/bifrost-kusama/src/{reserve_transfer.rs => xcm_transfer.rs} (80%) rename integration-tests/bifrost-polkadot/src/{reserve_transfer.rs => xcm_transfer.rs} (77%) diff --git a/Cargo.lock b/Cargo.lock index b04b433dbe..22f1e61a1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -731,76 +731,6 @@ dependencies = [ "substrate-wasm-builder", ] -[[package]] -name = "asset-hub-westend-runtime" -version = "0.9.420" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "assets-common", - "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "cumulus-primitives-utility", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "log", - "pallet-asset-conversion", - "pallet-asset-conversion-tx-payment", - "pallet-assets", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "pallet-multisig", - "pallet-nft-fractionalization", - "pallet-nfts", - "pallet-nfts-runtime-api", - "pallet-proxy", - "pallet-session", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-uniques", - "pallet-utility", - "pallet-xcm", - "pallet-xcm-benchmarks", - "parachain-info", - "parachains-common", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-common", - "primitive-types", - "scale-info", - "smallvec", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-core", - "sp-inherents", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std", - "sp-storage", - "sp-transaction-pool", - "sp-version", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "substrate-wasm-builder", - "westend-runtime-constants", -] - [[package]] name = "assets-common" version = "0.1.0" @@ -1323,18 +1253,24 @@ dependencies = [ "bifrost-asset-registry", "bifrost-kusama-runtime", "bifrost-primitives", + "bifrost-runtime-common", "bifrost-slp", "bifrost-vtoken-voting", "env_logger 0.10.0", "frame-support", "frame-system", + "hex-literal 0.3.4", "integration-tests-common", + "log", + "orml-tokens", + "orml-traits", "pallet-asset-conversion", "pallet-assets", "pallet-balances", "pallet-conviction-voting", "pallet-message-queue", "pallet-referenda", + "pallet-staking", "pallet-xcm", "parachains-common", "parity-scale-codec", @@ -1485,6 +1421,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime", "polkadot-runtime-parachains", + "sp-io", "sp-runtime", "staging-xcm", "xcm-emulator", @@ -2387,49 +2324,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "bp-bridge-hub-cumulus" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "bp-messages", - "bp-polkadot-core", - "bp-runtime", - "frame-support", - "frame-system", - "polkadot-primitives", - "sp-api", - "sp-std", -] - -[[package]] -name = "bp-bridge-hub-rococo" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "bp-bridge-hub-cumulus", - "bp-messages", - "bp-runtime", - "frame-support", - "sp-api", - "sp-runtime", - "sp-std", -] - -[[package]] -name = "bp-bridge-hub-wococo" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "bp-bridge-hub-cumulus", - "bp-messages", - "bp-runtime", - "frame-support", - "sp-api", - "sp-runtime", - "sp-std", -] - [[package]] name = "bp-header-chain" version = "0.1.0" @@ -2511,19 +2405,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "bp-rococo" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "bp-header-chain", - "bp-polkadot-core", - "bp-runtime", - "frame-support", - "sp-api", - "sp-std", -] - [[package]] name = "bp-runtime" version = "0.1.0" @@ -2567,20 +2448,6 @@ dependencies = [ "sp-trie", ] -[[package]] -name = "bp-wococo" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "bp-header-chain", - "bp-polkadot-core", - "bp-rococo", - "bp-runtime", - "frame-support", - "sp-api", - "sp-std", -] - [[package]] name = "bp-xcm-bridge-hub-router" version = "0.1.0" @@ -2718,84 +2585,6 @@ dependencies = [ "substrate-wasm-builder", ] -[[package]] -name = "bridge-hub-rococo-runtime" -version = "0.1.0" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "bp-bridge-hub-rococo", - "bp-bridge-hub-wococo", - "bp-header-chain", - "bp-messages", - "bp-parachains", - "bp-polkadot-core", - "bp-relayers", - "bp-rococo", - "bp-runtime", - "bp-wococo", - "bridge-runtime-common", - "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "cumulus-primitives-utility", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "hex-literal 0.4.1", - "log", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-bridge-grandpa", - "pallet-bridge-messages", - "pallet-bridge-parachains", - "pallet-bridge-relayers", - "pallet-collator-selection", - "pallet-multisig", - "pallet-session", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-utility", - "pallet-xcm", - "pallet-xcm-benchmarks", - "parachain-info", - "parachains-common", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-parachain-primitives", - "polkadot-runtime-common", - "rococo-runtime-constants", - "scale-info", - "serde", - "smallvec", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-core", - "sp-inherents", - "sp-io", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std", - "sp-storage", - "sp-transaction-pool", - "sp-version", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "substrate-wasm-builder", -] - [[package]] name = "bridge-runtime-common" version = "0.1.0" @@ -6312,17 +6101,16 @@ dependencies = [ [[package]] name = "integration-tests-common" -version = "1.0.0" +version = "0.8.0" dependencies = [ "asset-hub-kusama-runtime", "asset-hub-polkadot-runtime", - "asset-hub-westend-runtime", "bifrost-kusama-runtime", "bifrost-polkadot-runtime", + "bifrost-primitives", "bp-messages", "bridge-hub-kusama-runtime", "bridge-hub-polkadot-runtime", - "bridge-hub-rococo-runtime", "bridge-runtime-common", "collectives-polkadot-runtime", "cumulus-pallet-dmp-queue", @@ -6337,10 +6125,10 @@ dependencies = [ "pallet-message-queue", "pallet-staking", "pallet-xcm", + "parachain-staking", "parachains-common", "parity-scale-codec", "paste", - "penpal-runtime", "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-primitives", @@ -6348,8 +6136,6 @@ dependencies = [ "polkadot-runtime-constants", "polkadot-runtime-parachains", "polkadot-service", - "rococo-runtime", - "rococo-runtime-constants", "sc-consensus-grandpa", "sp-authority-discovery", "sp-consensus-babe", @@ -6358,8 +6144,6 @@ dependencies = [ "sp-runtime", "staging-kusama-runtime", "staging-xcm", - "westend-runtime", - "westend-runtime-constants", "xcm-emulator", ] @@ -9993,65 +9777,6 @@ dependencies = [ "base64ct", ] -[[package]] -name = "penpal-runtime" -version = "0.9.27" -source = "git+https://github.com/paritytech/polkadot-sdk?branch=release-polkadot-v1.1.0#c8d2251cafadc108ba2f1f8a3208dc547ff38901" -dependencies = [ - "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "cumulus-primitives-utility", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "log", - "pallet-asset-tx-payment", - "pallet-assets", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "pallet-session", - "pallet-sudo", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-xcm", - "parachain-info", - "parachains-common", - "parity-scale-codec", - "polkadot-parachain-primitives", - "polkadot-primitives", - "polkadot-runtime-common", - "scale-info", - "smallvec", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-core", - "sp-inherents", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std", - "sp-storage", - "sp-transaction-pool", - "sp-version", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "substrate-wasm-builder", -] - [[package]] name = "percent-encoding" version = "2.3.0" diff --git a/Cargo.toml b/Cargo.toml index 7ac37b55ad..4ffb1cab80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ cargo-features = ["resolver"] members = [ "integration-tests/bifrost-kusama", "integration-tests/bifrost-polkadot", + "integration-tests/common", "node/cli", "node/rpc", "node/service", diff --git a/integration-tests/bifrost-kusama/Cargo.toml b/integration-tests/bifrost-kusama/Cargo.toml index bb5530676d..d5eb3fd9b8 100644 --- a/integration-tests/bifrost-kusama/Cargo.toml +++ b/integration-tests/bifrost-kusama/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" [dependencies] env_logger = "0.10.0" +log = { version = "0.4.17" } +hex-literal = "0.3.1" codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } # Substrate @@ -18,6 +20,7 @@ pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", branch = " pallet-asset-conversion = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} pallet-referenda = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} +pallet-staking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} # Polkadot polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} @@ -40,3 +43,6 @@ bifrost-vtoken-voting = { path = "../../pallets/vtoken-voting" } bifrost-primitives = { path = "../../primitives" } bifrost-asset-registry = { path = "../../pallets/asset-registry" } bifrost-kusama-runtime = { path = "../../runtime/bifrost-kusama" } +bifrost-runtime-common = { path = "../../runtime/common" } +orml-traits = "0.4.1-dev" +orml-tokens = "0.4.1-dev" diff --git a/integration-tests/bifrost-kusama/src/account_id.rs b/integration-tests/bifrost-kusama/src/account_id.rs index 966d1516bd..20aa5d066e 100644 --- a/integration-tests/bifrost-kusama/src/account_id.rs +++ b/integration-tests/bifrost-kusama/src/account_id.rs @@ -1,7 +1,11 @@ -use crate::kusama_integration_tests::*; use frame_support::PalletId; -use polkadot_parachain::primitives::{Id as ParaId, Sibling}; +use integration_tests_common::{ + impls::{AccountId, ParaId}, + BifrostKusama, +}; +use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::{app_crypto::Ss58Codec, traits::AccountIdConversion}; +use xcm_emulator::TestExt; pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"bf/trsry"); pub const BIFROST_CROWDLOAN_ID: PalletId = PalletId(*b"bf/salp#"); @@ -24,7 +28,7 @@ pub const SYSTEM_MAKER_PALLET_ID: PalletId = PalletId(*b"bf/sysmk"); #[test] fn parachain_account_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!( >::into_account_truncating(&ParaId::from( 2001 @@ -48,7 +52,7 @@ fn parachain_account_should_work() { #[test] fn pallet_id_account_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!( >::into_account_truncating( &TREASURY_PALLET_ID diff --git a/integration-tests/bifrost-kusama/src/dollor_tests.rs b/integration-tests/bifrost-kusama/src/dollor_tests.rs index a168e7b219..9ba5c8ed9d 100644 --- a/integration-tests/bifrost-kusama/src/dollor_tests.rs +++ b/integration-tests/bifrost-kusama/src/dollor_tests.rs @@ -19,6 +19,8 @@ use bifrost_kusama_runtime::Runtime; use bifrost_primitives::{CurrencyId, TokenSymbol::*}; use bifrost_runtime_common::{cent, dollar, micro, microcent, milli, millicent}; +use integration_tests_common::BifrostKusama; +use xcm_emulator::TestExt; const DECIMAL_18: u128 = 1_000_000_000_000_000_000; const DECIMAL_12: u128 = 1_000_000_000_000; @@ -26,7 +28,7 @@ const DOT_DECIMALS: u128 = 10_000_000_000; #[test] fn dollar_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!(dollar::(CurrencyId::Token(ASG)), DECIMAL_12); assert_eq!(dollar::(CurrencyId::Token(BNC)), DECIMAL_12); assert_eq!(dollar::(CurrencyId::Token(KUSD)), DECIMAL_12); @@ -43,7 +45,7 @@ fn dollar_should_work() { #[test] fn milli_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!(milli::(CurrencyId::Token(ASG)), DECIMAL_12 / 1000); assert_eq!(milli::(CurrencyId::Token(BNC)), DECIMAL_12 / 1000); assert_eq!(milli::(CurrencyId::Token(KUSD)), DECIMAL_12 / 1000); @@ -60,7 +62,7 @@ fn milli_should_work() { #[test] fn micro_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!(micro::(CurrencyId::Token(ASG)), DECIMAL_12 / 1_000_000); assert_eq!(micro::(CurrencyId::Token(BNC)), DECIMAL_12 / 1_000_000); assert_eq!(micro::(CurrencyId::Token(KUSD)), DECIMAL_12 / 1_000_000); @@ -77,7 +79,7 @@ fn micro_should_work() { #[test] fn cent_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!(cent::(CurrencyId::Token(ASG)), DECIMAL_12 / 100); assert_eq!(cent::(CurrencyId::Token(BNC)), DECIMAL_12 / 100); assert_eq!(cent::(CurrencyId::Token(KUSD)), DECIMAL_12 / 100); @@ -94,7 +96,7 @@ fn cent_should_work() { #[test] fn millicent_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!(millicent::(CurrencyId::Token(ASG)), DECIMAL_12 / 100_000); assert_eq!(millicent::(CurrencyId::Token(BNC)), DECIMAL_12 / 100_000); assert_eq!(millicent::(CurrencyId::Token(KUSD)), DECIMAL_12 / 100_000); @@ -111,7 +113,7 @@ fn millicent_should_work() { #[test] fn microcent_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { assert_eq!(microcent::(CurrencyId::Token(ASG)), DECIMAL_12 / 100_000_000); assert_eq!(microcent::(CurrencyId::Token(BNC)), DECIMAL_12 / 100_000_000); assert_eq!(microcent::(CurrencyId::Token(KUSD)), DECIMAL_12 / 100_000_000); diff --git a/integration-tests/bifrost-kusama/src/general_key.rs b/integration-tests/bifrost-kusama/src/general_key.rs index 2c09399691..f2b10938ac 100644 --- a/integration-tests/bifrost-kusama/src/general_key.rs +++ b/integration-tests/bifrost-kusama/src/general_key.rs @@ -1,11 +1,13 @@ use bifrost_primitives::{CurrencyId, TokenSymbol}; use codec::Encode; +use integration_tests_common::BifrostKusama; use sp_runtime::BoundedVec; use xcm::prelude::*; +use xcm_emulator::TestExt; #[test] fn dollar_should_work() { - sp_io::TestExternalities::default().execute_with(|| { + BifrostKusama::execute_with(|| { let id = CurrencyId::Token(TokenSymbol::KSM); assert_eq!( Junction::from(BoundedVec::try_from(id.encode()).unwrap()), diff --git a/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs b/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs deleted file mode 100644 index b110772675..0000000000 --- a/integration-tests/bifrost-kusama/src/kusama_cross_chain_transact.rs +++ /dev/null @@ -1,134 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use crate::{ - kusama_integration_tests::*, kusama_test_net::*, vtoken_voting::set_balance_proposal_bounded, -}; -use frame_support::{ - assert_ok, - dispatch::{GetDispatchInfo, RawOrigin}, -}; -use pallet_conviction_voting::{AccountVote, Vote}; -use xcm::v3::{prelude::*, Weight}; -use xcm_emulator::TestExt; - -#[test] -fn relaychain_transact_works() { - sp_io::TestExternalities::default().execute_with(|| { - let vote_call = - kusama_runtime::RuntimeCall::ConvictionVoting(pallet_conviction_voting::Call::< - kusama_runtime::Runtime, - >::vote { - poll_index: 0, - vote: aye(2, 1), - }); - - let notify_vote_call = - RuntimeCall::VtokenVoting(bifrost_vtoken_voting::Call::::notify_vote { - query_id: 0, - response: Default::default(), - }); - - KusamaNet::execute_with(|| { - use frame_support::traits::schedule::DispatchTime; - use kusama_runtime::{Referenda, RuntimeEvent, RuntimeOrigin, System}; - - println!("KusamaNet vote_call weight: {:?}", vote_call.get_dispatch_info().weight); - - assert_ok!(Referenda::submit( - RuntimeOrigin::signed(ALICE.into()), - Box::new(RawOrigin::Root.into()), - set_balance_proposal_bounded(1), - DispatchTime::At(1), - )); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Referenda(pallet_referenda::Event::Submitted { - index: 0, - track: _, - proposal: _, - }) - ))); - }); - - Bifrost::execute_with(|| { - let notify_vote_call_weight = notify_vote_call.get_dispatch_info().weight; - let query_id = pallet_xcm::Pallet::::new_notify_query( - MultiLocation::parent(), - notify_vote_call, - 100u32.into(), - Here, - ); - - let asset: MultiAsset = - MultiAsset { id: Concrete(MultiLocation::here()), fun: Fungible(517318631) }; - let msg = Xcm(vec![ - WithdrawAsset(asset.clone().into()), - BuyExecution { fees: asset, weight_limit: Unlimited }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(961496000, 83866), - call: vote_call.encode().into(), - }, - ReportTransactStatus(QueryResponseInfo { - destination: MultiLocation::from(X1(Parachain(2001))), - query_id, - max_weight: notify_vote_call_weight, - }), - RefundSurplus, - DepositAsset { - assets: All.into(), - beneficiary: MultiLocation { parents: 0, interior: X1(Parachain(2001)) }, - }, - ]); - assert_ok!(pallet_xcm::Pallet::::send_xcm(Here, MultiLocation::parent(), msg)); - }); - - KusamaNet::execute_with(|| { - use kusama_runtime::{RuntimeEvent, System}; - - System::events().iter().for_each(|r| println!("KusamaNet >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - &r.event, - RuntimeEvent::Ump(polkadot_runtime_parachains::ump::Event::ExecutedUpward( - _, - crate::kusama_cross_chain_transact::Outcome::Complete(_) - )) - ))); - }); - - Bifrost::execute_with(|| { - System::events().iter().for_each(|r| println!("Bifrost >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::ResponseReceived { - responder: MultiLocation { parents: 1, interior: Here }, - query_id: 0, - response: crate::kusama_cross_chain_transact::Response::DispatchResult( - MaybeErrorCode::Success - ) - }) - ))); - }); - }) -} - -pub fn aye(amount: Balance, conviction: u8) -> AccountVote { - let vote = Vote { aye: true, conviction: conviction.try_into().unwrap() }; - AccountVote::Standard { vote, balance: amount } -} diff --git a/integration-tests/bifrost-kusama/src/kusama_integration_tests.rs b/integration-tests/bifrost-kusama/src/kusama_integration_tests.rs deleted file mode 100644 index 2edecad907..0000000000 --- a/integration-tests/bifrost-kusama/src/kusama_integration_tests.rs +++ /dev/null @@ -1,181 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -pub use bifrost_primitives::*; -pub use codec::Encode; -use frame_support::weights::constants::*; -pub use orml_traits::{Change, GetByKey, MultiCurrency}; -pub use sp_runtime::{ - traits::{AccountIdConversion, BadOrigin, Convert, Zero}, - BuildStorage, DispatchError, DispatchResult, FixedPointNumber, MultiAddress, -}; - -pub const ALICE: [u8; 32] = - hex_literal::hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"]; -pub const BOB: [u8; 32] = - hex_literal::hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"]; -pub const KUSAMA_ALICE_STASH_ACCOUNT: [u8; 32] = - hex_literal::hex!["be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f"]; -pub const KUSAMA_BOB_STASH_ACCOUNT: [u8; 32] = - hex_literal::hex!["fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e"]; -// pub const CATHI: [u8; 32] = [2u8; 32]; - -pub const KSM_DECIMALS: u128 = 1000_000_000_000; -// pub const BNC_DECIMALS: u128 = 1000_000_000_000; -//pub const CONTRIBUTON_INDEX: MessageId = [0; 32]; -const SECONDS_PER_YEAR: u32 = 31557600; -const SECONDS_PER_BLOCK: u32 = 12; -pub const BLOCKS_PER_YEAR: u32 = SECONDS_PER_YEAR / SECONDS_PER_BLOCK; - -pub use bifrost_imports::*; -use bifrost_kusama_runtime::{ExistentialDeposit, NativeCurrencyId}; - -mod bifrost_imports { - pub use bifrost_kusama_runtime::{ - create_x2_multilocation, AccountId, AssetRegistry, Balance, Balances, BifrostCrowdloanId, - BlockNumber, Currencies, CurrencyId, ExistentialDeposit, ExistentialDeposits, - NativeCurrencyId, OriginCaller, ParachainInfo, ParachainSystem, Proxy, RelayCurrencyId, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, Salp, Scheduler, Session, SlotLength, - Slp, SlpEntrancePalletId, System, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, - XcmConfig, XcmInterface, - }; - pub use bifrost_runtime_common::dollar; - pub use frame_support::parameter_types; - pub use sp_runtime::traits::AccountIdConversion; -} - -pub fn get_all_module_accounts() -> Vec { - vec![BifrostCrowdloanId::get().into_account_truncating()] -} - -pub struct ExtBuilder { - balances: Vec<(AccountId, CurrencyId, Balance)>, - parachain_id: u32, -} - -impl Default for ExtBuilder { - fn default() -> Self { - Self { balances: vec![], parachain_id: 2001 } - } -} - -impl ExtBuilder { - pub fn balances(mut self, balances: Vec<(AccountId, CurrencyId, Balance)>) -> Self { - self.balances = balances; - self - } - - #[allow(dead_code)] - pub fn parachain_id(mut self, parachain_id: u32) -> Self { - self.parachain_id = parachain_id; - self - } - - pub fn build(self) -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - let native_currency_id = NativeCurrencyId::get(); - let existential_deposit = ExistentialDeposit::get(); - - pallet_balances::GenesisConfig:: { - balances: self - .balances - .clone() - .into_iter() - .filter(|(_, currency_id, _)| *currency_id == native_currency_id) - .map(|(account_id, _, initial_balance)| (account_id, initial_balance)) - .chain(get_all_module_accounts().iter().map(|x| (x.clone(), existential_deposit))) - .collect::>(), - } - .assimilate_storage(&mut t) - .unwrap(); - - orml_tokens::GenesisConfig:: { - balances: self - .balances - .into_iter() - .filter(|(_, currency_id, _)| *currency_id != native_currency_id) - .collect::>(), - } - .assimilate_storage(&mut t) - .unwrap(); - - pallet_membership::GenesisConfig:: { - members: Default::default(), - phantom: Default::default(), - } - .assimilate_storage(&mut t) - .unwrap(); - - >::assimilate_storage( - ¶chain_info::GenesisConfig { parachain_id: self.parachain_id.into() }, - &mut t, - ) - .unwrap(); - - >::assimilate_storage( - &pallet_xcm::GenesisConfig { safe_xcm_version: Some(3) }, - &mut t, - ) - .unwrap(); - - as GenesisBuild>::assimilate_storage( - &bifrost_salp::GenesisConfig { initial_multisig_account: Some(AccountId::new(ALICE)) }, - &mut t, - ) - .unwrap(); - - as GenesisBuild>::assimilate_storage( - &bifrost_asset_registry::GenesisConfig { - currency: vec![ - (CurrencyId::Token(TokenSymbol::DOT), 100_000_000, None), - (CurrencyId::Token(TokenSymbol::KSM), 10_000_000, None), - ], - vcurrency: vec![], - vsbond: vec![], - phantom: Default::default() - }, - &mut t, - ) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext - } -} - -#[test] -fn sanity_check_weight_per_time_constants_are_as_expected() { - assert_eq!(WEIGHT_REF_TIME_PER_SECOND, 1_000_000_000_000); - assert_eq!(WEIGHT_REF_TIME_PER_MILLIS, WEIGHT_REF_TIME_PER_SECOND / 1000); - assert_eq!(WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_MILLIS / 1000); - assert_eq!(WEIGHT_REF_TIME_PER_NANOS, WEIGHT_REF_TIME_PER_MICROS / 1000); -} - -#[test] -fn parachain_subaccounts_are_unique() { - sp_io::TestExternalities::default().execute_with(|| { - let parachain: AccountId = ParachainInfo::parachain_id().into_account_truncating(); - assert_eq!( - parachain, - hex_literal::hex!["7061726164000000000000000000000000000000000000000000000000000000"] - .into() - ); - }); -} diff --git a/integration-tests/bifrost-kusama/src/kusama_test_net.rs b/integration-tests/bifrost-kusama/src/kusama_test_net.rs deleted file mode 100644 index 3ed860fc1c..0000000000 --- a/integration-tests/bifrost-kusama/src/kusama_test_net.rs +++ /dev/null @@ -1,187 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//! Relay chain and parachains emulation. - -use bifrost_runtime_common::dollar; -use frame_support::{traits::GenesisBuild, weights::Weight}; -use pallet_staking::Forcing; -use polkadot_primitives::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE}; -use polkadot_runtime_parachains::configuration::HostConfiguration; -use sp_runtime::Perbill; -use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, ParaId}; - -use crate::kusama_integration_tests::*; - -decl_test_relay_chain! { - pub struct KusamaNet { - Runtime = kusama_runtime::Runtime, - XcmConfig = kusama_runtime::xcm_config::XcmConfig, - new_ext = kusama_ext(), - } -} - -decl_test_parachain! { - pub struct Bifrost { - Runtime = Runtime, - RuntimeOrigin = RuntimeOrigin, - XcmpMessageHandler = bifrost_kusama_runtime ::XcmpQueue, - DmpMessageHandler = bifrost_kusama_runtime::DmpQueue, - new_ext = para_ext(2001), - } -} - -decl_test_parachain! { - pub struct Statemine { - Runtime = statemine_runtime::Runtime, - RuntimeOrigin = statemine_runtime::RuntimeOrigin, - XcmpMessageHandler = statemine_runtime::XcmpQueue, - DmpMessageHandler = statemine_runtime::DmpQueue, - new_ext = para_ext(1000), - } -} - -decl_test_network! { - pub struct TestNet { - relay_chain = KusamaNet, - parachains = vec![ - (1000, Statemine), - (2001, Bifrost), - ], - } -} - -fn default_parachains_host_configuration() -> HostConfiguration { - HostConfiguration { - minimum_validation_upgrade_delay: 5, - validation_upgrade_cooldown: 5u32, - validation_upgrade_delay: 5, - code_retention_period: 1200, - max_code_size: MAX_CODE_SIZE, - max_pov_size: MAX_POV_SIZE, - max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - chain_availability_period: 4, - thread_availability_period: 4, - max_upward_queue_count: 8, - max_upward_queue_size: 1024 * 1024, - max_downward_message_size: 1024, - ump_service_total_weight: Weight::from_parts(4 * 1_000_000_000, 0), - max_upward_message_size: 1024 * 50, - max_upward_message_num_per_candidate: 5, - hrmp_sender_deposit: 0, - hrmp_recipient_deposit: 0, - hrmp_channel_max_capacity: 8, - hrmp_channel_max_total_size: 8 * 1024, - hrmp_max_parachain_inbound_channels: 4, - hrmp_max_parathread_inbound_channels: 4, - hrmp_channel_max_message_size: 1024 * 1024, - hrmp_max_parachain_outbound_channels: 4, - hrmp_max_parathread_outbound_channels: 4, - hrmp_max_message_num_per_candidate: 5, - dispute_period: 6, - no_show_slots: 2, - n_delay_tranches: 25, - needed_approvals: 2, - relay_vrf_modulo_samples: 2, - zeroth_delay_tranche_width: 0, - ..Default::default() - } -} - -pub fn kusama_ext() -> sp_io::TestExternalities { - use kusama_runtime::{Runtime, System}; - - let bifrost_para_account: AccountId = ParaId::from(2001u32).into_account_truncating(); - - let mut t = frame_system::GenesisConfig::default().build_storage::().unwrap(); - - pallet_balances::GenesisConfig:: { - balances: vec![ - (AccountId::from(ALICE), 100 * KSM_DECIMALS), - (AccountId::from(KUSAMA_ALICE_STASH_ACCOUNT), 10000 * KSM_DECIMALS), - (AccountId::from(KUSAMA_BOB_STASH_ACCOUNT), 10000 * KSM_DECIMALS), - (bifrost_para_account.clone(), 2 * KSM_DECIMALS), - (Utility::derivative_account_id(bifrost_para_account.clone(), 5), 10 * KSM_DECIMALS), - (Utility::derivative_account_id(bifrost_para_account, 21), 10 * KSM_DECIMALS), - ], - } - .assimilate_storage(&mut t) - .unwrap(); - pallet_staking::GenesisConfig:: { - validator_count: 50, - minimum_validator_count: 2, - invulnerables: vec![ - AccountId::from(KUSAMA_ALICE_STASH_ACCOUNT), - AccountId::from(KUSAMA_BOB_STASH_ACCOUNT), - ], - stakers: vec![ - ( - AccountId::from(KUSAMA_ALICE_STASH_ACCOUNT), - AccountId::from(KUSAMA_ALICE_STASH_ACCOUNT), - 100 * KSM_DECIMALS, - kusama_runtime::StakerStatus::Validator, - ), - ( - AccountId::from(KUSAMA_BOB_STASH_ACCOUNT), - AccountId::from(KUSAMA_BOB_STASH_ACCOUNT), - 100 * KSM_DECIMALS, - kusama_runtime::StakerStatus::Validator, - ), - ], - force_era: Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); - - polkadot_runtime_parachains::configuration::GenesisConfig:: { - config: default_parachains_host_configuration(), - } - .assimilate_storage(&mut t) - .unwrap(); - - >::assimilate_storage( - &pallet_xcm::GenesisConfig { safe_xcm_version: Some(3) }, - &mut t, - ) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} - -pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities { - ExtBuilder::default() - .balances(vec![ - ( - AccountId::from(ALICE), - RelayCurrencyId::get(), - 10 * dollar::(RelayCurrencyId::get()), - ), - ( - AccountId::from(BOB), - RelayCurrencyId::get(), - 10 * dollar::(RelayCurrencyId::get()), - ), - ]) - .parachain_id(parachain_id) - .build() -} diff --git a/integration-tests/bifrost-kusama/src/lib.rs b/integration-tests/bifrost-kusama/src/lib.rs index 555fd8ed4d..0f1b1985dd 100644 --- a/integration-tests/bifrost-kusama/src/lib.rs +++ b/integration-tests/bifrost-kusama/src/lib.rs @@ -17,89 +17,14 @@ // along with this program. If not, see . #![cfg(test)] -// mod account_id; -// mod dollor_tests; -// mod general_key; -// mod kusama_cross_chain_transact; -// mod kusama_integration_tests; -// mod kusama_test_net; +mod account_id; +mod dollor_tests; +mod general_key; +mod transact; // mod salp; -// mod slp; -// mod total_issuance; -// mod treasury; -// mod vtoken_minting; -// mod vtoken_voting; -mod reserve_transfer; - -pub use codec::Encode; -pub use frame_support::{ - assert_err, assert_ok, - pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult}, - traits::fungibles::Inspect, -}; -pub use integration_tests_common::{ - constants::{ - asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, kusama::ED as KUSAMA_ED, PROOF_SIZE_THRESHOLD, - REF_TIME_THRESHOLD, XCM_V3, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - AssetHubKusama, AssetHubKusamaPallet, AssetHubKusamaReceiver, AssetHubKusamaSender, - BifrostKusama, BifrostKusamaReceiver, Kusama, KusamaPallet, KusamaReceiver, KusamaSender, - PenpalKusamaA, PenpalKusamaAPallet, PenpalKusamaAReceiver, PenpalKusamaASender, PenpalKusamaB, - PenpalKusamaBPallet, -}; -pub use parachains_common::{AccountId, Balance}; -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{Error, NetworkId::Kusama as KusamaId}, -}; -pub use xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, -}; - -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -// `Assets` pallet index -pub const ASSETS_PALLET_ID: u8 = 50; - -pub type RelayToSystemParaTest = Test; -pub type SystemParaToRelayTest = Test; -pub type SystemParaToParaTest = Test; - -/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests -pub fn relay_test_args(amount: Balance) -> TestArgs { - TestArgs { - dest: Kusama::child_location_of(AssetHubKusama::para_id()), - beneficiary: AccountId32Junction { - network: None, - id: AssetHubKusamaReceiver::get().into(), - } - .into(), - amount, - assets: (Here, amount).into(), - asset_id: None, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} - -/// Returns a `TestArgs` instance to de used for the System Parachain accross integraton tests -pub fn system_para_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, - assets: MultiAssets, - asset_id: Option, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets, - asset_id, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} +mod slp; +mod total_issuance; +mod vtoken_minting; +mod vtoken_voting; +mod xcm_interface; +mod xcm_transfer; diff --git a/integration-tests/bifrost-kusama/src/slp.rs b/integration-tests/bifrost-kusama/src/slp.rs index b121cdeb98..85cdfa1980 100644 --- a/integration-tests/bifrost-kusama/src/slp.rs +++ b/integration-tests/bifrost-kusama/src/slp.rs @@ -18,80 +18,28 @@ //! Cross-chain transfer tests within Kusama network. -/* - -fail_validators_by_delegator_query_response -confirm_validators_by_delegator_query_response -fail_delegator_ledger_query_response -confirm_delegator_ledger_query_response - -remove_supplement_fee_account_from_whitelist -add_supplement_fee_account_to_whitelist -supplement_fee_reserve - -set_ongoing_time_unit_update_interval -update_ongoing_time_unit - -set_currency_tune_exchange_rate_limit -set_hosting_fees -set_currency_delays -set_minimums_and_maximums - -set_delegator_ledger -set_validators_by_delegator -set_fee_source -set_operate_origin -set_xcm_dest_weight_and_fee - -remove_validator -add_validator - -initialize_delegator -remove_delegator -add_delegator - -charge_host_fee_and_tune_vtoken_exchange_rate -refund_currency_due_unbond - -decrease_token_pool -increase_token_pool - -transfer_to -transfer_back - -chill -liquidize -payout - -redelegate -undelegate -delegate - -rebond -unbond_all -unbond -bond_extra -bond - - -bond/unbond/bond_extra/unbond_all/rebond/chill/liquidize confirm_delegator_ledger_query_response -delegate/undelegate/redelegate confirm_validators_by_delegator_query_response - -*/ - -#![cfg(test)] -use bifrost_kusama_runtime::{NativeCurrencyId, VtokenMinting}; -use bifrost_primitives::{TimeUnit, XcmOperationType as XcmOperation}; +use bifrost_kusama_runtime::{ + Balances, Currencies, NativeCurrencyId, RelayCurrencyId, Runtime, RuntimeOrigin, Slp, + VtokenMinting, XcmDestWeightAndFeeHandler, +}; +use bifrost_primitives::{TimeUnit, XcmOperationType as XcmOperation, KSM, VKSM}; use bifrost_slp::{primitives::UnlockChunk, Delays, Ledger, MinimumsMaximums, SubstrateLedger}; use frame_support::{assert_ok, BoundedVec}; +use integration_tests_common::{impls::AccountId, BifrostKusama, Kusama}; use orml_traits::MultiCurrency; use pallet_staking::{Nominations, StakingLedger}; use sp_runtime::Permill; use xcm::{prelude::*, v3::Weight, VersionedMultiAssets, VersionedMultiLocation}; use xcm_emulator::TestExt; -use crate::{kusama_integration_tests::*, kusama_test_net::*}; - +pub const ALICE: [u8; 32] = + hex_literal::hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"]; +pub const BOB: [u8; 32] = + hex_literal::hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"]; +pub const KUSAMA_ALICE_STASH_ACCOUNT: [u8; 32] = + hex_literal::hex!["be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f"]; +pub const KUSAMA_BOB_STASH_ACCOUNT: [u8; 32] = + hex_literal::hex!["fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e"]; const ENTRANCE_ACCOUNT: [u8; 32] = hex_literal::hex!["6d6f646c62662f76746b696e0000000000000000000000000000000000000000"]; const BIFROST_TREASURY_ACCOUNT: [u8; 32] = @@ -128,6 +76,9 @@ const KUSAMA_BOB_STASH_MULTILOCATION: MultiLocation = MultiLocation { interior: X1(AccountId32 { network: None, id: KUSAMA_BOB_STASH_ACCOUNT }), }; +const KSM_DECIMALS: u128 = 1_000_000_000_000; +const BNC_DECIMALS: u128 = 1_000_000_000_000; + /// **************************************************** /// ********* Preparation section ******************** /// **************************************************** @@ -139,7 +90,7 @@ fn slp_setup() { cross_ksm_to_bifrost(ALICE, 10000 * KSM_DECIMALS); cross_ksm_to_bifrost(BOB, 10000 * KSM_DECIMALS); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_ok!(kusama_runtime::Balances::force_set_balance( kusama_runtime::RuntimeOrigin::root(), sp_runtime::MultiAddress::Id(AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), @@ -147,7 +98,7 @@ fn slp_setup() { )); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { assert_ok!(Balances::force_set_balance( RuntimeOrigin::root(), sp_runtime::MultiAddress::Id(AccountId::from(BIFROST_TREASURY_ACCOUNT)), @@ -157,7 +108,7 @@ fn slp_setup() { vksm_vtoken_minting_setup(); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // set operate origin to be ALICE for vksm assert_ok!(Slp::set_operate_origin( RuntimeOrigin::root(), @@ -337,7 +288,7 @@ fn slp_setup() { } fn vksm_vtoken_minting_setup() { - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // Set the vtoken-minting mint and redeem fee rate to 0.1% with origin root. This is for all // tokens, not just vksm. assert_ok!(VtokenMinting::set_fees( @@ -381,7 +332,7 @@ fn vksm_vtoken_minting_setup() { } fn cross_ksm_to_bifrost(to: [u8; 32], amount: u128) { - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_ok!(kusama_runtime::Balances::force_set_balance( kusama_runtime::RuntimeOrigin::root(), sp_runtime::MultiAddress::Id(AccountId::from(to)), @@ -403,40 +354,19 @@ fn cross_ksm_to_bifrost(to: [u8; 32], amount: u128) { fn vtoken_minting() { sp_io::TestExternalities::default().execute_with(|| { slp_setup(); - Bifrost::execute_with(|| { - println!( - "{:?}", - Currencies::free_balance( - CurrencyId::VToken(TokenSymbol::KSM), - &AccountId::from(ALICE) - ) - ); - println!( - "{:?}", - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(ALICE) - ) - ); + BifrostKusama::execute_with(|| { + println!("{:?}", Currencies::free_balance(VKSM, &AccountId::from(ALICE))); + println!("{:?}", Currencies::free_balance(KSM, &AccountId::from(ALICE))); assert_ok!(VtokenMinting::mint( RuntimeOrigin::signed(AccountId::from(ALICE)), - CurrencyId::Token(TokenSymbol::KSM), + KSM, 100 * KSM_DECIMALS, BoundedVec::default() )); // alice account should have 99.9 vKSM + assert_eq!(Currencies::free_balance(VKSM, &AccountId::from(ALICE)), 99900000000000); assert_eq!( - Currencies::free_balance( - CurrencyId::VToken(TokenSymbol::KSM), - &AccountId::from(ALICE) - ), - 99900000000000 - ); - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(ENTRANCE_ACCOUNT) - ), + Currencies::free_balance(KSM, &AccountId::from(ENTRANCE_ACCOUNT)), 99900000000000 ) }) @@ -445,101 +375,79 @@ fn vtoken_minting() { #[test] fn transfer_to() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - KusamaNet::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - ); - }); + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + 10000 * KSM_DECIMALS + ); + }); - Bifrost::execute_with(|| { - // Bond 50 ksm for sub-account index 0 - assert_ok!(VtokenMinting::mint( - RuntimeOrigin::signed(AccountId::from(ALICE)), - CurrencyId::Token(TokenSymbol::KSM), - 100 * KSM_DECIMALS, - BoundedVec::default() - )); + BifrostKusama::execute_with(|| { + // Bond 50 ksm for sub-account index 0 + assert_ok!(VtokenMinting::mint( + RuntimeOrigin::signed(AccountId::from(ALICE)), + KSM, + 100 * KSM_DECIMALS, + BoundedVec::default() + )); - assert_ok!(Slp::transfer_to( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(ENTRANCE_ACCOUNT_MULTILOCATION), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - )); + assert_ok!(Slp::transfer_to( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(ENTRANCE_ACCOUNT_MULTILOCATION), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + )); - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(ENTRANCE_ACCOUNT) - ), - 49900000000000 - ); - }); + assert_eq!( + Currencies::free_balance(KSM, &AccountId::from(ENTRANCE_ACCOUNT)), + 49900000000000 + ); + }); - KusamaNet::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10049999909994200 - ); - }); - }) + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + 10049999918220455 + ); + }); } #[test] fn transfer_back() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - - KusamaNet::execute_with(|| { - use kusama_runtime::System; - System::reset_events(); - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - ); - }); + slp_setup(); + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + 10000 * KSM_DECIMALS + ); + }); - Bifrost::execute_with(|| { - // Bond 50 ksm for sub-account index 0 - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(EXIT_ACCOUNT) - ), - 0 - ); + BifrostKusama::execute_with(|| { + // Bond 50 ksm for sub-account index 0 + assert_eq!(Currencies::free_balance(KSM, &AccountId::from(EXIT_ACCOUNT)), 0); - assert_ok!(Slp::transfer_back( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Box::new(EXIT_ACCOUNT_MULTILOCATION), - 50 * KSM_DECIMALS, - )); - }); + assert_ok!(Slp::transfer_back( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + Box::new(EXIT_ACCOUNT_MULTILOCATION), + 50 * KSM_DECIMALS, + )); + }); - Bifrost::execute_with(|| { - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(EXIT_ACCOUNT) - ), - 49999929608000 - ); - }); + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + 9950 * KSM_DECIMALS + ); + }); - KusamaNet::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 9950 * KSM_DECIMALS - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_eq!(Currencies::free_balance(KSM, &AccountId::from(EXIT_ACCOUNT)), 49999919630000); + }); } #[test] @@ -547,7 +455,7 @@ fn bond_works() { sp_io::TestExternalities::default().execute_with(|| { slp_setup(); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // Bond 50 ksm for sub-account index 0 assert_ok!(Slp::bond( RuntimeOrigin::signed(AccountId::from(ALICE)), @@ -558,7 +466,7 @@ fn bond_works() { )); }); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_eq!( kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), Some(StakingLedger { @@ -571,7 +479,7 @@ fn bond_works() { ); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // Bond 50 ksm and auto confirm assert_eq!( Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), @@ -591,12 +499,12 @@ fn bond_extra_works() { sp_io::TestExternalities::default().execute_with(|| { slp_setup(); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { use kusama_runtime::System; System::reset_events(); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { assert_ok!(Slp::bond( RuntimeOrigin::signed(AccountId::from(ALICE)), RelayCurrencyId::get(), @@ -605,7 +513,7 @@ fn bond_extra_works() { None )); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // Bond_extra 20 ksm for sub-account index 0 assert_ok!(Slp::bond_extra( RuntimeOrigin::signed(AccountId::from(ALICE)), @@ -616,7 +524,7 @@ fn bond_extra_works() { )); }); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_eq!( kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), Some(StakingLedger { @@ -629,7 +537,7 @@ fn bond_extra_works() { ); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // Bond 70 ksm and auto confirm assert_eq!( Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), @@ -646,182 +554,182 @@ fn bond_extra_works() { #[test] fn unbond_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - Bifrost::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::bond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + None + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::unbond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 20 * KSM_DECIMALS, - )); - }); - // KusamaNet::execute_with(|| { - // use kusama_runtime::System; - // assert_eq!( - // kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - // Some(StakingLedger { - // stash: AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - // total: 50 * KSM_DECIMALS, - // active: 30 * KSM_DECIMALS, - // unlocking: _, - // claimed_rewards: BoundedVec::try_from(vec![]).unwrap(), - // }) - // ); - // }); - - Bifrost::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 30 * KSM_DECIMALS, - unlocking: vec![UnlockChunk { - value: 20 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); - }) + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + Some(StakingLedger { + stash: AccountId::from(KSM_DELEGATOR_0_ACCOUNT), + total: 50 * KSM_DECIMALS, + active: 50 * KSM_DECIMALS, + unlocking: BoundedVec::try_from(vec![]).unwrap(), + claimed_rewards: BoundedVec::try_from(vec![]).unwrap(), + }) + ); + }); + + BifrostKusama::execute_with(|| { + assert_ok!(Slp::unbond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + None, + 20 * KSM_DECIMALS, + )); + }); + + Kusama::execute_with(|| { + // TODO: Assert events; + println!( + "{:?}", + kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)) + ); + }); + + BifrostKusama::execute_with(|| { + // Bond 70 ksm and auto confirm + assert_eq!( + Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), + Some(Ledger::Substrate(SubstrateLedger { + account: KSM_DELEGATOR_0_MULTILOCATION, + total: 50 * KSM_DECIMALS, + active: 30 * KSM_DECIMALS, + unlocking: vec![UnlockChunk { + value: 20 * KSM_DECIMALS, + unlock_time: TimeUnit::Era(0) + }], + })) + ); + }); } #[test] fn unbond_all_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - Bifrost::execute_with(|| { - // Unbond 0.5 ksm, 0.5 ksm left. - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); + BifrostKusama::execute_with(|| { + // Unbond 0.5 ksm, 0.5 ksm left. + assert_ok!(Slp::bond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + None + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::unbond_all( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - )); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + println!( + "{:?}", + kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)) + ); + }); - // KusamaNet::execute_with(|| { - // use kusama_runtime::System; - // println!("{:?}", System::events()); - // assert_eq!( - // kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - // Some(StakingLedger { - // stash: AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - // total: 50 * KSM_DECIMALS, - // active: 0, - // unlocking: BoundedVec::try_from(vec![]).unwrap(), - // claimed_rewards: BoundedVec::try_from(vec![]).unwrap(), - // }) - // ); - // }); - - Bifrost::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 0, - unlocking: vec![UnlockChunk { - value: 50 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(Slp::unbond_all( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + )); + }); + + Kusama::execute_with(|| { + use kusama_runtime::System; + println!("{:?}", System::events()); + }); + + BifrostKusama::execute_with(|| { + // Bond 70 ksm and auto confirm + assert_eq!( + Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), + Some(Ledger::Substrate(SubstrateLedger { + account: KSM_DELEGATOR_0_MULTILOCATION, + total: 50 * KSM_DECIMALS, + active: 0, + unlocking: vec![UnlockChunk { + value: 50 * KSM_DECIMALS, + unlock_time: TimeUnit::Era(0) + }], + })) + ); + }); } #[test] fn rebond_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - Bifrost::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::bond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + None + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::unbond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 30 * KSM_DECIMALS - )); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + }); - Bifrost::execute_with(|| { - // rebond 0.5 ksm. - assert_ok!(Slp::rebond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - Some(20 * KSM_DECIMALS), - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::unbond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + None, + 30 * KSM_DECIMALS + )); + }); - // So the bonded amount should be 1 ksm - // KusamaNet::execute_with(|| { - // assert_eq!( - // kusama_runtime::Staking::ledger(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - // Some(StakingLedger { - // stash: AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - // total: 50 * KSM_DECIMALS, - // active: 40 * KSM_DECIMALS, - // unlocking: BoundedVec::try_from(vec![]).unwrap(), - // claimed_rewards: BoundedVec::try_from(vec![]).unwrap(), - // }) - // ); - // }); - Bifrost::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 40 * KSM_DECIMALS, - unlocking: vec![UnlockChunk { - value: 10 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); - }) + Kusama::execute_with(|| { + // TODO: Assert events; + }); + + BifrostKusama::execute_with(|| { + // rebond 0.5 ksm. + assert_ok!(Slp::rebond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + None, + Some(20 * KSM_DECIMALS), + )); + }); + + // So the bonded amount should be 1 ksm + Kusama::execute_with(|| { + // TODO: Assert events; + }); + + BifrostKusama::execute_with(|| { + // Bond 70 ksm and auto confirm + assert_eq!( + Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), + Some(Ledger::Substrate(SubstrateLedger { + account: KSM_DELEGATOR_0_MULTILOCATION, + total: 50 * KSM_DECIMALS, + active: 40 * KSM_DECIMALS, + unlocking: vec![UnlockChunk { + value: 10 * KSM_DECIMALS, + unlock_time: TimeUnit::Era(0) + }], + })) + ); + }); } #[test] @@ -830,16 +738,16 @@ fn delegate_works() { // bond 1 ksm for sub-account index 0 slp_setup(); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { use kusama_runtime::System; System::reset_events(); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // Unbond 0.5 ksm, 0.5 ksm left. assert_ok!(VtokenMinting::mint( RuntimeOrigin::signed(AccountId::from(ALICE)), - CurrencyId::Token(TokenSymbol::KSM), + KSM, 100 * KSM_DECIMALS, BoundedVec::default() )); @@ -853,13 +761,13 @@ fn delegate_works() { )); }); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { use kusama_runtime::System; println!("{:?}", System::events()); System::reset_events(); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { // delegate assert_ok!(Slp::delegate( RuntimeOrigin::signed(AccountId::from(ALICE)), @@ -869,7 +777,7 @@ fn delegate_works() { )); }); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { use kusama_runtime::System; println!("{:?}", System::events()); assert_eq!( @@ -890,201 +798,229 @@ fn delegate_works() { #[test] fn undelegate_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - Bifrost::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::bond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + None + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - )); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + }); - Bifrost::execute_with(|| { - // Undelegate validator 0. Only validator 1 left. - assert_ok!(Slp::undelegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION], - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::delegate( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], + )); + }); - KusamaNet::execute_with(|| { - assert_eq!( - kusama_runtime::Staking::nominators(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - Some(Nominations { - targets: BoundedVec::try_from(vec![KUSAMA_BOB_STASH_ACCOUNT.into()]).unwrap(), - submitted_in: 0, - suppressed: false - },) - ); - }); - }) + Kusama::execute_with(|| { + // TODO: Assert events; + }); + + BifrostKusama::execute_with(|| { + // Undelegate validator 0. Only validator 1 left. + assert_ok!(Slp::undelegate( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + vec![KUSAMA_ALICE_STASH_MULTILOCATION], + )); + }); + + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Staking::nominators(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + Some(Nominations { + targets: BoundedVec::try_from(vec![KUSAMA_BOB_STASH_ACCOUNT.into()]).unwrap(), + submitted_in: 0, + suppressed: false + },) + ); + }); } #[test] fn redelegate_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - Bifrost::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::bond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + None + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - )); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + }); - Bifrost::execute_with(|| { - // Undelegate validator 0. Only validator 1 left. - assert_ok!(Slp::undelegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION], - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::delegate( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::redelegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Some(vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION]) - )); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + }); - KusamaNet::execute_with(|| { - assert_eq!( - kusama_runtime::Staking::nominators(AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - Some(Nominations { - targets: BoundedVec::try_from(vec![ - KUSAMA_ALICE_STASH_ACCOUNT.into(), - KUSAMA_BOB_STASH_ACCOUNT.into(), - ]) - .unwrap(), - submitted_in: 0, - suppressed: false - }) - ); - }); - }) + BifrostKusama::execute_with(|| { + // Undelegate validator 0. Only validator 1 left. + assert_ok!(Slp::undelegate( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + vec![KUSAMA_ALICE_STASH_MULTILOCATION], + )); + }); + + Kusama::execute_with(|| { + // TODO: Assert events; + }); + + BifrostKusama::execute_with(|| { + assert_ok!(Slp::redelegate( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + Some(vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION]) + )); + }); + + Kusama::execute_with(|| { + assert_eq!( + kusama_runtime::Staking::nominators(AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), + Some(Nominations { + targets: BoundedVec::try_from(vec![ + KUSAMA_ALICE_STASH_ACCOUNT.into(), + KUSAMA_BOB_STASH_ACCOUNT.into(), + ]) + .unwrap(), + submitted_in: 0, + suppressed: false + }) + ); + }); } #[test] fn payout_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - Bifrost::execute_with(|| { - // Bond 1 ksm for sub-account index 0 - assert_ok!(Slp::payout( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Box::new(KUSAMA_ALICE_STASH_MULTILOCATION), - Some(TimeUnit::Era(27)) - )); - }); - }) + slp_setup(); + BifrostKusama::execute_with(|| { + // Bond 1 ksm for sub-account index 0 + assert_ok!(Slp::payout( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + Box::new(KUSAMA_ALICE_STASH_MULTILOCATION), + Some(TimeUnit::Era(27)) + )); + }); } #[test] fn liquidize_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); + slp_setup(); - Bifrost::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::bond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + 50 * KSM_DECIMALS, + None + )); + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - )); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::unbond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 20 * KSM_DECIMALS - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::delegate( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], + )); + }); - Bifrost::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 30 * KSM_DECIMALS, - unlocking: vec![UnlockChunk { - value: 20 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); + Kusama::execute_with(|| { + // TODO: Assert events; + }); - Bifrost::execute_with(|| { - assert_ok!(Slp::liquidize( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Some(TimeUnit::SlashingSpan(5)), - None, - None - )); - }); + BifrostKusama::execute_with(|| { + assert_ok!(Slp::unbond( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + None, + 20 * KSM_DECIMALS + )); + }); - Bifrost::execute_with(|| { - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 30 * KSM_DECIMALS, - active: 30 * KSM_DECIMALS, - unlocking: vec![], - })) - ); - }); - }) + Kusama::execute_with(|| { + // TODO: Assert events; + }); + + BifrostKusama::execute_with(|| { + // Bond 70 ksm and auto confirm + assert_eq!( + Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), + Some(Ledger::Substrate(SubstrateLedger { + account: KSM_DELEGATOR_0_MULTILOCATION, + total: 50 * KSM_DECIMALS, + active: 30 * KSM_DECIMALS, + unlocking: vec![UnlockChunk { + value: 20 * KSM_DECIMALS, + unlock_time: TimeUnit::Era(0) + }], + })) + ); + }); + + BifrostKusama::execute_with(|| { + assert_ok!(Slp::liquidize( + RuntimeOrigin::signed(AccountId::from(ALICE)), + RelayCurrencyId::get(), + Box::new(KSM_DELEGATOR_0_MULTILOCATION), + Some(TimeUnit::SlashingSpan(5)), + None, + None + )); + }); + + Kusama::execute_with(|| { + // TODO: Assert events; + }); + + BifrostKusama::execute_with(|| { + assert_eq!( + Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), + Some(Ledger::Substrate(SubstrateLedger { + account: KSM_DELEGATOR_0_MULTILOCATION, + total: 30 * KSM_DECIMALS, + active: 30 * KSM_DECIMALS, + unlocking: vec![], + })) + ); + }); } #[test] @@ -1092,7 +1028,7 @@ fn chill_works() { sp_io::TestExternalities::default().execute_with(|| { slp_setup(); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { assert_ok!(Slp::bond( RuntimeOrigin::signed(AccountId::from(ALICE)), RelayCurrencyId::get(), @@ -1102,7 +1038,7 @@ fn chill_works() { )); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { assert_ok!(Slp::delegate( RuntimeOrigin::signed(AccountId::from(ALICE)), RelayCurrencyId::get(), @@ -1112,7 +1048,7 @@ fn chill_works() { }); // check if sub-account index 0 belongs to the group of nominators - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_eq!( kusama_runtime::Staking::nominators(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)) .is_some(), @@ -1125,7 +1061,7 @@ fn chill_works() { ); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { assert_ok!(Slp::chill( RuntimeOrigin::signed(AccountId::from(ALICE)), RelayCurrencyId::get(), @@ -1134,7 +1070,7 @@ fn chill_works() { }); // check if sub-account index 0 belongs to the group of nominators - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_eq!( kusama_runtime::Staking::nominators(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)) .is_some(), @@ -1148,14 +1084,14 @@ fn chill_works() { fn supplement_fee_reserve_works() { sp_io::TestExternalities::default().execute_with(|| { slp_setup(); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_eq!( kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), 10000 * KSM_DECIMALS ); }); - Bifrost::execute_with(|| { + BifrostKusama::execute_with(|| { assert_ok!(Slp::supplement_fee_reserve( RuntimeOrigin::root(), RelayCurrencyId::get(), @@ -1163,7 +1099,7 @@ fn supplement_fee_reserve_works() { )); }); - KusamaNet::execute_with(|| { + Kusama::execute_with(|| { assert_eq!( kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), 10000 * KSM_DECIMALS diff --git a/integration-tests/bifrost-kusama/src/total_issuance.rs b/integration-tests/bifrost-kusama/src/total_issuance.rs index dca1249bf6..3dec79e522 100644 --- a/integration-tests/bifrost-kusama/src/total_issuance.rs +++ b/integration-tests/bifrost-kusama/src/total_issuance.rs @@ -16,68 +16,36 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{ - kusama_integration_tests::{ALICE, BOB}, - kusama_test_net::Bifrost, -}; use bifrost_kusama_runtime::{ - constants::currency::MILLIBNC, Balances, Runtime, RuntimeOrigin, System, + constants::currency::{BNCS, MILLIBNC}, + Balances, RuntimeOrigin, }; -use bifrost_slp::BalanceOf; use frame_support::{assert_ok, traits::Currency}; -use sp_runtime::{traits::AccountIdConversion, AccountId32, SaturatedConversion}; +use integration_tests_common::{ + BifrostKusama, BifrostKusamaAlice, BifrostKusamaBob, BifrostKusamaTreasury, +}; use xcm_emulator::TestExt; #[test] -fn dollar_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - let treasury_account: AccountId32 = - bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(); - assert_eq!( - BalanceOf::::saturated_from(10 * MILLIBNC), - Balances::minimum_balance() - ); - - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(ALICE.into()), - BalanceOf::::saturated_from(20 * MILLIBNC) - )); - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(BOB.into()), - BalanceOf::::saturated_from(20 * MILLIBNC) - )); - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - treasury_account.clone().into(), - BalanceOf::::saturated_from(20 * MILLIBNC) - )); - - assert_eq!( - Balances::total_issuance(), - BalanceOf::::saturated_from(70000000000u128) - ); - - System::reset_events(); - - assert_ok!(Balances::transfer_allow_death( - RuntimeOrigin::signed(ALICE.into()), - sp_runtime::MultiAddress::Id(BOB.into()), - BalanceOf::::saturated_from(20 * MILLIBNC - 1) - )); - - println!("{:?}", System::events()); - - // As expected dust balance is removed. - assert_eq!(Balances::free_balance(&ALICE.into()), 0); - assert_eq!(Balances::free_balance(&treasury_account.into()), 20 * MILLIBNC + 1); - - assert_eq!( - Balances::total_issuance(), - BalanceOf::::saturated_from(70000000000u128) - ); - }); +fn remove_dust_account_should_work() { + BifrostKusama::execute_with(|| { + assert_eq!(Balances::minimum_balance(), 10 * MILLIBNC); + + assert_eq!(Balances::total_issuance(), 8_000_0000 * BNCS); + + assert_ok!(Balances::transfer_allow_death( + RuntimeOrigin::signed(BifrostKusamaAlice::get()), + BifrostKusamaBob::get().into(), + Balances::free_balance(&BifrostKusamaAlice::get()) - MILLIBNC + )); + + // As expected dust balance is removed. + assert_eq!(Balances::free_balance(&BifrostKusamaAlice::get()), 0); + assert_eq!( + Balances::free_balance(&BifrostKusamaTreasury::get()), + 1_000_0000 * BNCS + MILLIBNC + ); + + assert_eq!(Balances::total_issuance(), 8_000_0000 * BNCS); }); } diff --git a/integration-tests/bifrost-kusama/src/transact.rs b/integration-tests/bifrost-kusama/src/transact.rs new file mode 100644 index 0000000000..ae8d163057 --- /dev/null +++ b/integration-tests/bifrost-kusama/src/transact.rs @@ -0,0 +1,141 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +use crate::vtoken_voting::set_balance_proposal_bounded; +use bifrost_kusama_runtime::{Runtime, RuntimeCall, RuntimeEvent, System}; +use bifrost_primitives::Balance; +use codec::Encode; +use frame_support::{ + assert_ok, + dispatch::{GetDispatchInfo, RawOrigin}, +}; +use integration_tests_common::{BifrostKusama, Kusama, KusamaAlice}; +use pallet_conviction_voting::{AccountVote, Vote}; +use xcm::v3::{prelude::*, Weight}; +use xcm_emulator::{bx, Parachain, RelayChain, TestExt}; + +#[test] +fn relaychain_transact_works() { + let vote_call = + kusama_runtime::RuntimeCall::ConvictionVoting(pallet_conviction_voting::Call::< + kusama_runtime::Runtime, + >::vote { + poll_index: 0, + vote: aye(1_000_000_000_000u128, 1), + }); + + let notify_vote_call = + RuntimeCall::VtokenVoting(bifrost_vtoken_voting::Call::::notify_vote { + query_id: 0, + response: Default::default(), + }); + + Kusama::execute_with(|| { + use frame_support::traits::schedule::DispatchTime; + use kusama_runtime::{Balances, Referenda, RuntimeEvent, RuntimeOrigin, System}; + + println!("KusamaNet vote_call weight: {:?}", vote_call.get_dispatch_info().weight); + + assert_ok!(Referenda::submit( + RuntimeOrigin::signed(KusamaAlice::get()), + bx!(RawOrigin::Root.into()), + set_balance_proposal_bounded(1), + DispatchTime::At(1), + )); + + assert_ok!(Balances::force_set_balance( + RuntimeOrigin::root(), + Kusama::sovereign_account_id_of_child_para(BifrostKusama::para_id()).into(), + 100_000_000_000_000u128 + )); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Referenda(pallet_referenda::Event::Submitted { + index: 0, + track: _, + proposal: _, + }) + ))); + }); + + BifrostKusama::execute_with(|| { + let notify_vote_call_weight = notify_vote_call.get_dispatch_info().weight; + let query_id = pallet_xcm::Pallet::::new_notify_query( + MultiLocation::parent(), + notify_vote_call, + 100u32.into(), + Here, + ); + + let asset: MultiAsset = + MultiAsset { id: Concrete(MultiLocation::here()), fun: Fungible(1000000000000) }; + let msg = Xcm(vec![ + WithdrawAsset(asset.clone().into()), + BuyExecution { fees: asset, weight_limit: Unlimited }, + Transact { + origin_kind: OriginKind::SovereignAccount, + require_weight_at_most: Weight::from_parts(1019439000, 83866), + call: vote_call.encode().into(), + }, + ReportTransactStatus(QueryResponseInfo { + destination: MultiLocation::from(X1(Parachain(2001))), + query_id, + max_weight: notify_vote_call_weight, + }), + RefundSurplus, + DepositAsset { + assets: All.into(), + beneficiary: MultiLocation { parents: 0, interior: X1(Parachain(2001)) }, + }, + ]); + assert_ok!(pallet_xcm::Pallet::::send_xcm(Here, MultiLocation::parent(), msg)); + }); + + Kusama::execute_with(|| { + use kusama_runtime::{RuntimeEvent, System}; + + System::events().iter().for_each(|r| println!("KusamaNet >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + &r.event, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { + id: _, + origin: _, + weight_used: _, + success: true + }) + ))); + }); + + BifrostKusama::execute_with(|| { + System::events().iter().for_each(|r| println!("Bifrost >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::ResponseReceived { + responder: MultiLocation { parents: 1, interior: Here }, + query_id: 0, + response: Response::DispatchResult(MaybeErrorCode::Success) + }) + ))); + }); +} + +pub fn aye(amount: Balance, conviction: u8) -> AccountVote { + let vote = Vote { aye: true, conviction: conviction.try_into().unwrap() }; + AccountVote::Standard { vote, balance: amount } +} diff --git a/integration-tests/bifrost-kusama/src/treasury.rs b/integration-tests/bifrost-kusama/src/treasury.rs deleted file mode 100644 index 499264ac59..0000000000 --- a/integration-tests/bifrost-kusama/src/treasury.rs +++ /dev/null @@ -1,141 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) 2019-2022 Liebi Technologies (UK) Ltd. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -use frame_support::assert_ok; -use sp_runtime::{traits::AccountIdConversion, AccountId32, BoundedVec}; -use xcm_emulator::TestExt; - -use crate::{ - kusama_integration_tests::{RelayCurrencyId, RuntimeOrigin, TimeUnit, ALICE, BLOCKS_PER_YEAR}, - kusama_test_net::{Bifrost, KusamaNet}, -}; -use node_primitives::{ - currency::{KSM, VKSM}, - AccountId, TryConvertFrom, VtokenMintingOperator, -}; - -pub fn para_account_2001() -> AccountId { - // 5Ec4AhPV91i9yNuiWuNunPf6AQCYDhFTTA4G5QCbtqYApH9E - let para_account_2001: AccountId = - hex_literal::hex!["70617261d1070000000000000000000000000000000000000000000000000000"] - .into(); - - para_account_2001 -} - -#[test] -fn kusama_treasury_propose_spend() { - sp_io::TestExternalities::default().execute_with(|| { - KusamaNet::execute_with(|| { - assert_ok!(kusama_runtime::Treasury::propose_spend( - kusama_runtime::RuntimeOrigin::signed(ALICE.into()), - 50_000_000_000_000_000, - sp_runtime::MultiAddress::Id(para_account_2001()), - )); - }); - }) -} - -#[test] -fn bifrost_treasury_operations() { - sp_io::TestExternalities::default().execute_with(|| { - let para_id = 2001u32; - let treasury_account: AccountId32 = - bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(); - Bifrost::execute_with(|| { - let treasury_derivative_account_id = - bifrost_kusama_runtime::Utility::derivative_account_id(treasury_account.clone(), 0); - assert_ok!(bifrost_kusama_runtime::Tokens::set_balance( - bifrost_kusama_runtime::RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(treasury_derivative_account_id.clone()), - RelayCurrencyId::get(), - 50_000_000_000_000_000, - 0, - )); - assert_ok!(bifrost_kusama_runtime::Tokens::force_transfer( - bifrost_kusama_runtime::RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(treasury_derivative_account_id), - sp_runtime::MultiAddress::Id(treasury_account.clone()), - RelayCurrencyId::get(), - 50_000_000_000_000_000, - )); - - assert_ok!(bifrost_kusama_runtime::VtokenMinting::mint( - bifrost_kusama_runtime::RuntimeOrigin::signed(treasury_account.clone()), - RelayCurrencyId::get(), - 25_000_000_000_000_000, - BoundedVec::default() - )); - - assert_ok!(bifrost_kusama_runtime::ZenlinkProtocol::create_pair( - bifrost_kusama_runtime::RuntimeOrigin::root(), - zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), - zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), - )); - - assert_ok!(bifrost_kusama_runtime::ZenlinkProtocol::add_liquidity( - bifrost_kusama_runtime::RuntimeOrigin::signed(treasury_account.clone()), - zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), - zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), - 25_000_000_000_000_000, - 25_000_000_000_000_000, - 0, - 0, - BLOCKS_PER_YEAR, - )); - - let lp_asset_id = bifrost_kusama_runtime::ZenlinkProtocol::lp_asset_id( - &zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), - &zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), - ) - .unwrap(); - - let lp = bifrost_kusama_runtime::ZenlinkProtocol::foreign_balance_of( - lp_asset_id, - &treasury_account, - ); - - assert_ok!(bifrost_kusama_runtime::ZenlinkProtocol::remove_liquidity( - bifrost_kusama_runtime::RuntimeOrigin::signed(treasury_account.clone()), - zenlink_protocol::AssetId::try_convert_from(KSM, para_id).unwrap(), - zenlink_protocol::AssetId::try_convert_from(VKSM, para_id).unwrap(), - lp, - 0, - 0, - sp_runtime::MultiAddress::Id(treasury_account.clone()), - BLOCKS_PER_YEAR, - )); - - assert_ok!(bifrost_kusama_runtime::VtokenMinting::set_unlock_duration( - RuntimeOrigin::root(), - KSM, - TimeUnit::Era(0) - )); - assert_ok!(bifrost_kusama_runtime::VtokenMinting::update_ongoing_time_unit( - KSM, - TimeUnit::Era(1) - )); - - assert_ok!(bifrost_kusama_runtime::VtokenMinting::redeem( - bifrost_kusama_runtime::RuntimeOrigin::signed(treasury_account), - VKSM, - 0, - )); - }); - }) -} diff --git a/integration-tests/bifrost-kusama/src/vtoken_minting.rs b/integration-tests/bifrost-kusama/src/vtoken_minting.rs index 5dea71277a..610e4d1169 100644 --- a/integration-tests/bifrost-kusama/src/vtoken_minting.rs +++ b/integration-tests/bifrost-kusama/src/vtoken_minting.rs @@ -1,255 +1,166 @@ -use crate::{kusama_integration_tests::*, kusama_test_net::*}; use bifrost_asset_registry::AssetIdMaps; -use bifrost_kusama_runtime::{Runtime, VtokenMinting}; +use bifrost_kusama_runtime::{ + Currencies, MultiCurrency, Runtime, SlpEntrancePalletId, VtokenMinting, VtokenMintingOperator, +}; +use bifrost_primitives::{CurrencyIdRegister, TimeUnit, TokenSymbol, KSM, VKSM}; use frame_support::{assert_ok, dispatch::RawOrigin}; +use integration_tests_common::{BifrostKusama, BifrostKusamaAlice}; use sp_runtime::{traits::AccountIdConversion, BoundedVec, Permill}; use xcm_emulator::TestExt; -/* -set_unlock_duration unlock_duration TimeUnit::Era(28) -set_minimum_mint minimum_mint 0.5 KSM -set_minimum_redeem minimum_redeem 0 KSM -add_support_rebond_token token_to_rebond Some(0) -remove_support_rebond_token token_to_rebond -set_fees fees (0%,0.1%) -set_hook_iteration_limit hook_iteration_limit 10 -set_unlocking_total unlocking_total -set_min_time_unit min_time_unit TimeUnit::Era(4362) - -mint -redeem - */ - #[test] fn set_unlock_duration_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_unlock_duration( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - TimeUnit::Era(28), - )); - assert_eq!( - VtokenMinting::unlock_duration(CurrencyId::Token(TokenSymbol::KSM)), - Some(TimeUnit::Era(28)) - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(VtokenMinting::set_unlock_duration( + RawOrigin::Root.into(), + KSM, + TimeUnit::Era(28), + )); + assert_eq!(VtokenMinting::unlock_duration(KSM), Some(TimeUnit::Era(28))); + }); } #[test] fn set_minimum_mint_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_minimum_mint( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - 50_000_000_000, - )); - assert_eq!( - VtokenMinting::minimum_mint(CurrencyId::Token(TokenSymbol::KSM)), - 50_000_000_000 - ); - assert_eq!(AssetIdMaps::::check_vtoken_registered(TokenSymbol::KSM), true); - assert_eq!(AssetIdMaps::::check_token_registered(TokenSymbol::KSM), true); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(VtokenMinting::set_minimum_mint(RawOrigin::Root.into(), KSM, 50_000_000_000,)); + assert_eq!(VtokenMinting::minimum_mint(KSM), 50_000_000_000); + assert_eq!(AssetIdMaps::::check_vtoken_registered(TokenSymbol::KSM), true); + assert_eq!(AssetIdMaps::::check_token_registered(TokenSymbol::KSM), true); + }); } #[test] fn set_minimum_redeem_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_minimum_redeem( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - 10_000, - )); - assert_eq!(VtokenMinting::minimum_redeem(CurrencyId::Token(TokenSymbol::KSM)), 10_000); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(VtokenMinting::set_minimum_redeem(RawOrigin::Root.into(), KSM, 10_000,)); + assert_eq!(VtokenMinting::minimum_redeem(KSM), 10_000); + }); } #[test] fn add_support_rebond_token_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_eq!(VtokenMinting::token_to_rebond(CurrencyId::Token(TokenSymbol::KSM)), None); - assert_ok!(VtokenMinting::add_support_rebond_token( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - )); - assert_eq!( - VtokenMinting::token_to_rebond(CurrencyId::Token(TokenSymbol::KSM)), - Some(0) - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_eq!(VtokenMinting::token_to_rebond(KSM), None); + assert_ok!(VtokenMinting::add_support_rebond_token(RawOrigin::Root.into(), KSM,)); + assert_eq!(VtokenMinting::token_to_rebond(KSM), Some(0)); + }); } #[test] fn remove_support_rebond_token_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_eq!(VtokenMinting::token_to_rebond(CurrencyId::Token(TokenSymbol::KSM)), None); - assert_ok!(VtokenMinting::add_support_rebond_token( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - )); - assert_eq!( - VtokenMinting::token_to_rebond(CurrencyId::Token(TokenSymbol::KSM)), - Some(0) - ); - assert_ok!(VtokenMinting::remove_support_rebond_token( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - )); - assert_eq!(VtokenMinting::token_to_rebond(CurrencyId::Token(TokenSymbol::KSM)), None); - }); - }) + BifrostKusama::execute_with(|| { + assert_eq!(VtokenMinting::token_to_rebond(KSM), None); + assert_ok!(VtokenMinting::add_support_rebond_token(RawOrigin::Root.into(), KSM,)); + assert_eq!(VtokenMinting::token_to_rebond(KSM), Some(0)); + assert_ok!(VtokenMinting::remove_support_rebond_token(RawOrigin::Root.into(), KSM,)); + assert_eq!(VtokenMinting::token_to_rebond(KSM), None); + }); } #[test] fn set_fees_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_fees( - RawOrigin::Root.into(), - Permill::from_perthousand(0), - Permill::from_perthousand(1), - )); - assert_eq!( - VtokenMinting::fees(), - (Permill::from_perthousand(0), Permill::from_perthousand(1)) - ); - println!("{:#?}", Permill::from_perthousand(1)); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(VtokenMinting::set_fees( + RawOrigin::Root.into(), + Permill::from_perthousand(0), + Permill::from_perthousand(1), + )); + assert_eq!( + VtokenMinting::fees(), + (Permill::from_perthousand(0), Permill::from_perthousand(1)) + ); + println!("{:#?}", Permill::from_perthousand(1)); + }); } #[test] fn set_hook_iteration_limit_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_hook_iteration_limit(RawOrigin::Root.into(), 10)); - assert_eq!(VtokenMinting::hook_iteration_limit(), 10); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(VtokenMinting::set_hook_iteration_limit(RawOrigin::Root.into(), 10)); + assert_eq!(VtokenMinting::hook_iteration_limit(), 10); + }); } #[test] fn set_unlocking_total_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_unlocking_total( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - 10_000_000_000, - )); - assert_eq!( - VtokenMinting::unlocking_total(CurrencyId::Token(TokenSymbol::KSM)), - 10_000_000_000 - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!( + VtokenMinting::set_unlocking_total(RawOrigin::Root.into(), KSM, 10_000_000_000,) + ); + assert_eq!(VtokenMinting::unlocking_total(KSM), 10_000_000_000); + }); } #[test] fn set_min_time_unit_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(VtokenMinting::set_min_time_unit( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - TimeUnit::Era(4362), - )); - assert_eq!( - VtokenMinting::min_time_unit(CurrencyId::Token(TokenSymbol::KSM)), - TimeUnit::Era(4362) - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_ok!(VtokenMinting::set_min_time_unit( + RawOrigin::Root.into(), + KSM, + TimeUnit::Era(4362), + )); + assert_eq!(VtokenMinting::min_time_unit(KSM), TimeUnit::Era(4362)); + }); } #[test] fn mint_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_eq!(VtokenMinting::token_pool(CurrencyId::Token(TokenSymbol::KSM)), 0); - assert_eq!(Currencies::total_issuance(CurrencyId::VToken(TokenSymbol::KSM)), 0); - assert_eq!( - VtokenMinting::fees(), - (Permill::from_perthousand(0), Permill::from_perthousand(0)) - ); - - assert_ok!(VtokenMinting::mint( - RawOrigin::Signed(AccountId::new(ALICE)).into(), - CurrencyId::Token(TokenSymbol::KSM), - 5_000_000_000_000, - BoundedVec::default() - )); - - //check balance - let entrance_account: AccountId = SlpEntrancePalletId::get().into_account_truncating(); - assert_eq!( - Currencies::free_balance( - CurrencyId::VToken(TokenSymbol::KSM), - &AccountId::from(ALICE) - ), - 5_000_000_000_000 - ); - assert_eq!( - Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &entrance_account), - 5_000_000_000_000 - ); - assert_eq!( - VtokenMinting::token_pool(CurrencyId::Token(TokenSymbol::KSM)), - 5_000_000_000_000 - ); - }); - }) + BifrostKusama::execute_with(|| { + assert_eq!(VtokenMinting::token_pool(KSM), 0); + assert_eq!(Currencies::total_issuance(VKSM), 0); + assert_eq!( + VtokenMinting::fees(), + (Permill::from_perthousand(0), Permill::from_perthousand(0)) + ); + + assert_ok!(VtokenMinting::mint( + RawOrigin::Signed(BifrostKusamaAlice::get()).into(), + KSM, + 5_000_000_000_000, + BoundedVec::default() + )); + + //check balance + let entrance_account = SlpEntrancePalletId::get().into_account_truncating(); + assert_eq!(Currencies::free_balance(VKSM, &BifrostKusamaAlice::get()), 5_000_000_000_000); + assert_eq!(Currencies::free_balance(KSM, &entrance_account), 5_000_000_000_000); + assert_eq!(VtokenMinting::token_pool(KSM), 5_000_000_000_000); + }); } #[test] fn redeem_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - pub const FEE: Permill = Permill::from_percent(2); - assert_ok!(VtokenMinting::set_fees(RawOrigin::Root.into(), FEE, FEE)); - assert_ok!(VtokenMinting::set_unlock_duration( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - TimeUnit::Era(1) - )); - assert_ok!(VtokenMinting::update_ongoing_time_unit( - CurrencyId::Token(TokenSymbol::KSM), - TimeUnit::Era(1) - )); - assert_ok!(VtokenMinting::set_minimum_redeem( - RawOrigin::Root.into(), - CurrencyId::Token(TokenSymbol::KSM), - 2 * 1_000_000_000_000 - )); - assert_ok!(VtokenMinting::mint( - RawOrigin::Signed(AccountId::new(ALICE)).into(), - CurrencyId::Token(TokenSymbol::KSM), - 5 * 1_000_000_000_000, - BoundedVec::default() - )); - assert_eq!( - VtokenMinting::token_pool(CurrencyId::Token(TokenSymbol::KSM)), - 5 * 1_000_000_000_000 - 5 * 20_000_000_000 - ); // 1000 + 980 - 98 - 196 - - assert_ok!(VtokenMinting::redeem( - RawOrigin::Signed(AccountId::new(ALICE)).into(), - CurrencyId::VToken(TokenSymbol::KSM), - 1 * 1_000_000_000_000 - )); - assert_eq!( - VtokenMinting::token_pool(CurrencyId::Token(TokenSymbol::KSM)), - 5 * 1_000_000_000_000 - 5 * 20_000_000_000 - 1_000_000_000_000 + 20_000_000_000 - ); - }); - }) + BifrostKusama::execute_with(|| { + pub const FEE: Permill = Permill::from_percent(2); + assert_ok!(VtokenMinting::set_fees(RawOrigin::Root.into(), FEE, FEE)); + assert_ok!(VtokenMinting::set_unlock_duration( + RawOrigin::Root.into(), + KSM, + TimeUnit::Era(1) + )); + assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(1))); + assert_ok!(VtokenMinting::set_minimum_redeem( + RawOrigin::Root.into(), + KSM, + 2 * 1_000_000_000_000 + )); + assert_ok!(VtokenMinting::mint( + RawOrigin::Signed(BifrostKusamaAlice::get()).into(), + KSM, + 5 * 1_000_000_000_000, + BoundedVec::default() + )); + assert_eq!(VtokenMinting::token_pool(KSM), 5 * 1_000_000_000_000 - 5 * 20_000_000_000); // 1000 + 980 - 98 - 196 + + assert_ok!(VtokenMinting::redeem( + RawOrigin::Signed(BifrostKusamaAlice::get()).into(), + VKSM, + 1 * 1_000_000_000_000 + )); + assert_eq!( + VtokenMinting::token_pool(KSM), + 5 * 1_000_000_000_000 - 5 * 20_000_000_000 - 1_000_000_000_000 + 20_000_000_000 + ); + }); } diff --git a/integration-tests/bifrost-kusama/src/vtoken_voting.rs b/integration-tests/bifrost-kusama/src/vtoken_voting.rs index bcd6ed323c..83677554ed 100644 --- a/integration-tests/bifrost-kusama/src/vtoken_voting.rs +++ b/integration-tests/bifrost-kusama/src/vtoken_voting.rs @@ -16,7 +16,13 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{kusama_integration_tests::*, kusama_test_net::*}; +use bifrost_kusama_runtime::{ + Runtime, RuntimeOrigin, Slp, XcmDestWeightAndFeeHandler, XcmInterface, +}; +use bifrost_primitives::{ + currency::VKSM, Balance, CurrencyId, VTokenSupplyProvider, XcmOperationType as XcmOperation, + KSM, +}; use bifrost_slp::{Ledger, MinimumsMaximums, SubstrateLedger}; use bifrost_vtoken_voting::{AccountVote, TallyOf, VoteRole}; use frame_support::{ @@ -25,207 +31,223 @@ use frame_support::{ traits::{schedule::DispatchTime, StorePreimage}, weights::Weight, }; -use node_primitives::{currency::VKSM, XcmOperationType as XcmOperation}; +use integration_tests_common::{BifrostKusama, BifrostKusamaAlice, Kusama, KusamaAlice}; use pallet_conviction_voting::{Conviction, Vote}; use xcm::v3::Parent; -use xcm_emulator::TestExt; +use xcm_emulator::{Parachain, RelayChain, TestExt}; #[test] fn vote_works() { - env_logger::init(); - - sp_io::TestExternalities::default().execute_with(|| { - let vtoken = VKSM; - let poll_index = 0; - - KusamaNet::execute_with(|| { - use kusama_runtime::{Referenda, RuntimeEvent, RuntimeOrigin, System}; - - assert_ok!(Referenda::submit( - RuntimeOrigin::signed(ALICE.into()), - Box::new(RawOrigin::Root.into()), - set_balance_proposal_bounded(1), - DispatchTime::At(10), - )); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Referenda(pallet_referenda::Event::Submitted { - index: 0, - track: 0, - proposal: _, - }) - ))); - System::reset_events(); - }); - - Bifrost::execute_with(|| { - use bifrost_kusama_runtime::{ - RuntimeEvent, RuntimeOrigin, System, VtokenMinting, VtokenVoting, - }; - - assert_ok!(VtokenMinting::mint( - RuntimeOrigin::signed(ALICE.into()), - KSM, - 1_000_000_000_000, - Default::default() - )); - assert_eq!( - ::VTokenSupplyProvider::get_token_supply( - KSM - ), - Some(1_000_000_000_000) - ); - assert_eq!( - ::VTokenSupplyProvider::get_vtoken_supply( - VKSM - ), - Some(1_000_000_000_000) - ); - let token = CurrencyId::to_token(&vtoken).unwrap(); - assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( - token, - XcmOperation::Vote, - Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), - )); - assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( - token, - XcmOperation::RemoveVote, - Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), - )); - assert_ok!(Slp::set_minimums_and_maximums( - RuntimeOrigin::root(), - token, - Some(MinimumsMaximums { - delegator_bonded_minimum: 0u32.into(), - bond_extra_minimum: 0u32.into(), - unbond_minimum: 0u32.into(), - rebond_minimum: 0u32.into(), - unbond_record_maximum: 0u32, - validators_back_maximum: 0u32, - delegator_active_staking_maximum: 0u32.into(), - validators_reward_maximum: 0u32, - delegation_amount_minimum: 0u32.into(), - delegators_maximum: u16::MAX, - validators_maximum: 0u16, - }) - )); - assert_ok!(Slp::add_delegator( - RuntimeOrigin::root(), - token, - 5, - Box::new(Parent.into()) - )); - assert_ok!(Slp::set_delegator_ledger( - RuntimeOrigin::root(), - token, - Box::new(Parent.into()), - Box::new(Some(Ledger::Substrate(SubstrateLedger { - account: Parent.into(), - total: 100u32.into(), - active: 100u32.into(), - unlocking: vec![], - }))) - )); - - assert_ok!(VtokenVoting::set_delegator_role( - RuntimeOrigin::root(), - vtoken, - 5, - VoteRole::Standard { aye: true, conviction: Conviction::Locked5x }, - )); - assert_ok!(VtokenVoting::set_vote_locking_period(RuntimeOrigin::root(), vtoken, 0)); - assert_ok!(VtokenVoting::set_undeciding_timeout(RuntimeOrigin::root(), vtoken, 100)); - - assert_ok!(VtokenVoting::vote( - RuntimeOrigin::signed(ALICE.into()), - vtoken, - poll_index, - aye(2, 5) - )); - assert_eq!(tally(vtoken, poll_index), TallyOf::::from_parts(10, 0, 2)); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::Voted { - who: _, - vtoken: VKSM, - poll_index: 0, - new_vote: _, - delegator_vote: _, - }) - ))); - System::reset_events(); - }); - - KusamaNet::execute_with(|| { - use kusama_runtime::System; - - System::events().iter().for_each(|r| log::debug!("KusamaNet >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - kusama_runtime::RuntimeEvent::Ump( - polkadot_runtime_parachains::ump::Event::ExecutedUpward(..) - ) - ))); - System::reset_events(); - }); - - Bifrost::execute_with(|| { - use bifrost_kusama_runtime::{RuntimeEvent, System, VtokenVoting}; - - System::events().iter().for_each(|r| log::debug!("Bifrost >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::VoteNotified { + let vtoken = VKSM; + let poll_index = 0; + + Kusama::execute_with(|| { + use kusama_runtime::{Balances, Referenda, RuntimeEvent, RuntimeOrigin, System, Utility}; + + assert_ok!(Balances::force_set_balance( + RuntimeOrigin::root(), + Kusama::sovereign_account_id_of_child_para(BifrostKusama::para_id()).into(), + 1_000_000_000_000_000u128 + )); + assert_ok!(Balances::force_set_balance( + RuntimeOrigin::root(), + Utility::derivative_account_id( + Kusama::sovereign_account_id_of_child_para(BifrostKusama::para_id()).into(), + 5 + ) + .into(), + 1_000_000_000_000_000u128 + )); + assert_ok!(Referenda::submit( + RuntimeOrigin::signed(BifrostKusamaAlice::get()), + Box::new(RawOrigin::Root.into()), + set_balance_proposal_bounded(1), + DispatchTime::At(10), + )); + System::events().iter().for_each(|r| log::debug!("Kusama >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Referenda(pallet_referenda::Event::Submitted { + index: 0, + track: 0, + proposal: _, + }) + ))); + System::reset_events(); + }); + + BifrostKusama::execute_with(|| { + use bifrost_kusama_runtime::{ + RuntimeEvent, RuntimeOrigin, System, VtokenMinting, VtokenVoting, + }; + + assert_ok!(VtokenMinting::mint( + RuntimeOrigin::signed(BifrostKusamaAlice::get()), + KSM, + 1_000_000_000_000, + Default::default() + )); + assert_eq!( + ::VTokenSupplyProvider::get_token_supply(KSM), + Some(1_000_000_000_000) + ); + assert_eq!( + ::VTokenSupplyProvider::get_vtoken_supply( + VKSM + ), + Some(1_000_000_000_000) + ); + let token = CurrencyId::to_token(&vtoken).unwrap(); + assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( + token, + XcmOperation::Vote, + Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), + )); + assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( + token, + XcmOperation::RemoveVote, + Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), + )); + assert_ok!(Slp::set_minimums_and_maximums( + RuntimeOrigin::root(), + token, + Some(MinimumsMaximums { + delegator_bonded_minimum: 0u32.into(), + bond_extra_minimum: 0u32.into(), + unbond_minimum: 0u32.into(), + rebond_minimum: 0u32.into(), + unbond_record_maximum: 0u32, + validators_back_maximum: 0u32, + delegator_active_staking_maximum: 0u32.into(), + validators_reward_maximum: 0u32, + delegation_amount_minimum: 0u32.into(), + delegators_maximum: u16::MAX, + validators_maximum: 0u16, + }) + )); + assert_ok!(Slp::add_delegator(RuntimeOrigin::root(), token, 5, Box::new(Parent.into()))); + assert_ok!(Slp::set_delegator_ledger( + RuntimeOrigin::root(), + token, + Box::new(Parent.into()), + Box::new(Some(Ledger::Substrate(SubstrateLedger { + account: Parent.into(), + total: 1_000_000_000_000u128, + active: 1_000_000_000_000u128, + unlocking: vec![], + }))) + )); + + assert_ok!(VtokenVoting::set_delegator_role( + RuntimeOrigin::root(), + vtoken, + 5, + VoteRole::Standard { aye: true, conviction: Conviction::Locked5x }, + )); + assert_ok!(VtokenVoting::set_vote_locking_period(RuntimeOrigin::root(), vtoken, 0)); + assert_ok!(VtokenVoting::set_undeciding_timeout(RuntimeOrigin::root(), vtoken, 100)); + + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(BifrostKusamaAlice::get()), + vtoken, + poll_index, + aye(1_000_000_000_000u128, 5) + )); + + assert_eq!( + tally(vtoken, poll_index), + TallyOf::::from_parts(5_000_000_000_000, 0, 1_000_000_000_000) + ); + + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::Voted { + who: _, + vtoken: VKSM, + poll_index: 0, + new_vote: _, + delegator_vote: _, + }) + ))); + System::reset_events(); + }); + + Kusama::execute_with(|| { + use kusama_runtime::System; + + System::events().iter().for_each(|r| log::debug!("Kusama >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + r.event, + kusama_runtime::RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { + id: _, + origin: _, + weight_used: _, + success: true + }) + ))); + System::reset_events(); + }); + + BifrostKusama::execute_with(|| { + use bifrost_kusama_runtime::{RuntimeEvent, System, VtokenVoting}; + + System::events() + .iter() + .for_each(|r| log::debug!("BifrostKusama >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::VoteNotified { + vtoken: VKSM, + poll_index: 0, + success: true, + }) + ))); + assert_ok!(VtokenVoting::set_referendum_status( + RuntimeOrigin::root(), + VKSM, + 0, + bifrost_vtoken_voting::ReferendumInfoOf::::Completed(1), + )); + assert_ok!(VtokenVoting::remove_delegator_vote( + RuntimeOrigin::signed(BifrostKusamaAlice::get()), + VKSM, + 0, + 5, + )); + System::reset_events(); + }); + + Kusama::execute_with(|| { + use kusama_runtime::{RuntimeEvent, System}; + + System::events().iter().for_each(|r| log::debug!("Kusama >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + &r.event, + RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { + id: _, + origin: _, + weight_used: _, + success: true + }) + ))); + }); + + BifrostKusama::execute_with(|| { + use bifrost_kusama_runtime::{RuntimeEvent, System}; + + System::events() + .iter() + .for_each(|r| log::debug!("BifrostKusama >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::VtokenVoting( + bifrost_vtoken_voting::Event::DelegatorVoteRemovedNotified { vtoken: VKSM, poll_index: 0, success: true, - }) - ))); - assert_ok!(VtokenVoting::set_referendum_status( - RuntimeOrigin::root(), - VKSM, - 0, - bifrost_vtoken_voting::ReferendumInfoOf::::Completed(1), - )); - assert_ok!(VtokenVoting::remove_delegator_vote( - RuntimeOrigin::signed(ALICE.into()), - VKSM, - 0, - 5, - )); - System::reset_events(); - }); - - KusamaNet::execute_with(|| { - use kusama_runtime::System; - - System::events().iter().for_each(|r| log::debug!("KusamaNet >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - kusama_runtime::RuntimeEvent::Ump( - polkadot_runtime_parachains::ump::Event::ExecutedUpward(..) - ) - ))); - System::reset_events(); - }); - - Bifrost::execute_with(|| { - use bifrost_kusama_runtime::{RuntimeEvent, System}; - - System::events().iter().for_each(|r| log::debug!("Bifrost >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting( - bifrost_vtoken_voting::Event::DelegatorVoteRemovedNotified { - vtoken: VKSM, - poll_index: 0, - success: true, - } - ) - ))); - System::reset_events(); - }); + } + ) + ))); }); } @@ -233,7 +255,7 @@ pub fn set_balance_proposal_bounded( value: Balance, ) -> pallet_referenda::BoundedCallOf { let c = kusama_runtime::RuntimeCall::Balances(pallet_balances::Call::force_set_balance { - who: MultiAddress::Id(AccountId::new(ALICE)), + who: KusamaAlice::get().into(), new_free: value, }); ::bound(c).unwrap() diff --git a/integration-tests/bifrost-kusama/src/xcm_interface.rs b/integration-tests/bifrost-kusama/src/xcm_interface.rs index abbc02af3c..0a88d64933 100644 --- a/integration-tests/bifrost-kusama/src/xcm_interface.rs +++ b/integration-tests/bifrost-kusama/src/xcm_interface.rs @@ -16,169 +16,159 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{kusama_integration_tests::*, kusama_test_net::*}; use bifrost_asset_registry::AssetMetadata; -use frame_support::assert_ok; -use bifrost_primitives::XcmOperationType as XcmOperation; -use polkadot_parachain::primitives::Sibling; -use sp_runtime::traits::AccountIdConversion; +use bifrost_kusama_runtime::{ + AssetRegistry, RelayCurrencyId, RuntimeEvent, RuntimeOrigin, System, + XcmDestWeightAndFeeHandler, XcmInterface, +}; +use bifrost_primitives::{CurrencyId, XcmOperationType as XcmOperation}; +use frame_support::{assert_ok, traits::Currency}; +use integration_tests_common::{ + impls::Outcome::Complete, AssetHubKusama, AssetHubKusamaAlice, BifrostKusama, + BifrostKusamaAlice, +}; +use polkadot_parachain_primitives::primitives::Sibling; +use sp_runtime::{traits::AccountIdConversion, MultiAddress}; use xcm::{ v3::{prelude::*, Weight}, VersionedMultiAssets, VersionedMultiLocation, }; -use xcm_emulator::TestExt; +use xcm_emulator::{bx, Parachain, TestExt}; const USDT: u128 = 1_000_000; #[test] fn cross_usdt() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - let metadata = AssetMetadata { - name: b"USDT".to_vec(), - symbol: b"USDT".to_vec(), - decimals: 6, - minimal_balance: 10, - }; - - assert_ok!(AssetRegistry::register_token_metadata( - RuntimeOrigin::root(), - Box::new(metadata.clone()) - )); - - let location = VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984)), - }); - - assert_ok!(AssetRegistry::register_multilocation( - RuntimeOrigin::root(), - CurrencyId::Token2(0), - Box::new(location.clone()), - Weight::zero() - )); - }); - - Statemine::execute_with(|| { - use frame_support::traits::Currency; - use statemine_runtime::*; - - let origin = RuntimeOrigin::signed(ALICE.into()); - - statemine_runtime::Balances::make_free_balance_be(&ALICE.into(), 10 * KSM_DECIMALS); - statemine_runtime::Balances::make_free_balance_be(&BOB.into(), 10 * KSM_DECIMALS); - - // need to have some KSM to be able to receive user assets - statemine_runtime::Balances::make_free_balance_be( - &Sibling::from(2001).into_account_truncating(), - 10 * KSM_DECIMALS, - ); - - assert_ok!(Assets::create( - statemine_runtime::RuntimeOrigin::signed(ALICE.into()), - codec::Compact(1984), - MultiAddress::Id(ALICE.into()), - 10 - )); - - assert_ok!(Assets::set_metadata( - statemine_runtime::RuntimeOrigin::signed(ALICE.into()), - codec::Compact(1984), - b"USDT".to_vec(), - b"USDT".to_vec(), - 6 - )); - - assert_ok!(Assets::mint( - statemine_runtime::RuntimeOrigin::signed(ALICE.into()), - codec::Compact(1984), - MultiAddress::Id(ALICE.into()), - 100 * USDT - )); - assert_eq!(Assets::balance(1984, sp_runtime::AccountId32::from(ALICE)), 100 * USDT); - - let para_acc: AccountId = Sibling::from(2001).into_account_truncating(); - println!("{:?}", para_acc); - - let assets = MultiAssets::from(vec![MultiAsset::from(( - Concrete(MultiLocation::new(0, X2(PalletInstance(50), GeneralIndex(1984)))), - Fungibility::from(10 * USDT), - ))]); - - assert_ok!( - pallet_xcm::Pallet::::limited_reserve_transfer_assets( - origin.clone(), - Box::new(VersionedMultiLocation::V3(MultiLocation::new( - 1, - X1(Parachain(2001)) - ))), - Box::new(VersionedMultiLocation::V3(MultiLocation::new( - 0, - X1(Junction::AccountId32 { id: BOB, network: None }) - ))), - Box::new(VersionedMultiAssets::V3(assets)), - 0, - WeightLimit::Unlimited, - ) - ); - assert_eq!(Assets::balance(1984, para_acc), 10 * USDT); - System::reset_events(); + BifrostKusama::execute_with(|| { + let metadata = AssetMetadata { + name: b"USDT".to_vec(), + symbol: b"USDT".to_vec(), + decimals: 6, + minimal_balance: 10, + }; + + assert_ok!(AssetRegistry::register_token_metadata( + RuntimeOrigin::root(), + bx!(metadata.clone()) + )); + + let location = VersionedMultiLocation::V3(MultiLocation { + parents: 1, + interior: X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984)), }); - Bifrost::execute_with(|| { - assert_ok!(Tokens::deposit( - CurrencyId::Token2(0), - &sp_runtime::AccountId32::from(ALICE), - 10 * USDT - )); - - assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::StatemineTransfer, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - )); - - // get the fee balance of the alice before the transfer transaction - let alice_fee_balance_before = - Currencies::free_balance(RelayCurrencyId::get(), &AccountId::from(ALICE)); - - // Alice transfers 5 statemine asset to Bob - assert_ok!(XcmInterface::transfer_statemine_assets( - RuntimeOrigin::signed(ALICE.into()), - 5 * USDT, - 1984, - Some(sp_runtime::AccountId32::from(BOB)) - )); - - // get the fee balance of the alice after the transfer transaction - let alice_fee_balance_after = - Currencies::free_balance(RelayCurrencyId::get(), &AccountId::from(ALICE)); - - // assert alice_fee_balance_before and alice_fee_balance_after are equal, since we - // didn't deduct any fee from alice in this test (integration test doesn't go through - // flexible fee) - assert_eq!(alice_fee_balance_before, alice_fee_balance_after); - - // assert Alice has 10-5 =5 statemine asset - assert_eq!( - Tokens::free_balance(CurrencyId::Token2(0), &AccountId::from(ALICE),), - 5 * USDT - ); - }); - Statemine::execute_with(|| { - use statemine_runtime::*; - println!("{:?}", System::events()); - - // assert Bob has 5 statemine asset - assert_eq!(Assets::balance(1984, AccountId::from(BOB)), 5 * USDT); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { - message_hash: _, - weight: _ - }) - ))); - }); - }) + assert_ok!(AssetRegistry::register_multilocation( + RuntimeOrigin::root(), + CurrencyId::Token2(0), + bx!(location.clone()), + Weight::zero() + )); + }); + + AssetHubKusama::execute_with(|| { + use asset_hub_kusama_runtime::{ + Assets, Balances, Runtime, RuntimeEvent, RuntimeOrigin, System, + }; + + let sibling_account = Sibling::from(2001).into_account_truncating(); + + // need to have some KSM to be able to receive user assets + Balances::make_free_balance_be(&sibling_account, 10 * 1_000_000_000_000u128); + + assert_ok!(Assets::create( + RuntimeOrigin::signed(AssetHubKusamaAlice::get()), + codec::Compact(1984), + MultiAddress::Id(AssetHubKusamaAlice::get()), + 10 + )); + + assert_ok!(Assets::set_metadata( + RuntimeOrigin::signed(AssetHubKusamaAlice::get()), + codec::Compact(1984), + b"USDT".to_vec(), + b"USDT".to_vec(), + 6 + )); + + assert_ok!(Assets::mint( + RuntimeOrigin::signed(AssetHubKusamaAlice::get()), + codec::Compact(1984), + MultiAddress::Id(AssetHubKusamaAlice::get()), + 100 * USDT + )); + assert_eq!(Assets::balance(1984, AssetHubKusamaAlice::get()), 100 * USDT); + + let assets = MultiAssets::from(vec![MultiAsset::from(( + Concrete(MultiLocation::new(0, X2(PalletInstance(50), GeneralIndex(1984)))), + Fungibility::from(10 * USDT), + ))]); + + assert_ok!(pallet_xcm::Pallet::::limited_reserve_transfer_assets( + RuntimeOrigin::signed(AssetHubKusamaAlice::get()), + bx!(AssetHubKusama::sibling_location_of(BifrostKusama::para_id()).into()), + bx!(AccountId32 { network: None, id: BifrostKusamaAlice::get().into() }.into()), + Box::new(VersionedMultiAssets::V3(assets)), + 0, + WeightLimit::Unlimited, + )); + assert!(System::events().iter().any(|r| matches!( + r.event, + RuntimeEvent::Assets(pallet_assets::Event::Transferred { + asset_id: 1984, + from: _, + to: _, + amount: 10_000_000 + }) + ))); + assert!(System::events().iter().any(|r| matches!( + &r.event, + RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Attempted { outcome: Complete(_) }) + ))); + System::reset_events(); + }); + + BifrostKusama::execute_with(|| { + System::events().iter().for_each(|r| println!("Bifrost >>> {:?}", r.event)); + assert!(System::events().iter().any(|r| matches!( + &r.event, + RuntimeEvent::Tokens(orml_tokens::Event::Deposited { + currency_id: CurrencyId::Token2(0), + who: _, + amount: 10_000_000 + }) + ))); + + System::reset_events(); + + assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( + RelayCurrencyId::get(), + XcmOperation::StatemineTransfer, + Some((Weight::from_parts(400_000_000_000, 10_000), 4_000_000_000)), + )); + + // Alice transfers 5 statemine asset to Bob + // TODO: Failed to process XCMP-XCM message, caused by Barrier + // assert_ok!(XcmInterface::transfer_statemine_assets( + // RuntimeOrigin::signed(BifrostKusamaAlice::get()), + // 5 * USDT, + // 1984, + // Some(BifrostKusamaBob::get()) + // )); + }); + + // AsserHubKusama::execute_with(|| { + // use statemine_runtime::*; + // println!("{:?}", System::events()); + // + // // assert Bob has 5 statemine asset + // assert_eq!(Assets::balance(1984, AccountId::from(BOB)), 5 * USDT); + // + // assert!(System::events().iter().any(|r| matches!( + // r.event, + // RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { + // message_hash: _, + // weight: _ + // }) + // ))); + // }); } diff --git a/integration-tests/bifrost-kusama/src/reserve_transfer.rs b/integration-tests/bifrost-kusama/src/xcm_transfer.rs similarity index 80% rename from integration-tests/bifrost-kusama/src/reserve_transfer.rs rename to integration-tests/bifrost-kusama/src/xcm_transfer.rs index c4d78431b1..439f2b7cb4 100644 --- a/integration-tests/bifrost-kusama/src/reserve_transfer.rs +++ b/integration-tests/bifrost-kusama/src/xcm_transfer.rs @@ -16,7 +16,64 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::*; +use frame_support::{ + pallet_prelude::Weight, + sp_runtime::{AccountId32, DispatchResult}, +}; +use integration_tests_common::{ + constants::asset_hub_kusama::ED as ASSET_HUB_KUSAMA_ED, AssetHubKusama, AssetHubKusamaPallet, + AssetHubKusamaSender, BifrostKusama, BifrostKusamaReceiver, +}; +use parachains_common::Balance; +use xcm::prelude::{AccountId32 as AccountId32Junction, *}; +use xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, Test, TestArgs, TestContext, +}; + +pub const ASSET_ID: u32 = 1; +pub const ASSET_MIN_BALANCE: u128 = 1000; +// `Assets` pallet index +pub const ASSETS_PALLET_ID: u8 = 50; + +// pub type RelayToSystemParaTest = Test; +// pub type SystemParaToRelayTest = Test; +pub type SystemParaToParaTest = Test; + +/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests +// pub fn relay_test_args(amount: Balance) -> TestArgs { +// TestArgs { +// dest: Kusama::child_location_of(AssetHubKusama::para_id()), +// beneficiary: AccountId32Junction { +// network: None, +// id: AssetHubKusamaReceiver::get().into(), +// } +// .into(), +// amount, +// assets: (Here, amount).into(), +// asset_id: None, +// fee_asset_item: 0, +// weight_limit: WeightLimit::Unlimited, +// } +// } + +/// Returns a `TestArgs` instance to de used for the System Parachain accross integraton tests +pub fn system_para_test_args( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, + assets: MultiAssets, + asset_id: Option, +) -> TestArgs { + TestArgs { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets, + asset_id, + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, + } +} fn system_para_to_para_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; diff --git a/integration-tests/bifrost-polkadot/Cargo.toml b/integration-tests/bifrost-polkadot/Cargo.toml index d5d2210598..36d111dc07 100644 --- a/integration-tests/bifrost-polkadot/Cargo.toml +++ b/integration-tests/bifrost-polkadot/Cargo.toml @@ -9,6 +9,7 @@ codec = { package = "parity-scale-codec", version = "3.4.0", default-features = # Substrate sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} +sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} @@ -32,4 +33,4 @@ xcm-emulator = { git = "https://github.com/paritytech/polkadot-sdk", branch = "r integration-tests-common = { path = "../common", default-features = false} bifrost-primitives = { path = "../../primitives" } bifrost-asset-registry = { path = "../../pallets/asset-registry" } -bifrost-polkadot-runtime = { path = "../../runtime/bifrost-polkadot" } \ No newline at end of file +bifrost-polkadot-runtime = { path = "../../runtime/bifrost-polkadot" } diff --git a/integration-tests/bifrost-polkadot/src/lib.rs b/integration-tests/bifrost-polkadot/src/lib.rs index 170f8af808..8f69cc8193 100644 --- a/integration-tests/bifrost-polkadot/src/lib.rs +++ b/integration-tests/bifrost-polkadot/src/lib.rs @@ -19,78 +19,4 @@ #![cfg(test)] // mod hrmp_channels; -mod reserve_transfer; - -pub use codec::Encode; -pub use frame_support::{ - assert_err, assert_ok, - pallet_prelude::Weight, - sp_runtime::{AccountId32, DispatchError, DispatchResult}, - traits::fungibles::Inspect, -}; -use integration_tests_common::BifrostPolkadot; -pub use integration_tests_common::{ - constants::{ - asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, polkadot::ED as POLKADOT_ED, - PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD, XCM_V3, - }, - xcm_helpers::{xcm_transact_paid_execution, xcm_transact_unpaid_execution}, - AssetHubPolkadot, AssetHubPolkadotPallet, AssetHubPolkadotReceiver, AssetHubPolkadotSender, - BifrostPolkadotReceiver, PenpalPolkadotA, PenpalPolkadotAPallet, PenpalPolkadotAReceiver, - PenpalPolkadotB, PenpalPolkadotBPallet, Polkadot, PolkadotPallet, PolkadotReceiver, - PolkadotSender, -}; -pub use parachains_common::{AccountId, Balance}; -pub use xcm::{ - prelude::{AccountId32 as AccountId32Junction, *}, - v3::{Error, NetworkId::Polkadot as PolkadotId}, -}; -pub use xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, Chain, Parachain as Para, - RelayChain as Relay, Test, TestArgs, TestContext, TestExt, -}; - -pub const ASSET_ID: u32 = 1; -pub const ASSET_MIN_BALANCE: u128 = 1000; -// `Assets` pallet index -pub const ASSETS_PALLET_ID: u8 = 50; - -pub type RelayToSystemParaTest = Test; -pub type SystemParaToRelayTest = Test; -pub type SystemParaToParaTest = Test; - -/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests -pub fn relay_test_args(amount: Balance) -> TestArgs { - TestArgs { - dest: Polkadot::child_location_of(AssetHubPolkadot::para_id()), - beneficiary: AccountId32Junction { - network: None, - id: AssetHubPolkadotReceiver::get().into(), - } - .into(), - amount, - assets: (Here, amount).into(), - asset_id: None, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} - -/// Returns a `TestArgs` instance to de used for the System Parachain accross integraton tests -pub fn system_para_test_args( - dest: MultiLocation, - beneficiary_id: AccountId32, - amount: Balance, - assets: MultiAssets, - asset_id: Option, -) -> TestArgs { - TestArgs { - dest, - beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), - amount, - assets, - asset_id, - fee_asset_item: 0, - weight_limit: WeightLimit::Unlimited, - } -} +mod xcm_transfer; diff --git a/integration-tests/bifrost-polkadot/src/reserve_transfer.rs b/integration-tests/bifrost-polkadot/src/xcm_transfer.rs similarity index 77% rename from integration-tests/bifrost-polkadot/src/reserve_transfer.rs rename to integration-tests/bifrost-polkadot/src/xcm_transfer.rs index 21bfc50a17..bb04c8db9d 100644 --- a/integration-tests/bifrost-polkadot/src/reserve_transfer.rs +++ b/integration-tests/bifrost-polkadot/src/xcm_transfer.rs @@ -16,7 +16,64 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::*; +use frame_support::{ + pallet_prelude::Weight, + sp_runtime::{AccountId32, DispatchResult}, +}; +use integration_tests_common::{ + constants::asset_hub_polkadot::ED as ASSET_HUB_POLKADOT_ED, AssetHubPolkadot, + AssetHubPolkadotPallet, AssetHubPolkadotSender, BifrostPolkadot, BifrostPolkadotReceiver, +}; +use parachains_common::Balance; +use xcm::prelude::{AccountId32 as AccountId32Junction, *}; +use xcm_emulator::{ + assert_expected_events, bx, Chain, Parachain as Para, Test, TestArgs, TestContext, +}; + +pub const ASSET_ID: u32 = 1; +pub const ASSET_MIN_BALANCE: u128 = 1000; +// `Assets` pallet index +pub const ASSETS_PALLET_ID: u8 = 50; + +// pub type RelayToSystemParaTest = Test; +// pub type SystemParaToRelayTest = Test; +pub type SystemParaToParaTest = Test; + +/// Returns a `TestArgs` instance to de used for the Relay Chain accross integraton tests +// pub fn relay_test_args(amount: Balance) -> TestArgs { +// TestArgs { +// dest: Polkadot::child_location_of(BifrostPolkadot::para_id()), +// beneficiary: AccountId32Junction { +// network: None, +// id: BifrostPolkadotReceiver::get().into(), +// } +// .into(), +// amount, +// assets: (Here, amount).into(), +// asset_id: None, +// fee_asset_item: 0, +// weight_limit: WeightLimit::Unlimited, +// } +// } + +/// Returns a `TestArgs` instance to de used for the System Parachain accross integraton tests +pub fn system_para_test_args( + dest: MultiLocation, + beneficiary_id: AccountId32, + amount: Balance, + assets: MultiAssets, + asset_id: Option, +) -> TestArgs { + TestArgs { + dest, + beneficiary: AccountId32Junction { network: None, id: beneficiary_id.into() }.into(), + amount, + assets, + asset_id, + fee_asset_item: 0, + weight_limit: WeightLimit::Unlimited, + } +} fn system_para_to_para_assertions(t: SystemParaToParaTest) { type RuntimeEvent = ::RuntimeEvent; @@ -90,9 +147,9 @@ fn system_para_to_para_reserve_transfer_assets(t: SystemParaToParaTest) -> Dispa ) } -/// Limited Reserve Transfers of native asset from AssetHub to BifrostPolkadot should work +/// Reserve Transfers of native asset from AssetHub to BifrostPolkadot should work #[test] -fn limited_reserve_transfer_native_asset_from_asset_hub_to_bifrost_polkadot() { +fn reserve_transfer_native_asset_from_polkadot_to_bifrost_polkadot() { // Init values for System Parachain let destination = AssetHubPolkadot::sibling_location_of(BifrostPolkadot::para_id()); let beneficiary_id = BifrostPolkadotReceiver::get(); @@ -101,7 +158,7 @@ fn limited_reserve_transfer_native_asset_from_asset_hub_to_bifrost_polkadot() { let test_args = TestContext { sender: AssetHubPolkadotSender::get(), - receiver: PenpalPolkadotAReceiver::get(), + receiver: BifrostPolkadotReceiver::get(), args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None), }; @@ -168,7 +225,7 @@ fn limited_reserve_transfer_asset_from_asset_hub_to_bifrost_polkadot() { let system_para_test_args = TestContext { sender: AssetHubPolkadotSender::get(), - receiver: PenpalPolkadotAReceiver::get(), + receiver: BifrostPolkadotReceiver::get(), args: system_para_test_args(destination, beneficiary_id, amount_to_send, assets, None), }; @@ -193,7 +250,7 @@ fn reserve_transfer_asset_from_asset_hub_to_bifrost_polkadot() { ); // Init values for System Parachain - let destination = AssetHubPolkadot::sibling_location_of(PenpalPolkadotA::para_id()); + let destination = AssetHubPolkadot::sibling_location_of(BifrostPolkadot::para_id()); let beneficiary_id = BifrostPolkadotReceiver::get(); let amount_to_send = ASSET_MIN_BALANCE * 1000; let assets = diff --git a/integration-tests/common/Cargo.toml b/integration-tests/common/Cargo.toml index cfea3db986..08ee00fe67 100644 --- a/integration-tests/common/Cargo.toml +++ b/integration-tests/common/Cargo.toml @@ -1,9 +1,8 @@ [package] name = "integration-tests-common" -version = "1.0.0" -license = "Apache-2.0" -description = "Common resources for integration testing with xcm-emulator" -publish = false +version = "0.8.0" +authors = ["hqwangningbo <2536935847@qq.com>"] +edition = "2021" [dependencies] codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } @@ -32,24 +31,17 @@ polkadot-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch polkadot-runtime-constants = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } kusama-runtime = { package = "staging-kusama-runtime", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } kusama-runtime-constants = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -rococo-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -rococo-runtime-constants = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -westend-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -westend-runtime-constants = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} # Cumulus parachains-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -penpal-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } asset-hub-polkadot-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } asset-hub-kusama-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -asset-hub-westend-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } collectives-polkadot-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } bridge-hub-kusama-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } bridge-hub-polkadot-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } -bridge-hub-rococo-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } xcm-emulator = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false} @@ -59,4 +51,6 @@ pallet-bridge-messages = { git = "https://github.com/paritytech/polkadot-sdk", b bridge-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" } bifrost-polkadot-runtime = { path = "../../runtime/bifrost-polkadot" } -bifrost-kusama-runtime = { path = "../../runtime/bifrost-kusama" } \ No newline at end of file +bifrost-kusama-runtime = { path = "../../runtime/bifrost-kusama" } +parachain-staking = { path = "../../pallets/parachain-staking" } +bifrost-primitives = { path = "../../primitives" } diff --git a/integration-tests/common/src/constants.rs b/integration-tests/common/src/constants.rs index f429f5e5ff..467f3883bd 100644 --- a/integration-tests/common/src/constants.rs +++ b/integration-tests/common/src/constants.rs @@ -29,6 +29,10 @@ use sp_runtime::{ }; // Cumulus +use bifrost_kusama_runtime::{ + constants::currency::DOLLARS, DefaultBlocksPerRound, InflationInfo, Range, +}; +use bifrost_primitives::DOT; use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber}; use polkadot_parachain_primitives::primitives::{HeadData, ValidationCode}; use polkadot_primitives::{AssignmentId, ValidatorId}; @@ -63,6 +67,7 @@ where pub mod accounts { use super::*; + use sp_runtime::traits::AccountIdConversion; pub const ALICE: &str = "Alice"; pub const BOB: &str = "Bob"; pub const CHARLIE: &str = "Charlie"; @@ -71,11 +76,6 @@ pub mod accounts { pub const FERDIE: &str = "Ferdei"; pub const ALICE_STASH: &str = "Alice//stash"; pub const BOB_STASH: &str = "Bob//stash"; - pub const CHARLIE_STASH: &str = "Charlie//stash"; - pub const DAVE_STASH: &str = "Dave//stash"; - pub const EVE_STASH: &str = "Eve//stash"; - pub const FERDIE_STASH: &str = "Ferdie//stash"; - pub const FERDIE_BEEFY: &str = "Ferdie//stash"; pub fn init_balances() -> Vec { vec![ @@ -84,13 +84,9 @@ pub mod accounts { get_account_id_from_seed::(CHARLIE), get_account_id_from_seed::(DAVE), get_account_id_from_seed::(EVE), - get_account_id_from_seed::(FERDIE), get_account_id_from_seed::(ALICE_STASH), get_account_id_from_seed::(BOB_STASH), - get_account_id_from_seed::(CHARLIE_STASH), - get_account_id_from_seed::(DAVE_STASH), - get_account_id_from_seed::(EVE_STASH), - get_account_id_from_seed::(FERDIE_STASH), + bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(), ] } } @@ -120,6 +116,55 @@ pub mod collators { (get_account_id_from_seed::("Bob"), get_from_seed::("Bob")), ] } + + pub fn candidates() -> Vec<(AccountId, Balance)> { + vec![ + (get_account_id_from_seed::("Alice"), 10000 * 1_000_000_000_000u128), + (get_account_id_from_seed::("Bob"), 10000 * 1_000_000_000_000u128), + ] + } + + pub fn delegations() -> Vec<(AccountId, AccountId, Balance)> { + vec![ + ( + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Alice"), + 5000 * 1_000_000_000_000u128, + ), + ( + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Bob"), + 5000 * 1_000_000_000_000u128, + ), + ] + } + + pub fn inflation_config() -> InflationInfo { + fn to_round_inflation(annual: Range) -> Range { + use parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}; + perbill_annual_to_perbill_round( + annual, + // rounds per year + BLOCKS_PER_YEAR / DefaultBlocksPerRound::get(), + ) + } + let annual = Range { + min: Perbill::from_percent(4), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }; + InflationInfo { + // staking expectations + expect: Range { + min: 100_000 * DOLLARS, + ideal: 200_000 * DOLLARS, + max: 500_000 * DOLLARS, + }, + // annual inflation + annual, + round: to_round_inflation(annual), + } + } } pub mod validators { @@ -239,149 +284,18 @@ pub mod polkadot { }, configuration: polkadot_runtime::ConfigurationConfig { config: get_host_config() }, paras: polkadot_runtime::ParasConfig { - paras: vec![ - ( - asset_hub_polkadot::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - asset_hub_polkadot_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - penpal::PARA_ID_A.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - penpal_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - penpal::PARA_ID_B.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - penpal_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ], - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Westend -pub mod westend { - use super::*; - use westend_runtime_constants::currency::UNITS as WND; - pub const ED: Balance = westend_runtime_constants::currency::EXISTENTIAL_DEPOSIT; - const ENDOWMENT: u128 = 1_000_000 * WND; - const STASH: u128 = 100 * WND; - - pub fn get_host_config() -> HostConfiguration { - HostConfiguration { - max_upward_queue_count: 10, - max_upward_queue_size: 51200, - max_upward_message_size: 51200, - max_upward_message_num_per_candidate: 10, - max_downward_message_size: 51200, - hrmp_sender_deposit: 100_000_000_000, - hrmp_recipient_deposit: 100_000_000_000, - hrmp_channel_max_capacity: 1000, - hrmp_channel_max_message_size: 102400, - hrmp_channel_max_total_size: 102400, - hrmp_max_parachain_outbound_channels: 30, - hrmp_max_parachain_inbound_channels: 30, - ..Default::default() - } - } - - fn session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, - ) -> westend_runtime::SessionKeys { - westend_runtime::SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } - } - - pub fn genesis() -> Storage { - let genesis_config = westend_runtime::RuntimeGenesisConfig { - system: westend_runtime::SystemConfig { - code: westend_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: westend_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ENDOWMENT)) - .collect(), - }, - session: westend_runtime::SessionConfig { - keys: validators::initial_authorities() - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - westend::session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - get_from_seed::("Alice"), - ), - ) - }) - .collect::>(), - }, - staking: westend_runtime::StakingConfig { - validator_count: validators::initial_authorities().len() as u32, - minimum_validator_count: 1, - stakers: validators::initial_authorities() - .iter() - .map(|x| { - (x.0.clone(), x.1.clone(), STASH, westend_runtime::StakerStatus::Validator) - }) - .collect(), - invulnerables: validators::initial_authorities() - .iter() - .map(|x| x.0.clone()) - .collect(), - force_era: pallet_staking::Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), + paras: vec![( + asset_hub_polkadot::PARA_ID.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + asset_hub_polkadot_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + )], ..Default::default() }, - babe: westend_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - configuration: westend_runtime::ConfigurationConfig { config: get_host_config() }, ..Default::default() }; @@ -491,136 +405,16 @@ pub mod kusama { }, configuration: kusama_runtime::ConfigurationConfig { config: get_host_config() }, paras: kusama_runtime::ParasConfig { - paras: vec![ - ( - asset_hub_kusama::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - asset_hub_kusama_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - penpal::PARA_ID_A.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - penpal_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - penpal::PARA_ID_B.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - penpal_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ], - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Rococo -pub mod rococo { - use super::*; - pub const ED: Balance = rococo_runtime_constants::currency::EXISTENTIAL_DEPOSIT; - use rococo_runtime_constants::currency::UNITS as ROC; - const ENDOWMENT: u128 = 1_000_000 * ROC; - - pub fn get_host_config() -> HostConfiguration { - HostConfiguration { - max_upward_queue_count: 10, - max_upward_queue_size: 51200, - max_upward_message_size: 51200, - max_upward_message_num_per_candidate: 10, - max_downward_message_size: 51200, - hrmp_sender_deposit: 0, - hrmp_recipient_deposit: 0, - hrmp_channel_max_capacity: 1000, - hrmp_channel_max_message_size: 102400, - hrmp_channel_max_total_size: 102400, - hrmp_max_parachain_outbound_channels: 30, - hrmp_max_parachain_inbound_channels: 30, - ..Default::default() - } - } - - fn session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, - ) -> rococo_runtime::SessionKeys { - rococo_runtime::SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } - } - - pub fn genesis() -> Storage { - let genesis_config = rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig { - code: rococo_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: rococo_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .map(|k| (k.clone(), ENDOWMENT)) - .collect(), - }, - // indices: rococo_runtime::IndicesConfig { indices: vec![] }, - session: rococo_runtime::SessionConfig { - keys: validators::initial_authorities() - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - get_from_seed::("Alice"), - ), - ) - }) - .collect::>(), - }, - babe: rococo_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - sudo: rococo_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), - }, - configuration: rococo_runtime::ConfigurationConfig { config: get_host_config() }, - registrar: rococo_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, + paras: vec![( + asset_hub_kusama::PARA_ID.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + asset_hub_kusama_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + )], ..Default::default() }, ..Default::default() @@ -633,6 +427,7 @@ pub mod rococo { // Asset Hub Polkadot pub mod bifrost_polkadot { use super::*; + use crate::BOB; pub const PARA_ID: u32 = 2030; pub const ED: Balance = 10_000_000_000; @@ -680,6 +475,13 @@ pub mod bifrost_polkadot { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, + tokens: bifrost_polkadot_runtime::TokensConfig { + balances: vec![( + get_account_id_from_seed::(BOB), + DOT, + 10 * 10_000_000_000u128, + )], + }, ..Default::default() }; @@ -690,8 +492,11 @@ pub mod bifrost_polkadot { // Asset Hub Polkadot pub mod bifrost_kusama { use super::*; + use crate::ALICE; + use bifrost_primitives::KSM; + pub const PARA_ID: u32 = 2001; - pub const ED: Balance = 10_000_000_000; + pub const ED: Balance = 1_000_000_000_000; pub fn genesis() -> Storage { let genesis_config = bifrost_kusama_runtime::RuntimeGenesisConfig { @@ -705,7 +510,7 @@ pub mod bifrost_kusama { balances: accounts::init_balances() .iter() .cloned() - .map(|k| (k, ED * 4096)) + .map(|k| (k, ED * 10_000_000)) .collect(), }, parachain_info: bifrost_kusama_runtime::ParachainInfoConfig { @@ -724,10 +529,28 @@ pub mod bifrost_kusama { }) .collect(), }, + // parachain_staking: bifrost_kusama_runtime::ParachainStakingConfig { + // candidates: collators::candidates(), + // delegations: collators::delegations(), + // inflation_config: collators::inflation_config(), + // }, polkadot_xcm: bifrost_kusama_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, + tokens: bifrost_kusama_runtime::TokensConfig { + balances: vec![( + get_account_id_from_seed::(ALICE), + KSM, + 10 * 1_000_000_000_000u128, + )], + }, + asset_registry: bifrost_kusama_runtime::AssetRegistryConfig { + currency: vec![(KSM, 10_000_000, None)], + vcurrency: vec![], + vsbond: vec![], + phantom: Default::default(), + }, ..Default::default() }; @@ -740,6 +563,7 @@ pub mod asset_hub_polkadot { use super::*; pub const PARA_ID: u32 = 1000; pub const ED: Balance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; + pub const DOT_DECIMALS: Balance = parachains_common::polkadot::currency::DOLLARS; pub fn genesis() -> Storage { let genesis_config = asset_hub_polkadot_runtime::RuntimeGenesisConfig { @@ -792,63 +616,6 @@ pub mod asset_hub_polkadot { } } -// Asset Hub Westend -pub mod asset_hub_westend { - use super::*; - pub const PARA_ID: u32 = 1000; - pub const ED: Balance = parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; - - pub fn genesis() -> Storage { - let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig { - system: asset_hub_westend_runtime::SystemConfig { - code: asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_westend_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: asset_hub_westend_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_westend_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - // Asset Hub Kusama pub mod asset_hub_kusama { use super::*; @@ -906,67 +673,6 @@ pub mod asset_hub_kusama { } } -// Penpal -pub mod penpal { - use super::*; - pub const PARA_ID_A: u32 = 2000; - pub const PARA_ID_B: u32 = 2001; - pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT; - - pub fn genesis(para_id: u32) -> Storage { - let genesis_config = penpal_runtime::RuntimeGenesisConfig { - system: penpal_runtime::SystemConfig { - code: penpal_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: penpal_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: penpal_runtime::ParachainInfoConfig { - parachain_id: para_id.into(), - ..Default::default() - }, - collator_selection: penpal_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: penpal_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - penpal_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: penpal_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - sudo: penpal_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - // Collectives pub mod collectives { use super::*; @@ -1137,76 +843,3 @@ pub mod bridge_hub_polkadot { genesis_config.build_storage().unwrap() } } - -// Bridge Hub Rococo & Bridge Hub Wococo -pub mod bridge_hub_rococo { - use super::*; - pub const PARA_ID: u32 = 1013; - pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; - - pub fn genesis() -> Storage { - let genesis_config = bridge_hub_rococo_runtime::RuntimeGenesisConfig { - system: bridge_hub_rococo_runtime::SystemConfig { - code: bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_rococo_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: bridge_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: bridge_hub_rococo_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: bridge_hub_rococo_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - bridge_wococo_grandpa: bridge_hub_rococo_runtime::BridgeWococoGrandpaConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() - }, - bridge_rococo_grandpa: bridge_hub_rococo_runtime::BridgeRococoGrandpaConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() - }, - bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() - }, - bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} diff --git a/integration-tests/common/src/impls.rs b/integration-tests/common/src/impls.rs index eed61d9417..422fc430b9 100644 --- a/integration-tests/common/src/impls.rs +++ b/integration-tests/common/src/impls.rs @@ -19,28 +19,22 @@ pub use paste; pub use crate::{ constants::{PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD}, xcm_helpers::xcm_transact_unpaid_execution, - BridgeHubRococo, BridgeHubWococo, }; // Substrate pub use frame_support::{assert_ok, traits::fungibles::Inspect}; pub use pallet_assets; pub use pallet_message_queue; -use sp_core::Get; +#[allow(unused_imports)] +use sp_runtime::traits::AccountIdConversion; // Cumulus -use bp_messages::{ - target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch}, - LaneId, MessageKey, OutboundLaneData, -}; -use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult; pub use cumulus_pallet_dmp_queue; pub use cumulus_pallet_parachain_system; pub use cumulus_pallet_xcmp_queue; pub use cumulus_primitives_core::{ relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler, }; -use pallet_bridge_messages::{Config, Instance1, Instance2, OutboundLanes, Pallet}; pub use parachains_common::{AccountId, Balance}; pub use xcm_emulator::{ assert_expected_events, bx, helpers::weight_within_threshold, BridgeMessage, @@ -59,119 +53,21 @@ pub use xcm::{ DoubleEncoded, }; -pub struct BridgeHubMessageHandler { - _marker: std::marker::PhantomData<(S, T, I)>, -} - -struct LaneIdWrapper(LaneId); - -impl From for u32 { - fn from(lane_id: LaneIdWrapper) -> u32 { - u32::from_be_bytes(lane_id.0 .0) - } -} - -impl From for LaneIdWrapper { - fn from(id: u32) -> LaneIdWrapper { - LaneIdWrapper(LaneId(id.to_be_bytes())) - } -} - -type BridgeHubRococoRuntime = ::Runtime; -type BridgeHubWococoRuntime = ::Runtime; - -// TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged -// type BridgeHubPolkadotRuntime = ::Runtime; -// type BridgeHubKusamaRuntime = ::Runtime; - -pub type RococoWococoMessageHandler = - BridgeHubMessageHandler; -pub type WococoRococoMessageHandler = - BridgeHubMessageHandler; - -// TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged -// pub type PolkadotKusamaMessageHandler -// = BridgeHubMessageHandler; -// pub type KusamaPolkadotMessageHandler -// = BridgeHubMessageHandler; - -impl BridgeMessageHandler for BridgeHubMessageHandler -where - S: Config, - T: Config, - I: 'static, - >::InboundPayload: From>, - >::MessageDispatch: - MessageDispatch, -{ - fn get_source_outbound_messages() -> Vec { - // get the source active outbound lanes - let active_lanes = S::ActiveOutboundLanes::get(); - - let mut messages: Vec = Default::default(); - - // collect messages from `OutboundMessages` for each active outbound lane in the source - for lane in active_lanes { - let latest_generated_nonce = - OutboundLanes::::get(lane).latest_generated_nonce; - let latest_received_nonce = - OutboundLanes::::get(lane).latest_received_nonce; - - (latest_received_nonce + 1..=latest_generated_nonce).for_each(|nonce| { - let encoded_payload: Vec = - Pallet::::outbound_message_data(*lane, nonce) - .expect("Bridge message does not exist") - .into(); - let payload = Vec::::decode(&mut &encoded_payload[..]) - .expect("Decodign XCM message failed"); - let id: u32 = LaneIdWrapper(*lane).into(); - let message = BridgeMessage { id, nonce, payload }; - - messages.push(message); - }); +#[macro_export] +macro_rules! impl_test_accounts_helpers_for_chain { + ( $( $chain:ident),+ ) => { + xcm_emulator::paste::paste! { + xcm_emulator::parameter_types! { + $( + pub [<$chain Alice>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::ALICE); + pub [<$chain Bob>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::BOB); + pub [<$chain Charlie>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::CHARLIE); + pub [<$chain Dave>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::DAVE); + pub [<$chain Treasury>]: parachains_common::AccountId = bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(); + )+ + } } - messages - } - - fn dispatch_target_inbound_message( - message: BridgeMessage, - ) -> Result<(), BridgeMessageDispatchError> { - type TargetMessageDispatch = >::MessageDispatch; - type InboundPayload = >::InboundPayload; - - let lane_id = LaneIdWrapper::from(message.id).0; - let nonce = message.nonce; - let payload = Ok(From::from(message.payload)); - - // Directly dispatch outbound messages assuming everything is correct - // and bypassing the `Relayers` and `InboundLane` logic - let dispatch_result = TargetMessageDispatch::::dispatch(DispatchMessage { - key: MessageKey { lane_id, nonce }, - data: DispatchMessageData::> { payload }, - }); - - let result = match dispatch_result.dispatch_level_result { - XcmBlobMessageDispatchResult::Dispatched => Ok(()), - XcmBlobMessageDispatchResult::InvalidPayload => Err(BridgeMessageDispatchError( - Box::new(XcmBlobMessageDispatchResult::InvalidPayload), - )), - XcmBlobMessageDispatchResult::NotDispatched(e) => Err(BridgeMessageDispatchError( - Box::new(XcmBlobMessageDispatchResult::NotDispatched(e)), - )), - }; - result - } - - fn notify_source_message_delivery(lane_id: u32) { - let data = OutboundLanes::::get(LaneIdWrapper::from(lane_id).0); - let new_data = OutboundLaneData { - oldest_unpruned_nonce: data.oldest_unpruned_nonce + 1, - latest_received_nonce: data.latest_received_nonce + 1, - ..data - }; - - OutboundLanes::::insert(LaneIdWrapper::from(lane_id).0, new_data); - } + }; } #[macro_export] diff --git a/integration-tests/common/src/lib.rs b/integration-tests/common/src/lib.rs index c0d2cf2b26..b78296f1ed 100644 --- a/integration-tests/common/src/lib.rs +++ b/integration-tests/common/src/lib.rs @@ -16,55 +16,23 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -pub extern crate beefy_primitives; -pub extern crate bp_messages; -pub extern crate bridge_runtime_common; -pub extern crate codec; -pub extern crate cumulus_pallet_dmp_queue; -pub extern crate cumulus_pallet_parachain_system; -pub extern crate cumulus_pallet_xcmp_queue; -pub extern crate cumulus_primitives_core; -pub extern crate frame_support; -pub extern crate grandpa; -pub extern crate kusama_runtime_constants; -pub extern crate pallet_assets; -pub extern crate pallet_bridge_messages; -pub extern crate pallet_im_online; -pub extern crate pallet_message_queue; -pub extern crate pallet_xcm; -pub extern crate parachains_common; -pub extern crate paste; -pub extern crate polkadot_parachain_primitives; -pub extern crate polkadot_primitives; -pub extern crate polkadot_runtime_parachains; -pub extern crate polkadot_service; -pub extern crate rococo_runtime_constants; -pub extern crate sp_authority_discovery; -pub extern crate sp_consensus_babe; -pub extern crate sp_core; -pub extern crate sp_runtime; -pub extern crate westend_runtime_constants; -pub extern crate xcm; -pub extern crate xcm_emulator; - pub mod constants; pub mod impls; pub mod xcm_helpers; pub use constants::{ accounts::{ALICE, BOB}, - asset_hub_kusama, asset_hub_polkadot, asset_hub_westend, bifrost_kusama, bifrost_polkadot, - bridge_hub_kusama, bridge_hub_polkadot, bridge_hub_rococo, collectives, kusama, penpal, - polkadot, rococo, westend, + asset_hub_kusama, asset_hub_polkadot, bifrost_kusama, bifrost_polkadot, bridge_hub_kusama, + bridge_hub_polkadot, collectives, kusama, polkadot, }; -use impls::{RococoWococoMessageHandler, WococoRococoMessageHandler}; // Substrate use frame_support::traits::OnInitialize; // Cumulus +use sp_runtime::traits::AccountIdConversion; use xcm_emulator::{ - decl_test_bridges, decl_test_networks, decl_test_parachains, decl_test_relay_chains, + decl_test_networks, decl_test_parachains, decl_test_relay_chains, decl_test_sender_receiver_accounts_parameter_types, DefaultMessageProcessor, }; @@ -79,6 +47,7 @@ decl_test_relay_chains! { SovereignAccountOf: polkadot_runtime::xcm_config::SovereignAccountOf, }, pallets = { + System: polkadot_runtime::System, XcmPallet: polkadot_runtime::XcmPallet, Balances: polkadot_runtime::Balances, Hrmp: polkadot_runtime::Hrmp, @@ -94,54 +63,11 @@ decl_test_relay_chains! { SovereignAccountOf: kusama_runtime::xcm_config::SovereignAccountOf, }, pallets = { + System: kusama_runtime::System, XcmPallet: kusama_runtime::XcmPallet, Balances: kusama_runtime::Balances, Hrmp: kusama_runtime::Hrmp, - } - }, - #[api_version(6)] - pub struct Westend { - genesis = westend::genesis(), - on_init = (), - runtime = westend_runtime, - core = { - MessageProcessor: DefaultMessageProcessor, - SovereignAccountOf: westend_runtime::xcm_config::LocationConverter, //TODO: rename to SovereignAccountOf, - }, - pallets = { - XcmPallet: westend_runtime::XcmPallet, - Sudo: westend_runtime::Sudo, - Balances: westend_runtime::Balances, - } - }, - #[api_version(5)] - pub struct Rococo { - genesis = rococo::genesis(), - on_init = (), - runtime = rococo_runtime, - core = { - MessageProcessor: DefaultMessageProcessor, - SovereignAccountOf: rococo_runtime::xcm_config::LocationConverter, //TODO: rename to SovereignAccountOf, - }, - pallets = { - XcmPallet: rococo_runtime::XcmPallet, - Sudo: rococo_runtime::Sudo, - Balances: rococo_runtime::Balances, - } - }, - #[api_version(5)] - pub struct Wococo { - genesis = rococo::genesis(), - on_init = (), - runtime = rococo_runtime, - core = { - MessageProcessor: DefaultMessageProcessor, - SovereignAccountOf: rococo_runtime::xcm_config::LocationConverter, //TODO: rename to SovereignAccountOf, - }, - pallets = { - XcmPallet: rococo_runtime::XcmPallet, - Sudo: rococo_runtime::Sudo, - Balances: rococo_runtime::Balances, + Referenda: kusama_runtime::Referenda, } } } @@ -161,6 +87,7 @@ decl_test_parachains! { ParachainInfo: bifrost_polkadot_runtime::ParachainInfo, }, pallets = { + System: bifrost_polkadot_runtime::System, PolkadotXcm: bifrost_polkadot_runtime::PolkadotXcm, Tokens: bifrost_polkadot_runtime::Tokens, XTokens: bifrost_polkadot_runtime::XTokens, @@ -218,40 +145,6 @@ decl_test_parachains! { PolkadotXcm: bridge_hub_polkadot_runtime::PolkadotXcm, } }, - pub struct PenpalPolkadotA { - genesis = penpal::genesis(penpal::PARA_ID_A), - on_init = { - penpal_runtime::AuraExt::on_initialize(1); - }, - runtime = penpal_runtime, - core = { - XcmpMessageHandler: penpal_runtime::XcmpQueue, - DmpMessageHandler: penpal_runtime::DmpQueue, - LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId, - ParachainInfo: penpal_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: penpal_runtime::PolkadotXcm, - Assets: penpal_runtime::Assets, - } - }, - pub struct PenpalPolkadotB { - genesis = penpal::genesis(penpal::PARA_ID_B), - on_init = { - penpal_runtime::AuraExt::on_initialize(1); - }, - runtime = penpal_runtime, - core = { - XcmpMessageHandler: penpal_runtime::XcmpQueue, - DmpMessageHandler: penpal_runtime::DmpQueue, - LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId, - ParachainInfo: penpal_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: penpal_runtime::PolkadotXcm, - Assets: penpal_runtime::Assets, - } - }, // Kusama Parachains pub struct BifrostKusama { genesis = bifrost_kusama::genesis(), @@ -266,6 +159,7 @@ decl_test_parachains! { ParachainInfo: bifrost_kusama_runtime::ParachainInfo, }, pallets = { + System: bifrost_kusama_runtime::System, PolkadotXcm: bifrost_kusama_runtime::PolkadotXcm, Tokens: bifrost_kusama_runtime::Tokens, XTokens: bifrost_kusama_runtime::XTokens, @@ -309,166 +203,6 @@ decl_test_parachains! { PolkadotXcm: bridge_hub_kusama_runtime::PolkadotXcm, } }, - pub struct PenpalKusamaA { - genesis = penpal::genesis(penpal::PARA_ID_A), - on_init = { - penpal_runtime::AuraExt::on_initialize(1); - }, - runtime = penpal_runtime, - core = { - XcmpMessageHandler: penpal_runtime::XcmpQueue, - DmpMessageHandler: penpal_runtime::DmpQueue, - LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId, - ParachainInfo: penpal_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: penpal_runtime::PolkadotXcm, - Assets: penpal_runtime::Assets, - } - }, - pub struct PenpalKusamaB { - genesis = penpal::genesis(penpal::PARA_ID_B), - on_init = { - penpal_runtime::AuraExt::on_initialize(1); - }, - runtime = penpal_runtime, - core = { - XcmpMessageHandler: penpal_runtime::XcmpQueue, - DmpMessageHandler: penpal_runtime::DmpQueue, - LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId, - ParachainInfo: penpal_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: penpal_runtime::PolkadotXcm, - Assets: penpal_runtime::Assets, - } - }, - // Westend Parachains - pub struct AssetHubWestend { - genesis = asset_hub_westend::genesis(), - on_init = { - asset_hub_westend_runtime::AuraExt::on_initialize(1); - }, - runtime = asset_hub_westend_runtime, - core = { - XcmpMessageHandler: asset_hub_westend_runtime::XcmpQueue, - DmpMessageHandler: asset_hub_westend_runtime::DmpQueue, - LocationToAccountId: asset_hub_westend_runtime::xcm_config::LocationToAccountId, - ParachainInfo: asset_hub_westend_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm, - Balances: asset_hub_westend_runtime::Balances, - Assets: asset_hub_westend_runtime::Assets, - ForeignAssets: asset_hub_westend_runtime::ForeignAssets, - PoolAssets: asset_hub_westend_runtime::PoolAssets, - AssetConversion: asset_hub_westend_runtime::AssetConversion, - } - }, - pub struct PenpalWestendA { - genesis = penpal::genesis(penpal::PARA_ID_A), - on_init = { - penpal_runtime::AuraExt::on_initialize(1); - }, - runtime = penpal_runtime, - core = { - XcmpMessageHandler: penpal_runtime::XcmpQueue, - DmpMessageHandler: penpal_runtime::DmpQueue, - LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId, - ParachainInfo: penpal_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: penpal_runtime::PolkadotXcm, - Assets: penpal_runtime::Assets, - } - }, - // Rococo Parachains - pub struct BridgeHubRococo { - genesis = bridge_hub_rococo::genesis(), - on_init = { - bridge_hub_rococo_runtime::AuraExt::on_initialize(1); - }, - runtime = bridge_hub_rococo_runtime, - core = { - XcmpMessageHandler: bridge_hub_rococo_runtime::XcmpQueue, - DmpMessageHandler: bridge_hub_rococo_runtime::DmpQueue, - LocationToAccountId: bridge_hub_rococo_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bridge_hub_rococo_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm, - Balances: bridge_hub_rococo_runtime::Balances, - } - }, - // AssetHubRococo (aka Rockmine/Rockmine2) mirrors AssetHubKusama - pub struct AssetHubRococo { - genesis = asset_hub_kusama::genesis(), - on_init = { - asset_hub_polkadot_runtime::AuraExt::on_initialize(1); - }, - runtime = asset_hub_kusama_runtime, - core = { - XcmpMessageHandler: asset_hub_kusama_runtime::XcmpQueue, - DmpMessageHandler: asset_hub_kusama_runtime::DmpQueue, - LocationToAccountId: asset_hub_kusama_runtime::xcm_config::LocationToAccountId, - ParachainInfo: asset_hub_kusama_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: asset_hub_kusama_runtime::PolkadotXcm, - Assets: asset_hub_kusama_runtime::Assets, - } - }, - // Wococo Parachains - pub struct BridgeHubWococo { - genesis = bridge_hub_rococo::genesis(), - on_init = { - bridge_hub_rococo_runtime::AuraExt::on_initialize(1); - }, - runtime = bridge_hub_rococo_runtime, - core = { - XcmpMessageHandler: bridge_hub_rococo_runtime::XcmpQueue, - DmpMessageHandler: bridge_hub_rococo_runtime::DmpQueue, - LocationToAccountId: bridge_hub_rococo_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bridge_hub_rococo_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: bridge_hub_rococo_runtime::PolkadotXcm, - } - }, - pub struct AssetHubWococo { - genesis = asset_hub_polkadot::genesis(), - on_init = { - asset_hub_polkadot_runtime::AuraExt::on_initialize(1); - }, - runtime = asset_hub_polkadot_runtime, - core = { - XcmpMessageHandler: asset_hub_polkadot_runtime::XcmpQueue, - DmpMessageHandler: asset_hub_polkadot_runtime::DmpQueue, - LocationToAccountId: asset_hub_polkadot_runtime::xcm_config::LocationToAccountId, - ParachainInfo: asset_hub_polkadot_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: asset_hub_polkadot_runtime::PolkadotXcm, - Assets: asset_hub_polkadot_runtime::Assets, - } - }, - pub struct PenpalRococoA { - genesis = penpal::genesis(penpal::PARA_ID_A), - on_init = { - penpal_runtime::AuraExt::on_initialize(1); - }, - runtime = penpal_runtime, - core = { - XcmpMessageHandler: penpal_runtime::XcmpQueue, - DmpMessageHandler: penpal_runtime::DmpQueue, - LocationToAccountId: penpal_runtime::xcm_config::LocationToAccountId, - ParachainInfo: penpal_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: penpal_runtime::PolkadotXcm, - Assets: penpal_runtime::Assets, - } - } } decl_test_networks! { @@ -479,8 +213,6 @@ decl_test_networks! { AssetHubPolkadot, Collectives, BridgeHubPolkadot, - PenpalPolkadotA, - PenpalPolkadotB, ], // TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged // bridge = PolkadotKusamaMockBridge @@ -491,63 +223,12 @@ decl_test_networks! { parachains = vec![ BifrostKusama, AssetHubKusama, - PenpalKusamaA, BridgeHubKusama, - PenpalKusamaB, ], // TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged // bridge = KusamaPolkadotMockBridge bridge = () }, - pub struct WestendMockNet { - relay_chain = Westend, - parachains = vec![ - AssetHubWestend, - PenpalWestendA, - ], - bridge = () - }, - pub struct RococoMockNet { - relay_chain = Rococo, - parachains = vec![ - AssetHubRococo, - BridgeHubRococo, - PenpalRococoA, - ], - bridge = RococoWococoMockBridge - }, - pub struct WococoMockNet { - relay_chain = Wococo, - parachains = vec![ - AssetHubWococo, - BridgeHubWococo, - ], - bridge = WococoRococoMockBridge - } -} - -decl_test_bridges! { - pub struct RococoWococoMockBridge { - source = BridgeHubRococo, - target = BridgeHubWococo, - handler = RococoWococoMessageHandler - }, - pub struct WococoRococoMockBridge { - source = BridgeHubWococo, - target = BridgeHubRococo, - handler = WococoRococoMessageHandler - } - // TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged - // pub struct PolkadotKusamaMockBridge { - // source = BridgeHubPolkadot, - // target = BridgeHubKusama, - // handler = PolkadotKusamaMessageHandler - // }, - // pub struct KusamaPolkadotMockBridge { - // source = BridgeHubKusama, - // target = BridgeHubPolkadot, - // handler = KusamaPolkadotMessageHandler - // } } // Polkadot implementation @@ -560,18 +241,6 @@ impl_accounts_helpers_for_relay_chain!(Kusama); impl_assert_events_helpers_for_relay_chain!(Kusama); impl_hrmp_channels_helpers_for_relay_chain!(Kusama); -// Westend implementation -impl_accounts_helpers_for_relay_chain!(Westend); -impl_assert_events_helpers_for_relay_chain!(Westend); - -// Rococo implementation -impl_accounts_helpers_for_relay_chain!(Rococo); -impl_assert_events_helpers_for_relay_chain!(Rococo); - -// Wococo implementation -impl_accounts_helpers_for_relay_chain!(Wococo); -impl_assert_events_helpers_for_relay_chain!(Wococo); - // BifrostPolkadot implementation impl_accounts_helpers_for_parachain!(BifrostPolkadot); impl_assert_events_helpers_for_parachain!(BifrostPolkadot); @@ -590,57 +259,26 @@ impl_accounts_helpers_for_parachain!(AssetHubKusama); impl_assets_helpers_for_parachain!(AssetHubKusama, Kusama); impl_assert_events_helpers_for_parachain!(AssetHubKusama); -// AssetHubWestend implementation -impl_accounts_helpers_for_parachain!(AssetHubWestend); -impl_assets_helpers_for_parachain!(AssetHubWestend, Westend); -impl_assert_events_helpers_for_parachain!(AssetHubWestend); - -// PenpalPolkadot implementations -impl_assert_events_helpers_for_parachain!(PenpalPolkadotA); -impl_assert_events_helpers_for_parachain!(PenpalPolkadotB); - -// PenpalKusama implementations -impl_assert_events_helpers_for_parachain!(PenpalKusamaA); -impl_assert_events_helpers_for_parachain!(PenpalKusamaB); - -// PenpalWestendA implementation -impl_assert_events_helpers_for_parachain!(PenpalWestendA); - // Collectives implementation impl_accounts_helpers_for_parachain!(Collectives); impl_assert_events_helpers_for_parachain!(Collectives); -// BridgeHubRococo implementation -impl_accounts_helpers_for_parachain!(BridgeHubRococo); -impl_assert_events_helpers_for_parachain!(BridgeHubRococo); - decl_test_sender_receiver_accounts_parameter_types! { // Relays Polkadot { sender: ALICE, receiver: BOB }, Kusama { sender: ALICE, receiver: BOB }, - Westend { sender: ALICE, receiver: BOB }, - Rococo { sender: ALICE, receiver: BOB }, - Wococo { sender: ALICE, receiver: BOB }, // Asset Hubs BifrostPolkadot { sender: ALICE, receiver: BOB }, BifrostKusama { sender: ALICE, receiver: BOB }, AssetHubPolkadot { sender: ALICE, receiver: BOB }, AssetHubKusama { sender: ALICE, receiver: BOB }, - AssetHubWestend { sender: ALICE, receiver: BOB }, - AssetHubRococo { sender: ALICE, receiver: BOB }, - AssetHubWococo { sender: ALICE, receiver: BOB }, // Collectives Collectives { sender: ALICE, receiver: BOB }, // Bridged Hubs BridgeHubPolkadot { sender: ALICE, receiver: BOB }, - BridgeHubKusama { sender: ALICE, receiver: BOB }, - BridgeHubRococo { sender: ALICE, receiver: BOB }, - BridgeHubWococo { sender: ALICE, receiver: BOB }, - // Penpals - PenpalPolkadotA { sender: ALICE, receiver: BOB }, - PenpalPolkadotB { sender: ALICE, receiver: BOB }, - PenpalKusamaA { sender: ALICE, receiver: BOB }, - PenpalKusamaB { sender: ALICE, receiver: BOB }, - PenpalWestendA { sender: ALICE, receiver: BOB }, - PenpalRococoA { sender: ALICE, receiver: BOB } + BridgeHubKusama { sender: ALICE, receiver: BOB } +} + +impl_test_accounts_helpers_for_chain! { + Polkadot, Kusama, BifrostPolkadot, BifrostKusama, AssetHubKusama, AssetHubPolkadot }