Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion pallets/energy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,58 @@ fn existential_deposit_and_providers() {
});
}

// TODO Add a test for DustLost event

// Tests for DustLost 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

Expand Down