diff --git a/crates/testing-utils/src/constants.rs b/crates/testing-utils/src/constants.rs index 8a377e462..ada142829 100644 --- a/crates/testing-utils/src/constants.rs +++ b/crates/testing-utils/src/constants.rs @@ -32,6 +32,8 @@ lazy_static! { hex!["2cbc68e8bf0fbc1c28c282d1263fc9d29267dc12a1044fb730e8b65abc37524c"].into(), // Charlie - from DEFAULT_CHARLIE_MNEMONIC in entropy_tss::helpers::launch hex!["946140d3d5ddb980c74ffa1bb64353b5523d2d77cdf3dc617fd63de9d3b66338"].into(), + // Dave - from DEFAULT_DAVE_MNEMONIC in entropy_tss::helpers::launch + hex!["0a9054ef6b6b8ad0dd2c89895b2515583f2fbf1edced68e7328ae456d86b9402"].into(), ]; // See entropy_tss::helpers::validator::get_signer_and_x25519_secret for how these are derived @@ -57,6 +59,13 @@ lazy_static! { ] .try_into() .unwrap(), + // Dave - from DEFAULT_DAVE_MNEMONIC in entropy_tss::helpers::launch + vec![ + 165, 202, 97, 104, 222, 190, 168, 183, 231, 63, 209, 233, 19, 185, 187, 200, 10, 29, 102, + 240, 39, 50, 140, 15, 124, 112, 94, 121, 44, 182, 40, 71 + ] + .try_into() + .unwrap() ]; } diff --git a/crates/testing-utils/src/helpers.rs b/crates/testing-utils/src/helpers.rs new file mode 100644 index 000000000..60194a153 --- /dev/null +++ b/crates/testing-utils/src/helpers.rs @@ -0,0 +1,54 @@ +// Copyright (C) 2023 Entropy Cryptography Inc. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +use crate::{ + chain_api::{get_api, get_rpc, EntropyConfig}, + spawn_testing_validators, + substrate_context::{test_context_stationary, test_node_process_testing_state}, + ChainSpecType, +}; +use entropy_protocol::PartyId; +use subxt::{backend::legacy::LegacyRpcMethods, OnlineClient}; + +/// A helper for setting up tests which starts both a set of TS servers and a chain node and returns +/// the chain API as well as IP addresses and PartyId of the started validators +pub async fn spawn_tss_nodes_and_start_chain( + add_parent_key: bool, + chain_spec_type: ChainSpecType, +) -> (OnlineClient, LegacyRpcMethods, Vec, Vec) { + let (validator_ips, validator_ids) = + spawn_testing_validators(add_parent_key, chain_spec_type.clone()).await; + + let (api, rpc) = match chain_spec_type { + ChainSpecType::Development => { + let substrate_context = test_context_stationary().await; + ( + get_api(&substrate_context.node_proc.ws_url).await.unwrap(), + get_rpc(&substrate_context.node_proc.ws_url).await.unwrap(), + ) + }, + ChainSpecType::Integration => { + // Here we need to use `--chain=integration-tests` and force authoring otherwise we won't be + // able to get our chain in the right state to be jump started. + let force_authoring = true; + let substrate_context = test_node_process_testing_state(force_authoring).await; + ( + get_api(&substrate_context.ws_url).await.unwrap(), + get_rpc(&substrate_context.ws_url).await.unwrap(), + ) + }, + }; + (api, rpc, validator_ips, validator_ids) +} diff --git a/crates/testing-utils/src/lib.rs b/crates/testing-utils/src/lib.rs index 8da2a5cda..22329cb1c 100644 --- a/crates/testing-utils/src/lib.rs +++ b/crates/testing-utils/src/lib.rs @@ -19,10 +19,11 @@ extern crate lazy_static; pub use entropy_tss::chain_api; pub mod constants; pub mod create_test_keyshares; +pub mod helpers; mod node_proc; pub mod substrate_context; pub use entropy_tss::helpers::tests::{ - jump_start_network_with_signer as jump_start_network, spawn_testing_validators, + jump_start_network_with_signer as jump_start_network, spawn_testing_validators, ChainSpecType, }; pub use node_proc::TestNodeProcess; pub use substrate_context::*; diff --git a/crates/threshold-signature-server/src/attestation/tests.rs b/crates/threshold-signature-server/src/attestation/tests.rs index fb31117b9..6dc8a495c 100644 --- a/crates/threshold-signature-server/src/attestation/tests.rs +++ b/crates/threshold-signature-server/src/attestation/tests.rs @@ -16,7 +16,7 @@ use crate::{ chain_api::{entropy, get_api, get_rpc}, helpers::{ substrate::query_chain, - tests::{initialize_test_logger, run_to_block, spawn_testing_validators}, + tests::{initialize_test_logger, run_to_block, spawn_testing_validators, ChainSpecType}, }, }; use entropy_kvdb::clean_tests; @@ -32,7 +32,9 @@ async fn test_attest() { clean_tests(); let cxt = test_node_process_stationary().await; - let (_validator_ips, _validator_ids) = spawn_testing_validators(false).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(false, ChainSpecType::Integration).await; + let api = get_api(&cxt.ws_url).await.unwrap(); let rpc = get_rpc(&cxt.ws_url).await.unwrap(); diff --git a/crates/threshold-signature-server/src/helpers/tests.rs b/crates/threshold-signature-server/src/helpers/tests.rs index e684e491d..e754a8f88 100644 --- a/crates/threshold-signature-server/src/helpers/tests.rs +++ b/crates/threshold-signature-server/src/helpers/tests.rs @@ -42,7 +42,6 @@ use entropy_kvdb::{encrypted_sled::PasswordMethod, get_db_path, kv_manager::KvMa use entropy_protocol::PartyId; use entropy_shared::{DAVE_VERIFYING_KEY, EVE_VERIFYING_KEY, NETWORK_PARENT_KEY}; use std::time::Duration; - use subxt::{ backend::legacy::LegacyRpcMethods, ext::sp_core::sr25519, tx::PairSigner, utils::AccountId32 as SubxtAccountId32, Config, OnlineClient, @@ -119,10 +118,29 @@ pub async fn create_clients( (app, kv_store) } -/// Spawn 3 TSS nodes with pre-stored keyshares -pub async fn spawn_testing_validators(add_parent_key: bool) -> (Vec, Vec) { +/// A way to specify which chainspec to use in testing +#[derive(Clone, PartialEq)] +pub enum ChainSpecType { + /// The development chainspec, which has 3 TSS nodes + Development, + /// The integration test chainspec, which has 4 TSS nodes + Integration, +} + +/// Spawn either 3 or 4 TSS nodes depending on chain configuration, adding pre-stored keyshares if +/// desired +pub async fn spawn_testing_validators( + add_parent_key: bool, + chain_spec_type: ChainSpecType, +) -> (Vec, Vec) { + let add_fourth_server = chain_spec_type == ChainSpecType::Integration; + // spawn threshold servers - let ports = [3001i64, 3002, 3003]; + let mut ports = vec![3001i64, 3002, 3003]; + + if add_fourth_server { + ports.push(3004); + } let (alice_axum, alice_kv) = create_clients("validator1".to_string(), vec![], vec![], &Some(ValidatorName::Alice)).await; @@ -143,11 +161,12 @@ pub async fn spawn_testing_validators(add_parent_key: bool) -> (Vec, Vec *get_signer(&charlie_kv).await.unwrap().account_id().clone().as_ref(), )); - let ids = vec![alice_id, bob_id, charlie_id]; + let mut ids = vec![alice_id, bob_id, charlie_id]; put_keyshares_in_db("alice", alice_kv, add_parent_key).await; put_keyshares_in_db("bob", bob_kv, add_parent_key).await; put_keyshares_in_db("charlie", charlie_kv, add_parent_key).await; + // Don't give dave keyshares as dave is not initially in the signing committee let listener_alice = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", ports[0])) .await @@ -170,6 +189,23 @@ pub async fn spawn_testing_validators(add_parent_key: bool) -> (Vec, Vec axum::serve(listener_charlie, charlie_axum).await.unwrap(); }); + if add_fourth_server { + let (dave_axum, dave_kv) = + create_clients("validator4".to_string(), vec![], vec![], &Some(ValidatorName::Dave)) + .await; + + let listener_dave = tokio::net::TcpListener::bind(format!("0.0.0.0:{}", ports[3])) + .await + .expect("Unable to bind to given server address."); + tokio::spawn(async move { + axum::serve(listener_dave, dave_axum).await.unwrap(); + }); + let dave_id = PartyId::new(SubxtAccountId32( + *get_signer(&dave_kv).await.unwrap().account_id().clone().as_ref(), + )); + ids.push(dave_id); + } + tokio::time::sleep(Duration::from_secs(1)).await; let ips = ports.iter().map(|port| format!("127.0.0.1:{port}")).collect(); diff --git a/crates/threshold-signature-server/src/signing_client/tests.rs b/crates/threshold-signature-server/src/signing_client/tests.rs index b4a9ee4ff..63cc8f6b3 100644 --- a/crates/threshold-signature-server/src/signing_client/tests.rs +++ b/crates/threshold-signature-server/src/signing_client/tests.rs @@ -20,7 +20,7 @@ use crate::{ launch::LATEST_BLOCK_NUMBER_PROACTIVE_REFRESH, tests::{ initialize_test_logger, run_to_block, setup_client, spawn_testing_validators, - unsafe_get, + unsafe_get, ChainSpecType, }, }, }; @@ -45,7 +45,8 @@ async fn test_proactive_refresh() { clean_tests(); let _cxt = test_node_process_testing_state(false).await; - let (validator_ips, _ids) = spawn_testing_validators(false).await; + let (validator_ips, _ids) = spawn_testing_validators(false, ChainSpecType::Integration).await; + let signing_committee_ips = &validator_ips[..3].to_vec(); let client = reqwest::Client::new(); @@ -78,14 +79,14 @@ async fn test_proactive_refresh() { }; let test_fail_incorrect_data = - submit_transaction_requests(validator_ips.clone(), ocw_message.clone()).await; + submit_transaction_requests(signing_committee_ips.clone(), ocw_message.clone()).await; for res in test_fail_incorrect_data { assert_eq!(res.unwrap().text().await.unwrap(), "Proactive Refresh data incorrect"); } ocw_message.validators_info[0].x25519_public_key = X25519_PUBLIC_KEYS[0]; let test_user_res = - submit_transaction_requests(validator_ips.clone(), ocw_message.clone()).await; + submit_transaction_requests(signing_committee_ips.clone(), ocw_message.clone()).await; for res in test_user_res { assert_eq!(res.unwrap().text().await.unwrap(), ""); @@ -104,7 +105,7 @@ async fn test_proactive_refresh() { ocw_message.validators_info[2].tss_account = alice.public().encode(); let test_user_res_not_in_group = - submit_transaction_requests(validator_ips.clone(), ocw_message.clone()).await; + submit_transaction_requests(signing_committee_ips.clone(), ocw_message.clone()).await; for res in test_user_res_not_in_group { assert_eq!( res.unwrap().text().await.unwrap(), diff --git a/crates/threshold-signature-server/src/user/tests.rs b/crates/threshold-signature-server/src/user/tests.rs index 59d41f3d8..7ae0cd3b6 100644 --- a/crates/threshold-signature-server/src/user/tests.rs +++ b/crates/threshold-signature-server/src/user/tests.rs @@ -122,7 +122,7 @@ use crate::{ substrate::{get_oracle_data, query_chain, submit_transaction}, tests::{ create_clients, initialize_test_logger, jump_start_network_with_signer, remove_program, - run_to_block, setup_client, spawn_testing_validators, unsafe_get, + run_to_block, setup_client, spawn_testing_validators, unsafe_get, ChainSpecType, }, user::compute_hash, validator::get_signer_and_x25519_secret_from_mnemonic, @@ -169,7 +169,8 @@ async fn test_signature_requests_fail_on_different_conditions() { let two = AccountKeyring::Two; let add_parent_key_to_kvdb = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key_to_kvdb, ChainSpecType::Integration).await; // Here we need to use `--chain=integration-tests` and force authoring otherwise we won't be // able to get our chain in the right state to be jump started. @@ -326,7 +327,8 @@ async fn signature_request_with_derived_account_works() { let charlie = AccountKeyring::Charlie; let add_parent_key_to_kvdb = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key_to_kvdb, ChainSpecType::Integration).await; // Here we need to use `--chain=integration-tests` and force authoring otherwise we won't be // able to get our chain in the right state to be jump started. @@ -396,7 +398,8 @@ async fn test_signing_fails_if_wrong_participants_are_used() { let one = AccountKeyring::Dave; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; @@ -470,7 +473,8 @@ async fn test_request_limit_are_updated_during_signing() { let two = AccountKeyring::Two; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; @@ -592,7 +596,8 @@ async fn test_fails_to_sign_if_non_signing_group_participants_are_used() { let two = AccountKeyring::Two; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; @@ -703,7 +708,8 @@ async fn test_program_with_config() { let two = AccountKeyring::Two; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; @@ -790,7 +796,8 @@ async fn test_jumpstart_network() { let alice = AccountKeyring::Alice; let cxt = test_context_stationary().await; - let (_validator_ips, _validator_ids) = spawn_testing_validators(false).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(false, ChainSpecType::Development).await; let api = get_api(&cxt.node_proc.ws_url).await.unwrap(); let rpc = get_rpc(&cxt.node_proc.ws_url).await.unwrap(); @@ -1002,7 +1009,8 @@ async fn test_fail_infinite_program() { let two = AccountKeyring::Two; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; @@ -1085,7 +1093,8 @@ async fn test_device_key_proxy() { let two = AccountKeyring::Two; let add_parent_key_to_kvdb = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key_to_kvdb, ChainSpecType::Integration).await; // Here we need to use `--chain=integration-tests` and force authoring otherwise we won't be // able to get our chain in the right state to be jump started. @@ -1223,7 +1232,8 @@ async fn test_faucet() { let two = AccountKeyring::Eve; let alice = AccountKeyring::Alice; - let (validator_ips, _validator_ids) = spawn_testing_validators(false).await; + let (validator_ips, _validator_ids) = + spawn_testing_validators(false, ChainSpecType::Development).await; let substrate_context = test_node_process_testing_state(true).await; let entropy_api = get_api(&substrate_context.ws_url).await.unwrap(); let rpc = get_rpc(&substrate_context.ws_url).await.unwrap(); @@ -1395,7 +1405,8 @@ async fn test_new_registration_flow() { let charlie = AccountKeyring::Charlie; let add_parent_key_to_kvdb = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key_to_kvdb, ChainSpecType::Integration).await; // Here we need to use `--chain=integration-tests` and force authoring otherwise we won't be // able to get our chain in the right state to be jump started. diff --git a/crates/threshold-signature-server/src/validator/tests.rs b/crates/threshold-signature-server/src/validator/tests.rs index 07854ac49..bb8057793 100644 --- a/crates/threshold-signature-server/src/validator/tests.rs +++ b/crates/threshold-signature-server/src/validator/tests.rs @@ -14,19 +14,27 @@ // along with this program. If not, see . use super::api::{check_balance_for_fees, check_forbidden_key}; use crate::{ - chain_api::{get_api, get_rpc}, helpers::{ launch::{FORBIDDEN_KEYS, LATEST_BLOCK_NUMBER_RESHARE}, tests::{ initialize_test_logger, run_to_block, setup_client, spawn_testing_validators, - unsafe_get, + unsafe_get, ChainSpecType, }, }, + user::tests::jump_start_network, validator::{ api::{is_signer_or_delete_parent_key, prune_old_holders, validate_new_reshare}, errors::ValidatorErr, }, }; +use entropy_client as test_client; +use entropy_client::{ + chain_api::{ + entropy::runtime_types::bounded_collections::bounded_vec::BoundedVec, + entropy::runtime_types::pallet_registry::pallet::ProgramInstance, get_api, get_rpc, + }, + Hasher, +}; use entropy_kvdb::{ clean_tests, kv_manager::helpers::{deserialize, serialize}, @@ -35,6 +43,9 @@ use entropy_protocol::KeyShareWithAuxInfo; use entropy_shared::{ OcwMessageReshare, MIN_BALANCE, NETWORK_PARENT_KEY, TEST_RESHARE_BLOCK_NUMBER, }; +use entropy_testing_utils::constants::{ + AUXILARY_DATA_SHOULD_SUCCEED, PREIMAGE_SHOULD_SUCCEED, TEST_PROGRAM_WASM_BYTECODE, +}; use entropy_testing_utils::{ constants::{ALICE_STASH_ADDRESS, RANDOM_ACCOUNT}, substrate_context::{test_node_process_testing_state, testing_context}, @@ -43,7 +54,10 @@ use entropy_testing_utils::{ use futures::future::join_all; use parity_scale_codec::Encode; use serial_test::serial; +use sp_core::Pair; use sp_keyring::AccountKeyring; +use subxt::utils::AccountId32; +use synedrion::k256::ecdsa::VerifyingKey; #[tokio::test] #[serial] @@ -51,33 +65,34 @@ async fn test_reshare() { initialize_test_logger().await; clean_tests(); - let alice = AccountKeyring::AliceStash; + let dave = AccountKeyring::DaveStash; let cxt = test_node_process_testing_state(true).await; let add_parent_key_to_kvdb = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key_to_kvdb, ChainSpecType::Integration).await; - let validator_ports = vec![3001, 3002, 3003]; + let validator_ports = vec![3001, 3002, 3003, 3004]; let api = get_api(&cxt.ws_url).await.unwrap(); let rpc = get_rpc(&cxt.ws_url).await.unwrap(); let client = reqwest::Client::new(); let mut key_shares_before = vec![]; - for port in &validator_ports { + for port in &validator_ports[..3] { key_shares_before.push(unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), *port).await); } - crate::user::tests::jump_start_network(&api, &rpc).await; + jump_start_network(&api, &rpc).await; let block_number = TEST_RESHARE_BLOCK_NUMBER; let onchain_reshare_request = - OcwMessageReshare { new_signer: alice.public().encode(), block_number }; + OcwMessageReshare { new_signer: dave.public().encode(), block_number }; run_to_block(&rpc, block_number + 1).await; let response_results = join_all( - validator_ports + validator_ports[1..] .iter() .map(|port| { client @@ -92,7 +107,7 @@ async fn test_reshare() { assert_eq!(response_result.unwrap().text().await.unwrap(), ""); } - for i in 0..validator_ports.len() { + for i in 0..3 { let (key_share_before, aux_info_before): KeyShareWithAuxInfo = deserialize(&key_shares_before[i]).unwrap(); @@ -105,7 +120,11 @@ async fn test_reshare() { assert_eq!(serialize(&key_share_before).unwrap(), serialize(&key_share_after).unwrap()); // Check aux info has not yet changed assert_eq!(serialize(&aux_info_before).unwrap(), serialize(&aux_info_after).unwrap()); + } + // We add one here because after the reshare the siging committee has + // shifted from alice, bob, charlie to bob, charlie, dave + for i in 1..4 { let _ = client .post(format!("http://127.0.0.1:{}/validator/rotate_network_key", validator_ports[i])) .send() @@ -117,16 +136,22 @@ async fn test_reshare() { let (key_share_after_rotate, aux_info_after_rotate): KeyShareWithAuxInfo = deserialize(&key_share_and_aux_data_after_rotate).unwrap(); - // Check key share has changed - assert_ne!( - serialize(&key_share_before).unwrap(), - serialize(&key_share_after_rotate).unwrap() - ); - // Check aux info has changed - assert_ne!( - serialize(&aux_info_before).unwrap(), - serialize(&aux_info_after_rotate).unwrap() - ); + // We can only check if the first two keyshares changed as dave did not have a keyshare at + // all before + if i < 3 { + let (key_share_before, aux_info_before): KeyShareWithAuxInfo = + deserialize(&key_shares_before[i]).unwrap(); + // Check key share has changed + assert_ne!( + serialize(&key_share_before).unwrap(), + serialize(&key_share_after_rotate).unwrap() + ); + // Check aux info has changed + assert_ne!( + serialize(&aux_info_before).unwrap(), + serialize(&aux_info_after_rotate).unwrap() + ); + } // calling twice doesn't do anything let response = client @@ -153,6 +178,7 @@ async fn test_reshare() { ); } + // Check that rotating the network key wont work again later run_to_block(&rpc, block_number + 7).await; let response_stale = @@ -160,7 +186,57 @@ async fn test_reshare() { assert_eq!(response_stale.text().await.unwrap(), "Data is stale"); - // TODO #981 - test signing a message with the new keyshare set + // Now test signing a message with the new keyshare set + let account_owner = AccountKeyring::Ferdie.pair(); + let signature_request_author = AccountKeyring::One; + // Store a program + let program_pointer = test_client::store_program( + &api, + &rpc, + &account_owner, + TEST_PROGRAM_WASM_BYTECODE.to_owned(), + vec![], + vec![], + vec![], + ) + .await + .unwrap(); + + // Register, using that program + let (verifying_key, _registered_info) = test_client::register( + &api, + &rpc, + account_owner.clone(), + AccountId32(account_owner.public().0), + BoundedVec(vec![ProgramInstance { program_pointer, program_config: vec![] }]), + ) + .await + .unwrap(); + + // Sign a message + let recoverable_signature = test_client::sign( + &api, + &rpc, + signature_request_author.pair(), + verifying_key, + PREIMAGE_SHOULD_SUCCEED.to_vec(), + Some(AUXILARY_DATA_SHOULD_SUCCEED.to_vec()), + ) + .await + .unwrap(); + + // Check the signature + let message_should_succeed_hash = Hasher::keccak(PREIMAGE_SHOULD_SUCCEED); + let recovery_key_from_sig = VerifyingKey::recover_from_prehash( + &message_should_succeed_hash, + &recoverable_signature.signature, + recoverable_signature.recovery_id, + ) + .unwrap(); + assert_eq!( + verifying_key.to_vec(), + recovery_key_from_sig.to_encoded_point(true).to_bytes().to_vec() + ); clean_tests(); } @@ -173,9 +249,10 @@ async fn test_reshare_none_called() { let _cxt = test_node_process_testing_state(true).await; let add_parent_key_to_kvdb = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key_to_kvdb).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key_to_kvdb, ChainSpecType::Integration).await; - let validator_ports = vec![3001, 3002, 3003]; + let validator_ports = vec![3001, 3002, 3003, 3004]; let client = reqwest::Client::new(); diff --git a/crates/threshold-signature-server/tests/register_and_sign.rs b/crates/threshold-signature-server/tests/register_and_sign.rs index 839bd41d9..d54c961b9 100644 --- a/crates/threshold-signature-server/tests/register_and_sign.rs +++ b/crates/threshold-signature-server/tests/register_and_sign.rs @@ -26,7 +26,7 @@ use entropy_testing_utils::{ constants::{ AUXILARY_DATA_SHOULD_SUCCEED, PREIMAGE_SHOULD_SUCCEED, TEST_PROGRAM_WASM_BYTECODE, }, - jump_start_network, spawn_testing_validators, test_node_process_testing_state, + jump_start_network, spawn_testing_validators, test_node_process_testing_state, ChainSpecType, }; use serial_test::serial; use sp_core::{sr25519, Pair}; @@ -42,7 +42,8 @@ async fn integration_test_register_and_sign() { let signature_request_author = AccountKeyring::One; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; diff --git a/crates/threshold-signature-server/tests/sign_eth_tx.rs b/crates/threshold-signature-server/tests/sign_eth_tx.rs index 00279dad4..1aa9cd399 100644 --- a/crates/threshold-signature-server/tests/sign_eth_tx.rs +++ b/crates/threshold-signature-server/tests/sign_eth_tx.rs @@ -25,7 +25,7 @@ use entropy_kvdb::clean_tests; use entropy_protocol::{decode_verifying_key, RecoverableSignature}; use entropy_testing_utils::{ constants::{AUXILARY_DATA_SHOULD_SUCCEED, TEST_PROGRAM_WASM_BYTECODE}, - jump_start_network, spawn_testing_validators, test_node_process_testing_state, + jump_start_network, spawn_testing_validators, test_node_process_testing_state, ChainSpecType, }; use ethers_core::{ abi::ethabi::ethereum_types::{H160, H256}, @@ -51,7 +51,8 @@ async fn integration_test_sign_eth_tx() { let signature_request_author = AccountKeyring::One; let add_parent_key = true; - let (_validator_ips, _validator_ids) = spawn_testing_validators(add_parent_key).await; + let (_validator_ips, _validator_ids) = + spawn_testing_validators(add_parent_key, ChainSpecType::Integration).await; let force_authoring = true; let substrate_context = test_node_process_testing_state(force_authoring).await; diff --git a/node/cli/src/chain_spec/integration_tests.rs b/node/cli/src/chain_spec/integration_tests.rs index c5dd75816..8798f35ca 100644 --- a/node/cli/src/chain_spec/integration_tests.rs +++ b/node/cli/src/chain_spec/integration_tests.rs @@ -58,7 +58,6 @@ pub fn integration_tests_config() -> ChainSpec { vec![], get_account_id_from_seed::("Alice"), vec![ - get_account_id_from_seed::("Alice//stash"), get_account_id_from_seed::("Bob//stash"), get_account_id_from_seed::("Charlie//stash"), ], @@ -182,7 +181,7 @@ pub fn integration_tests_genesis_config( ( crate::chain_spec::tss_account_id::DAVE.clone(), crate::chain_spec::tss_x25519_public_key::DAVE, - "127.0.0.1:3002".as_bytes().to_vec(), + "127.0.0.1:3004".as_bytes().to_vec(), ), ), ], @@ -215,7 +214,7 @@ pub fn integration_tests_genesis_config( ], vec![EVE_VERIFYING_KEY.to_vec(), DAVE_VERIFYING_KEY.to_vec()], ), - mock_signer_rotate: (true, mock_signer_rotate_data, vec![get_account_id_from_seed::("Alice//stash")],), + mock_signer_rotate: (true, mock_signer_rotate_data, vec![get_account_id_from_seed::("Dave//stash")],), }, "elections": ElectionsConfig { members: endowed_accounts diff --git a/pallets/staking/src/lib.rs b/pallets/staking/src/lib.rs index fd4c79f50..f6ea6f16a 100644 --- a/pallets/staking/src/lib.rs +++ b/pallets/staking/src/lib.rs @@ -279,14 +279,10 @@ pub mod pallet { ProactiveRefresh::::put(refresh_info); // mocks a signer rotation for tss new_reshare tests if self.mock_signer_rotate.0 { - self.mock_signer_rotate - .clone() - .1 - .push(self.mock_signer_rotate.clone().2[0].clone()); - NextSigners::::put(NextSignerInfo { - next_signers: self.mock_signer_rotate.clone().1, - confirmations: vec![], - }); + let next_signers = &mut self.mock_signer_rotate.1.clone(); + next_signers.push(self.mock_signer_rotate.2[0].clone()); + let next_signers = next_signers.to_vec(); + NextSigners::::put(NextSignerInfo { next_signers, confirmations: vec![] }); ReshareData::::put(ReshareInfo { // To give enough time for test_reshare setup