Skip to content

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hqwangningbo committed Oct 24, 2023
2 parents 449b16e + 3638e11 commit 2b87511
Show file tree
Hide file tree
Showing 27 changed files with 896 additions and 315 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Generate WeightInfo Files
run: make generate-bifrost-weights
- name: Commit Automatically
uses: stefanzweifel/git-auto-commit-action@v4
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 🤖 ($WEIGHT) Generate weightInfo files automatically
file_pattern: runtime/**/*.rs
3 changes: 2 additions & 1 deletion Cargo.lock

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

18 changes: 18 additions & 0 deletions integration-tests/bifrost-kusama/src/xcm_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,28 @@ fn cross_usdt() {
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));

// get the fee balance of the alice before the transfer transaction
let alice_fee_balance_before =
Currencies::free_balance(RelayCurrencyId::get(), &AccountId::from(ALICE));

// Alice transfers 5 statemine asset to Bob
assert_ok!(XcmInterface::transfer_statemine_assets(
RuntimeOrigin::signed(ALICE.into()),
5 * USDT,
1984,
Some(sp_runtime::AccountId32::from(BOB))
));

// get the fee balance of the alice after the transfer transaction
let alice_fee_balance_after =
Currencies::free_balance(RelayCurrencyId::get(), &AccountId::from(ALICE));

// assert alice_fee_balance_before and alice_fee_balance_after are equal, since we
// didn't deduct any fee from alice in this test (integration test doesn't go through
// flexible fee)
assert_eq!(alice_fee_balance_before, alice_fee_balance_after);

