Skip to content

Commit

Permalink
remove Test reshare block
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Dec 16, 2024
1 parent 246351d commit 346d664
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 38 deletions.
3 changes: 0 additions & 3 deletions crates/shared/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,5 @@ pub const MAX_SIGNERS: u8 = 15;
/// Threshold for those signers
pub const SIGNER_THRESHOLD: u8 = 2;

/// For testing to line up chain mock data and reshare_test
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 10;

/// Program version number, must be incremented if version number changes
pub const PROGRAM_VERSION_NUMBER: u8 = 0;
35 changes: 31 additions & 4 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async fn test_reshare_basic() {
let api = get_api(&context[0].ws_url).await.unwrap();
let rpc = get_rpc(&context[0].ws_url).await.unwrap();
let alice_stash = AccountKeyring::AliceStash;
let dave_stash = AccountKeyring::DaveStash;
let client = reqwest::Client::new();

// Get current signers
Expand All @@ -96,6 +97,27 @@ async fn test_reshare_basic() {
let key_share = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), port).await;
assert!(!key_share.is_empty());
}
next_signers.remove(0);
let binding = dave_stash.to_account_id().into();
next_signers.push(&binding);
let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let storage_address_next_signers = entropy::storage().staking_extension().next_signers();
let value_next_signers =
NextSignerInfo { confirmations: vec![], next_signers: next_signers.clone() };
// Add reshare
let call = RuntimeCall::System(SystemsCall::set_storage {
items: vec![(storage_address_next_signers.to_root_bytes(), value_next_signers.encode())],
});
call_set_storage(&api, &rpc, call).await;

let storage_address_reshare_data = entropy::storage().staking_extension().reshare_data();
let value_reshare_info =
ReshareInfo { block_number, new_signers: vec![dave_stash.public().encode()] };
// Add reshare
let call = RuntimeCall::System(SystemsCall::set_storage {
items: vec![(storage_address_reshare_data.to_root_bytes(), value_reshare_info.encode())],
});
call_set_storage(&api, &rpc, call).await;

let key_share_before = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3002).await;

Expand All @@ -110,7 +132,7 @@ async fn test_reshare_basic() {
if new_signer_ids != old_signer_ids {
break Ok(new_signer_ids);
}
if i > 120 {
if i > 240 {
break Err("Timed out waiting for reshare");
}
i += 1;
Expand Down Expand Up @@ -187,8 +209,12 @@ async fn test_reshare_basic() {
let key_share = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), port).await;
assert!(!key_share.is_empty());
}
let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 2;
let key_share_before_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3002).await;
let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let key_share_before_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3003).await;

next_signers.remove(0);
let binding = alice_stash.to_account_id().into();
next_signers.push(&binding);

let storage_address_next_signers = entropy::storage().staking_extension().next_signers();
let value_next_signers = NextSignerInfo { confirmations: vec![], next_signers };
Expand All @@ -210,7 +236,7 @@ async fn test_reshare_basic() {
// wait for roatate keyshare
tokio::time::sleep(std::time::Duration::from_secs(60)).await;

let key_share_after_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3002).await;
let key_share_after_2 = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3003).await;
assert_ne!(key_share_before_2, key_share_after_2);

