Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade to polkadot v1.11.0 #889

Merged
merged 61 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
6dc194e
fix build
Roznovjak Aug 7, 2024
d230c7c
satisfy clippy
Roznovjak Aug 7, 2024
9339bd1
formatting
Roznovjak Aug 7, 2024
e8f5d2b
fix runtime tests
Roznovjak Aug 7, 2024
968ca07
small fixes in mock files
Roznovjak Aug 9, 2024
def29e1
impl DisabledEvmPermitHandler
Roznovjak Aug 9, 2024
124e289
export publicly DisabledEvmPermitHandler
Roznovjak Aug 9, 2024
625cde2
Revert "export publicly DisabledEvmPermitHandler"
Roznovjak Aug 9, 2024
76b333b
move runtime apis to separate file
Roznovjak Aug 23, 2024
1f8711c
fix dependencies
Roznovjak Aug 23, 2024
79f3c66
various updates
Roznovjak Sep 5, 2024
90514bc
use workspace dependencies
Roznovjak Sep 6, 2024
e465fe2
implement XcmPaymentApi
Roznovjak Sep 8, 2024
c34d1db
fix some integration tests
Roznovjak Sep 9, 2024
55b78ae
Merge branch 'master' into polkadot-v1.11.0
Roznovjak Sep 9, 2024
12f6594
formatting
Roznovjak Sep 9, 2024
8c86b33
bump crate versions
Roznovjak Sep 10, 2024
dc5622e
satisfy clippy
Roznovjak Sep 10, 2024
bb3bf1b
rebenchmarking
Roznovjak Sep 11, 2024
c9a599c
rebenchmark router
Roznovjak Sep 11, 2024
117aa79
rebenchmark dca and otc-settlements
Roznovjak Sep 11, 2024
205248b
fix import of WeightInfo in otc-settlements weight file
Roznovjak Sep 11, 2024
49dba56
fix integration tests
Roznovjak Sep 11, 2024
6d01464
remove unused import from weight file
Roznovjak Sep 11, 2024
39879cd
Merge branch 'master' into polkadot-v1.11.0
Roznovjak Sep 13, 2024
8101993
set IdleMaxServiceWeight
Roznovjak Sep 13, 2024
e4b3df4
Merge branch 'master' into polkadot-v1.11.0
Roznovjak Sep 19, 2024
936f5c5
rebenchmark omnipool liquidity mining
Roznovjak Sep 19, 2024
597cad1
bump crate versions
Roznovjak Sep 19, 2024
5ceffff
update scraper to use dependencies from main cargo file
Roznovjak Sep 23, 2024
2f5304f
rebenchmark utility pallet
Roznovjak Sep 23, 2024
8f101ca
satisfy clippy
Roznovjak Sep 23, 2024
043bd32
do not use exact balance checks in exchange_asset integration tests
Roznovjak Sep 23, 2024
c475e79
remove whitelist check in liquidity mining tests
Roznovjak Sep 23, 2024
4d0fad8
formatting
Roznovjak Sep 23, 2024
03e0bf1
add logic for accepting DOT from AH
dmoka Sep 23, 2024
1a1a580
add test for transfering dot to AH while AH is the reserve chain
dmoka Sep 23, 2024
ae9f1eb
formatting
dmoka Sep 23, 2024
2b6a290
bump versions
dmoka Sep 23, 2024
90a02c6
formatting
dmoka Sep 23, 2024
53e6862
adjust integration test
dmoka Sep 24, 2024
d6a58eb
Merge branch 'master' into polkadot-v1.11.0
Roznovjak Sep 24, 2024
e5d99f9
fix typo in integration tests
Roznovjak Sep 24, 2024
e974e75
fix integration tests
Roznovjak Sep 24, 2024
20a7520
bump crate versions
Roznovjak Sep 24, 2024
f720fcb
satisfy clippy
Roznovjak Sep 24, 2024
5903e92
add xcm fee payment api tests
Roznovjak Sep 25, 2024
ed82551
Merge remote-tracking branch 'origin/polkadot-v1.11.0' into feat/make…
dmoka Sep 25, 2024
bdf96de
formatting
Roznovjak Sep 26, 2024
9e283e6
Merge branch 'master' into polkadot-v1.11.0
Roznovjak Sep 26, 2024
e0bf16d
fix naming
dmoka Sep 27, 2024
b65cfc4
Update integration-tests/src/cross_chain_transfer.rs
dmoka Sep 27, 2024
d641057
formatting
dmoka Sep 27, 2024
8ce272e
Merge remote-tracking branch 'origin/polkadot-v1.11.0' into feat/make…
dmoka Sep 27, 2024
b4fe1bf
bump versions
dmoka Sep 27, 2024
1507f37
Merge pull request #911 from galacticcouncil/feat/make-ah-dot-reserve2
dmoka Sep 27, 2024
dcaae53
Merge branch 'master' into polkadot-v1.11.0
Roznovjak Sep 29, 2024
d034bff
bump runtime version
Roznovjak Sep 30, 2024
9f62818
do not store duplicate values in duster whitelist in liq mining mock …
Roznovjak Oct 3, 2024
bf74970
fix integration tests with exact values that often change
Roznovjak Oct 3, 2024
04e34c4
remove impl of EstimateGasAdapter
Roznovjak Oct 3, 2024
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
3,436 changes: 1,935 additions & 1,501 deletions Cargo.lock

