emulated_integration_tests_common/
dap_helpers.rs1use frame_support::{
17 assert_ok,
18 traits::{
19 fungible::{Inspect as FungibleInspect, Mutate as FungibleMutate},
20 Get, Hooks,
21 },
22 weights::Weight,
23};
24use parachains_common::{AccountId, Balance};
25
26use xcm_emulator::{Chain, TestExt};
27
28pub fn test_accumulate_forward_transfers_to_asset_hub<Sender, AH>()
32where
33 Sender: Chain + TestExt,
34 Sender::Runtime: pallet_accumulate_and_forward::Config
35 + pallet_balances::Config<Balance = Balance>
36 + frame_system::Config<AccountId = AccountId>,
37 Sender::RuntimeEvent: TryInto<pallet_accumulate_and_forward::Event<Sender::Runtime>>,
38 pallet_accumulate_and_forward::Pallet<Sender::Runtime>: Hooks<u32>,
39 <Sender::Runtime as pallet_accumulate_and_forward::Config>::MinTransferAmount: Get<Balance>,
40 AH: Chain + TestExt,
41 AH::Runtime: pallet_xcm::Config
42 + pallet_dap::Config
43 + pallet_balances::Config<Balance = Balance>
44 + pallet_message_queue::Config
45 + frame_system::Config<AccountId = AccountId>,
46 AH::RuntimeEvent: TryInto<pallet_message_queue::Event<AH::Runtime>>,
47 pallet_dap::Pallet<AH::Runtime>: Hooks<u32>,
48{
49 let sender_ed = <Sender::Runtime as pallet_balances::Config>::ExistentialDeposit::get();
50 let ah_ed = <AH::Runtime as pallet_balances::Config>::ExistentialDeposit::get();
51 let accumulation_account =
52 pallet_accumulate_and_forward::Pallet::<Sender::Runtime>::accumulation_account();
53 let dap_staging_account: AccountId = pallet_dap::Pallet::<AH::Runtime>::staging_account();
54 let dap_buffer_account: AccountId = pallet_dap::Pallet::<AH::Runtime>::buffer_account();
55
56 let fund_amount =
58 <Sender::Runtime as pallet_accumulate_and_forward::Config>::MinTransferAmount::get() + 1;
59
60 let check_account: AccountId =
63 AH::execute_with(|| pallet_xcm::Pallet::<AH::Runtime>::check_account());
64 AH::execute_with(|| {
65 assert_ok!(pallet_balances::Pallet::<AH::Runtime>::mint_into(
66 &check_account,
67 fund_amount + ah_ed
68 ));
69 });
70
71 let (ah_total_issuance_before, ah_inactive_issuance_before, buffer_balance_before) =
72 AH::execute_with(|| {
73 (
74 pallet_balances::Pallet::<AH::Runtime>::total_issuance(),
75 pallet_balances::Pallet::<AH::Runtime>::inactive_issuance(),
76 pallet_balances::Pallet::<AH::Runtime>::balance(&dap_buffer_account),
77 )
78 });
79
80 let (available_funds, sender_total_issuance_before) = Sender::execute_with(|| {
83 assert_ok!(pallet_balances::Pallet::<Sender::Runtime>::mint_into(
84 &accumulation_account,
85 sender_ed + fund_amount
86 ));
87 let available_funds =
88 pallet_balances::Pallet::<Sender::Runtime>::balance(&accumulation_account) - sender_ed;
89 let total_issuance_before = pallet_balances::Pallet::<Sender::Runtime>::total_issuance();
90
91 let _ = <pallet_accumulate_and_forward::Pallet<Sender::Runtime> as Hooks<u32>>::on_idle(
92 1,
93 Weight::MAX,
94 );
95 let forward_succeeded = Sender::events().into_iter().any(|e| {
96 matches!(
97 e.try_into(),
98 Ok(pallet_accumulate_and_forward::Event::ForwardSucceeded { .. })
99 )
100 });
101 assert!(forward_succeeded, "Expected AccumulateForward::ForwardSucceeded event");
102
103 (available_funds, total_issuance_before)
104 });
105
106 let accumulation_balance_after = Sender::account_data_of(accumulation_account).free;
108 assert_eq!(accumulation_balance_after, sender_ed);
109
110 let sender_total_issuance_after =
111 Sender::execute_with(|| pallet_balances::Pallet::<Sender::Runtime>::total_issuance());
112 assert_eq!(sender_total_issuance_after, sender_total_issuance_before - available_funds);
113
114 let amount_received = AH::execute_with(|| {
117 let mq_processed = AH::events().into_iter().any(|e| {
118 matches!(e.try_into(), Ok(pallet_message_queue::Event::Processed { success: true, .. }))
119 });
120 assert!(mq_processed, "Expected MessageQueue::Processed(success: true) on AssetHub");
121
122 let staging_balance = pallet_balances::Pallet::<AH::Runtime>::balance(&dap_staging_account);
123 let ah_ed_balance = <AH::Runtime as pallet_balances::Config>::ExistentialDeposit::get();
124 let received = staging_balance.saturating_sub(ah_ed_balance);
125 assert!(received > 0, "DAP staging account should have received funds");
126
127 assert_eq!(
129 pallet_balances::Pallet::<AH::Runtime>::balance(&dap_buffer_account),
130 buffer_balance_before,
131 );
132 assert_eq!(
133 pallet_balances::Pallet::<AH::Runtime>::inactive_issuance(),
134 ah_inactive_issuance_before,
135 );
136
137 assert_eq!(
139 pallet_balances::Pallet::<AH::Runtime>::total_issuance(),
140 ah_total_issuance_before
141 );
142
143 received
144 });
145
146 AH::execute_with(|| {
149 let _ = <pallet_dap::Pallet<AH::Runtime> as Hooks<u32>>::on_idle(1, Weight::MAX);
150
151 let buffer_balance_after =
152 pallet_balances::Pallet::<AH::Runtime>::balance(&dap_buffer_account);
153 assert_eq!(buffer_balance_after, buffer_balance_before + amount_received);
154
155 assert_eq!(
156 pallet_balances::Pallet::<AH::Runtime>::inactive_issuance(),
157 ah_inactive_issuance_before + amount_received
158 );
159 });
160}