use super::{mock::*, *};
use pezframe_support::{assert_ok, traits::tokens::Pay};
parameter_types! {
pub SenderAccount: AccountId = AccountId::new([3u8; 32]);
pub InteriorAccount: InteriorLocation = AccountId32 { id: SenderAccount::get().into(), network: None }.into();
pub InteriorBody: InteriorLocation = Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into();
pub Timeout: BlockNumber = 5; }
#[test]
fn pay_over_xcm_works() {
let recipient = AccountId::new([5u8; 32]);
let asset_kind =
AssetKind { destination: (Parent, Teyrchain(2)).into(), asset_id: Here.into() };
let amount = 10 * UNITS;
new_test_ext().execute_with(|| {
assert_eq!(mock::Assets::balance(0, &recipient), 0);
assert_ok!(PayOverXcm::<
InteriorAccount,
TestMessageSender,
TestQueryHandler<TestConfig, BlockNumber>,
Timeout,
AccountId,
AssetKind,
LocatableAssetKindConverter,
AliasesIntoAccountId32<AnyNetwork, AccountId>,
>::pay(&recipient, asset_kind, amount));
let expected_message = Xcm(vec![
DescendOrigin(AccountId32 { id: SenderAccount::get().into(), network: None }.into()),
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
SetAppendix(Xcm(vec![
SetFeesMode { jit_withdraw: true },
ReportError(QueryResponseInfo {
destination: (Parent, Teyrchain(42)).into(),
query_id: 1,
max_weight: Weight::zero(),
}),
])),
TransferAsset {
assets: (Here, amount).into(),
beneficiary: AccountId32 { id: recipient.clone().into(), network: None }.into(),
},
]);
let expected_hash = fake_message_hash(&expected_message);
assert_eq!(
sent_xcm(),
vec![((Parent, Teyrchain(2)).into(), expected_message, expected_hash)]
);
let (_, message, mut hash) = sent_xcm()[0].clone();
let message =
Xcm::<<XcmConfig as xcm_executor::Config>::RuntimeCall>::from(message.clone());
let origin = (Parent, Teyrchain(42));
XcmExecutor::<XcmConfig>::prepare_and_execute(
origin,
message,
&mut hash,
Weight::MAX,
Weight::zero(),
);
assert_eq!(mock::Assets::balance(0, &recipient), amount);
});
}
#[test]
fn pay_over_xcm_governance_body() {
let recipient = AccountId::new([7u8; 32]);
let asset_kind =
AssetKind { destination: (Parent, Teyrchain(2)).into(), asset_id: Parent.into() };
let amount = 10 * UNITS;
let relay_asset_index = 1;
new_test_ext().execute_with(|| {
assert_eq!(mock::Assets::balance(relay_asset_index, &recipient), 0);
assert_ok!(PayOverXcm::<
InteriorBody,
TestMessageSender,
TestQueryHandler<TestConfig, BlockNumber>,
Timeout,
AccountId,
AssetKind,
LocatableAssetKindConverter,
AliasesIntoAccountId32<AnyNetwork, AccountId>,
>::pay(&recipient, asset_kind, amount));
let expected_message = Xcm(vec![
DescendOrigin(Plurality { id: BodyId::Treasury, part: BodyPart::Voice }.into()),
UnpaidExecution { weight_limit: Unlimited, check_origin: None },
SetAppendix(Xcm(vec![
SetFeesMode { jit_withdraw: true },
ReportError(QueryResponseInfo {
destination: (Parent, Teyrchain(42)).into(),
query_id: 1,
max_weight: Weight::zero(),
}),
])),
TransferAsset {
assets: (Parent, amount).into(),
beneficiary: AccountId32 { id: recipient.clone().into(), network: None }.into(),
},
]);
let expected_hash = fake_message_hash(&expected_message);
assert_eq!(
sent_xcm(),
vec![((Parent, Teyrchain(2)).into(), expected_message, expected_hash)]
);
let (_, message, mut hash) = sent_xcm()[0].clone();
let message =
Xcm::<<XcmConfig as xcm_executor::Config>::RuntimeCall>::from(message.clone());
let origin = (Parent, Teyrchain(42));
XcmExecutor::<XcmConfig>::prepare_and_execute(
origin,
message,
&mut hash,
Weight::MAX,
Weight::zero(),
);
assert_eq!(mock::Assets::balance(relay_asset_index, &recipient), amount);
});
}