Skip to content

Commit

Permalink
Update test names and add more assertions
Browse files Browse the repository at this point in the history
- fix initial WeightInfo to be greater than zero before benchmarks
  have the chance to update this appropriately
  • Loading branch information
atodorov committed Aug 25, 2023
1 parent 59a7323 commit 50de22f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions pallets/creditcoin/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2935,6 +2935,9 @@ fn exercise_weightinfo_functions() {

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

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

#[test]
Expand Down Expand Up @@ -3238,24 +3241,17 @@ fn register_address_v2_should_error_with_unsupported_blockchain() {
});
}

use hex_literal::hex;

#[test]
fn set_burn_gate_contract_should_return_default_goerli_contract_when_not_set() {
fn gate_contract_storage_should_return_default_goerli_contract_when_not_set() {
ExtBuilder::default().build_and_execute(|| {
let contract: DeployedContract = Creditcoin::gate_contract();

assert_eq!(
contract.address,
sp_core::H160(hex!("a3EE21C306A700E682AbCdfe9BaA6A08F3820419"))
);

assert_eq!(contract.chain, Blockchain::Ethereum);
assert_eq!(contract, DeployedContract::default());
});
}

#[test]
fn set_burn_gate_contract_fails_with_non_root() {
fn set_gate_contract_should_fail_when_not_signed_by_root() {
ExtBuilder::default().build_and_execute(|| {
let acct: AccountId = AccountId::new([0; 32]);
let gate_contract = DeployedContract::default();
Expand All @@ -3265,14 +3261,16 @@ fn set_burn_gate_contract_fails_with_non_root() {
}

#[test]
fn set_burn_gate_contract_passes_and_storage_is_updated() {
fn set_gate_contract_passes_and_storage_is_updated() {
ExtBuilder::default().build_and_execute(|| {
let fake_address =
sp_core::H160([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);

let gate_contract =
DeployedContract { address: fake_address, chain: Blockchain::Luniverse };

assert_ne!(gate_contract, DeployedContract::default());
assert_eq!(Creditcoin::gate_contract(), DeployedContract::default());
assert_ok!(Creditcoin::set_gate_contract(RawOrigin::Root.into(), gate_contract));

let stored_contract = Creditcoin::gate_contract();
Expand Down
2 changes: 1 addition & 1 deletion pallets/creditcoin/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,6 @@ impl<T: frame_system::Config> crate::WeightInfo for WeightInfo<T> {
}

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

0 comments on commit 50de22f

Please sign in to comment.