Skip to content

Commit

Permalink
fix router benchmarking and failing integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roznovjak committed Dec 6, 2023
1 parent d58f479 commit ff82bc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions integration-tests/src/transact_call_filter.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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(),
},
Expand Down
11 changes: 0 additions & 11 deletions runtime/basilisk/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod tokens;
pub mod vesting;

use crate::AssetRegistry;
use crate::XYK;

use crate::Currencies;

Expand Down Expand Up @@ -55,13 +54,3 @@ pub fn update_asset(asset_id: AssetId, name: Vec<u8>, 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,
));
}
24 changes: 17 additions & 7 deletions runtime/basilisk/src/benchmarking/route_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -219,29 +221,37 @@ 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,
)?;

let better_route = vec![Trade {
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);
}
}
Expand All @@ -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)
Expand Down

0 comments on commit ff82bc1

Please sign in to comment.