Skip to content

Commit

Permalink
Tests for registry pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Sep 16, 2024
1 parent 9c52270 commit 35b7068
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pallets/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,12 @@ pub mod pallet {
origin: OriginFor<T>,
verifying_key: VerifyingKey,
) -> DispatchResultWithPostInfo {
// Chack that the confirmation is coming from one of the selected validators
let ts_server_account = ensure_signed(origin)?;
let validator_stash =
pallet_staking_extension::Pallet::<T>::threshold_to_stash(&ts_server_account)
.ok_or(Error::<T>::NoThresholdKey)?;

// Check that the confirmation is coming from one of the selected validators
let (_block_number, selected_validators) =
JumpstartDkg::<T>::iter().last().ok_or(Error::<T>::JumpStartNotInProgress)?;
let selected_validators: Vec<_> =
Expand All @@ -295,10 +299,6 @@ pub mod pallet {
Error::<T>::JumpStartNotInProgress
);

let validator_stash =
pallet_staking_extension::Pallet::<T>::threshold_to_stash(&ts_server_account)
.ok_or(Error::<T>::NoThresholdKey)?;

ensure!(
!jump_start_info.confirmations.contains(&validator_stash),
Error::<T>::AlreadyConfirmed
Expand Down
33 changes: 24 additions & 9 deletions pallets/registry/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#[allow(unused)]
use pallet_registry::Call as RegistryCall;

use codec::Encode;
use entropy_shared::{NETWORK_PARENT_KEY, VERIFICATION_KEY_LENGTH};
use entropy_shared::{ValidatorInfo, VERIFICATION_KEY_LENGTH};
use frame_support::{assert_noop, assert_ok, BoundedVec};
use pallet_programs::ProgramInfo;
use pallet_staking_extension::{JumpStartDetails, JumpStartProgress, JumpStartStatus, ServerInfo};
Expand Down Expand Up @@ -300,7 +299,23 @@ fn it_jumps_the_network() {
assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1)));
assert_eq!(
Registry::jumpstart_dkg(0),
vec![NETWORK_PARENT_KEY.encode()],
vec![
ValidatorInfo {
x25519_public_key: [0; 32],
ip_address: vec![20],
tss_account: vec![7, 0, 0, 0, 0, 0, 0, 0]
},
ValidatorInfo {
x25519_public_key: [0; 32],
ip_address: vec![10],
tss_account: vec![3, 0, 0, 0, 0, 0, 0, 0]
},
ValidatorInfo {
x25519_public_key: [0; 32],
ip_address: vec![11],
tss_account: vec![4, 0, 0, 0, 0, 0, 0, 0]
},
],
"ensures a dkg message for the jump start network is prepped"
);
assert_eq!(
Expand Down Expand Up @@ -344,20 +359,20 @@ fn it_tests_jump_start_result() {
Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()),
Error::<Test>::NoThresholdKey
);
pallet_staking_extension::ThresholdToStash::<Test>::insert(1, 1);

pallet_staking_extension::ThresholdToStash::<Test>::insert(1, 1);
pallet_staking_extension::ThresholdToStash::<Test>::insert(7, 7);
assert_noop!(
Registry::confirm_jump_start(RuntimeOrigin::signed(7), expected_verifying_key.clone()),
Error::<Test>::NotValidator
);

assert_noop!(
Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()),
Error::<Test>::JumpStartNotInProgress
);

// trigger jump start
assert_ok!(Registry::jump_start_network(RuntimeOrigin::signed(1)));
assert_noop!(
Registry::confirm_jump_start(RuntimeOrigin::signed(1), expected_verifying_key.clone()),
Error::<Test>::NotValidator
);

assert_ok!(Registry::confirm_jump_start(
RuntimeOrigin::signed(1),
Expand Down

0 comments on commit 35b7068

Please sign in to comment.