Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.75.1"
version = "1.76.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::polkadot_test_net::*;
use frame_support::assert_ok;
use frame_support::traits::fungible::Mutate;
use frame_support::BoundedVec;
use hydradx_runtime::bifrost_account;
use hydradx_runtime::AssetLocation;
use hydradx_runtime::*;
use hydradx_traits::stableswap::AssetAmount;
Expand Down Expand Up @@ -125,13 +124,22 @@ impl HydrationTestDriver {
self
}

#[allow(deprecated)]
pub fn update_bifrost_oracle(
&self,
asset_a: Box<polkadot_xcm::VersionedLocation>,
asset_b: Box<polkadot_xcm::VersionedLocation>,
price: (Balance, Balance),
) -> &Self {
self.execute(|| {
// Ensure BIFROST_SOURCE is registered and bifrost_account is authorized
// We need this because we added support for multiple oracle sources which required migration
let _ = EmaOracle::register_external_source(RuntimeOrigin::root(), pallet_ema_oracle::BIFROST_SOURCE);
let _ = EmaOracle::add_authorized_account(
RuntimeOrigin::root(),
pallet_ema_oracle::BIFROST_SOURCE,
bifrost_account(),
);
assert_ok!(EmaOracle::update_bifrost_oracle(
RuntimeOrigin::signed(bifrost_account()),
asset_a,
Expand Down
52 changes: 48 additions & 4 deletions integration-tests/src/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use frame_support::{
traits::tokens::fungibles::Mutate,
};
use hydra_dx_math::ema::smoothing_from_period;
use hydradx_runtime::bifrost_account;
use hydradx_runtime::AssetLocation;
use hydradx_runtime::AssetRegistry;
use hydradx_runtime::{EmaOracle, RuntimeOrigin};
Expand All @@ -30,7 +29,6 @@ use pallet_ema_oracle::BIFROST_SOURCE;
use pallet_transaction_payment::ChargeTransactionPayment;
use primitives::constants::chain::{OMNIPOOL_SOURCE, XYK_SOURCE};
use sp_runtime::traits::{DispatchTransaction, TransactionExtension};
use sp_runtime::DispatchError::BadOrigin;
use sp_runtime::DispatchResult;
use sp_runtime::TransactionOutcome;
use sp_std::collections::btree_map::BTreeMap;
Expand Down Expand Up @@ -441,12 +439,24 @@ fn arrange_bifrost_assets() -> (
}

#[test]
#[allow(deprecated)]
fn bifrost_oracle_should_be_updated() {
TestNet::reset();

let (asset_a_id, asset_b_id, asset_a, asset_b) = arrange_bifrost_assets();

Hydra::execute_with(|| {
// Register BIFROST_SOURCE as external source and authorize bifrost account
assert_ok!(EmaOracle::register_external_source(
RuntimeOrigin::root(),
BIFROST_SOURCE,
));
assert_ok!(EmaOracle::add_authorized_account(
RuntimeOrigin::root(),
BIFROST_SOURCE,
bifrost_account(),
));

assert_ok!(EmaOracle::add_oracle(
RuntimeOrigin::root(),
BIFROST_SOURCE,
Expand Down Expand Up @@ -477,13 +487,25 @@ fn bifrost_oracle_should_be_updated() {
}

#[test]
#[allow(deprecated)]
fn bifrost_oracle_should_be_added_when_pair_not_whitelisted() {
TestNet::reset();

let (asset_a_id, asset_b_id, asset_a, asset_b) = arrange_bifrost_assets();

Hydra::execute_with(|| {
// act
// Register BIFROST_SOURCE as external source and authorize bifrost account
assert_ok!(EmaOracle::register_external_source(
RuntimeOrigin::root(),
BIFROST_SOURCE,
));
assert_ok!(EmaOracle::add_authorized_account(
RuntimeOrigin::root(),
BIFROST_SOURCE,
bifrost_account(),
));

// act - no whitelist setup, external sources bypass whitelist
assert_ok!(EmaOracle::update_bifrost_oracle(
RuntimeOrigin::signed(bifrost_account()),
asset_a,
Expand All @@ -507,12 +529,24 @@ fn bifrost_oracle_should_be_added_when_pair_not_whitelisted() {
}

#[test]
#[allow(deprecated)]
fn bifrost_oracle_update_should_return_fee() {
// arrange
TestNet::reset();
let (_asset_a_id, _asset_b_id, asset_a, asset_b) = arrange_bifrost_assets();
let balance = 10 * UNITS;
Hydra::execute_with(|| {
// Register BIFROST_SOURCE as external source and authorize bifrost account
assert_ok!(EmaOracle::register_external_source(
RuntimeOrigin::root(),
BIFROST_SOURCE,
));
assert_ok!(EmaOracle::add_authorized_account(
RuntimeOrigin::root(),
BIFROST_SOURCE,
bifrost_account(),
));

assert_ok!(hydradx_runtime::Currencies::update_balance(
hydradx_runtime::RuntimeOrigin::root(),
bifrost_account(),
Expand Down Expand Up @@ -559,11 +593,18 @@ fn bifrost_oracle_update_should_return_fee() {
}

#[test]
#[allow(deprecated)]
fn bifrost_oracle_update_fail_should_charge_fee() {
// arrange
TestNet::reset();
let (_asset_a_id, _asset_b_id, asset_a, asset_b) = arrange_bifrost_assets();
Hydra::execute_with(|| {
// Register BIFROST_SOURCE but do NOT authorize ALICE
assert_ok!(EmaOracle::register_external_source(
RuntimeOrigin::root(),
BIFROST_SOURCE,
));

let balance = hydradx_runtime::Currencies::free_balance(0, &ALICE.into());
let oracle_call = hydradx_runtime::RuntimeCall::EmaOracle(
pallet_ema_oracle::Call::<hydradx_runtime::Runtime>::update_bifrost_oracle {
Expand All @@ -586,7 +627,10 @@ fn bifrost_oracle_update_fail_should_charge_fee() {
"fee should be withdrawn"
);
let exec = EmaOracle::update_bifrost_oracle(RuntimeOrigin::signed(ALICE.into()), asset_a, asset_b, (50, 100));
assert_noop!(exec.clone(), BadOrigin);
assert_noop!(
exec.clone(),
pallet_ema_oracle::Error::<hydradx_runtime::Runtime>::NotAuthorized
);
let mut exec_err_post_info = exec.err().unwrap().post_info;
assert_ok!(ChargeTransactionPayment::<hydradx_runtime::Runtime>::post_dispatch(
pre_data,
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/src/polkadot_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ pub const BOB_INITIAL_DAI_BALANCE: Balance = 1_000_000_000 * UNITS;
pub const CHARLIE_INITIAL_NATIVE_BALANCE: Balance = 1_000 * UNITS;
pub const CHARLIE_INITIAL_LRNA_BALANCE: Balance = 1_000 * UNITS;

pub fn bifrost_account() -> AccountId {
hydradx_runtime::BifrostAccount::get()
}

pub fn parachain_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(ACALA_PARA_ID).into_account_truncating()
}
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/stableswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ mod circuit_breaker {
}

#[test]
#[allow(deprecated)]
fn pool_with_pegs_should_update_pegs_only_once_per_block() {
let dot_location: polkadot_xcm::v5::Location = polkadot_xcm::v5::Location::new(
1,
Expand Down
2 changes: 1 addition & 1 deletion pallets/dca/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = 'pallet-dca'
version = "1.17.0"
version = "1.17.1"
description = 'A pallet to manage DCA scheduling'
authors = ['GalacticCouncil']
edition = '2021'
Expand Down
11 changes: 1 addition & 10 deletions pallets/dca/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate as dca;
use crate::{Config, Error, RandomnessProvider, RelayChainBlockHashProvider};
use cumulus_primitives_core::relay_chain::Hash;
use frame_support::traits::{Everything, Nothing, SortedMembers};
use frame_support::traits::{Everything, Nothing};
use frame_support::weights::constants::ExtrinsicBaseWeight;
use frame_support::weights::WeightToFeeCoefficient;
use frame_support::weights::{IdentityFee, Weight};
Expand Down Expand Up @@ -139,15 +139,8 @@ parameter_types! {
pub static MockBlockNumberProvider: u64 = 0;
pub SupportedPeriods: BoundedVec<OraclePeriod, ConstU32<MAX_PERIODS>> = BoundedVec::truncate_from(vec![
OraclePeriod::LastBlock, OraclePeriod::Short, OraclePeriod::TenMinutes]);
pub PriceDifference: Permill = Permill::from_percent(10);
}

pub struct BifrostAcc;
impl SortedMembers<AccountId> for BifrostAcc {
fn sorted_members() -> Vec<AccountId> {
vec![ALICE]
}
}
impl pallet_ema_oracle::Config for Test {
type AuthorityOrigin = EnsureRoot<AccountId>;
type BlockNumberProvider = MockBlockNumberProvider;
Expand All @@ -157,8 +150,6 @@ impl pallet_ema_oracle::Config for Test {
type LocationToAssetIdConversion = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
type BifrostOrigin = frame_system::EnsureSignedBy<BifrostAcc, AccountId>;
type MaxAllowedPriceDifference = PriceDifference;
type WeightInfo = ();
}

Expand Down
Loading
Loading