From ff82bc1821dc0444eeaf21f731ac034858290894 Mon Sep 17 00:00:00 2001 From: Roznovjak Date: Thu, 7 Dec 2023 00:39:30 +0100 Subject: [PATCH] fix router benchmarking and failing integration test --- integration-tests/src/transact_call_filter.rs | 4 ++-- runtime/basilisk/src/benchmarking/mod.rs | 11 --------- .../src/benchmarking/route_executor.rs | 24 +++++++++++++------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/integration-tests/src/transact_call_filter.rs b/integration-tests/src/transact_call_filter.rs index 223f3ba1ba..aa1694a0fe 100644 --- a/integration-tests/src/transact_call_filter.rs +++ b/integration-tests/src/transact_call_filter.rs @@ -1,7 +1,7 @@ #![cfg(test)] use crate::kusama_test_net::*; -use frame_support::{assert_ok, weights::Weight}; +use frame_support::{assert_ok, weights::Weight, dispatch::GetDispatchInfo}; use sp_runtime::codec::Encode; use polkadot_xcm::latest::prelude::*; @@ -49,7 +49,7 @@ fn allowed_transact_call_should_pass_filter() { weight_limit: Unlimited, }, Transact { - require_weight_at_most: Weight::from_parts(10_000_000_000, 0u64), + require_weight_at_most: call.get_dispatch_info().weight, origin_kind: OriginKind::SovereignAccount, call: basilisk_runtime::RuntimeCall::Balances(call).encode().into(), }, diff --git a/runtime/basilisk/src/benchmarking/mod.rs b/runtime/basilisk/src/benchmarking/mod.rs index 575a63cecf..881b47b851 100644 --- a/runtime/basilisk/src/benchmarking/mod.rs +++ b/runtime/basilisk/src/benchmarking/mod.rs @@ -9,7 +9,6 @@ pub mod tokens; pub mod vesting; use crate::AssetRegistry; -use crate::XYK; use crate::Currencies; @@ -55,13 +54,3 @@ pub fn update_asset(asset_id: AssetId, name: Vec, deposit: Balance) -> Resul ) .map_err(|_| ()) } - -pub fn create_pool(who: AccountId, asset_a: AssetId, amount_a: Balance, asset_b: AssetId, amount_b: Balance) { - assert_ok!(XYK::create_pool( - RawOrigin::Signed(who).into(), - asset_a, - amount_a, - asset_b, - amount_b, - )); -} diff --git a/runtime/basilisk/src/benchmarking/route_executor.rs b/runtime/basilisk/src/benchmarking/route_executor.rs index 711aba3e9d..00ae84da55 100644 --- a/runtime/basilisk/src/benchmarking/route_executor.rs +++ b/runtime/basilisk/src/benchmarking/route_executor.rs @@ -204,12 +204,14 @@ runtime_benchmarks! { let asset_1 = 1u32; let asset_2 = AssetRegistry::create_asset(&b"FCA".to_vec(), Balance::one())?; let asset_3 = AssetRegistry::create_asset(&b"FCB".to_vec(), Balance::one())?; + let asset_4 = AssetRegistry::create_asset(&b"FCC".to_vec(), Balance::one())?; - let caller: AccountId = funded_account("caller", 0, &[asset_1, asset_2,asset_3]); - let buyer: AccountId = funded_account("buyer", 1, &[asset_1, asset_2,asset_3]); + let caller: AccountId = funded_account("caller", 0, &[asset_1, asset_2, asset_3, asset_4]); + let buyer: AccountId = funded_account("buyer", 1, &[asset_1, asset_2, asset_3, asset_4]); create_xyk_pool(asset_1, asset_2); - create_xyk_pool(asset_1, asset_3); create_xyk_pool(asset_2, asset_3); + create_xyk_pool(asset_3, asset_4); + create_xyk_pool(asset_1, asset_3); let route = vec![Trade { pool: PoolType::XYK, @@ -219,11 +221,15 @@ runtime_benchmarks! { pool: PoolType::XYK, asset_in: asset_2, asset_out: asset_3 + },Trade { + pool: PoolType::XYK, + asset_in: asset_3, + asset_out: asset_4 }]; Router::set_route( RawOrigin::Signed(caller.clone()).into(), - AssetPair::new(asset_1, asset_3), + AssetPair::new(asset_1, asset_4), route, )?; @@ -231,17 +237,21 @@ runtime_benchmarks! { pool: PoolType::XYK, asset_in: asset_1, asset_out: asset_3 + },Trade { + pool: PoolType::XYK, + asset_in: asset_3, + asset_out: asset_4 }]; }: { Router::set_route( RawOrigin::Signed(caller.clone()).into(), - AssetPair::new(asset_1, asset_3), + AssetPair::new(asset_1, asset_4), better_route.clone(), )?; } verify { - let stored_route = Router::route(AssetPair::new(asset_1, asset_3)).unwrap(); + let stored_route = Router::route(AssetPair::new(asset_1, asset_4)).unwrap(); assert_eq!(stored_route, better_route); } } @@ -263,7 +273,7 @@ mod tests { (b"LRNA".to_vec(), 1_000u128, Some(1)), (b"DAI".to_vec(), 1_000u128, Some(2)), ], - native_asset_name: b"HDX".to_vec(), + native_asset_name: b"BSX".to_vec(), native_existential_deposit: NativeExistentialDeposit::get(), } .assimilate_storage(&mut t)