mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 12:51:02 +00:00
Fix weights on hard-coded XCM fragments (#4144)
* Fix weights on hard-coded XCM fragments * Formatting
This commit is contained in:
@@ -234,7 +234,7 @@ fn teleport_assets_works() {
|
||||
Xcm(vec![
|
||||
ReceiveTeleportedAsset((Here, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_limited_execution((Here, SEND_AMOUNT), 2000),
|
||||
buy_limited_execution((Here, SEND_AMOUNT), 4000),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]),
|
||||
)]
|
||||
@@ -248,6 +248,88 @@ fn teleport_assets_works() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Test `limited_teleport_assets`
|
||||
///
|
||||
/// Asserts that the sender's balance is decreased as a result of execution of
|
||||
/// local effects.
|
||||
#[test]
|
||||
fn limmited_teleport_assets_works() {
|
||||
let balances =
|
||||
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = 2 * BaseXcmWeight::get();
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||
let dest: MultiLocation = AccountId32 { network: Any, id: BOB.into() }.into();
|
||||
assert_ok!(XcmPallet::limited_teleport_assets(
|
||||
Origin::signed(ALICE),
|
||||
Box::new(RelayLocation::get().into()),
|
||||
Box::new(dest.clone().into()),
|
||||
Box::new((Here, SEND_AMOUNT).into()),
|
||||
0,
|
||||
WeightLimit::Limited(5000),
|
||||
));
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT);
|
||||
assert_eq!(
|
||||
sent_xcm(),
|
||||
vec![(
|
||||
RelayLocation::get().into(),
|
||||
Xcm(vec![
|
||||
ReceiveTeleportedAsset((Here, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_limited_execution((Here, SEND_AMOUNT), 5000),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]),
|
||||
)]
|
||||
);
|
||||
let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1);
|
||||
let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap();
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Test `limited_teleport_assets` with unlimited weight
|
||||
///
|
||||
/// Asserts that the sender's balance is decreased as a result of execution of
|
||||
/// local effects.
|
||||
#[test]
|
||||
fn unlimmited_teleport_assets_works() {
|
||||
let balances =
|
||||
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = 2 * BaseXcmWeight::get();
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||
let dest: MultiLocation = AccountId32 { network: Any, id: BOB.into() }.into();
|
||||
assert_ok!(XcmPallet::limited_teleport_assets(
|
||||
Origin::signed(ALICE),
|
||||
Box::new(RelayLocation::get().into()),
|
||||
Box::new(dest.clone().into()),
|
||||
Box::new((Here, SEND_AMOUNT).into()),
|
||||
0,
|
||||
WeightLimit::Unlimited,
|
||||
));
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE - SEND_AMOUNT);
|
||||
assert_eq!(
|
||||
sent_xcm(),
|
||||
vec![(
|
||||
RelayLocation::get().into(),
|
||||
Xcm(vec![
|
||||
ReceiveTeleportedAsset((Here, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_execution((Here, SEND_AMOUNT)),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]),
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Test `reserve_transfer_assets`
|
||||
///
|
||||
/// Asserts that the sender's balance is decreased and the beneficiary's balance
|
||||
@@ -280,7 +362,7 @@ fn reserve_transfer_assets_works() {
|
||||
Xcm(vec![
|
||||
ReserveAssetDeposited((Parent, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_limited_execution((Parent, SEND_AMOUNT), 2000),
|
||||
buy_limited_execution((Parent, SEND_AMOUNT), 4000),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]),
|
||||
)]
|
||||
@@ -294,6 +376,98 @@ fn reserve_transfer_assets_works() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Test `limited_reserve_transfer_assets`
|
||||
///
|
||||
/// Asserts that the sender's balance is decreased and the beneficiary's balance
|
||||
/// is increased. Verifies the correct message is sent and event is emitted.
|
||||
#[test]
|
||||
fn limited_reserve_transfer_assets_works() {
|
||||
let balances =
|
||||
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = BaseXcmWeight::get();
|
||||
let dest: MultiLocation =
|
||||
Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into() }.into();
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||
assert_ok!(XcmPallet::limited_reserve_transfer_assets(
|
||||
Origin::signed(ALICE),
|
||||
Box::new(Parachain(PARA_ID).into().into()),
|
||||
Box::new(dest.clone().into()),
|
||||
Box::new((Here, SEND_AMOUNT).into()),
|
||||
0,
|
||||
WeightLimit::Limited(5000),
|
||||
));
|
||||
// Alice spent amount
|
||||
assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT);
|
||||
// Destination account (parachain account) has amount
|
||||
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
|
||||
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT);
|
||||
assert_eq!(
|
||||
sent_xcm(),
|
||||
vec![(
|
||||
Parachain(PARA_ID).into(),
|
||||
Xcm(vec![
|
||||
ReserveAssetDeposited((Parent, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_limited_execution((Parent, SEND_AMOUNT), 5000),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]),
|
||||
)]
|
||||
);
|
||||
let versioned_sent = VersionedXcm::from(sent_xcm().into_iter().next().unwrap().1);
|
||||
let _check_v0_ok: xcm::v0::Xcm<()> = versioned_sent.try_into().unwrap();
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Test `limited_reserve_transfer_assets` with unlimited weight purchasing
|
||||
///
|
||||
/// Asserts that the sender's balance is decreased and the beneficiary's balance
|
||||
/// is increased. Verifies the correct message is sent and event is emitted.
|
||||
#[test]
|
||||
fn unlimited_reserve_transfer_assets_works() {
|
||||
let balances =
|
||||
vec![(ALICE, INITIAL_BALANCE), (ParaId::from(PARA_ID).into_account(), INITIAL_BALANCE)];
|
||||
new_test_ext_with_balances(balances).execute_with(|| {
|
||||
let weight = BaseXcmWeight::get();
|
||||
let dest: MultiLocation =
|
||||
Junction::AccountId32 { network: NetworkId::Any, id: ALICE.into() }.into();
|
||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||
assert_ok!(XcmPallet::limited_reserve_transfer_assets(
|
||||
Origin::signed(ALICE),
|
||||
Box::new(Parachain(PARA_ID).into().into()),
|
||||
Box::new(dest.clone().into()),
|
||||
Box::new((Here, SEND_AMOUNT).into()),
|
||||
0,
|
||||
WeightLimit::Unlimited,
|
||||
));
|
||||
// Alice spent amount
|
||||
assert_eq!(Balances::free_balance(ALICE), INITIAL_BALANCE - SEND_AMOUNT);
|
||||
// Destination account (parachain account) has amount
|
||||
let para_acc: AccountId = ParaId::from(PARA_ID).into_account();
|
||||
assert_eq!(Balances::free_balance(para_acc), INITIAL_BALANCE + SEND_AMOUNT);
|
||||
assert_eq!(
|
||||
sent_xcm(),
|
||||
vec![(
|
||||
Parachain(PARA_ID).into(),
|
||||
Xcm(vec![
|
||||
ReserveAssetDeposited((Parent, SEND_AMOUNT).into()),
|
||||
ClearOrigin,
|
||||
buy_execution((Parent, SEND_AMOUNT)),
|
||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: dest },
|
||||
]),
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
last_event(),
|
||||
Event::XcmPallet(crate::Event::Attempted(Outcome::Complete(weight)))
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// Test local execution of XCM
|
||||
///
|
||||
/// Asserts that the sender's balance is decreased and the beneficiary's balance
|
||||
|
||||
Reference in New Issue
Block a user