@@ -13,6 +13,7 @@ use utils::{build_wasm_transction, RunUntilCondition, TestScenarioBuilder};
1313
1414use crate :: {
1515 reactor:: main_reactor:: tests:: {
16+ transaction_scenario:: asertions:: BalanceChange ,
1617 transactions:: {
1718 invalid_wasm_txn, ALICE_PUBLIC_KEY , ALICE_SECRET_KEY , BOB_PUBLIC_KEY , BOB_SECRET_KEY ,
1819 CHARLIE_PUBLIC_KEY , MIN_GAS_PRICE ,
@@ -98,19 +99,25 @@ async fn should_native_transfer_nofee_norefund_fixed() {
9899 Gas :: new ( expected_transfer_gas) ,
99100 ) )
100101 . await ;
102+
103+ let transfer_amount = U512 :: from ( TRANSFER_AMOUNT ) ;
104+ let transfer_amount_and_gas: U512 = transfer_amount
105+ . checked_add ( expected_transfer_gas)
106+ . expect ( "should math" ) ;
107+
101108 test_scenario
102109 . assert ( PublicKeyBalanceChange :: new (
103110 ALICE_PUBLIC_KEY . clone ( ) ,
104- - ( TRANSFER_AMOUNT as i64 ) ,
105- - ( ( TRANSFER_AMOUNT + expected_transfer_gas . as_u64 ( ) ) as i64 ) ,
111+ BalanceChange :: Down ( transfer_amount ) ,
112+ BalanceChange :: Down ( transfer_amount_and_gas ) ,
106113 ) )
107114 . await ;
108115 //Charlie should have the transfer amount at his disposal
109116 test_scenario
110117 . assert ( PublicKeyBalanceChange :: new (
111118 CHARLIE_PUBLIC_KEY . clone ( ) ,
112- TRANSFER_AMOUNT as i64 ,
113- TRANSFER_AMOUNT as i64 ,
119+ BalanceChange :: Up ( transfer_amount ) ,
120+ BalanceChange :: Up ( transfer_amount ) ,
114121 ) )
115122 . await ;
116123 // Check if the hold is released.
@@ -190,11 +197,17 @@ async fn erroneous_native_transfer_nofee_norefund_fixed() {
190197 . await ;
191198 // Even though the transaction failed, a hold must still be in place for the transfer cost.
192199 // The hold will show up in "available" being smaller than "total"
200+
201+ let transfer_amount_x = U512 :: from ( transfer_amount) ;
202+ let transfer_amount_y = transfer_amount_x
203+ . checked_sub ( U512 :: from ( expected_transfer_cost) )
204+ . expect ( "should sub transfer from transfer amount" ) ;
205+
193206 test_scenario
194207 . assert ( PublicKeyBalanceChange :: new (
195208 CHARLIE_PUBLIC_KEY . clone ( ) ,
196- transfer_amount as i64 ,
197- ( transfer_amount - expected_transfer_cost ) as i64 ,
209+ BalanceChange :: Up ( transfer_amount_x ) ,
210+ BalanceChange :: Up ( transfer_amount_y ) ,
198211 ) )
199212 . await ;
200213}
@@ -233,24 +246,20 @@ async fn should_cancel_refund_for_erroneous_wasm() {
233246 ) )
234247 . await ;
235248
236- test_scenario. assert ( TransactionFailure :: new ( hash) ) . await ; // transaction should have failed.
237- // Bob gets no refund because the wasm errored
249+ // transaction should have failed.
250+ test_scenario. assert ( TransactionFailure :: new ( hash) ) . await ;
251+
252+ let x = BalanceChange :: Down ( U512 :: from ( expected_transaction_cost) ) ;
253+ // Bob gets no refund because the wasm errored
238254 test_scenario
239- . assert ( PublicKeyBalanceChange :: new (
240- BOB_PUBLIC_KEY . clone ( ) ,
241- -( expected_transaction_cost as i64 ) ,
242- -( expected_transaction_cost as i64 ) ,
243- ) )
255+ . assert ( PublicKeyBalanceChange :: new ( BOB_PUBLIC_KEY . clone ( ) , x, x) )
244256 . await ;
245257
258+ let y = BalanceChange :: Up ( U512 :: from ( expected_transaction_cost) ) ;
246259 // Alice should get the all the fee since it's set to pay to proposer
247260 // AND Bob didn't get a refund
248261 test_scenario
249- . assert ( PublicKeyBalanceChange :: new (
250- ALICE_PUBLIC_KEY . clone ( ) ,
251- expected_transaction_cost as i64 ,
252- expected_transaction_cost as i64 ,
253- ) )
262+ . assert ( PublicKeyBalanceChange :: new ( ALICE_PUBLIC_KEY . clone ( ) , y, y) )
254263 . await ;
255264}
256265
@@ -291,19 +300,21 @@ async fn should_not_refund_erroneous_wasm_burn_fixed() {
291300 // Bobs transaction was invalid. He should get NO refund. But also -
292301 // since no refund is calculated nothing will be burned (despite
293302 // RefundHandling::Burn - we don't calculate refunds for erroneous wasms)
303+ let gas_limit_x = BalanceChange :: Down ( U512 :: from ( gas_limit) ) ;
294304 test_scenario
295305 . assert ( PublicKeyBalanceChange :: new (
296306 BOB_PUBLIC_KEY . clone ( ) ,
297- - ( gas_limit as i64 ) ,
298- - ( gas_limit as i64 ) ,
307+ gas_limit_x ,
308+ gas_limit_x ,
299309 ) )
300310 . await ;
311+ let gas_limit_y = BalanceChange :: Up ( U512 :: from ( gas_limit) ) ;
301312 // Alice gets payed for executing the transaction since it's set to pay to proposer
302313 test_scenario
303314 . assert ( PublicKeyBalanceChange :: new (
304315 ALICE_PUBLIC_KEY . clone ( ) ,
305- gas_limit as i64 ,
306- gas_limit as i64 ,
316+ gas_limit_y ,
317+ gas_limit_y ,
307318 ) )
308319 . await ;
309320}
0 commit comments