Skip to content

Commit

Permalink
fix integration and benchmarking test
Browse files Browse the repository at this point in the history
  • Loading branch information
Roznovjak committed Aug 19, 2024
1 parent cab3512 commit 1f53f91
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
11 changes: 0 additions & 11 deletions integration-tests/src/exchange_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,6 @@ fn basilisk_should_swap_assets_coming_from_karura_when_onchain_route_present() {
))
));

assert_ok!(basilisk_runtime::EmaOracle::add_oracle(
frame_system::RawOrigin::Root.into(),
basilisk_runtime::XYKOracleSourceIdentifier::get(),
(KAR, BSX)
));
assert_ok!(basilisk_runtime::EmaOracle::add_oracle(
frame_system::RawOrigin::Root.into(),
basilisk_runtime::XYKOracleSourceIdentifier::get(),
(BSX, KSM)
));

assert_ok!(basilisk_runtime::Tokens::set_balance(
frame_system::RawOrigin::Root.into(),
ALICE.into(),
Expand Down
56 changes: 48 additions & 8 deletions runtime/basilisk/src/benchmarking/route_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
// limitations under the License.
#![allow(clippy::result_large_err)]

use crate::{AccountId, AssetId, Balance, Currencies, Router, Runtime, RuntimeOrigin, System, LBP, XYK};
use crate::{AccountId, AssetId, Balance, Currencies, EmaOracle, Router, Runtime, RuntimeOrigin, System, LBP, XYK};

use super::*;
use frame_benchmarking::{account, BenchmarkError};
use frame_support::dispatch::DispatchResult;
use frame_support::{assert_ok, ensure, parameter_types};
use frame_support::{
assert_ok, ensure, parameter_types,
dispatch::DispatchResult,
traits::{OnFinalize, OnInitialize},
};
use frame_system::RawOrigin;
use hydradx_traits::router::inverse_route;
use hydradx_traits::router::AssetPair;
use hydradx_traits::router::{PoolType, RouterT, Trade};
use hydradx_traits::router::{inverse_route, AssetPair, PoolType, RouterT, Trade};
use orml_benchmarking::runtime_benchmarks;
use orml_traits::{MultiCurrency, MultiCurrencyExtended};
use primitives::constants::currency::UNITS;
use primitives::{
BlockNumber,
constants::currency::UNITS,
};
use sp_runtime::{FixedPointNumber, FixedU128};
use sp_std::vec;
pub const INITIAL_BALANCE: Balance = 10_000_000 * UNITS;
Expand Down Expand Up @@ -141,6 +145,20 @@ fn create_xyk_pool(asset_a: u32, asset_b: u32) {
));
}

fn set_period(to: u32) {
while System::block_number() < Into::<BlockNumber>::into(to) {
let b = System::block_number();

System::on_finalize(b);
EmaOracle::on_finalize(b);

System::on_initialize(b + 1_u32);
EmaOracle::on_initialize(b + 1_u32);

System::set_block_number(b + 1_u32);
}
}

runtime_benchmarks! {
{Runtime, pallet_route_executor}

Expand Down Expand Up @@ -222,7 +240,7 @@ runtime_benchmarks! {
let asset_5 = register_asset(b"AS5".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?;
let asset_6 = register_asset(b"AS6".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?;

let caller: AccountId = funded_account("caller", 0, &[asset_1, asset_2,asset_3]);
let caller: AccountId = funded_account("caller", 0, &[asset_1, asset_2, asset_3, asset_4, asset_5, asset_6]);
create_xyk_pool(HDX, asset_2);
create_xyk_pool(asset_2, asset_3);
create_xyk_pool(asset_3, asset_4);
Expand Down Expand Up @@ -252,6 +270,17 @@ runtime_benchmarks! {
asset_out: asset_6
}];

assert_ok!(Router::sell(
RawOrigin::Signed(caller.clone().into()).into(),
HDX,
asset_6,
10_000,
0,
route.clone()
));

set_period(10);

Router::set_route(
RawOrigin::Signed(caller.clone()).into(),
AssetPair::new(HDX, asset_6),
Expand All @@ -266,6 +295,17 @@ runtime_benchmarks! {
asset_out: asset_6
},];

assert_ok!(Router::sell(
RawOrigin::Signed(caller.clone().into()).into(),
HDX,
asset_6,
10_000,
0,
better_route.clone()
));

set_period(11);

}: {
Router::set_route(
RawOrigin::Signed(caller.clone()).into(),
Expand Down

0 comments on commit 1f53f91

Please sign in to comment.