Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Oct 4, 2024
1 parent 940b650 commit a27a9ec
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use entropy_protocol::{
};
use entropy_shared::{
HashingAlgorithm, DAVE_VERIFYING_KEY, DEFAULT_VERIFYING_KEY_NOT_REGISTERED, DEVICE_KEY_HASH,
EVE_VERIFYING_KEY, NETWORK_PARENT_KEY,
NETWORK_PARENT_KEY,
};
use entropy_testing_utils::{
chain_api::{
Expand Down
8 changes: 5 additions & 3 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async fn test_reshare() {

let block_number = TEST_RESHARE_BLOCK_NUMBER;
let onchain_reshare_request =
OcwMessageReshare { new_signer: new_signer.0.to_vec(), block_number };
OcwMessageReshare { new_signers: vec![new_signer.0.to_vec()], block_number };

run_to_block(&rpc, block_number + 1).await;
// Send the OCW message to all TS servers who don't have a chain node
Expand Down Expand Up @@ -323,7 +323,8 @@ async fn test_reshare_validation_fail() {
let kv = setup_client().await;

let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let mut ocw_message = OcwMessageReshare { new_signer: dave.public().encode(), block_number };
let mut ocw_message =
OcwMessageReshare { new_signers: vec![dave.public().encode()], block_number };

let err_stale_data =
validate_new_reshare(&api, &rpc, &ocw_message, &kv).await.map_err(|e| e.to_string());
Expand Down Expand Up @@ -361,7 +362,8 @@ async fn test_reshare_validation_fail_not_in_reshare() {
let kv = setup_client().await;

let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let ocw_message = OcwMessageReshare { new_signer: alice.public().encode(), block_number };
let ocw_message =
OcwMessageReshare { new_signers: vec![alice.public().encode()], block_number };

run_to_block(&rpc, block_number + 1).await;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ async fn do_reshare(api: &OnlineClient<EntropyConfig>, rpc: &LegacyRpcMethods<En

let block_number = TEST_RESHARE_BLOCK_NUMBER;
let onchain_reshare_request =
OcwMessageReshare { new_signer: new_signer.0.to_vec(), block_number };
OcwMessageReshare { new_signers: vec![new_signer.0.to_vec()], block_number };

run_to_block(&rpc, block_number + 1).await;
// Send the OCW message to all TS servers who don't have a chain node
Expand Down
19 changes: 6 additions & 13 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,13 @@ pub mod pallet {
// mocks a signer rotation for tss new_reshare tests
if self.mock_signer_rotate.0 {
let next_signers = &mut self.mock_signer_rotate.1.clone();
next_signers.push(self.mock_signer_rotate.2[0].clone());
let mut new_signers = vec![];
for new_signer in self.mock_signer_rotate.2.clone() {
next_signers.push(new_signer.clone());
new_signers.push(new_signer.encode())
}
let next_signers = next_signers.to_vec();
NextSigners::<T>::put(NextSignerInfo { next_signers, confirmations: vec![] });
let new_signers = self
.mock_signer_rotate
.clone()
.2
.into_iter()
.map(|x| x.encode())
.collect::<Vec<_>>();
ReshareData::<T>::put(ReshareInfo {
// To give enough time for test_reshare setup
block_number: TEST_RESHARE_BLOCK_NUMBER.into(),
Expand Down Expand Up @@ -730,11 +727,10 @@ pub mod pallet {
remove_indexs.push(i);
}
}
if remove_indexs.len() == 0 {
if remove_indexs.is_empty() {
current_signers.remove(0);
} else {
let remove_indexs_reversed: Vec<_> = remove_indexs.iter().rev().collect();
dbg!(remove_indexs_reversed.clone());
for remove_index in remove_indexs_reversed {
current_signers.remove(*remove_index);
}
Expand All @@ -746,13 +742,10 @@ pub mod pallet {
// grab a current signer to initiate value
let mut next_signer_up = &validators[0].clone();
let mut index;
dbg!(current_signers.clone());
// loops to find signer in validator that is not already signer
while current_signers.contains(next_signer_up) {
dbg!(current_signers.clone());
index = randomness.next_u32() % validators.len() as u32;
next_signer_up = &validators[index as usize];
dbg!(next_signer_up.clone());
count += 1;
}

Expand Down

0 comments on commit a27a9ec

Please sign in to comment.