Skip to content

Commit

Permalink
Improve integration tests with CI
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Nov 2, 2023
1 parent 235c581 commit b5911d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/parachain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ jobs:
--package bridge-hub-rococo-runtime
--features runtime-benchmarks
integration-tests:
needs: test
runs-on: snowbridge-runner
steps:
- uses: actions/checkout@v2
with:
submodules: "true"
- uses: arduino/setup-protoc@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: setup rust toolchain
run: rustup show
- name: snowbridge integration
run: >
cargo test
--manifest-path polkadot-sdk/Cargo.toml
-p bridge-hub-rococo-integration-tests
beacon-fuzz:
if: false
needs: test
Expand Down
30 changes: 21 additions & 9 deletions parachain/pallets/inbound-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ use frame_system::ensure_signed;
use scale_info::TypeInfo;
use sp_core::H160;
use sp_std::convert::TryFrom;
use xcm::v3::{
send_xcm, Junction::*, Junctions::*, MultiLocation, SendError as XcmpSendError, SendXcm,
use xcm::prelude::{
send_xcm, Junction::*, Junctions::*, MultiLocation, SendError as XcmpSendError, SendXcm, Xcm,
XcmHash,
};

Expand Down Expand Up @@ -130,8 +130,8 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T> {
/// A message was received from Ethereum
MessageReceived {
/// Xcm message sent to dest chain
MessageSent {
/// The destination parachain
dest: ParaId,
/// The message nonce
Expand Down Expand Up @@ -245,16 +245,14 @@ pub mod pallet {

// Decode message into XCM
let xcm = match inbound::VersionedMessage::decode_all(&mut envelope.payload.as_ref()) {
Ok(message) => T::MessageConverter::convert(message)
.map_err(|e| Error::<T>::ConvertMessage(e))?,
Ok(message) => Self::do_convert(message)?,
Err(_) => return Err(Error::<T>::InvalidPayload.into()),
};

// Attempt to send XCM to a dest parachain
let dest = MultiLocation { parents: 1, interior: X1(Parachain(envelope.dest.into())) };
let (xcm_hash, _) = send_xcm::<T::XcmSender>(dest, xcm).map_err(Error::<T>::from)?;
let xcm_hash = Self::send_xcm(xcm, envelope.dest)?;

Self::deposit_event(Event::MessageReceived {
Self::deposit_event(Event::MessageSent {
dest: envelope.dest,
nonce: envelope.nonce,
xcm_hash,
Expand All @@ -276,4 +274,18 @@ pub mod pallet {
Ok(())
}
}

impl<T: Config> Pallet<T> {
pub fn do_convert(message: inbound::VersionedMessage) -> Result<Xcm<()>, Error<T>> {
let xcm =
T::MessageConverter::convert(message).map_err(|e| Error::<T>::ConvertMessage(e))?;
Ok(xcm)
}

pub fn send_xcm(xcm: Xcm<()>, dest: ParaId) -> Result<XcmHash, Error<T>> {
let dest = MultiLocation { parents: 1, interior: X1(Parachain(dest.into())) };
let (xcm_hash, _) = send_xcm::<T::XcmSender>(dest, xcm).map_err(Error::<T>::from)?;
Ok(xcm_hash)
}
}
}
2 changes: 1 addition & 1 deletion parachain/pallets/inbound-queue/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ fn test_submit_happy_path() {
},
};
assert_ok!(InboundQueue::submit(origin.clone(), message.clone()));
expect_events(vec![InboundQueueEvent::MessageReceived {
expect_events(vec![InboundQueueEvent::MessageSent {
dest: ASSET_HUB_PARAID.into(),
nonce: 1,
xcm_hash: XCM_HASH,
Expand Down

0 comments on commit b5911d9

Please sign in to comment.