From 64ea0a2059f678541dce32a3df909f0fee6b05d1 Mon Sep 17 00:00:00 2001 From: Tarek Mohamed Abdalla Date: Thu, 30 Mar 2023 00:25:53 +0200 Subject: [PATCH 1/2] review --- pallets/energy/src/tests.rs | 53 ++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/pallets/energy/src/tests.rs b/pallets/energy/src/tests.rs index 1b637252..47adb5a8 100644 --- a/pallets/energy/src/tests.rs +++ b/pallets/energy/src/tests.rs @@ -572,7 +572,58 @@ fn existential_deposit_and_providers() { }); } -// TODO Add a test for DustLost event + +///// tests for dust lost event + +#[test] +fn dust_lost_should_not_be_emitted_when_ed_is_zero() { + ExtBuilder::default() + .energy_existential_deposit(0) + .build() + .execute_with(|| { + let account = 1; + set_energy_balance(account, 100); + + assert_ok!(charge_transaction(&account, 100, 100, 0, || {})); + + assert!(!System::events() + .iter() + .any(|record| matches!(record.event, RuntimeEvent::Energy(EnergyEvent::DustLost { .. })))); + }); +} + +#[test] +fn dust_lost_should_not_be_emitted_when_energy_still_above_ed() { + ExtBuilder::default() + .energy_existential_deposit(10) + .build() + .execute_with(|| { + let account = 1; + set_energy_balance(account, 100); + + assert_ok!(charge_transaction(&account, 90, 90, 0, || {})); + + assert!(!System::events() + .iter() + .any(|record| matches!(record.event, RuntimeEvent::Energy(EnergyEvent::DustLost { .. })))); + }); +} + +#[test] +fn dust_lost_should_be_emitted_when_energy_still_below_ed() { + ExtBuilder::default() + .energy_existential_deposit(10) + .build() + .execute_with(|| { + let account = 1; + set_energy_balance(account, 100); + + assert_ok!(charge_transaction(&account, 98, 98, 0, || {})); + + System::assert_has_event(EnergyEvent::DustLost { account, amount: 2 }.into()); + }); +} + ///// test native_token_to_energy From 220f1b4fcd50e67a30bad589f59cb8c70cc7cb26 Mon Sep 17 00:00:00 2001 From: Vlad Proshchavaiev <32250097+F3Joule@users.noreply.github.com> Date: Fri, 5 Jan 2024 16:23:10 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- pallets/energy/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/energy/src/tests.rs b/pallets/energy/src/tests.rs index 47adb5a8..34062636 100644 --- a/pallets/energy/src/tests.rs +++ b/pallets/energy/src/tests.rs @@ -573,7 +573,7 @@ fn existential_deposit_and_providers() { } -///// tests for dust lost event +// Tests for DustLost event #[test] fn dust_lost_should_not_be_emitted_when_ed_is_zero() {