diff --git a/pallets/energy/src/lib.rs b/pallets/energy/src/lib.rs index f8e5d6e8..c62b0f38 100644 --- a/pallets/energy/src/lib.rs +++ b/pallets/energy/src/lib.rs @@ -386,10 +386,10 @@ pub mod pallet { let real_account = T::Lookup::lookup(real.clone())?; is_who_a_proxy = pallet_proxy::Pallet::::find_proxy(&real_account, who, None).is_ok(); - if is_who_a_proxy { - real_account - } else { - who.clone() + match is_who_a_proxy { + true if Self::energy_balance(&who) >= energy_fee => who.clone(), + true => real_account, + false => who.clone(), } } _ => who.clone(), diff --git a/pallets/energy/src/tests.rs b/pallets/energy/src/tests.rs index c8a621df..0c7770f9 100644 --- a/pallets/energy/src/tests.rs +++ b/pallets/energy/src/tests.rs @@ -363,6 +363,45 @@ fn charge_transaction_should_pay_with_energy_if_enough() { #[test] fn charge_transaction_should_pay_with_energy_if_proxy_caller() { + ExtBuilder::default().value_coefficient(2f64).build().execute_with(|| { + let real_account = account(1); + let proxy_account = account(2); + + assert_ok!(pallet_proxy::Pallet::::add_proxy_delegate( + &real_account, + proxy_account, + MockProxyType::Any, + Zero::zero(), + )); + + set_native_balance(proxy_account, 1000); + set_energy_balance(proxy_account, 1000); + + assert_ok!(charge_transaction_with_proxy(&proxy_account, real_account, 150, 100, 20, || { + // subtract the expected fees / coefficient from real account + assert_energy_balance!(proxy_account, 1000 - div_coeff!(150, 2)); + // tip subtracted from the native balance of proxy account + assert_balance!(proxy_account, 1000 - 20); + + assert!( + get_captured_withdraw_fee_args().is_none(), + "Shouldn't go through the fallback OnChargeTransaction" + ); + },),); + + assert_energy_balance!(proxy_account, 1000 - div_coeff!(100, 2)); + + // subtract the actual (fees + tip) / coefficient + assert_balance!(proxy_account, 1000 - 20); // tip subtracted from the native balance + assert!( + get_corrected_and_deposit_fee_args().is_none(), + "Shouldn't go through the fallback OnChargeTransaction" + ); + }); +} + +#[test] +fn charge_transaction_should_pay_with_real_account_energy_if_proxy_balance_low() { ExtBuilder::default().value_coefficient(2f64).build().execute_with(|| { let real_account = account(1); let proxy_account = account(2); diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index df077b74..2ab91fc2 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -189,7 +189,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("subsocial-parachain"), impl_name: create_runtime_str!("subsocial-parachain"), authoring_version: 1, - spec_version: 43, + spec_version: 44, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 9,