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 {
18
    frame_support::{
19
        assert_ok,
20
        weights::{Weight, WeightToFee},
21
    },
22
    westend_emulated_chain::WestendRelayPallet,
23
    westend_system_emulated_network::westend_emulated_chain::westend_runtime::Dmp,
24
    westend_system_emulated_network::{DanceboxPara as Dancebox, WestendRelay as Westend},
25
    xcm::{latest::prelude::*, VersionedLocation, VersionedXcm},
26
    xcm_emulator::{
27
        assert_expected_events, bx, Chain, Parachain as Para, RelayChain as Relay, TestExt,
28
    },
29
};
30

            
31
#[test]
32
1
fn trapping_asserts_works_with_polkadot_xcm() {
33
1
    Westend::execute_with(|| {
34
1
        Dmp::make_parachain_reachable(Dancebox::para_id());
35
1
    });
36
1

            
37
1
    // XcmPallet send arguments
38
1
    let sudo_origin = <Westend as Chain>::RuntimeOrigin::root();
39
1
    let dancebox_para_destination: VersionedLocation =
40
1
        Westend::child_location_of(Dancebox::para_id()).into();
41
1

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

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

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

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

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

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

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