Large diffs are not rendered by default.

900 changes: 544 additions & 356 deletions Cargo.toml

Large diffs are not rendered by default.

6 changes: 3 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.23.6"
version = "1.23.7"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/galacticcouncil/HydraDX-node"
[dependencies]
hex-literal = { workspace = true }
frame-remote-externalities = { workspace = true }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
tokio = { workspace = true }
scraper = { workspace = true }
primitives = { workspace = true }
hydradx-runtime = { workspace = true }
Expand Down Expand Up @@ -134,7 +134,7 @@ polkadot-runtime-parachains = { workspace = true }
rococo-runtime = { workspace = true }

[dev-dependencies]
pretty_assertions = "1.2.1"
pretty_assertions = { workspace = true }
pallet-relaychain-info = { workspace = true }
xcm-emulator = { workspace = true }
test-utils = { workspace = true }
Expand Down
210 changes: 187 additions & 23 deletions integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#![cfg(test)]
use crate::polkadot_test_net::Rococo;
use crate::polkadot_test_net::*;
use xcm_emulator::ConvertLocation;
use xcm_executor::traits::TransferType;

use frame_support::{assert_noop, assert_ok};

use polkadot_xcm::{v4::prelude::*, VersionedAssets, VersionedXcm};
use polkadot_xcm::{v4::prelude::*, VersionedAssetId, VersionedAssets, VersionedXcm};

