Skip to content

Commit

Permalink
Merge branch 'master' into feat/ice
Browse files Browse the repository at this point in the history
  • Loading branch information
enthusiastmartin committed Dec 18, 2024
2 parents d586ee8 + 71bf42b commit f62935e
Show file tree
Hide file tree
Showing 114 changed files with 9,092 additions and 3,414 deletions.
3,133 changes: 1,477 additions & 1,656 deletions Cargo.lock

Large diffs are not rendered by default.

906 changes: 453 additions & 453 deletions Cargo.toml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM ubuntu:22.04
LABEL org.opencontainers.image.source = "https://github.com/galacticcouncil/HydraDX-node"

RUN apt-get update && apt-get install -y ca-certificates

RUN useradd -m -u 1000 -U -s /bin/sh -d /hydra hydra && \
mkdir -p /hydra/.local/share && \
chown -R hydra:hydra /hydra
Expand Down
10 changes: 7 additions & 3 deletions 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.25.0"
version = "1.26.0"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -44,14 +44,17 @@ pallet-xyk = { workspace = true }
pallet-evm-accounts = { workspace = true }
pallet-ice = { workspace = true}
ice-solver = { workspace = true}
pallet-xyk-liquidity-mining = { workspace = true }
pallet-transaction-pause = { workspace = true }
pallet-liquidation = { workspace = true }

pallet-treasury = { workspace = true }
pallet-democracy = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-elections-phragmen = { workspace = true }
pallet-tips = { workspace = true }
pallet-xyk-liquidity-mining = { workspace = true }
pallet-transaction-pause = { workspace = true }
pallet-referenda = { workspace = true }
pallet-conviction-voting = { workspace = true }

# collator support
pallet-collator-selection = { workspace = true }
Expand Down Expand Up @@ -220,6 +223,7 @@ std = [
"pallet-dynamic-evm-fee/std",
"precompile-utils/std",
"pallet-transaction-pause/std",
"pallet-liquidation/std",
"pallet-ice/std",
"ice-solver/std",
]
Expand Down
Binary file added integration-tests/evm-snapshot/SNAPSHOT
Binary file not shown.
86 changes: 2 additions & 84 deletions integration-tests/src/asset_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use crate::asset_registry::Junction::GeneralIndex;
use crate::polkadot_test_net::*;
use frame_support::{assert_noop, assert_ok};
use frame_support::assert_ok;
use frame_system::RawOrigin;
use hydradx_runtime::{AssetRegistry as Registry, TechnicalCollective};
use hydradx_runtime::AssetRegistry as Registry;
use polkadot_xcm::v3::{
Junction::{self, Parachain},
Junctions::X2,
Expand Down Expand Up @@ -38,88 +38,6 @@ fn root_should_update_decimals_when_it_was_already_set() {
});
}

#[test]
fn tech_comm_should_not_update_decimals_when_it_was_aleady_set() {
TestNet::reset();
Hydra::execute_with(|| {
let tech_comm = pallet_collective::RawOrigin::<AccountId, TechnicalCollective>::Members(1, 1);
let new_decimals = 53_u8;

assert_ne!(Registry::assets(HDX).unwrap().decimals.unwrap(), new_decimals);

assert_noop!(
Registry::update(
tech_comm.into(),
HDX,
None,
None,
None,
None,
None,
None,
Some(new_decimals),
None
),
pallet_asset_registry::Error::<hydradx_runtime::Runtime>::Forbidden
);
});
}

#[test]
fn tech_comm_should_update_decimals_when_it_wasnt_set_yet() {
TestNet::reset();
Hydra::execute_with(|| {
let tech_comm = pallet_collective::RawOrigin::<AccountId, TechnicalCollective>::Members(1, 1);
let new_decimals = 12_u8;

assert!(Registry::assets(LRNA).unwrap().decimals.is_none());

assert_ok!(Registry::update(
tech_comm.into(),
LRNA,
None,
None,
None,
None,
None,
None,
Some(new_decimals),
None
));

assert_eq!(Registry::assets(LRNA).unwrap().decimals.unwrap(), new_decimals);
});
}