clean_tests();
Expand Down Expand Up @@ -266,6 +292,7 @@ async fn test_reshare_validation_fail() {
assert_eq!(err_stale_data, Err("Data is stale".to_string()));

let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;

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

Expand Down
1 change: 0 additions & 1 deletion node/cli/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ pub fn development_genesis_config(
})
.collect::<Vec<_>>(),
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
jump_started_signers: None,
},
"elections": ElectionsConfig {
Expand Down
6 changes: 0 additions & 6 deletions node/cli/src/chain_spec/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ pub fn integration_tests_config(jumpstarted: bool) -> ChainSpec {
],
vec![],
get_account_id_from_seed::<sr25519::Public>("Alice"),
vec![
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
],
jump_started_signers,
))
.build()
Expand All @@ -87,7 +83,6 @@ pub fn integration_tests_genesis_config(
)>,
initial_nominators: Vec<AccountId>,
root_key: AccountId,
mock_signer_rotate_data: Vec<AccountId>,
jump_started_signers: Option<Vec<AccountId>>,
) -> serde_json::Value {
// Note that any endowed_accounts added here will be included in the `elections` and
Expand Down Expand Up @@ -229,7 +224,6 @@ pub fn integration_tests_genesis_config(
],
vec![PREGENERATED_NETWORK_VERIFYING_KEY.to_vec(), DAVE_VERIFYING_KEY.to_vec()],
),
mock_signer_rotate: (true, mock_signer_rotate_data, vec![get_account_id_from_seed::<sr25519::Public>("Dave//stash")]),
jump_started_signers,
},
"elections": ElectionsConfig {
Expand Down
1 change: 0 additions & 1 deletion node/cli/src/chain_spec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ pub fn testnet_genesis_config(
})
.collect::<Vec<_>>(),
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
jump_started_signers: None,
},
"elections": ElectionsConfig {
Expand Down
1 change: 0 additions & 1 deletion pallets/attestation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(5, (0, NULL_ARR, vec![20], pck_encoded.to_vec().try_into().unwrap())),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
jump_started_signers: None,
};
pallet_staking_extension.assimilate_storage(&mut t).unwrap();
Expand Down
1 change: 0 additions & 1 deletion pallets/propagation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(2, (4, NULL_ARR, vec![11], BoundedVec::with_max_capacity())),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
jump_started_signers: None,
};

Expand Down
1 change: 0 additions & 1 deletion pallets/registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(7, (4, NULL_ARR, vec![50], BoundedVec::with_max_capacity())),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
jump_started_signers: None,
};

Expand Down
20 changes: 1 addition & 19 deletions pallets/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use sp_staking::SessionIndex;
pub mod pallet {
use entropy_shared::{
QuoteContext, ValidatorInfo, X25519PublicKey, MAX_SIGNERS,
PREGENERATED_NETWORK_VERIFYING_KEY, TEST_RESHARE_BLOCK_NUMBER, VERIFICATION_KEY_LENGTH,
PREGENERATED_NETWORK_VERIFYING_KEY, VERIFICATION_KEY_LENGTH,
};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo},
Expand Down Expand Up @@ -262,8 +262,6 @@ pub mod pallet {
pub threshold_servers: Vec<ThresholdServersConfig<T>>,
/// validator info and accounts to take part in proactive refresh
pub proactive_refresh_data: (Vec<ValidatorInfo>, Vec<Vec<u8>>),
/// validator info and account new signer to take part in a reshare
pub mock_signer_rotate: (bool, Vec<T::ValidatorId>, Vec<T::ValidatorId>),
/// Whether to begin in an already jumpstarted state in order to be able to test signing
/// using pre-generated keyshares
pub jump_started_signers: Option<Vec<T::ValidatorId>>,
Expand Down Expand Up @@ -295,22 +293,6 @@ pub mod pallet {
proactive_refresh_keys: self.proactive_refresh_data.1.clone(),
};
ProactiveRefresh::<T>::put(refresh_info);
// 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();
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![] });
ReshareData::<T>::put(ReshareInfo {
// To give enough time for test_reshare setup
block_number: TEST_RESHARE_BLOCK_NUMBER.into(),
new_signers,
})
}

if let Some(jump_started_signers) = &self.jump_started_signers {
Signers::<T>::put(jump_started_signers.clone());
Expand Down
1 change: 0 additions & 1 deletion pallets/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
(6, (8, NULL_ARR, vec![40], BoundedVec::with_max_capacity())),
],
proactive_refresh_data: (vec![], vec![]),
mock_signer_rotate: (false, vec![], vec![]),
jump_started_signers: None,
};
pallet_balances.assimilate_storage(&mut t).unwrap();
Expand Down

0 comments on commit 346d664

Please sign in to comment.