mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
companion: for call usage https://github.com/paritytech/substrate/pull/9418 (#3522)
* add test for call size * fix box arg * fix xcm variant length + increase limit a bit * fix para sudo wrapper call length * reorganize * fmt * fix tests * update Substrate Co-authored-by: parity-processbot <>
This commit is contained in:
committed by
GitHub
parent
36b390ceea
commit
f78f803698
Generated
+154
-154
File diff suppressed because it is too large
Load Diff
@@ -26,6 +26,7 @@ use runtime_parachains::{
|
|||||||
paras::{self, ParaGenesisArgs},
|
paras::{self, ParaGenesisArgs},
|
||||||
ump, ParaLifecycle,
|
ump, ParaLifecycle,
|
||||||
};
|
};
|
||||||
|
use sp_std::boxed::Box;
|
||||||
|
|
||||||
#[frame_support::pallet]
|
#[frame_support::pallet]
|
||||||
pub mod pallet {
|
pub mod pallet {
|
||||||
@@ -132,7 +133,7 @@ pub mod pallet {
|
|||||||
pub fn sudo_queue_downward_xcm(
|
pub fn sudo_queue_downward_xcm(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
id: ParaId,
|
id: ParaId,
|
||||||
xcm: xcm::opaque::VersionedXcm,
|
xcm: Box<xcm::opaque::VersionedXcm>,
|
||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
ensure_root(origin)?;
|
ensure_root(origin)?;
|
||||||
ensure!(<paras::Pallet<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
|
ensure!(<paras::Pallet<T>>::is_valid_para(id), Error::<T>::ParaDoesntExist);
|
||||||
|
|||||||
@@ -168,3 +168,13 @@ fn era_payout_should_give_sensible_results() {
|
|||||||
assert_eq!(era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (10, 0));
|
assert_eq!(era_payout(75, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (10, 0));
|
||||||
assert_eq!(era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (6, 4));
|
assert_eq!(era_payout(80, 100, Perquintill::from_percent(10), Perquintill::one(), 0,), (6, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn call_size() {
|
||||||
|
assert!(
|
||||||
|
core::mem::size_of::<Call>() <= 230,
|
||||||
|
"size of Call is more than 230 bytes: some calls have too big arguments, use Box to reduce \
|
||||||
|
the size of Call.
|
||||||
|
If the limit is too strong, maybe consider increase the limit to 300.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1683,3 +1683,18 @@ mod test_fees {
|
|||||||
assert!(active > target_voters, "we need to reevaluate the weight of the election system");
|
assert!(active > target_voters, "we need to reevaluate the weight of the election system");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn call_size() {
|
||||||
|
assert!(
|
||||||
|
core::mem::size_of::<Call>() <= 230,
|
||||||
|
"size of Call is more than 230 bytes: some calls have too big arguments, use Box to \
|
||||||
|
reduce the size of Call.
|
||||||
|
If the limit is too strong, maybe consider increase the limit",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,3 +39,13 @@ fn sample_size_is_sensible() {
|
|||||||
BlockWeights::get().max_block
|
BlockWeights::get().max_block
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn call_size() {
|
||||||
|
assert!(
|
||||||
|
core::mem::size_of::<Call>() <= 230,
|
||||||
|
"size of Call is more than 230 bytes: some calls have too big arguments, use Box to reduce \
|
||||||
|
the size of Call.
|
||||||
|
If the limit is too strong, maybe consider increase the limit to 300.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ macro_rules! construct_runtime_prelude {
|
|||||||
|
|
||||||
let crate::signer::Signer { account, pair, .. } = signer;
|
let crate::signer::Signer { account, pair, .. } = signer;
|
||||||
|
|
||||||
let local_call = EPMCall::<Runtime>::submit(raw_solution, witness);
|
let local_call = EPMCall::<Runtime>::submit(Box::new(raw_solution), witness);
|
||||||
let call: Call = <EPMCall<Runtime> as std::convert::TryInto<Call>>::try_into(local_call)
|
let call: Call = <EPMCall<Runtime> as std::convert::TryInto<Call>>::try_into(local_call)
|
||||||
.expect("election provider pallet must exist in the runtime, thus \
|
.expect("election provider pallet must exist in the runtime, thus \
|
||||||
inner call can be converted, qed."
|
inner call can be converted, qed."
|
||||||
|
|||||||
@@ -114,15 +114,19 @@ pub mod pallet {
|
|||||||
#[pallet::call]
|
#[pallet::call]
|
||||||
impl<T: Config> Pallet<T> {
|
impl<T: Config> Pallet<T> {
|
||||||
#[pallet::weight(100_000_000)]
|
#[pallet::weight(100_000_000)]
|
||||||
pub fn send(origin: OriginFor<T>, dest: MultiLocation, message: Xcm<()>) -> DispatchResult {
|
pub fn send(
|
||||||
|
origin: OriginFor<T>,
|
||||||
|
dest: Box<MultiLocation>,
|
||||||
|
message: Box<Xcm<()>>,
|
||||||
|
) -> DispatchResult {
|
||||||
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
|
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
|
||||||
Self::send_xcm(origin_location.clone(), dest.clone(), message.clone()).map_err(
|
Self::send_xcm(origin_location.clone(), *dest.clone(), *message.clone()).map_err(
|
||||||
|e| match e {
|
|e| match e {
|
||||||
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
|
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
|
||||||
_ => Error::<T>::SendFailure,
|
_ => Error::<T>::SendFailure,
|
||||||
},
|
},
|
||||||
)?;
|
)?;
|
||||||
Self::deposit_event(Event::Sent(origin_location, dest, message));
|
Self::deposit_event(Event::Sent(origin_location, *dest, *message));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +148,7 @@ pub mod pallet {
|
|||||||
assets: assets.clone(),
|
assets: assets.clone(),
|
||||||
effects: sp_std::vec![ InitiateTeleport {
|
effects: sp_std::vec![ InitiateTeleport {
|
||||||
assets: Wild(All),
|
assets: Wild(All),
|
||||||
dest: dest.clone(),
|
dest: *dest.clone(),
|
||||||
effects: sp_std::vec![],
|
effects: sp_std::vec![],
|
||||||
} ]
|
} ]
|
||||||
};
|
};
|
||||||
@@ -152,8 +156,8 @@ pub mod pallet {
|
|||||||
})]
|
})]
|
||||||
pub fn teleport_assets(
|
pub fn teleport_assets(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
dest: MultiLocation,
|
dest: Box<MultiLocation>,
|
||||||
beneficiary: MultiLocation,
|
beneficiary: Box<MultiLocation>,
|
||||||
assets: MultiAssets,
|
assets: MultiAssets,
|
||||||
fee_asset_item: u32,
|
fee_asset_item: u32,
|
||||||
dest_weight: Weight,
|
dest_weight: Weight,
|
||||||
@@ -176,7 +180,7 @@ pub mod pallet {
|
|||||||
assets,
|
assets,
|
||||||
effects: vec![InitiateTeleport {
|
effects: vec![InitiateTeleport {
|
||||||
assets: Wild(All),
|
assets: Wild(All),
|
||||||
dest,
|
dest: *dest,
|
||||||
effects: vec![
|
effects: vec![
|
||||||
BuyExecution {
|
BuyExecution {
|
||||||
fees,
|
fees,
|
||||||
@@ -187,7 +191,7 @@ pub mod pallet {
|
|||||||
orders: vec![],
|
orders: vec![],
|
||||||
instructions: vec![],
|
instructions: vec![],
|
||||||
},
|
},
|
||||||
DepositAsset { assets: Wild(All), max_assets, beneficiary },
|
DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary },
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
@@ -216,15 +220,15 @@ pub mod pallet {
|
|||||||
#[pallet::weight({
|
#[pallet::weight({
|
||||||
let mut message = Xcm::TransferReserveAsset {
|
let mut message = Xcm::TransferReserveAsset {
|
||||||
assets: assets.clone(),
|
assets: assets.clone(),
|
||||||
dest: dest.clone(),
|
dest: *dest.clone(),
|
||||||
effects: sp_std::vec![],
|
effects: sp_std::vec![],
|
||||||
};
|
};
|
||||||
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000 + w)
|
T::Weigher::weight(&mut message).map_or(Weight::max_value(), |w| 100_000_000 + w)
|
||||||
})]
|
})]
|
||||||
pub fn reserve_transfer_assets(
|
pub fn reserve_transfer_assets(
|
||||||
origin: OriginFor<T>,
|
origin: OriginFor<T>,
|
||||||
dest: MultiLocation,
|
dest: Box<MultiLocation>,
|
||||||
beneficiary: MultiLocation,
|
beneficiary: Box<MultiLocation>,
|
||||||
assets: MultiAssets,
|
assets: MultiAssets,
|
||||||
fee_asset_item: u32,
|
fee_asset_item: u32,
|
||||||
dest_weight: Weight,
|
dest_weight: Weight,
|
||||||
@@ -245,7 +249,7 @@ pub mod pallet {
|
|||||||
let assets = assets.into();
|
let assets = assets.into();
|
||||||
let mut message = Xcm::TransferReserveAsset {
|
let mut message = Xcm::TransferReserveAsset {
|
||||||
assets,
|
assets,
|
||||||
dest,
|
dest: *dest,
|
||||||
effects: vec![
|
effects: vec![
|
||||||
BuyExecution {
|
BuyExecution {
|
||||||
fees,
|
fees,
|
||||||
@@ -256,7 +260,7 @@ pub mod pallet {
|
|||||||
orders: vec![],
|
orders: vec![],
|
||||||
instructions: vec![],
|
instructions: vec![],
|
||||||
},
|
},
|
||||||
DepositAsset { assets: Wild(All), max_assets, beneficiary },
|
DepositAsset { assets: Wild(All), max_assets, beneficiary: *beneficiary },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
let weight =
|
let weight =
|
||||||
|
|||||||
@@ -46,7 +46,11 @@ fn send_works() {
|
|||||||
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: sender.clone() },
|
DepositAsset { assets: All.into(), max_assets: 1, beneficiary: sender.clone() },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
assert_ok!(XcmPallet::send(Origin::signed(ALICE), RelayLocation::get(), message.clone()));
|
assert_ok!(XcmPallet::send(
|
||||||
|
Origin::signed(ALICE),
|
||||||
|
Box::new(RelayLocation::get()),
|
||||||
|
Box::new(message.clone())
|
||||||
|
));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
sent_xcm(),
|
sent_xcm(),
|
||||||
vec![(
|
vec![(
|
||||||
@@ -83,7 +87,7 @@ fn send_fails_when_xcm_router_blocks() {
|
|||||||
assert_noop!(
|
assert_noop!(
|
||||||
XcmPallet::send(
|
XcmPallet::send(
|
||||||
Origin::signed(ALICE),
|
Origin::signed(ALICE),
|
||||||
X8(
|
Box::new(X8(
|
||||||
Junction::Parent,
|
Junction::Parent,
|
||||||
Junction::Parent,
|
Junction::Parent,
|
||||||
Junction::Parent,
|
Junction::Parent,
|
||||||
@@ -92,8 +96,8 @@ fn send_fails_when_xcm_router_blocks() {
|
|||||||
Junction::Parent,
|
Junction::Parent,
|
||||||
Junction::Parent,
|
Junction::Parent,
|
||||||
Junction::Parent
|
Junction::Parent
|
||||||
),
|
)),
|
||||||
message.clone()
|
Box::new(message.clone())
|
||||||
),
|
),
|
||||||
crate::Error::<Test>::SendFailure
|
crate::Error::<Test>::SendFailure
|
||||||
);
|
);
|
||||||
@@ -113,8 +117,8 @@ fn teleport_assets_works() {
|
|||||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||||
assert_ok!(XcmPallet::teleport_assets(
|
assert_ok!(XcmPallet::teleport_assets(
|
||||||
Origin::signed(ALICE),
|
Origin::signed(ALICE),
|
||||||
RelayLocation::get(),
|
Box::new(RelayLocation::get()),
|
||||||
X1(AccountId32 { network: Any, id: BOB.into() }),
|
Box::new(X1(AccountId32 { network: Any, id: BOB.into() })),
|
||||||
(Here, SEND_AMOUNT).into(),
|
(Here, SEND_AMOUNT).into(),
|
||||||
0,
|
0,
|
||||||
weight,
|
weight,
|
||||||
@@ -142,8 +146,8 @@ fn reserve_transfer_assets_works() {
|
|||||||
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
assert_eq!(Balances::total_balance(&ALICE), INITIAL_BALANCE);
|
||||||
assert_ok!(XcmPallet::reserve_transfer_assets(
|
assert_ok!(XcmPallet::reserve_transfer_assets(
|
||||||
Origin::signed(ALICE),
|
Origin::signed(ALICE),
|
||||||
Parachain(PARA_ID).into(),
|
Box::new(Parachain(PARA_ID).into()),
|
||||||
dest.clone(),
|
Box::new(dest.clone()),
|
||||||
(Here, SEND_AMOUNT).into(),
|
(Here, SEND_AMOUNT).into(),
|
||||||
0,
|
0,
|
||||||
weight
|
weight
|
||||||
|
|||||||
@@ -190,8 +190,8 @@ mod tests {
|
|||||||
Relay::execute_with(|| {
|
Relay::execute_with(|| {
|
||||||
assert_ok!(RelayChainPalletXcm::reserve_transfer_assets(
|
assert_ok!(RelayChainPalletXcm::reserve_transfer_assets(
|
||||||
relay_chain::Origin::signed(ALICE),
|
relay_chain::Origin::signed(ALICE),
|
||||||
X1(Parachain(1)),
|
Box::new(X1(Parachain(1))),
|
||||||
X1(AccountId32 { network: Any, id: ALICE.into() }),
|
Box::new(X1(AccountId32 { network: Any, id: ALICE.into() })),
|
||||||
(Here, 123).into(),
|
(Here, 123).into(),
|
||||||
0,
|
0,
|
||||||
3,
|
3,
|
||||||
|
|||||||
Reference in New Issue
Block a user