Skip to content

Commit

Permalink
Ammend tests for set_gate_faucet()
Browse files Browse the repository at this point in the history
- more descriptive names
- assert on WeightInfo
- return WeightInfo > 0 to pass CI before benchmarks have the chance to
  update the weights with correct values
  • Loading branch information
atodorov committed Aug 25, 2023
1 parent 138b347 commit 9a3478c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions pallets/creditcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2938,6 +2938,9 @@ fn exercise_weightinfo_functions() {

let result = super::weights::WeightInfo::<Test>::set_gate_contract();
assert!(result.ref_time() > 0);

let result = super::weights::WeightInfo::<Test>::set_gate_faucet();
assert!(result.ref_time() > 0);
}

#[test]
Expand Down Expand Up @@ -3281,23 +3284,14 @@ fn set_gate_contract_passes_and_storage_is_updated() {
}

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

assert_noop!(Creditcoin::set_gate_faucet(Origin::signed(acct.clone()), acct), BadOrigin);
});
}

#[test]
fn gate_faucet_returns_none_when_not_set() {
ExtBuilder::default().build_and_execute(|| {
let gate_faucet = Creditcoin::gate_faucet_address();

assert!(gate_faucet.is_none());
});
}

#[test]
fn set_gate_faucet_passes_and_storage_is_updated() {
ExtBuilder::default().build_and_execute(|| {
Expand All @@ -3312,3 +3306,12 @@ fn set_gate_faucet_passes_and_storage_is_updated() {
assert_eq!(faucet_addr.unwrap(), addr)
});
}

#[test]
fn gate_faucet_address_storage_should_return_none_when_not_set() {
ExtBuilder::default().build_and_execute(|| {
let gate_faucet = Creditcoin::gate_faucet_address();

assert!(gate_faucet.is_none());
});
}
2 changes: 1 addition & 1 deletion pallets/creditcoin/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,6 @@ impl<T: frame_system::Config> crate::WeightInfo for WeightInfo<T> {
}

fn set_gate_faucet() -> Weight {
Weight::from_parts(0,0)
Weight::from_parts(1,1)
}
}

0 comments on commit 9a3478c

Please sign in to comment.