Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 47e58ac

Browse files
Add tests for PayOverXcm (#7319)
* PayOverXcm: Add test skeleton * PayOverXcm: Add tests checking PayOverXcm generates correct message * Add PayOverXcm and salary pallet integration test * Fix XCM execution issue * Fix documentation issues * Add missing period at the end of comment * Fix mock problems * Add missing licenses * Fix lints * Fix more lints * Add docs to mock * Add transfer assertions * Remove magic numbers --------- Co-authored-by: parity-processbot <>
1 parent 4b7822a commit 47e58ac

File tree

8 files changed

+770
-1
lines changed

8 files changed

+770
-1
lines changed

Cargo.lock

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xcm/xcm-builder/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ polkadot-parachain = { path = "../../parachain", default-features = false }
2929
primitive-types = "0.12.1"
3030
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
3131
pallet-xcm = { path = "../pallet-xcm" }
32+
pallet-salary = { git = "https://github.com/paritytech/substrate", branch = "master" }
33+
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "master" }
34+
primitives = { package = "polkadot-primitives", path = "../../primitives" }
3235
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
3336
assert_matches = "1.5.0"
3437
polkadot-test-runtime = { path = "../../runtime/test-runtime" }

xcm/xcm-builder/src/tests/mock.rs

+60-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//! Mock implementations to test XCM builder configuration types.
18+
1719
use crate::{
1820
barriers::{AllowSubscriptionsFrom, RespectSuspension, TrailingSetTopicAsId},
1921
test_utils::*,
@@ -42,7 +44,7 @@ pub use sp_std::{
4244
marker::PhantomData,
4345
};
4446
pub use xcm::latest::{prelude::*, Weight};
45-
use xcm_executor::traits::Properties;
47+
use xcm_executor::traits::{Properties, QueryHandler, QueryResponseStatus};
4648
pub use xcm_executor::{
4749
traits::{
4850
AssetExchange, AssetLock, CheckSuspension, ConvertOrigin, Enact, ExportXcm, FeeManager,
@@ -410,6 +412,63 @@ pub fn response(query_id: u64) -> Option<Response> {
410412
})
411413
}
412414

415+
/// Mock implementation of the [`QueryHandler`] trait for creating XCM success queries and expecting
416+
/// responses.
417+
pub struct TestQueryHandler<T, BlockNumber>(core::marker::PhantomData<(T, BlockNumber)>);
418+
impl<T: Config, BlockNumber: sp_runtime::traits::Zero> QueryHandler
419+
for TestQueryHandler<T, BlockNumber>
420+
{
421+
type QueryId = u64;
422+
type BlockNumber = BlockNumber;
423+
type Error = XcmError;
424+
type UniversalLocation = T::UniversalLocation;
425+
426+
fn new_query(
427+
responder: impl Into<MultiLocation>,
428+
_timeout: Self::BlockNumber,
429+
_match_querier: impl Into<MultiLocation>,
430+
) -> Self::QueryId {
431+
let query_id = 1;
432+
expect_response(query_id, responder.into());
433+
query_id
434+
}
435+
436+
fn report_outcome(
437+
message: &mut Xcm<()>,
438+
responder: impl Into<MultiLocation>,
439+
timeout: Self::BlockNumber,
440+
) -> Result<Self::QueryId, Self::Error> {
441+
let responder = responder.into();
442+
let destination = Self::UniversalLocation::get()
443+
.invert_target(&responder)
444+
.map_err(|()| XcmError::LocationNotInvertible)?;
445+
let query_id = Self::new_query(responder, timeout, Here);
446+
let response_info = QueryResponseInfo { destination, query_id, max_weight: Weight::zero() };
447+
let report_error = Xcm(vec![ReportError(response_info)]);
448+
message.0.insert(0, SetAppendix(report_error));
449+
Ok(query_id)
450+
}
451+
452+
fn take_response(query_id: Self::QueryId) -> QueryResponseStatus<Self::BlockNumber> {
453+
QUERIES
454+
.with(|q| {
455+
q.borrow().get(&query_id).and_then(|v| match v {
456+
ResponseSlot::Received(r) => Some(QueryResponseStatus::Ready {
457+
response: r.clone(),
458+
at: Self::BlockNumber::zero(),
459+
}),
460+
_ => Some(QueryResponseStatus::NotFound),
461+
})
462+
})
463+
.unwrap_or(QueryResponseStatus::NotFound)
464+
}
465+
466+
#[cfg(feature = "runtime-benchmarks")]
467+
fn expect_response(_id: Self::QueryId, _response: xcm::latest::Response) {
468+
// Unnecessary since it's only a test implementation
469+
}
470+
}
471+
413472
parameter_types! {
414473
pub static ExecutorUniversalLocation: InteriorMultiLocation
415474
= (ByGenesis([0; 32]), Parachain(42)).into();

xcm/xcm-builder/src/tests/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ mod bridging;
3434
mod expecting;
3535
mod locking;
3636
mod origins;
37+
mod pay;
3738
mod querying;
3839
mod transacting;
3940
mod version_subscriptions;

0 commit comments

Comments
 (0)