use cumulus_primitives_core::ParaId;
use frame_support::dispatch::GetDispatchInfo;
use frame_support::storage::with_transaction;
use frame_support::traits::OnInitialize;
use frame_support::weights::Weight;
use hydradx_runtime::AssetRegistry;
use hydradx_runtime::{AssetRegistry, LocationToAccountId};
use hydradx_traits::{registry::Mutate, AssetKind, Create};
use orml_traits::currency::MultiCurrency;
use polkadot_xcm::opaque::v3::{
Expand Down Expand Up @@ -45,12 +47,13 @@ fn hydra_should_receive_asset_when_transferred_from_rococo_relay_chain() {

Rococo::execute_with(|| {
//Act
assert_ok!(rococo_runtime::XcmPallet::reserve_transfer_assets(
assert_ok!(rococo_runtime::XcmPallet::limited_reserve_transfer_assets(
rococo_runtime::RuntimeOrigin::signed(ALICE.into()),
Box::new(Parachain(HYDRA_PARA_ID).into_versioned()),
Box::new(Junction::AccountId32 { id: BOB, network: None }.into_versioned()),
Box::new((Here, 300 * UNITS).into()),
0,
WeightLimit::Unlimited,
));

//Assert
Expand Down Expand Up @@ -652,38 +655,31 @@ fn transfer_foreign_asset_from_acala_to_hydra_should_not_work() {
}

#[test]
fn transfer_dot_reserve_from_asset_hub_to_hydra_should_not_work() {
fn transfer_dot_from_asset_hub_to_hydra_should_work() {
//Arrange
TestNet::reset();

Hydra::execute_with(|| {
let _ = with_transaction(|| {
register_foreign_asset();
assert_ok!(hydradx_runtime::AssetRegistry::set_location(
DOT,
hydradx_runtime::AssetLocation(MultiLocation::new(1, polkadot_xcm::opaque::v3::Junctions::Here))
));
add_currency_price(DOT, FixedU128::from(1));

add_currency_price(FOREIGN_ASSET, FixedU128::from(1));
add_currency_price(DOT, FixedU128::from(1));
assert_ok!(hydradx_runtime::Tokens::deposit(
DOT,
&AccountId::from(ALICE),
3000 * UNITS
));

TransactionOutcome::Commit(DispatchResult::Ok(()))
});
assert_ok!(hydradx_runtime::AssetRegistry::set_location(
DOT,
hydradx_runtime::AssetLocation(MultiLocation::new(1, polkadot_xcm::opaque::v3::Junctions::Here))
));
});

AssetHub::execute_with(|| {
let _ = with_transaction(|| {
register_foreign_asset();
register_dot();
TransactionOutcome::Commit(DispatchResult::Ok(()))
});

assert_ok!(hydradx_runtime::Tokens::deposit(
FOREIGN_ASSET,
&AccountId::from(ALICE),
3000 * UNITS
));

assert_ok!(hydradx_runtime::Tokens::deposit(
DOT,
&AccountId::from(ALICE),
Expand All @@ -703,7 +699,8 @@ fn transfer_dot_reserve_from_asset_hub_to_hydra_should_not_work() {
}])),
);

let xcm = xcm_for_deposit_reserve_asset_to_hydra::<hydradx_runtime::RuntimeCall>(dot, bob_beneficiary);
let xcm =
xcm_transfer_reserve_asset_and_deposit_asset_to_hydra::<hydradx_runtime::RuntimeCall>(dot, bob_beneficiary);

//Act
let res = hydradx_runtime::PolkadotXcm::execute(
Expand All @@ -723,7 +720,111 @@ fn transfer_dot_reserve_from_asset_hub_to_hydra_should_not_work() {

//Assert
Hydra::execute_with(|| {
assert_xcm_message_processing_failed();
assert_xcm_message_processing_passed();

let fee = hydradx_runtime::Tokens::free_balance(DOT, &hydradx_runtime::Treasury::account_id());
assert!(fee > 0, "treasury should have received fees");
//Check if the foreign asset from Assethub has been deposited successfully
assert_eq!(
hydradx_runtime::Currencies::free_balance(DOT, &AccountId::from(BOB)),
100 * UNITS - fee
);
});
}

#[test]
fn transfer_dot_from_hydra_to_asset_hub_should_work() {
let init_hydra_para_dot_balance_on_ah = 4000 * UNITS;
let hydra_at_ah = Location::new(
1,
cumulus_primitives_core::Junctions::X1(Arc::new([cumulus_primitives_core::Junction::Parachain(HYDRA_PARA_ID)])),
);

let hydra_parachain_account_at_ah = LocationToAccountId::convert_location(&hydra_at_ah).unwrap();

let transfer_amount = 3 * UNITS;

AssetHub::execute_with(|| {
let _ = with_transaction(|| {
register_dot();
add_currency_price(DOT, FixedU128::from(1));
TransactionOutcome::Commit(DispatchResult::Ok(()))
});

assert_ok!(hydradx_runtime::Tokens::deposit(
DOT,
&hydra_parachain_account_at_ah,
init_hydra_para_dot_balance_on_ah
));
});

//Arrange
Hydra::execute_with(|| {
let dot_multiloc = MultiLocation::new(1, polkadot_xcm::opaque::v3::Junctions::Here);

assert_ok!(hydradx_runtime::AssetRegistry::set_location(
DOT,
hydradx_runtime::AssetLocation(dot_multiloc)
));

let dot_loc = Location::new(1, cumulus_primitives_core::Junctions::Here);

let dot: Asset = Asset {
id: cumulus_primitives_core::AssetId(dot_loc.clone()),
fun: Fungible(transfer_amount),
};

let bob_beneficiary = Location::new(
0,
cumulus_primitives_core::Junctions::X1(Arc::new([cumulus_primitives_core::Junction::AccountId32 {
id: BOB,
network: None,
}])),
);

let deposit_xcm = Xcm(vec![DepositAsset {
assets: Wild(WildAsset::AllCounted(1)),
beneficiary: bob_beneficiary.clone(),
}]);

//Act
assert_ok!(hydradx_runtime::PolkadotXcm::transfer_assets_using_type_and_then(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
Box::new(MultiLocation::new(1, X1(Junction::Parachain(ASSET_HUB_PARA_ID),)).into_versioned()),
Box::new(dot.into()),
Box::new(TransferType::DestinationReserve),
Box::new(VersionedAssetId::V4(cumulus_primitives_core::AssetId(dot_loc))),
Box::new(TransferType::DestinationReserve),
Box::new(VersionedXcm::from(deposit_xcm)),
WeightLimit::Unlimited,
));

assert_eq!(
hydradx_runtime::Tokens::free_balance(DOT, &AccountId::from(ALICE)),
ALICE_INITIAL_DOT_BALANCE - transfer_amount
);
});

//Needed to process horizontal xcm messages
Rococo::execute_with(|| {});

AssetHub::execute_with(|| {
assert_xcm_message_processing_passed();

//We check if the hydra parachain account balance is reduced on AH, meaning AH is responsible for reserve tracking
let hydra_sovereign_account_dot_balance =
hydradx_runtime::Currencies::free_balance(DOT, &hydra_parachain_account_at_ah);
assert_eq!(
hydra_sovereign_account_dot_balance,
init_hydra_para_dot_balance_on_ah - transfer_amount
);

let fee = hydradx_runtime::Currencies::free_balance(DOT, &hydradx_runtime::Treasury::account_id());

assert_eq!(
hydradx_runtime::Currencies::free_balance(DOT, &AccountId::from(BOB)),
transfer_amount - fee
);
});
}

Expand Down Expand Up @@ -1015,3 +1116,66 @@ fn rococo_xcm_execute_extrinsic_should_be_allowed() {
),);
});
}

fn xcm_transfer_reserve_asset_and_deposit_asset_to_hydra<RC: Decode + GetDispatchInfo>(
assets: Asset,
beneficiary: Location,
) -> VersionedXcm<RC> {
use rococo_runtime::xcm_config::BaseXcmWeight;
use xcm_builder::FixedWeightBounds;
use xcm_executor::traits::WeightBounds;

type Weigher<RC> = FixedWeightBounds<BaseXcmWeight, RC, ConstU32<100>>;

let dest = Location::new(
1,
cumulus_primitives_core::Junctions::X1(Arc::new([cumulus_primitives_core::Junction::Parachain(HYDRA_PARA_ID)])),
);

let max_assets = 1 + 1;

let context = cumulus_primitives_core::Junctions::X2(Arc::new([
cumulus_primitives_core::Junction::GlobalConsensus(cumulus_primitives_core::NetworkId::Polkadot),
cumulus_primitives_core::Junction::Parachain(ASSET_HUB_PARA_ID),
]));

let fee_asset = assets.clone().reanchored(&dest, &context).expect("should reanchor");
let fees = fee_asset.clone();

let weight_limit = {
let mut remote_message = Xcm(vec![
ReserveAssetDeposited::<RC>(assets.clone().into()),
ClearOrigin,
BuyExecution {
fees: fees.clone(),
weight_limit: Limited(Weight::zero()),
},
DepositAsset {
assets: Wild(AllCounted(max_assets)),
beneficiary: beneficiary.clone(),
},
]);
// use local weight for remote message and hope for the best.
let remote_weight = Weigher::weight(&mut remote_message).expect("weighing should not fail");
Limited(remote_weight)
};
// executed on remote (on hydra)
let xcm = Xcm(vec![
//ReserveAssetDeposited(assets.clone()),
BuyExecution { fees, weight_limit },
DepositAsset {
assets: Wild(AllCounted(max_assets)),
beneficiary,
},
]);
// executed on local (AssetHub)
let message = Xcm(vec![
SetFeesMode { jit_withdraw: true },
TransferReserveAsset {
assets: assets.into(),
dest,
xcm,
},
]);
VersionedXcm::from(message)
}
5 changes: 3 additions & 2 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ mod account_conversion {
let fee_raw = hydradx_runtime::TransactionPayment::compute_fee_details(len, &info, 0);
let fee = fee_raw.final_fee();

// simple test that the fee is approximately 10/4 HDX (it was originally 10 HDX, but we divided the fee by 4 in the config)
assert_eq!(fee / UNITS, 10 / 4);
// assert that the fee is within some range
assert!(fee > 2 * UNITS);
assert!(fee < 4 * UNITS);
});
}

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/evm_permit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ fn evm_permit_set_currency_dispatch_should_pay_evm_fee_in_chosen_currency() {
let user_dai_balance = user_acc.balance(DAI);
assert!(user_dai_balance < initial_user_dai_balance);
let dai_diff = initial_user_dai_balance - user_dai_balance;
assert!(dai_diff > 1000 * 1_000_000_000_000);
assert!(dai_diff > 1000 * UNITS);
})
}

Expand Down Expand Up @@ -1141,7 +1141,7 @@ fn dispatch_permit_should_increase_account_nonce_correctly() {

let hdx_balance = user_acc.balance(HDX);
let tx_fee = initial_user_hdx_balance - hdx_balance;
assert_eq!(tx_fee, 1_916_889_814_194);
assert!(tx_fee > 0);
})
}

