Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow offchain worker requests to all TSS nodes in entropy-tss test environment #1147

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
29 changes: 10 additions & 19 deletions crates/client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
},
staking_extension::events,
},
get_api, get_rpc, EntropyConfig,
get_api, get_rpc,
},
change_endpoint, change_threshold_accounts, get_oracle_headings, register, remove_program,
request_attestation, store_program,
Expand All @@ -20,8 +20,7 @@ use crate::{
use entropy_shared::{QuoteContext, QuoteInputData};
use entropy_testing_utils::{
constants::{TEST_PROGRAM_WASM_BYTECODE, TSS_ACCOUNTS, X25519_PUBLIC_KEYS},
helpers::encode_verifying_key,
jump_start_network, spawn_testing_validators,
helpers::{encode_verifying_key, spawn_tss_nodes_and_start_chain},
substrate_context::test_context_stationary,
test_node_process_testing_state, ChainSpecType,
};
Expand All @@ -32,7 +31,7 @@ use rand::{
use serial_test::serial;
use sp_core::{sr25519, Pair, H256};
use sp_keyring::AccountKeyring;
use subxt::{tx::PairSigner, utils::AccountId32};
use subxt::utils::AccountId32;

#[tokio::test]
#[serial]
Expand Down Expand Up @@ -211,18 +210,8 @@ async fn test_store_and_remove_program() {
async fn test_remove_program_reference_counter() {
let program_owner = AccountKeyring::Ferdie.pair();

let (_validator_ips, _validator_ids) =
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

// Jumpstart the network
let alice = AccountKeyring::Alice;
let signer = PairSigner::<EntropyConfig, sr25519::Pair>::new(alice.clone().into());
jump_start_network(&api, &rpc, &signer).await;
let (_ctx, api, rpc, _validator_ips, _validator_ids) =
spawn_tss_nodes_and_start_chain(ChainSpecType::IntegrationJumpStarted).await;

// Store a program
let program_pointer = store_program(
Expand Down Expand Up @@ -274,9 +263,11 @@ async fn test_remove_program_reference_counter() {
#[serial]
async fn test_get_oracle_headings() {
let force_authoring = true;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();
let context =
test_node_process_testing_state(ChainSpecType::IntegrationJumpStarted, force_authoring)
.await;
let api = get_api(&context[0].ws_url).await.unwrap();
let rpc = get_rpc(&context[0].ws_url).await.unwrap();

let mut current_block = 0;
while current_block < 2 {
Expand Down
6 changes: 5 additions & 1 deletion crates/protocol/src/execute_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ pub async fn execute_reshare(
(ThresholdKeyShare<KeyParams, PartyId>, AuxInfo<KeyParams, PartyId>),
ProtocolExecutionErr,
> {
tracing::debug!("Executing proactive refresh");
tracing::info!("Executing reshare");
tracing::debug!("Signing with {:?}", &threshold_pair.public());

let pair = PairWrapper(threshold_pair.clone());
Expand All @@ -399,9 +399,13 @@ pub async fn execute_reshare(
.map_err(ProtocolExecutionErr::SessionCreation)?;

let (new_key_share, chans) = execute_protocol_generic(chans, session, session_id_hash).await?;

tracing::info!("Completed reshare protocol");

let aux_info = if let Some(aux_info) = aux_info_option {
aux_info
} else {
tracing::info!("Executing aux gen session as part of reshare");
// Now run an aux gen session
let session_id_hash_aux_data = session_id.blake2(Some(Subsession::AuxGen))?;
let session = make_aux_gen_session(
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub const MAX_SIGNERS: u8 = 15;
pub const SIGNER_THRESHOLD: u8 = 2;

/// For testing to line up chain mock data and reshare_test
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 11;
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;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 20 additions & 23 deletions crates/testing-utils/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use crate::{
chain_api::{get_api, get_rpc, EntropyConfig},
spawn_testing_validators,
substrate_context::{test_context_stationary, test_node_process_testing_state},
ChainSpecType,
substrate_context::test_node_process_testing_state,
ChainSpecType, TestNodeProcess,
};
use entropy_protocol::PartyId;
use rand::{rngs::StdRng, SeedableRng};
Expand All @@ -26,31 +26,28 @@ pub use tdx_quote::encode_verifying_key;

/// 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
///
/// Note that since this function does not reside in entropy-tss, cfg(test) will be false when the
/// TSS nodes are set up, meaning the unsafe API will not be enabled
pub async fn spawn_tss_nodes_and_start_chain(
chain_spec_type: ChainSpecType,
) -> (OnlineClient<EntropyConfig>, LegacyRpcMethods<EntropyConfig>, Vec<String>, Vec<PartyId>) {
) -> (
Vec<TestNodeProcess<EntropyConfig>>,
OnlineClient<EntropyConfig>,
LegacyRpcMethods<EntropyConfig>,
Vec<String>,
Vec<PartyId>,
) {
let (validator_ips, validator_ids) = spawn_testing_validators(chain_spec_type).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[0];
(
get_api(&substrate_context.ws_url).await.unwrap(),
get_rpc(&substrate_context.ws_url).await.unwrap(),
)
},
};
(api, rpc, validator_ips, validator_ids)
// Here we need to 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(chain_spec_type, force_authoring).await;
let api = get_api(&substrate_context[0].ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context[0].ws_url).await.unwrap();

(substrate_context, api, rpc, validator_ips, validator_ids)
}

/// Get the mock PCK that will be used for a given TSS account ID
Expand Down
4 changes: 1 addition & 3 deletions crates/testing-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ 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, ChainSpecType,
};
pub use entropy_tss::helpers::tests::{spawn_testing_validators, ChainSpecType};
pub use node_proc::TestNodeProcess;
pub use substrate_context::*;

Expand Down
18 changes: 9 additions & 9 deletions crates/testing-utils/src/substrate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use entropy_tss::helpers::tests::ChainSpecType;
use sp_keyring::AccountKeyring;
use subxt::{config::substrate::SubstrateExtrinsicParams, OnlineClient};

Expand Down Expand Up @@ -110,43 +111,42 @@ pub async fn test_node_process_stationary() -> TestNodeProcess<EntropyConfig> {
///
/// Allowing `force_authoring` will produce blocks.
pub async fn test_node_process_testing_state(
chain_spec_type: ChainSpecType,
force_authoring: bool,
) -> Vec<TestNodeProcess<EntropyConfig>> {
let alice_bootnode = Some(
"/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWM7EoKJfwgzAR1nAVmYRuuFq2f3GpJPLrdfhQaRsKjn38"
.to_string(),
);
// reduses message from chain to same TSS cleaning up a lot of logging
let fuck_off_tss_ip = Some("127.0.0.1:4010".to_string());
let result = test_node(
AccountKeyring::Alice,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
None,
)
.await;
let result_bob = test_node_process_with(
AccountKeyring::Bob,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
Some("http://127.0.0.1:3002".into()),
)
.await;
let result_charlie = test_node_process_with(
AccountKeyring::Charlie,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
Some("http://127.0.0.1:3003".into()),
)
.await;
let result_dave = test_node_process_with(
AccountKeyring::Dave,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
Some("http://127.0.0.1:3004".into()),
)
.await;

Expand Down
Loading