@@ -23,7 +23,7 @@ use frame_support::traits::fungible::Mutate;
23
23
use macros:: generate_accounts;
24
24
use pallet_funding:: assert_close_enough;
25
25
use pallet_vesting:: VestingInfo ;
26
- use polimec_base_runtime:: { Balances , ParachainStaking , RuntimeOrigin , Vesting } ;
26
+ use polimec_base_runtime:: { Balances , ParachainStaking , PayMaster , RuntimeOrigin , Vesting } ;
27
27
use sp_runtime:: Perquintill ;
28
28
use tests:: defaults:: * ;
29
29
use xcm_emulator:: get_account_id_from_seed;
@@ -144,3 +144,40 @@ fn base_can_withdraw_when_free_is_below_frozen_with_hold() {
144
144
assert_eq ! ( Balances :: reserved_balance( & CARLOS . into( ) ) , 2_000 * PLMC ) ;
145
145
} )
146
146
}
147
+
148
+ // Tests the behavior of transferring the dust to the Blockchain Operation Treasury.
149
+ // When an account's balance falls below the Existential Deposit (ED) threshold following a transfer,
150
+ // the account is killed and the dust is sent to the treasury.
151
+ #[ test]
152
+ fn dust_to_treasury ( ) {
153
+ PolimecBase :: execute_with ( || {
154
+ // Create two new accounts: a sender and a receiver.
155
+ let sender = get_account_id_from_seed :: < sr25519:: Public > ( "SENDER" ) ;
156
+ let receiver = get_account_id_from_seed :: < sr25519:: Public > ( "RECEIVER" ) ;
157
+
158
+ // Set the sender's initial balance to 1 PLMC.
159
+ let initial_sender_balance = 1 * PLMC ;
160
+ Balances :: set_balance ( & sender, initial_sender_balance) ;
161
+
162
+ // Get the total issuance and Treasury balance before the transfer.
163
+ let initial_total_issuance = Balances :: total_issuance ( ) ;
164
+ let initial_treasury_balance = Balances :: free_balance ( PayMaster :: get ( ) ) ;
165
+
166
+ // Transfer funds from sender to receiver, designed to deplete the sender's balance below the ED.
167
+ // The sender account will be killed and the dust will be sent to the treasury.
168
+ // This happens because at the end of the transfer, the user has free_balance < ED.
169
+ assert_ok ! ( Balances :: transfer_allow_death(
170
+ RuntimeOrigin :: signed( sender) ,
171
+ sp_runtime:: MultiAddress :: Id ( receiver) ,
172
+ initial_sender_balance - ED + 1
173
+ ) ) ;
174
+
175
+ // Confirm the total issuance remains unchanged post-transfer.
176
+ let post_total_issuance = Balances :: total_issuance ( ) ;
177
+ assert_eq ! ( initial_total_issuance, post_total_issuance) ;
178
+
179
+ // Verify the Treasury has received the dust from the sender's account.
180
+ let final_treasury_balance = Balances :: free_balance ( PayMaster :: get ( ) ) ;
181
+ assert_eq ! ( initial_treasury_balance + ED - 1 , final_treasury_balance) ;
182
+ } )
183
+ }
0 commit comments