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

Flexible fee tests #1037

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
130 changes: 70 additions & 60 deletions integration-tests/bifrost-kusama/src/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,75 +251,85 @@ fn slp_setup() {
));

// Register Operation weight and fee
assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::TransferTo,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::TransferTo,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Bond,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Bond,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::BondExtra,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::BondExtra,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Unbond,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Unbond,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Rebond,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Rebond,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Delegate,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Delegate,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Payout,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Payout,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Liquidize,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Liquidize,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::Chill,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::Chill,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
RelayCurrencyId::get(),
XcmOperation::TransferBack,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
));
assert_ok!(
<Runtime as bifrost_slp::Config>::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee(
RelayCurrencyId::get(),
XcmOperation::TransferBack,
Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)),
)
);

// initialize two delegators
assert_ok!(Slp::initialize_delegator(RuntimeOrigin::root(), RelayCurrencyId::get(), None));
Expand Down
10 changes: 4 additions & 6 deletions integration-tests/bifrost-kusama/src/vtoken_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ fn vote_works() {
Zero::zero(),
));
let token = CurrencyId::to_token(&vtoken).unwrap();
assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee(
token,
XcmOperation::VoteVtoken,
XcmOperation::Vote,
Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())),
));
assert_ok!(Slp::set_xcm_dest_weight_and_fee(
RuntimeOrigin::root(),
assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee(
token,
XcmOperation::VoteRemoveDelegatorVote,
XcmOperation::RemoveVote,
Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())),
));
assert_ok!(Slp::set_minimums_and_maximums(
Expand Down
4 changes: 2 additions & 2 deletions node/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ pub enum XcmInterfaceOperation {
ExecuteLeave,
ConvertAsset,
// VtokenVoting operations
VoteVtoken,
VoteRemoveDelegatorVote,
Vote,
RemoveVote,
Any,
}

Expand Down
18 changes: 9 additions & 9 deletions pallets/flexible-fee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,15 @@ impl<T: Config> Pallet<T> {
.extra_fee_currency
.to_token()
.map_err(|_| Error::<T>::ConversionError)?;
(fee_currency, XcmInterfaceOperation::VoteVtoken)
(fee_currency, XcmInterfaceOperation::Vote)
},
ExtraFeeName::VoteRemoveDelegatorVote => {
// We define error code 77 for conversion failure error
let fee_currency = fee_info
.extra_fee_currency
.to_token()
.map_err(|_| Error::<T>::ConversionError)?;
(fee_currency, XcmInterfaceOperation::VoteRemoveDelegatorVote)
(fee_currency, XcmInterfaceOperation::RemoveVote)
},
ExtraFeeName::NoExtraFee =>
(fee_info.extra_fee_currency, XcmInterfaceOperation::Any),
Expand Down Expand Up @@ -319,6 +319,13 @@ impl<T: Config> Pallet<T> {
return Ok((total_fee, Zero::zero(), Zero::zero(), path));
}
}

fn get_currency_asset_id(currency_id: CurrencyIdOf<T>) -> Result<AssetId, Error<T>> {
let asset_id: AssetId =
AssetId::try_convert_from(currency_id, T::ParachainId::get().into())
.map_err(|_| Error::<T>::ConversionError)?;
Ok(asset_id)
}
}

/// Default implementation for a Currency and an OnUnbalanced handler.
Expand Down Expand Up @@ -486,11 +493,4 @@ impl<T: Config> Pallet<T> {
}
Ok(None)
}

fn get_currency_asset_id(currency_id: CurrencyIdOf<T>) -> Result<AssetId, Error<T>> {
let asset_id: AssetId =
AssetId::try_convert_from(currency_id, T::ParachainId::get().into())
.map_err(|_| Error::<T>::ConversionError)?;
Ok(asset_id)
}
}
7 changes: 7 additions & 0 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use super::*;
use crate::{self as flexible_fee, tests::CHARLIE};
use balances::Call as BalancesCall;
use bifrost_asset_registry::AssetIdMaps;
use cumulus_primitives_core::ParaId as Pid;
#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -82,6 +83,12 @@ frame_support::construct_runtime!(
}
);

pub(crate) const BALANCE_TRANSFER_CALL: <Test as frame_system::Config>::RuntimeCall =
RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest: ALICE, value: 69 });

pub(crate) const SALP_CONTRIBUTE_CALL: <Test as frame_system::Config>::RuntimeCall =
RuntimeCall::Salp(bifrost_salp::Call::contribute { index: 2001, value: 1_000_000_000_000 });

impl bifrost_asset_registry::Config for Test {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand Down
Loading