Skip to content

Commit

Permalink
Fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ameba23 committed Nov 25, 2024
1 parent 170b5cc commit 04b8309
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
10 changes: 9 additions & 1 deletion crates/threshold-signature-server/src/helpers/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ use crate::helpers::tests::entropy::runtime_types::bounded_collections::bounded_
use crate::{
app,
chain_api::{
entropy::{self, runtime_types::pallet_staking_extension::pallet::JumpStartStatus},
entropy::{
self,
runtime_types::pallet_staking_extension::pallet::{JumpStartStatus, ServerInfo},
},
EntropyConfig,
},
get_signer,
Expand Down Expand Up @@ -360,3 +363,8 @@ async fn put_jumpstart_request_on_chain(
let registering_tx = entropy::tx().registry().jump_start_network();
submit_transaction(api, rpc, &account, &registering_tx, None).await.unwrap();
}

/// Given a ServerInfo, get the port number
pub fn get_port(server_info: &ServerInfo<SubxtAccountId32>) -> u32 {
std::str::from_utf8(&server_info.endpoint).unwrap().split(":").last().unwrap().parse().unwrap()
}
53 changes: 38 additions & 15 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use entropy_testing_utils::{
},
helpers::spawn_tss_nodes_and_start_chain,
substrate_context::{test_context_stationary, testing_context},
ChainSpecType,
test_node_process_testing_state, ChainSpecType,
};
use more_asserts as ma;
use parity_scale_codec::{Decode, Encode};
Expand All @@ -69,7 +69,6 @@ use synedrion::k256::ecdsa::{RecoveryId, Signature as k256Signature, VerifyingKe
use synedrion::{ecdsa::VerifyingKey as SynedrionVerifyingKey, DeriveChildKey};
use tokio_tungstenite::connect_async;

use crate::helpers::tests::do_jump_start;
use crate::{
chain_api::{
entropy, entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec,
Expand All @@ -87,8 +86,8 @@ use crate::{
signing::Hasher,
substrate::{get_oracle_data, get_signers_from_chain, query_chain, submit_transaction},
tests::{
initialize_test_logger, run_to_block, setup_client, store_program_and_register,
unsafe_get,
do_jump_start, get_port, initialize_test_logger, run_to_block, setup_client,
spawn_testing_validators, store_program_and_register, unsafe_get,
},
user::compute_hash,
validator::get_signer_and_x25519_secret_from_mnemonic,
Expand Down Expand Up @@ -577,8 +576,16 @@ async fn test_request_limit_are_updated_during_signing() {
let one = AccountKeyring::One;
let two = AccountKeyring::Two;

let (_ctx, entropy_api, rpc, _validator_ips, _validator_ids) =
spawn_tss_nodes_and_start_chain(ChainSpecType::IntegrationJumpStarted).await;
let (_validator_ips, _validator_ids) =
spawn_testing_validators(crate::helpers::tests::ChainSpecType::IntegrationJumpStarted)
.await;

let force_authoring = true;
let context =
test_node_process_testing_state(ChainSpecType::IntegrationJumpStarted, force_authoring)
.await;
let entropy_api = get_api(&context[0].ws_url).await.unwrap();
let rpc = get_rpc(&context[0].ws_url).await.unwrap();

let non_signer = ValidatorName::Dave;
let (relayer_ip_and_key, _) =
Expand Down Expand Up @@ -850,23 +857,39 @@ async fn test_jumpstart_network() {
initialize_test_logger().await;
clean_tests();

let (_ctx, api, rpc, _validator_ips, _validator_ids) =
spawn_tss_nodes_and_start_chain(ChainSpecType::Integration).await;
let (_validator_ips, _validator_ids) =
spawn_testing_validators(crate::helpers::tests::ChainSpecType::Integration).await;

let force_authoring = true;
let context =
test_node_process_testing_state(ChainSpecType::Integration, force_authoring).await;
let api = get_api(&context[0].ws_url).await.unwrap();
let rpc = get_rpc(&context[0].ws_url).await.unwrap();

do_jump_start(&api, &rpc, AccountKeyring::Alice.pair()).await;

let signer_query = entropy::storage().staking_extension().signers();
let signer_stash_accounts = query_chain(&api, &rpc, signer_query, None).await.unwrap().unwrap();
let client = reqwest::Client::new();
let response_key = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await;
let mut verifying_key = Vec::new();
for signer in signer_stash_accounts.iter() {
let query = entropy::storage().staking_extension().threshold_servers(signer);
let server_info = query_chain(&api, &rpc, query, None).await.unwrap().unwrap();
let response_key =
unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), get_port(&server_info)).await;

// check to make sure keyshare is correct
let key_share: Option<KeyShareWithAuxInfo> =
entropy_kvdb::kv_manager::helpers::deserialize(&response_key);
assert!(key_share.is_some());

verifying_key =
key_share.unwrap().0.verifying_key().to_encoded_point(true).as_bytes().to_vec();
}

// check to make sure keyshare is correct
let key_share: Option<KeyShareWithAuxInfo> =
entropy_kvdb::kv_manager::helpers::deserialize(&response_key);
assert_eq!(key_share.is_some(), true);
let jump_start_progress_query = entropy::storage().staking_extension().jump_start_progress();
let jump_start_progress =
query_chain(&api, &rpc, jump_start_progress_query, None).await.unwrap().unwrap();
let verifying_key =
key_share.unwrap().0.verifying_key().to_encoded_point(true).as_bytes().to_vec();

assert_eq!(jump_start_progress.verifying_key.unwrap().0, verifying_key);
clean_tests();
Expand Down
16 changes: 5 additions & 11 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
helpers::{
launch::{FORBIDDEN_KEYS, LATEST_BLOCK_NUMBER_RESHARE},
tests::{
initialize_test_logger, run_to_block, setup_client, spawn_testing_validators,
get_port, initialize_test_logger, run_to_block, setup_client, spawn_testing_validators,
unsafe_get,
},
},
Expand All @@ -26,10 +26,7 @@ use crate::{
errors::ValidatorErr,
},
};
use entropy_client::{
self as test_client,
chain_api::entropy::runtime_types::pallet_staking_extension::pallet::ServerInfo,
};
use entropy_client::{self as test_client};
use entropy_client::{
chain_api::{
entropy, entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec,
Expand Down Expand Up @@ -178,7 +175,9 @@ async fn test_reshare_none_called() {
initialize_test_logger().await;
clean_tests();

// let _cxt = test_node_process_testing_state(true).await;
let force_authoring = true;
let _context =
test_node_process_testing_state(ChainSpecType::Integration, force_authoring).await;

let (_validator_ips, _validator_ids) =
spawn_testing_validators(crate::helpers::tests::ChainSpecType::Integration).await;
Expand Down Expand Up @@ -336,8 +335,3 @@ async fn test_deletes_key() {
assert!(!has_key);
clean_tests();
}

/// Given a ServerInfo, get the port number
fn get_port(server_info: &ServerInfo<AccountId32>) -> u32 {
std::str::from_utf8(&server_info.endpoint).unwrap().split(":").last().unwrap().parse().unwrap()
}

0 comments on commit 04b8309

Please sign in to comment.