// assert Alice has 10-5 =5 statemine asset
assert_eq!(
Tokens::free_balance(CurrencyId::Token2(0), &AccountId::from(ALICE),),
5 * USDT
Expand All @@ -153,7 +168,10 @@ fn cross_usdt() {
Statemine::execute_with(|| {
use statemine_runtime::*;
println!("{:?}", System::events());

// assert Bob has 5 statemine asset
assert_eq!(Assets::balance(1984, AccountId::from(BOB)), 5 * USDT);

assert!(System::events().iter().any(|r| matches!(
r.event,
RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success {
Expand Down
2 changes: 1 addition & 1 deletion node/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "node-cli"
version = "0.9.82"
version = "0.9.84"
authors = ["Liebi Technologies <[email protected]>"]
description = "Bifrost Parachain Node"
build = "build.rs"
Expand Down
5 changes: 5 additions & 0 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ impl VTokenSupplyProvider<CurrencyId, Balance> for SimpleVTokenSupplyProvider {
}
}

parameter_types! {
pub const ReferendumCheckInterval: BlockNumber = 300;
}

impl bifrost_vtoken_voting::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -524,6 +528,7 @@ impl bifrost_vtoken_voting::Config for Test {
type MaxVotes = ConstU32<256>;
type ParachainId = ParaInfo;
type QueryTimeout = QueryTimeout;
type ReferendumCheckInterval = ReferendumCheckInterval;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions pallets/salp/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ impl bifrost_xcm_interface::Config for Test {
type SalpHelper = Salp;
type ParachainId = ParaInfo;
type CallBackTimeOut = ConstU64<10>;
type CurrencyIdConvert = AssetIdMaps<Test>;
}

pub struct ParaInfo;
Expand Down
10 changes: 5 additions & 5 deletions pallets/slpx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use scale_info::TypeInfo;
use sp_core::{Hasher, H160};
use sp_runtime::{
traits::{BlakeTwo256, CheckedSub},
DispatchError, RuntimeDebug, Saturating,
DispatchError, RuntimeDebug,
};
use sp_std::vec;
use xcm::{latest::prelude::*, v3::MultiLocation};
Expand Down Expand Up @@ -654,16 +654,16 @@ impl<T: Config> Pallet<T> {
let free_balance = T::MultiCurrency::free_balance(currency_id, evm_caller_account_id);
let execution_fee =
Self::execution_fee(currency_id).unwrap_or_else(|| Self::get_default_fee(currency_id));
let minimum_balance = T::MultiCurrency::minimum_balance(currency_id);

T::MultiCurrency::transfer(
currency_id,
evm_caller_account_id,
&T::TreasuryAccount::get(),
execution_fee,
)?;
let balance_exclude_fee = free_balance
.checked_sub(&execution_fee.saturating_add(minimum_balance))
.ok_or(Error::<T>::FreeBalanceTooLow)?;

let balance_exclude_fee =
free_balance.checked_sub(&execution_fee).ok_or(Error::<T>::FreeBalanceTooLow)?;
Ok(balance_exclude_fee)
}

Expand Down
10 changes: 7 additions & 3 deletions pallets/slpx/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl frame_system::Config for Test {

// Pallet balances configuration
parameter_types! {
pub const ExistentialDeposit: u128 = 1;
pub const ExistentialDeposit: u128 = 10_000_000_000;
}

impl pallet_balances::Config for Test {
Expand Down Expand Up @@ -161,8 +161,12 @@ impl bifrost_currencies::Config for Test {

// Pallet orml-tokens configuration
parameter_type_with_key! {
pub ExistentialDeposits: |_currency_id: CurrencyId| -> u128 {
0
pub ExistentialDeposits: |currency_id: CurrencyId| -> u128 {
match currency_id {
&CurrencyId::Native(TokenSymbol::BNC) => 10 * 1_000_000_000,
&CurrencyId::Token(TokenSymbol::KSM) => 10 * 1_000_000_000,
_=> 10 * 1_000_000_000
}
};
}
pub type ReserveIdentifier = [u8; 8];
Expand Down
84 changes: 72 additions & 12 deletions pallets/slpx/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,41 @@ fn test_whitelist_work() {
#[test]
fn test_execution_fee_work() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Currencies::deposit(CurrencyId::Token2(0), &ALICE, 50));
assert_ok!(Currencies::deposit(CurrencyId::Token2(0), &ALICE, 50 * 1_000_000_000));

assert_ok!(Slpx::set_execution_fee(RuntimeOrigin::root(), CurrencyId::Token2(0), 10));
assert_eq!(Slpx::execution_fee(CurrencyId::Token2(0)), Some(10));
assert_ok!(Slpx::set_execution_fee(
RuntimeOrigin::root(),
CurrencyId::Token2(0),
10 * 1_000_000_000
));
assert_eq!(Slpx::execution_fee(CurrencyId::Token2(0)), Some(10 * 1_000_000_000));

let balance_exclude_fee =
Slpx::charge_execution_fee(CurrencyId::Token2(0), &ALICE).unwrap();
assert_eq!(balance_exclude_fee, 40);
assert_eq!(balance_exclude_fee, 40 * 1_000_000_000);

assert_ok!(Slpx::set_transfer_to_fee(RuntimeOrigin::root(), SupportChain::Moonbeam, 10));
assert_eq!(Slpx::transfer_to_fee(SupportChain::Moonbeam), Some(10));
assert_ok!(Slpx::set_transfer_to_fee(
RuntimeOrigin::root(),
SupportChain::Moonbeam,
10 * 1_000_000_000
));
assert_eq!(Slpx::transfer_to_fee(SupportChain::Moonbeam), Some(10 * 1_000_000_000));
});
}

#[test]
fn test_zenlink() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Currencies::deposit(CurrencyId::Native(TokenSymbol::BNC), &ALICE, 50));
assert_ok!(Currencies::deposit(CurrencyId::Token(TokenSymbol::KSM), &ALICE, 50));
assert_ok!(Currencies::deposit(
CurrencyId::Native(TokenSymbol::BNC),
&ALICE,
50 * 1_000_000_000
));
assert_ok!(Currencies::deposit(
CurrencyId::Token(TokenSymbol::KSM),
&ALICE,
50 * 1_000_000_000
));

let bnc_token: AssetId =
AssetId::try_convert_from(CurrencyId::Native(TokenSymbol::BNC), 2001).unwrap();
Expand All @@ -133,14 +149,20 @@ fn test_zenlink() {
RawOrigin::Signed(ALICE).into(),
bnc_token,
ksm_token,
20u128,
20u128,
20u128 * 1_000_000_000,
20u128 * 1_000_000_000,
0,
0,
100
));
assert_eq!(Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE), 30u128);
assert_eq!(Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &ALICE), 30u128);
assert_eq!(
Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE),
30u128 * 1_000_000_000
);
assert_eq!(
Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &ALICE),
30u128 * 1_000_000_000
);

let path = vec![bnc_token, ksm_token];
let balance = Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE);
Expand Down Expand Up @@ -172,3 +194,41 @@ fn test_get_default_fee() {
);
});
}

#[test]
fn test_ed() {
sp_io::TestExternalities::default().execute_with(|| {
assert_ok!(Currencies::deposit(
CurrencyId::Native(TokenSymbol::BNC),
&ALICE,
50 * 1_000_000_000
));
assert_ok!(Currencies::deposit(
CurrencyId::Token(TokenSymbol::KSM),
&ALICE,
50 * 1_000_000_000
));

assert_eq!(
Currencies::free_balance(CurrencyId::Native(TokenSymbol::BNC), &ALICE),
50 * 1_000_000_000
);
assert_eq!(
Currencies::free_balance(CurrencyId::Token(TokenSymbol::KSM), &ALICE),
50 * 1_000_000_000
);

assert_ok!(Currencies::transfer(
RawOrigin::Signed(ALICE).into(),
BOB,
CurrencyId::Native(TokenSymbol::BNC),
50 * 1_000_000_000
));
assert_ok!(Currencies::transfer(
RawOrigin::Signed(ALICE).into(),
BOB,
CurrencyId::Token(TokenSymbol::KSM),
50 * 1_000_000_000
));
});
}
Loading

0 comments on commit 2b87511

Please sign in to comment.