#[test]
fn tech_comm_should_not_update_location_when_asset_exists() {
TestNet::reset();
Hydra::execute_with(|| {
let tech_comm = pallet_collective::RawOrigin::<AccountId, TechnicalCollective>::Members(1, 1);

assert!(Registry::locations(LRNA).is_none());

assert_noop!(
Registry::update(
tech_comm.into(),
LRNA,
None,
None,
None,
None,
None,
None,
None,
Some(hydradx_runtime::AssetLocation(MultiLocation::new(
1,
X2(Parachain(MOONBEAM_PARA_ID), GeneralIndex(0))
))),
),
pallet_asset_registry::Error::<hydradx_runtime::Runtime>::Forbidden
);
});
}

#[test]
fn root_should_update_location_when_asset_exists() {
TestNet::reset();
Expand Down
35 changes: 34 additions & 1 deletion integration-tests/src/call_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ use crate::polkadot_test_net::*;
use frame_support::{
assert_ok,
sp_runtime::{FixedU128, Permill},
traits::Contains,
traits::{Contains, StorePreimage},
};
use hydradx_runtime::{origins, Preimage};
use polkadot_xcm::v3::prelude::*;
use polkadot_xcm::VersionedXcm;
use primitives::constants::currency::UNITS;
use xcm_emulator::TestExt;

#[test]
Expand Down Expand Up @@ -289,3 +291,34 @@ fn create_contract_from_evm_pallet_should_be_filtered_by_call_filter() {
assert!(!hydradx_runtime::CallFilter::contains(&call));
});
}

#[test]
fn referenda_can_not_be_filtered() {
TestNet::reset();

Hydra::execute_with(|| {
// Arrange
// Try to pause transactions for Referenda/submit
assert_ok!(hydradx_runtime::TransactionPause::pause_transaction(
hydradx_runtime::RuntimeOrigin::root(),
b"Referenda".to_vec(),
b"submit".to_vec()
));

// Prepare a Referenda/submit call
let spend_call = hydradx_runtime::RuntimeCall::Treasury(pallet_treasury::Call::spend_local {
amount: 100 * UNITS,
beneficiary: ALICE.into(),
});
let preimage = <Preimage as StorePreimage>::bound(spend_call).unwrap();

// Act & Assert
let successful_call = hydradx_runtime::RuntimeCall::Referenda(pallet_referenda::Call::submit {
proposal_origin: Box::new(hydradx_runtime::OriginCaller::Origins(origins::Origin::Tipper)),
proposal: preimage,
enactment_moment: frame_support::traits::schedule::DispatchTime::After(100),
});

assert!(hydradx_runtime::CallFilter::contains(&successful_call));
});
}
16 changes: 12 additions & 4 deletions integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2519,10 +2519,10 @@ mod stableswap {
assert_ok!(Stableswap::add_liquidity(
RuntimeOrigin::signed(ALICE.into()),
pool_id,
vec![AssetAmount {
BoundedVec::truncate_from(vec![AssetAmount {
asset_id: stable_asset_1,
amount: amount_to_sell,
}],
}]),
));
let alice_pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE));

