Skip to content

Commit

Permalink
Fix builder pattern issues in v4
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Nov 21, 2023
1 parent e9fff16 commit 4cf61b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 8 additions & 8 deletions polkadot/xcm/procedural/tests/builder_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use xcm::latest::prelude::*;

#[test]
fn builder_pattern_works() {
let asset: MultiAsset = (Here, 100u128).into();
let beneficiary: MultiLocation = AccountId32 { id: [0u8; 32], network: None }.into();
let asset: Asset = (Here, 100u128).into();
let beneficiary: Location = AccountId32 { id: [0u8; 32], network: None }.into();
let message: Xcm<()> = Xcm::builder()
.receive_teleported_asset(asset.clone().into())
.buy_execution(asset.clone(), Unlimited)
.deposit_asset(asset.clone().into(), beneficiary)
.deposit_asset(asset.clone().into(), beneficiary.clone())
.build();
assert_eq!(
message,
Expand All @@ -40,8 +40,8 @@ fn builder_pattern_works() {

#[test]
fn default_builder_requires_buy_execution() {
let asset: MultiAsset = (Here, 100u128).into();
let beneficiary: MultiLocation = AccountId32 { id: [0u8; 32], network: None }.into();
let asset: Asset = (Here, 100u128).into();
let beneficiary: Location = AccountId32 { id: [0u8; 32], network: None }.into();
// This is invalid, since it doesn't pay for fees.
// This is enforced by the runtime, because the build() method doesn't exist
// on the resulting type.
Expand All @@ -54,22 +54,22 @@ fn default_builder_requires_buy_execution() {
let message: Xcm<()> = Xcm::builder_unpaid()
.unpaid_execution(Unlimited, None)
.withdraw_asset(asset.clone().into())
.deposit_asset(asset.clone().into(), beneficiary)
.deposit_asset(asset.clone().into(), beneficiary.clone())
.build(); // This works
assert_eq!(
message,
Xcm(vec![
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
WithdrawAsset(asset.clone().into()),
DepositAsset { assets: asset.clone().into(), beneficiary },
DepositAsset { assets: asset.clone().into(), beneficiary: beneficiary.clone() },
])
);

// The other option doesn't have any limits whatsoever, so it should
// only be used when you really know what you're doing.
let message: Xcm<()> = Xcm::builder_unsafe()
.withdraw_asset(asset.clone().into())
.deposit_asset(asset.clone().into(), beneficiary)
.deposit_asset(asset.clone().into(), beneficiary.clone())
.build();
assert_eq!(
message,
Expand Down
6 changes: 5 additions & 1 deletion polkadot/xcm/src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl XcmContext {
///
/// This is the inner XCM format and is version-sensitive. Messages are typically passed using the
/// outer XCM format, known as `VersionedXcm`.
#[derive(Derivative, Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait)]
#[derive(Derivative, Encode, Decode, TypeInfo, xcm_procedural::XcmWeightInfoTrait, xcm_procedural::Builder)]
#[derivative(Clone(bound = ""), Eq(bound = ""), PartialEq(bound = ""), Debug(bound = ""))]
#[codec(encode_bound())]
#[codec(decode_bound())]
Expand All @@ -376,6 +376,7 @@ pub enum Instruction<Call> {
/// Kind: *Command*.
///
/// Errors:
#[builder(loads_holding)]
WithdrawAsset(Assets),

/// Asset(s) (`assets`) have been received into the ownership of this system on the `origin`
Expand All @@ -389,6 +390,7 @@ pub enum Instruction<Call> {
/// Kind: *Trusted Indication*.
///
/// Errors:
#[builder(loads_holding)]
ReserveAssetDeposited(Assets),

/// Asset(s) (`assets`) have been destroyed on the `origin` system and equivalent assets should
Expand All @@ -402,6 +404,7 @@ pub enum Instruction<Call> {
/// Kind: *Trusted Indication*.
///
/// Errors:
#[builder(loads_holding)]
ReceiveTeleportedAsset(Assets),

/// Respond with information that the local system is expecting.
Expand Down Expand Up @@ -726,6 +729,7 @@ pub enum Instruction<Call> {
/// Kind: *Command*
///
/// Errors:
#[builder(loads_holding)]
ClaimAsset { assets: Assets, ticket: Location },

/// Always throws an error of type `Trap`.
Expand Down

0 comments on commit 4cf61b8

Please sign in to comment.