Newer
Older
query_id: 70,
max_weight: Weight::zero(),
response: Response::Version(3),
querier: None,
};
let instr3 = QueryResponse {
query_id: 72,
max_weight: Weight::zero(),
response: Response::Version(3),
querier: None,
};
let mut sent = take_sent_xcm();
sent.sort_by_key(|k| match (k.1).0[0] {
QueryResponse { query_id: q, .. } => q,
_ => 0,
});
assert_eq!(
sent,
vec![
(Parachain(1001).into(), Xcm(vec![instr1])),
]
);
let mut contents = VersionNotifyTargets::<Test>::iter().collect::<Vec<_>>();
assert_eq!(
contents,
vec![
(XCM_VERSION, Parachain(1001).into_versioned(), (70, Weight::zero(), 3)),
(XCM_VERSION, Parachain(1003).into_versioned(), (72, Weight::zero(), 3)),
]
);
});
}
#[test]
fn subscription_side_upgrades_work_without_notify() {
new_test_ext_with_balances(vec![]).execute_with(|| {
// An entry from a previous runtime with v2 XCM.
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1001).into());
VersionNotifyTargets::<Test>::insert(1, v2_location, (70, Weight::zero(), 2));
let v3_location = Parachain(1003).into_versioned();
VersionNotifyTargets::<Test>::insert(3, v3_location, (72, Weight::zero(), 2));
// A runtime upgrade which alters the version does send notifications.
CurrentMigration::<Test>::put(VersionMigrationStage::default());
XcmPallet::on_initialize(1);
let mut contents = VersionNotifyTargets::<Test>::iter().collect::<Vec<_>>();
assert_eq!(
contents,
vec![
(XCM_VERSION, Parachain(1001).into_versioned(), (70, Weight::zero(), 3)),
(XCM_VERSION, Parachain(1003).into_versioned(), (72, Weight::zero(), 3)),
]
);
});
}
#[test]
fn subscriber_side_subscription_works() {
new_test_ext_with_balances(vec![]).execute_with(|| {
assert_ok!(XcmPallet::force_subscribe_version_notify(
));
take_sent_xcm();
// Assume subscription target is working ok.
let weight = BaseXcmWeight::get();
let message = Xcm(vec![
// Remote supports XCM v2
QueryResponse {
query_id: 0,
max_weight: Weight::zero(),
response: Response::Version(1),
querier: None,
},
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote, message, hash, weight);
assert_eq!(r, Outcome::Complete(weight));
assert_eq!(take_sent_xcm(), vec![]);
// This message cannot be sent to a v2 remote.
let v2_msg = xcm::v2::Xcm::<()>(vec![xcm::v2::Instruction::Trap(0)]);
assert_eq!(XcmPallet::wrap_version(&remote, v2_msg.clone()), Err(()));
let message = Xcm(vec![
// Remote upgraded to XCM v2
QueryResponse {
query_id: 0,
max_weight: Weight::zero(),
response: Response::Version(2),
querier: None,
},
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote, message, hash, weight);
assert_eq!(r, Outcome::Complete(weight));
// This message can now be sent to remote as it's v2.
assert_eq!(
XcmPallet::wrap_version(&remote, v2_msg.clone()),
Ok(VersionedXcm::from(v2_msg))
);
});
}
/// We should auto-subscribe when we don't know the remote's version.
#[test]
fn auto_subscription_works() {
new_test_ext_with_balances(vec![]).execute_with(|| {
let remote_v2: MultiLocation = Parachain(1000).into();
let remote_v3: MultiLocation = Parachain(1001).into();
assert_ok!(XcmPallet::force_default_xcm_version(RuntimeOrigin::root(), Some(2)));
// Wrapping a version for a destination we don't know elicits a subscription.
let msg_v2 = xcm::v2::Xcm::<()>(vec![xcm::v2::Instruction::Trap(0)]);
let msg_v3 = xcm::v3::Xcm::<()>(vec![xcm::v3::Instruction::ClearTopic]);
XcmPallet::wrap_version(&remote_v2, msg_v2.clone()),
Ok(VersionedXcm::from(msg_v2.clone())),
assert_eq!(XcmPallet::wrap_version(&remote_v2, msg_v3.clone()), Err(()));
let expected = vec![(remote_v2.into(), 2)];
assert_eq!(VersionDiscoveryQueue::<Test>::get().into_inner(), expected);
assert_eq!(
XcmPallet::wrap_version(&remote_v3, msg_v2.clone()),
Ok(VersionedXcm::from(msg_v2.clone())),
);
assert_eq!(XcmPallet::wrap_version(&remote_v3, msg_v3.clone()), Err(()));
let expected = vec![(remote_v2.into(), 2), (remote_v3.into(), 2)];
assert_eq!(VersionDiscoveryQueue::<Test>::get().into_inner(), expected);
XcmPallet::on_initialize(1);
assert_eq!(
take_sent_xcm(),
vec![(
Xcm(vec![SubscribeVersion { query_id: 0, max_response_weight: Weight::zero() }]),
let weight = BaseXcmWeight::get();
let message = Xcm(vec![
// Remote supports XCM v3
QueryResponse {
query_id: 0,
max_weight: Weight::zero(),
response: Response::Version(3),
querier: None,
},
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote_v3, message, hash, weight);
assert_eq!(r, Outcome::Complete(weight));
XcmPallet::wrap_version(&remote_v3, msg_v2.clone()),
Ok(VersionedXcm::from(msg_v2.clone()).into_version(3).unwrap()),
);
// This message can now be sent to remote_v3 as it's v3.
assert_eq!(
XcmPallet::wrap_version(&remote_v3, msg_v3.clone()),
Ok(VersionedXcm::from(msg_v3.clone()))
);
XcmPallet::on_initialize(2);
assert_eq!(
take_sent_xcm(),
vec![(
Xcm(vec![SubscribeVersion { query_id: 1, max_response_weight: Weight::zero() }]),
let weight = BaseXcmWeight::get();
let message = Xcm(vec![
// Remote supports XCM v2
QueryResponse {
query_id: 1,
max_weight: Weight::zero(),
response: Response::Version(2),
querier: None,
},
let r = XcmExecutor::<XcmConfig>::execute_xcm(remote_v2, message, hash, weight);
assert_eq!(r, Outcome::Complete(weight));
// v3 messages cannot be sent to remote_v2...
assert_eq!(
XcmPallet::wrap_version(&remote_v2, msg_v2.clone()),
Ok(VersionedXcm::V2(msg_v2))
);
assert_eq!(XcmPallet::wrap_version(&remote_v2, msg_v3.clone()), Err(()));
})
}
#[test]
fn subscription_side_upgrades_work_with_multistage_notify() {
new_test_ext_with_balances(vec![]).execute_with(|| {
AdvertisedXcmVersion::set(1);
// An entry from a previous runtime with v0 XCM.
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1001).into());
VersionNotifyTargets::<Test>::insert(1, v2_location, (70, Weight::zero(), 1));
let v2_location = VersionedMultiLocation::V2(xcm::v2::Junction::Parachain(1002).into());
VersionNotifyTargets::<Test>::insert(2, v2_location, (71, Weight::zero(), 1));
let v3_location = Parachain(1003).into_versioned();
VersionNotifyTargets::<Test>::insert(3, v3_location, (72, Weight::zero(), 1));
// A runtime upgrade which alters the version does send notifications.
CurrentMigration::<Test>::put(VersionMigrationStage::default());
let mut maybe_migration = CurrentMigration::<Test>::take();
let mut counter = 0;
while let Some(migration) = maybe_migration.take() {
counter += 1;
let (_, m) = XcmPallet::check_xcm_version_change(migration, Weight::zero());
maybe_migration = m;
}
assert_eq!(counter, 4);
let instr1 = QueryResponse {
query_id: 70,
max_weight: Weight::zero(),
response: Response::Version(3),
querier: None,
};
let instr2 = QueryResponse {
query_id: 71,
max_weight: Weight::zero(),
response: Response::Version(3),
querier: None,
};
let instr3 = QueryResponse {
query_id: 72,
max_weight: Weight::zero(),
response: Response::Version(3),
querier: None,
};
let mut sent = take_sent_xcm();
sent.sort_by_key(|k| match (k.1).0[0] {
QueryResponse { query_id: q, .. } => q,
_ => 0,
});
assert_eq!(
sent,
vec![
(Parachain(1001).into(), Xcm(vec![instr1])),
(Parachain(1002).into(), Xcm(vec![instr2])),
]
);
let mut contents = VersionNotifyTargets::<Test>::iter().collect::<Vec<_>>();
assert_eq!(
contents,
vec![
(XCM_VERSION, Parachain(1001).into_versioned(), (70, Weight::zero(), 3)),
(XCM_VERSION, Parachain(1002).into_versioned(), (71, Weight::zero(), 3)),
(XCM_VERSION, Parachain(1003).into_versioned(), (72, Weight::zero(), 3)),