Skip to content

Commit

Permalink
Add unit tests for burn_all() extrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Dec 15, 2023
1 parent 4141072 commit cfc0d97
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pallets/creditcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3329,3 +3329,31 @@ fn gate_faucet_account_storage_should_return_none_when_not_set() {
assert!(gate_faucet.is_none());
});
}

#[test]
fn burn_all_should_error_when_not_signed() {
ExtBuilder::default().build_and_execute(|| {
let acct: AccountId = AccountId::new([0; 32]);

assert_noop!(Creditcoin::burn_all(Origin::none(), acct), BadOrigin);
});
}

#[test]
fn burn_all_should_emit_event_and_update_storage_when_ok() {
ExtBuilder::default().build_and_execute(|| {
let acct: AccountId = AccountId::new([0; 32]);

// no funds have been burned
assert_eq!(crate::BurnedFunds::<Test>::count(), 0);

assert_ok!(Creditcoin::burn_all(Origin::signed(acct.clone()), acct));
assert_eq!(crate::BurnedFunds::<Test>::count(), 1); // burn has been registered

let event = <frame_system::Pallet<Test>>::events().pop().expect("expected an event").event;
assert_matches!(event, crate::mock::RuntimeEvent::Creditcoin(crate::Event::Burned(burn_id))=>{
let burn_info = crate::BurnedFunds::<Test>::try_get(burn_id).unwrap();

Check failure on line 3355 in pallets/creditcoin/src/tests.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused variable: `burn_info`

Check warning on line 3355 in pallets/creditcoin/src/tests.rs

View workflow job for this annotation

GitHub Actions / unit-test-creditcoin

unused variable: `burn_info`
// assert on burn_info
});
});
}

0 comments on commit cfc0d97

Please sign in to comment.