Expand Down
15 changes: 2 additions & 13 deletions integration-tests/src/fee_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ use crate::{oracle::hydradx_run_to_block, polkadot_test_net::*};
use frame_support::assert_ok;
use frame_support::dispatch::DispatchClass;
use frame_support::dispatch::GetDispatchInfo;
use frame_support::weights::constants::RocksDbWeight;
use frame_support::weights::WeightToFee as WeightToFeeTrait;
use hydradx_runtime::evm::precompiles::DISPATCH_ADDR;
use hydradx_runtime::TransactionPayment;
use hydradx_runtime::EVM;
use hydradx_runtime::{ExtrinsicBaseWeight, Runtime, Tokens, WeightToFee};
use hydradx_runtime::{Runtime, Tokens};
use orml_traits::MultiCurrency;
use pallet_evm::FeeCalculator;
use primitives::constants::chain::Weight;
use primitives::constants::currency::UNITS;
use primitives::constants::time::HOURS;
use sp_core::Encode;
use sp_core::U256;
use sp_io::storage::changes_root;
use sp_runtime::{FixedU128, Permill};
use test_utils::assert_eq_approx;
use xcm_emulator::TestExt;
Expand Down Expand Up @@ -191,7 +189,7 @@ fn substrate_and_evm_fee_growth_simulator_with_idle_chain() {
.max_total
.unwrap();

for (nonce, b) in (2..HOURS).enumerate() {
for b in 2..HOURS {
//=HOURS {
hydradx_run_to_block(b);
hydradx_runtime::System::set_block_consumed_resources(block_weight, 0);
Expand All @@ -206,16 +204,7 @@ fn substrate_and_evm_fee_growth_simulator_with_idle_chain() {
let info = call.get_dispatch_info();
let fee = TransactionPayment::compute_fee(SWAP_ENCODED_LEN, &info, 0);

let fee_in_cent = (fee as f64 * HDX_USD_SPOT_PRICE) / 1000000000000.0;
let fee_in_cent = round(fee_in_cent);

let evm_fee_in_cent = round(get_evm_fee_in_cent(nonce as u128));
let next = TransactionPayment::next_fee_multiplier();

let gas_price = hydradx_runtime::DynamicEvmFee::min_gas_price();

println!("{b:?} - fee: {fee:?}");
//println!("{b:?} - fee: ${fee_in_cent:?} - evm_fee: ${evm_fee_in_cent:?} - multiplier: {next:?} - gas {gas_price:?}");
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/insufficient_assets_ed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ fn ed_should_be_paid_in_insufficient_asset_through_dot() {
hydradx_runtime::Currencies::free_balance(insufficient_asset, &ALICE.into());

//Act
assert_ok!(Tokens::deposit(insufficient_asset2, &ALICE.into(), 1 * UNITS));
assert_ok!(Tokens::deposit(insufficient_asset2, &ALICE.into(), UNITS));

//Assert
let alice_new_insuff_balance = hydradx_runtime::Currencies::free_balance(insufficient_asset, &ALICE.into());
Expand Down
Loading
Loading