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

Add tests for PayOverXcm #7319

Merged
merged 15 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions xcm/xcm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ polkadot-parachain = { path = "../../parachain", default-features = false }
primitive-types = "0.12.1"
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-xcm = { path = "../pallet-xcm" }
pallet-salary = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-assets = { git = "https://github.com/paritytech/substrate", branch = "master" }
primitives = { package = "polkadot-primitives", path = "../../primitives" }
polkadot-runtime-parachains = { path = "../../runtime/parachains" }
assert_matches = "1.5.0"
polkadot-test-runtime = { path = "../../runtime/test-runtime" }
Expand Down
57 changes: 56 additions & 1 deletion xcm/xcm-builder/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub use sp_std::{
marker::PhantomData,
};
pub use xcm::latest::{prelude::*, Weight};
use xcm_executor::traits::Properties;
use xcm_executor::traits::{Properties, QueryHandler, QueryResponseStatus};
pub use xcm_executor::{
traits::{
AssetExchange, AssetLock, CheckSuspension, ConvertOrigin, Enact, ExportXcm, FeeManager,
Expand Down Expand Up @@ -410,6 +410,61 @@ pub fn response(query_id: u64) -> Option<Response> {
})
}

pub struct TestQueryHandler<T, BlockNumber>(core::marker::PhantomData<(T, BlockNumber)>);
franciscoaguirre marked this conversation as resolved.
Show resolved Hide resolved
impl<T: Config, BlockNumber: sp_runtime::traits::Zero> QueryHandler
for TestQueryHandler<T, BlockNumber>
{
type QueryId = u64;
type BlockNumber = BlockNumber;
type Error = XcmError;
type UniversalLocation = T::UniversalLocation;

fn new_query(
responder: impl Into<MultiLocation>,
_timeout: Self::BlockNumber,
_match_querier: impl Into<MultiLocation>,
) -> Self::QueryId {
let query_id = 1;
expect_response(query_id, responder.into());
query_id
}

fn report_outcome(
message: &mut Xcm<()>,
responder: impl Into<MultiLocation>,
timeout: Self::BlockNumber,
) -> Result<Self::QueryId, Self::Error> {
let responder = responder.into();
let destination = Self::UniversalLocation::get()
.invert_target(&responder)
.map_err(|()| XcmError::LocationNotInvertible)?;
let query_id = Self::new_query(responder, timeout, Here);
let response_info = QueryResponseInfo { destination, query_id, max_weight: Weight::zero() };
let report_error = Xcm(vec![ReportError(response_info)]);
message.0.insert(0, SetAppendix(report_error));
Ok(query_id)
}

fn take_response(query_id: Self::QueryId) -> QueryResponseStatus<Self::BlockNumber> {
QUERIES
.with(|q| {
q.borrow().get(&query_id).and_then(|v| match v {
ResponseSlot::Received(r) => Some(QueryResponseStatus::Ready {
response: r.clone(),
at: Self::BlockNumber::zero(),
}),
_ => Some(QueryResponseStatus::NotFound),
})
})
.unwrap_or(QueryResponseStatus::NotFound)
}

#[cfg(feature = "runtime-benchmarks")]
fn expect_response(_id: Self::QueryId, _response: xcm::latest::Response) {
// Unnecessary since it's only a test implementation
}
}

parameter_types! {
pub static ExecutorUniversalLocation: InteriorMultiLocation
= (ByGenesis([0; 32]), Parachain(42)).into();
Expand Down
1 change: 1 addition & 0 deletions xcm/xcm-builder/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod bridging;
mod expecting;
mod locking;
mod origins;
mod pay;
mod querying;
mod transacting;
mod version_subscriptions;
Expand Down
Loading