XCM: ExpectTransactStatus instruction (#6578)

* Introduce ExpectTransactStatus instruction

* Remove other changes

* Implement

* Implement rest

* Benchmark

* Update xcm/src/v3/mod.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

* Update xcm/src/v3/mod.rs

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>

Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
Gavin Wood
2023-01-19 03:59:38 -03:00
committed by GitHub
parent 90aa798b76
commit 8eeb654b04
10 changed files with 120 additions and 9 deletions
@@ -156,6 +156,68 @@ fn report_failed_transact_status_should_work() {
assert_eq!(sent_xcm(), vec![(Parent.into(), expected_msg, expected_hash)]);
}
#[test]
fn expect_successful_transact_status_should_work() {
AllowUnpaidFrom::set(vec![Parent.into()]);
let message = Xcm::<TestCall>(vec![
Transact {
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(50, 50),
call: TestCall::Any(Weight::from_parts(50, 50), None).encode().into(),
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);
let hash = fake_message_hash(&message);
let weight_limit = Weight::from_parts(70, 70);
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, hash, weight_limit);
assert_eq!(r, Outcome::Complete(Weight::from_parts(70, 70)));
let message = Xcm::<TestCall>(vec![
Transact {
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(50, 50),
call: TestCall::OnlyRoot(Weight::from_parts(50, 50), None).encode().into(),
},
ExpectTransactStatus(MaybeErrorCode::Success),
]);
let hash = fake_message_hash(&message);
let weight_limit = Weight::from_parts(70, 70);
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, hash, weight_limit);
assert_eq!(r, Outcome::Incomplete(Weight::from_parts(70, 70), XcmError::ExpectationFalse));
}
#[test]
fn expect_failed_transact_status_should_work() {
AllowUnpaidFrom::set(vec![Parent.into()]);
let message = Xcm::<TestCall>(vec![
Transact {
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(50, 50),
call: TestCall::OnlyRoot(Weight::from_parts(50, 50), None).encode().into(),
},
ExpectTransactStatus(MaybeErrorCode::Error(vec![2])),
]);
let hash = fake_message_hash(&message);
let weight_limit = Weight::from_parts(70, 70);
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, hash, weight_limit);
assert_eq!(r, Outcome::Complete(Weight::from_parts(70, 70)));
let message = Xcm::<TestCall>(vec![
Transact {
origin_kind: OriginKind::Native,
require_weight_at_most: Weight::from_parts(50, 50),
call: TestCall::Any(Weight::from_parts(50, 50), None).encode().into(),
},
ExpectTransactStatus(MaybeErrorCode::Error(vec![2])),
]);
let hash = fake_message_hash(&message);
let weight_limit = Weight::from_parts(70, 70);
let r = XcmExecutor::<TestConfig>::execute_xcm(Parent, message, hash, weight_limit);
assert_eq!(r, Outcome::Incomplete(Weight::from_parts(70, 70), XcmError::ExpectationFalse));
}
#[test]
fn clear_transact_status_should_work() {
AllowUnpaidFrom::set(vec![Parent.into()]);