Expand Down Expand Up @@ -4144,7 +4144,11 @@ pub fn init_stableswap() -> Result<(AssetId, AssetId, AssetId), DispatchError> {

Stableswap::create_pool(RuntimeOrigin::root(), pool_id, asset_ids, amplification, fee)?;

Stableswap::add_liquidity(RuntimeOrigin::signed(BOB.into()), pool_id, initial)?;
Stableswap::add_liquidity(
RuntimeOrigin::signed(BOB.into()),
pool_id,
BoundedVec::truncate_from(initial),
)?;

Ok((pool_id, asset_in, asset_out))
}
Expand Down Expand Up @@ -4208,7 +4212,11 @@ pub fn init_stableswap_with_three_assets_having_different_decimals(

Stableswap::create_pool(RuntimeOrigin::root(), pool_id, asset_ids, amplification, fee)?;

Stableswap::add_liquidity(RuntimeOrigin::signed(BOB.into()), pool_id, initial)?;
Stableswap::add_liquidity(
RuntimeOrigin::signed(BOB.into()),
pool_id,
BoundedVec::truncate_from(initial),
)?;

Ok((pool_id, asset_in, asset_out))
}
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ fn substrate_account_should_pay_gas_with_payment_currency() {
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
evm_address,
hydradx_runtime::evm::precompiles::IDENTITY,
vec![].into(),
vec![],
U256::zero(),
1000000,
U256::from(1000000000),
Expand Down Expand Up @@ -1740,26 +1740,26 @@ fn evm_account_always_pays_with_weth_for_evm_call() {
);
assert_ok!(Tokens::set_balance(
RawOrigin::Root.into(),
evm_account().into(),
evm_account(),
WETH,
to_ether(1),
0,
));
assert_ok!(Currencies::update_balance(
hydradx_runtime::RuntimeOrigin::root(),
evm_account().into(),
evm_account(),
HDX,
0,
));
let mut padded_evm_address = [0u8; 32];
padded_evm_address[..20].copy_from_slice(&evm_address.as_bytes());
padded_evm_address[..20].copy_from_slice(evm_address.as_bytes());

// Act
assert_ok!(EVM::call(
hydradx_runtime::RuntimeOrigin::signed(padded_evm_address.into()),
evm_address,
hydradx_runtime::evm::precompiles::IDENTITY,
vec![].into(),
vec![],
U256::zero(),
1000000,
U256::from(1000000000),
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/src/insufficient_assets_ed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use hydradx_runtime::Omnipool;
use hydradx_runtime::RuntimeOrigin as hydra_origin;
use hydradx_runtime::DOT_ASSET_LOCATION;
use hydradx_runtime::{
AssetRegistry as Registry, Currencies, DustRemovalWhitelist, InsufficientEDinHDX, MultiTransactionPayment,
NativeExistentialDeposit, RuntimeEvent, TechnicalCollective, Tokens, TreasuryAccount, SUFFICIENCY_LOCK,
origins::Origin, AssetRegistry as Registry, Currencies, DustRemovalWhitelist, InsufficientEDinHDX,
MultiTransactionPayment, NativeExistentialDeposit, RuntimeEvent, Tokens, TreasuryAccount, SUFFICIENCY_LOCK,
};
use hydradx_traits::AssetKind;
use hydradx_traits::Create;
Expand Down Expand Up @@ -1352,7 +1352,7 @@ fn tx_should_fail_with_unsupported_currency_error_when_fee_asset_price_was_not_p
fn banned_asset_should_not_create_new_account() {
TestNet::reset();
Hydra::execute_with(|| {
let tech_comm = pallet_collective::RawOrigin::<AccountId, TechnicalCollective>::Members(1, 1);
let update_origin = hydradx_runtime::OriginCaller::Origins(Origin::GeneralAdmin);
//Arrange
let sht1: AssetId = register_external_asset(0_u128);
assert_ok!(Tokens::set_balance(
Expand All @@ -1363,7 +1363,7 @@ fn banned_asset_should_not_create_new_account() {
0,
));

assert_ok!(Registry::ban_asset(tech_comm.into(), sht1));
assert_ok!(Registry::ban_asset(update_origin.into(), sht1));

assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0);
assert_eq!(treasury_sufficiency_lock(), 0);
Expand All @@ -1380,7 +1380,7 @@ fn banned_asset_should_not_create_new_account() {
fn banned_asset_should_not_be_transferable_to_existing_account() {
TestNet::reset();
Hydra::execute_with(|| {
let tech_comm = pallet_collective::RawOrigin::<AccountId, TechnicalCollective>::Members(1, 1);
let update_origin = hydradx_runtime::OriginCaller::Origins(Origin::GeneralAdmin);
//Arrange
let sht1: AssetId = register_external_asset(0_u128);
assert_ok!(Tokens::set_balance(
Expand All @@ -1399,7 +1399,7 @@ fn banned_asset_should_not_be_transferable_to_existing_account() {
0,
));

assert_ok!(Registry::ban_asset(tech_comm.into(), sht1));
assert_ok!(Registry::ban_asset(update_origin.into(), sht1));

//Act & assert
assert_noop!(
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod fee_calculation;
mod global_account_derivation;
mod ice;
mod insufficient_assets_ed;
mod liquidation;
mod multi_payment;
mod non_native_fee;
mod omnipool_init;
Expand Down
Loading

0 comments on commit f62935e

Please sign in to comment.