From 7f3c7425a34c2b9b614f7ab936e47952571e4a6c Mon Sep 17 00:00:00 2001 From: Diana Popa Date: Sat, 27 Apr 2024 19:03:05 +0300 Subject: [PATCH] fix pallet-asset-conversion-tx-payment --- .../asset-conversion-tx-payment/src/tests.rs | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs index 62faed269d37..699a5508fc53 100644 --- a/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs +++ b/substrate/frame/transaction-payment/asset-conversion-tx-payment/src/tests.rs @@ -113,7 +113,7 @@ fn default_post_info() -> PostDispatchInfo { fn setup_lp(asset_id: u32, balance_factor: u64) { let lp_provider = 5; let ed = Balances::minimum_balance(); - let ed_asset = Assets::minimum_balance(asset_id); + let ed_asset = Assets::minimum_balance(&asset_id); assert_ok!(Balances::force_set_balance( RuntimeOrigin::root(), lp_provider, @@ -121,7 +121,7 @@ fn setup_lp(asset_id: u32, balance_factor: u64) { )); let lp_provider_account = ::Lookup::unlookup(lp_provider); assert_ok!(Assets::mint_into( - asset_id.into(), + &asset_id, &lp_provider_account, 10_000 * balance_factor + ed_asset )); @@ -217,8 +217,8 @@ fn transaction_payment_in_asset_possible() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let len = 10; let tx_weight = 5; @@ -227,15 +227,15 @@ fn transaction_payment_in_asset_possible() { let fee_in_native = base_weight + tx_weight + len as u64; let input_quote = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ); assert_eq!(input_quote, Some(201)); let fee_in_asset = input_quote.unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_5), len) @@ -244,7 +244,7 @@ fn transaction_payment_in_asset_possible() { assert_eq!(Balances::free_balance(caller), 10 * balance_factor); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -254,7 +254,7 @@ fn transaction_payment_in_asset_possible() { &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); assert_eq!(TipUnbalancedAmount::get(), 0); assert_eq!(FeeUnbalancedAmount::get(), fee_in_native); }); @@ -285,8 +285,8 @@ fn transaction_payment_in_asset_fails_if_no_pool_for_that_asset() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let len = 10; let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)).pre_dispatch( @@ -329,15 +329,15 @@ fn transaction_payment_without_fee() { // mint into the caller account let beneficiary = ::Lookup::unlookup(caller); - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 5; let len = 10; let fee_in_native = base_weight + weight + len as u64; let input_quote = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ); @@ -351,11 +351,11 @@ fn transaction_payment_without_fee() { // assert that native balance is not used assert_eq!(Balances::free_balance(caller), 10 * balance_factor); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); let refund = AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), fee_in_native, true, ) @@ -371,7 +371,7 @@ fn transaction_payment_without_fee() { )); // caller should get refunded - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset + refund); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset + refund); assert_eq!(Balances::free_balance(caller), 10 * balance_factor); }); } @@ -403,16 +403,16 @@ fn asset_transaction_payment_with_tip_and_refund() { let beneficiary = ::Lookup::unlookup(caller); let balance = 10000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 100; let tip = 5; let len = 10; let fee_in_native = base_weight + weight + len as u64 + tip; let input_quote = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ); @@ -422,13 +422,13 @@ fn asset_transaction_payment_with_tip_and_refund() { let pre = ChargeAssetTxPayment::::from(tip, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(WEIGHT_100), len) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); let final_weight = 50; let expected_fee = fee_in_native - final_weight - tip; let expected_token_refund = AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), fee_in_native - expected_fee - tip, true, ) @@ -447,7 +447,7 @@ fn asset_transaction_payment_with_tip_and_refund() { // caller should get refunded assert_eq!( - Assets::balance(asset_id, caller), + Assets::balance(&asset_id, caller), balance - fee_in_asset + expected_token_refund ); assert_eq!(Balances::free_balance(caller), 20 * balance_factor); @@ -481,8 +481,8 @@ fn payment_from_account_with_only_assets() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); // assert that native balance is not necessary assert_eq!(Balances::free_balance(caller), 0); @@ -492,8 +492,8 @@ fn payment_from_account_with_only_assets() { let fee_in_native = base_weight + weight + len as u64; let ed = Balances::minimum_balance(); let fee_in_asset = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native + ed, true, ) @@ -505,11 +505,11 @@ fn payment_from_account_with_only_assets() { .unwrap(); assert_eq!(Balances::free_balance(caller), ed); // check that fee was charged in the given asset - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); let refund = AssetConversion::quote_price_exact_tokens_for_tokens( - NativeOrWithId::Native, - NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), ed, true, ) @@ -522,7 +522,7 @@ fn payment_from_account_with_only_assets() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset + refund); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset + refund); assert_eq!(Balances::free_balance(caller), 0); assert_eq!(TipUnbalancedAmount::get(), 0); @@ -557,8 +557,8 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; @@ -569,7 +569,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { .pre_dispatch(&caller, CALL, &info_from_pays(Pays::No), len) .unwrap(); // `Pays::No` implies there are no fees - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -578,14 +578,15 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); } // validate even a small fee gets converted to asset. let fee_in_native = base_weight + weight + len as u64; + let fee_in_asset = AssetConversion::quote_price_tokens_for_exact_tokens( - NativeOrWithId::WithId(asset_id), - NativeOrWithId::Native, + &NativeOrWithId::WithId(asset_id), + &NativeOrWithId::Native, fee_in_native, true, ) @@ -594,7 +595,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { let pre = ChargeAssetTxPayment::::from(0, Some(asset_id)) .pre_dispatch(&caller, CALL, &info_from_weight(Weight::from_parts(weight, 0)), len) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); assert_ok!(ChargeAssetTxPayment::::post_dispatch( Some(pre), @@ -603,7 +604,7 @@ fn converted_fee_is_never_zero_if_input_fee_is_not() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance - fee_in_asset); + assert_eq!(Assets::balance(&asset_id, caller), balance - fee_in_asset); }); } @@ -631,8 +632,8 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; @@ -646,7 +647,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { .unwrap(); // `Pays::No` implies no pre-dispatch fees - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); let (_tip, _who, initial_payment, _asset_id) = ⪯ let not_paying = match initial_payment { @@ -664,7 +665,7 @@ fn post_dispatch_fee_is_zero_if_pre_dispatch_fee_is_zero() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); }); } @@ -692,8 +693,8 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { let beneficiary = ::Lookup::unlookup(caller); let balance = 1000; - assert_ok!(Assets::mint_into(asset_id.into(), &beneficiary, balance)); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_ok!(Assets::mint_into(&asset_id, &beneficiary, balance)); + assert_eq!(Assets::balance(&asset_id, caller), balance); let weight = 1; let len = 1; @@ -704,7 +705,7 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { ) .unwrap(); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); // `Pays::Yes` on post-dispatch does not mean we pay (we never charge more than the // initial fee) @@ -715,6 +716,6 @@ fn post_dispatch_fee_is_zero_if_unsigned_pre_dispatch_fee_is_zero() { len, &Ok(()) )); - assert_eq!(Assets::balance(asset_id, caller), balance); + assert_eq!(Assets::balance(&asset_id, caller), balance); }); }