1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
use crate::tests::common::xcm::*;
18

            
19
use {
20
    crate::{
21
        assert_expected_events,
22
        tests::common::xcm::mocknets::{
23
            DanceboxPara as Dancebox, WestendRelay as Westend, WestendRelayPallet,
24
        },
25
    },
26
    frame_support::{
27
        assert_ok,
28
        weights::{Weight, WeightToFee},
29
    },
30
    staging_xcm::{latest::prelude::*, VersionedLocation, VersionedXcm},
31
    xcm_emulator::Chain,
32
};
33

            
34
#[test]
35
1
fn trapping_asserts_works_with_polkadot_xcm() {
36
1
    // XcmPallet send arguments
37
1
    let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
38
1
    let dancebox_para_destination: VersionedLocation =
39
1
        Westend::child_location_of(Dancebox::para_id()).into();
40
1

            
41
1
    let buy_execution_fee_amount =
42
1
        crate::WeightToFee::weight_to_fee(&Weight::from_parts(10_000_000_000, 300_000));
43
1

            
44
1
    let buy_execution_fee = Asset {
45
1
        id: crate::xcm_config::SelfReserve::get().into(),
46
1
        fun: Fungible(buy_execution_fee_amount),
47
1
    };
48
1

            
49
1
    let xcm = VersionedXcm::from(Xcm(vec![
50
1
        WithdrawAsset(vec![buy_execution_fee.clone()].into()),
51
1
        BuyExecution {
52
1
            fees: buy_execution_fee.clone(),
53
1
            weight_limit: Unlimited,
54
1
        },
55
1
        Trap(0),
56
1
    ]));
57
1

            
58
1
    // Send XCM message from Relay Chain
59
1
    Westend::execute_with(|| {
60
1
        assert_ok!(<Westend as WestendRelayPallet>::XcmPallet::send(
61
1
            sudo_origin,
62
1
            bx!(dancebox_para_destination),
63
1
            bx!(xcm),
64
1
        ));
65

            
66
        type RuntimeEvent = <Westend as Chain>::RuntimeEvent;
67

            
68
1
        assert_expected_events!(
69
            Westend,
70
            vec![
71
1
                RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {},
72
            ]
73
        );
74
1
    });
75
1

            
76
1
    // Receive XCM message in Assets Parachain
77
1
    Dancebox::execute_with(|| {
78
        type RuntimeEvent = <Dancebox as Chain>::RuntimeEvent;
79
1
        Dancebox::assert_dmp_queue_incomplete(None);
80
1
        assert_expected_events!(
81
            Dancebox,
82
            vec![
83
1
                RuntimeEvent::PolkadotXcm(
84
1
                    pallet_xcm::Event::AssetsTrapped{origin, ..}) => {
85
1
                        origin: *origin == Location::parent(),
86
                },
87
            ]
88
        );
89
1
    });
90
1
}