Skip to content

Commit

Permalink
Test: add/improve handover tests (#3959)
Browse files Browse the repository at this point in the history
* refactor: key verification callback registered internally

* feat: more precise comparison

* feat: differentiate between candidates and authorities in handover tests

* chore: deduplicate do_full_key_rotation in tests

* test: update test to do what is says

* test: check key verification request parameters

* feat: use log_or_panic

* test: all candidates participate in handover

* test: add missing vault rotator status checks

* chore: fix clippy

* test: fix incorrect assert
  • Loading branch information
msgmaxim authored Sep 8, 2023
1 parent 1645964 commit 57b2d5a
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 225 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion state-chain/pallets/cf-broadcast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub mod pallet {

let mut retries = BroadcastRetryQueue::<T, I>::take();

if retries.len() >= num_retries_that_fit {
if retries.len() > num_retries_that_fit {
BroadcastRetryQueue::<T, I>::put(retries.split_off(num_retries_that_fit));
}

Expand Down
1 change: 1 addition & 0 deletions state-chain/pallets/cf-threshold-signature/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ cf-chains = { path = '../../chains', default-features = false }
cf-primitives = { path = '../../primitives', default-features = false }
cf-runtime-upgrade-utilities = { path = '../../runtime-upgrade-utilities', default-features = false }
cf-traits = { path = '../../traits', default-features = false }
cf-runtime-utilities = { path = '../../runtime-utilities', default-features = false}

log = { version = '0.4.16', default-features = false }

Expand Down
13 changes: 11 additions & 2 deletions state-chain/pallets/cf-threshold-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use cf_traits::{
EpochKey, KeyProvider, ThresholdSignerNomination,
};

use cf_runtime_utilities::log_or_panic;
use frame_support::{
dispatch::UnfilteredDispatchable,
ensure,
Expand Down Expand Up @@ -823,11 +824,19 @@ where
participants: BTreeSet<Self::ValidatorId>,
key: <T::TargetChainCrypto as ChainCrypto>::AggKey,
epoch_index: EpochIndex,
on_signature_ready: impl FnOnce(cf_primitives::ThresholdSignatureRequestId) -> Self::Callback,
) -> RequestId {
Self::inner_request_signature(
let request_id = Self::inner_request_signature(
payload,
RequestType::KeygenVerification { key, participants, epoch_index },
)
);

if Self::register_callback(request_id, on_signature_ready(request_id)).is_err() {
// We should never fail to register a callback for a request that we just created.
log_or_panic!("Failed to register callback for request {}", request_id);
}

request_id
}

fn register_callback(
Expand Down
6 changes: 2 additions & 4 deletions state-chain/pallets/cf-threshold-signature/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,8 @@ fn keygen_verification_ceremony_calls_callback_on_failure() {
NOMINEES.into_iter().collect(),
key,
0,
MockCallback::new,
);
assert_ok!(EthereumThresholdSigner::register_callback(
request_id,
MockCallback::new(request_id)
));

// Callback was just registered, so cannot have been called.
assert!(!MockCallback::has_executed(request_id));
Expand Down Expand Up @@ -498,6 +495,7 @@ mod unsigned_validation {
participants,
CUSTOM_AGG_KEY,
0,
MockCallback::new,
);
let ceremony_id = MockCeremonyIdProvider::get();

Expand Down
9 changes: 1 addition & 8 deletions state-chain/pallets/cf-vaults/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,16 +893,9 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
participants,
new_agg_key,
next_epoch,
signature_callback_fn,
);

T::ThresholdSigner::register_callback(request_id, signature_callback_fn(request_id))
.unwrap_or_else(|e| {
log::error!(
"Unable to register threshold signature callback. This should not be possible. Error: '{:?}'",
e.into()
);
});

PendingVaultRotation::<T, I>::put(status_to_set);

request_id
Expand Down
Loading

0 comments on commit 57b2d5a

Please sign in to comment.