Skip to content

Commit

Permalink
Run multiple test validator (#1074)
Browse files Browse the repository at this point in the history
* run multiple test validators

* change same tss_endpoints

* fix test
  • Loading branch information
JesseAbram authored Sep 30, 2024
1 parent 508f6ef commit 61c77d4
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 38 deletions.
2 changes: 1 addition & 1 deletion crates/client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async fn test_remove_program_reference_counter() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
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();

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 = 5;
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 7;

/// Program version number, must be incremented if version number changes
pub const PROGRAM_VERSION_NUMBER: u8 = 0;
2 changes: 1 addition & 1 deletion crates/testing-utils/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn spawn_tss_nodes_and_start_chain(
// 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;
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(),
Expand Down
33 changes: 29 additions & 4 deletions crates/testing-utils/src/node_proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ where
R: Config,
{
/// Construct a builder for spawning a test node process.
pub fn build<S>(program: S, chain_type: String, force_authoring: bool) -> TestNodeProcessBuilder
pub fn build<S>(
program: S,
chain_type: String,
force_authoring: bool,
bootnode: Option<String>,
threshold_url: Option<String>,
) -> TestNodeProcessBuilder
where
S: AsRef<OsStr> + Clone,
{
TestNodeProcessBuilder::new(program, chain_type, force_authoring)
TestNodeProcessBuilder::new(program, chain_type, force_authoring, bootnode, threshold_url)
}

/// Attempt to kill the running substrate process.
Expand All @@ -76,10 +82,18 @@ pub struct TestNodeProcessBuilder {
scan_port_range: bool,
chain_type: String,
force_authoring: bool,
bootnode: Option<String>,
tss_server_endpoint: Option<String>,
}

impl TestNodeProcessBuilder {
pub fn new<P>(node_path: P, chain_type: String, force_authoring: bool) -> TestNodeProcessBuilder
pub fn new<P>(
node_path: P,
chain_type: String,
force_authoring: bool,
bootnode: Option<String>,
tss_server_endpoint: Option<String>,
) -> TestNodeProcessBuilder
where
P: AsRef<OsStr>,
{
Expand All @@ -89,6 +103,8 @@ impl TestNodeProcessBuilder {
scan_port_range: false,
chain_type,
force_authoring,
bootnode,
tss_server_endpoint,
}
}

Expand Down Expand Up @@ -122,10 +138,19 @@ impl TestNodeProcessBuilder {
cmd.arg(arg);
}

if let Some(bootnode) = &self.bootnode {
let arg = format!("--bootnodes={}", bootnode.as_str());
cmd.arg(arg);
}

if let Some(tss_server_endpoint) = &self.tss_server_endpoint {
let arg = format!("--tss-server-endpoint={}", tss_server_endpoint.as_str());
cmd.arg(arg);
}

let ws_port = if self.scan_port_range {
let (p2p_port, _http_port, ws_port) = next_open_port()
.ok_or_else(|| "No available ports in the given port range".to_owned())?;

cmd.arg(format!("--port={p2p_port}"));
cmd.arg(format!("--rpc-port={ws_port}"));
tracing::info!("ws port: {ws_port}");
Expand Down
75 changes: 61 additions & 14 deletions crates/testing-utils/src/substrate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use subxt::{config::substrate::SubstrateExtrinsicParams, OnlineClient};

use super::node_proc::TestNodeProcess;
use crate::chain_api::*;

/// Verifies that the Entropy node binary exists.
///
/// If a path is provided using the `ENTROPY_NODE` environment variable, that will take priority.
Expand Down Expand Up @@ -62,48 +61,96 @@ pub async fn test_node_process_with(
key: AccountKeyring,
chain_type: String,
force_authoring: bool,
bootnode: Option<String>,
tss_server_endpoint: Option<String>,
) -> TestNodeProcess<EntropyConfig> {
let path = get_path();
let path = path.to_str().expect("Path should've been checked to be valid earlier.");

let proc = TestNodeProcess::<EntropyConfig>::build(path, chain_type, force_authoring)
.with_authority(key)
.scan_for_open_ports()
.spawn::<EntropyConfig>()
.await;
let proc = TestNodeProcess::<EntropyConfig>::build(
path,
chain_type,
force_authoring,
bootnode,
tss_server_endpoint,
)
.with_authority(key)
.scan_for_open_ports()
.spawn::<EntropyConfig>()
.await;
proc.unwrap()
}

pub async fn test_node(
key: AccountKeyring,
chain_type: String,
force_authoring: bool,
bootnode: Option<String>,
) -> TestNodeProcess<EntropyConfig> {
let path = get_path();
let path = path.to_str().expect("Path should've been checked to be valid earlier.");

let proc = TestNodeProcess::<EntropyConfig>::build(path, chain_type, force_authoring)
.with_authority(key)
.spawn::<EntropyConfig>()
.await;
let proc =
TestNodeProcess::<EntropyConfig>::build(path, chain_type, force_authoring, bootnode, None)
.with_authority(key)
.spawn::<EntropyConfig>()
.await;
proc.unwrap()
}

pub async fn test_node_process() -> TestNodeProcess<EntropyConfig> {
test_node_process_with(AccountKeyring::Alice, "--dev".to_string(), false).await
test_node_process_with(AccountKeyring::Alice, "--dev".to_string(), false, None, None).await
}

pub async fn test_node_process_stationary() -> TestNodeProcess<EntropyConfig> {
test_node(AccountKeyring::Alice, "--dev".to_string(), false).await
test_node(AccountKeyring::Alice, "--dev".to_string(), false, None).await
}

/// Tests chain with test state in chain config
///
/// Allowing `force_authoring` will produce blocks.
pub async fn test_node_process_testing_state(
force_authoring: bool,
) -> TestNodeProcess<EntropyConfig> {
test_node(AccountKeyring::Alice, "--chain=integration-tests".to_string(), force_authoring).await
) -> 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(),
force_authoring,
None,
)
.await;
let result_bob = test_node_process_with(
AccountKeyring::Bob,
"--chain=integration-tests".to_string(),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
)
.await;
let result_charlie = test_node_process_with(
AccountKeyring::Charlie,
"--chain=integration-tests".to_string(),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
)
.await;
let result_dave = test_node_process_with(
AccountKeyring::Dave,
"--chain=integration-tests".to_string(),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
)
.await;

vec![result, result_bob, result_charlie, result_dave]
}

/// Spins up Substrate node and a connected `subxt` client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use sp_keyring::AccountKeyring;
async fn test_proactive_refresh() {
initialize_test_logger().await;
clean_tests();
let _cxt = test_node_process_testing_state(false).await;
let _cxt = &test_node_process_testing_state(false).await[0];

let (validator_ips, _ids) = spawn_testing_validators(ChainSpecType::Integration).await;
let signing_committee_ips = &validator_ips[..3].to_vec();
Expand Down
24 changes: 12 additions & 12 deletions crates/threshold-signature-server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async fn test_signature_requests_fail_on_different_conditions() {
// 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;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

Expand Down Expand Up @@ -418,7 +418,7 @@ async fn test_signature_requests_fail_validator_info_wrong() {
// 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;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

Expand Down Expand Up @@ -495,7 +495,7 @@ async fn signature_request_with_derived_account_works() {
// 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;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

Expand Down Expand Up @@ -540,7 +540,7 @@ async fn test_signing_fails_if_wrong_participants_are_used() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];

let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();
Expand Down Expand Up @@ -658,7 +658,7 @@ async fn test_request_limit_are_updated_during_signing() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];

let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();
Expand Down Expand Up @@ -763,7 +763,7 @@ async fn test_fails_to_sign_if_non_signing_group_participants_are_used() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];

let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();
Expand Down Expand Up @@ -863,7 +863,7 @@ async fn test_program_with_config() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];

let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();
Expand Down Expand Up @@ -949,7 +949,7 @@ async fn test_jumpstart_network() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
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();
Expand Down Expand Up @@ -1103,7 +1103,7 @@ async fn test_fail_infinite_program() {
get_signer_and_x25519_secret_from_mnemonic(&mnemonic.to_string()).unwrap();

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
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();
Expand Down Expand Up @@ -1199,7 +1199,7 @@ async fn test_device_key_proxy() {
// 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;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

Expand Down Expand Up @@ -1336,7 +1336,7 @@ async fn test_faucet() {
let (_validator_ips, _validator_ids) =
spawn_testing_validators(ChainSpecType::Development).await;
let relayer_ip_and_key = ("localhost:3001".to_string(), X25519_PUBLIC_KEYS[0]);
let substrate_context = test_node_process_testing_state(true).await;
let substrate_context = &test_node_process_testing_state(true).await[0];
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

Expand Down Expand Up @@ -1493,7 +1493,7 @@ async fn test_registration_flow() {
// 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;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let entropy_api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async fn test_reshare() {
initialize_test_logger().await;
clean_tests();

let cxt = test_node_process_testing_state(true).await;
let cxt = &test_node_process_testing_state(true).await[0];

let (_validator_ips, _validator_ids) =
spawn_testing_validators(ChainSpecType::Integration).await;
Expand Down Expand Up @@ -316,7 +316,7 @@ async fn test_reshare_validation_fail() {
clean_tests();

let dave = AccountKeyring::Dave;
let cxt = test_node_process_testing_state(true).await;
let cxt = &test_node_process_testing_state(true).await[0];
let api = get_api(&cxt.ws_url).await.unwrap();
let rpc = get_rpc(&cxt.ws_url).await.unwrap();
let kv = setup_client().await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn integration_test_register_and_sign() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
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();
Expand Down
2 changes: 1 addition & 1 deletion crates/threshold-signature-server/tests/sign_eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn integration_test_sign_eth_tx() {
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = test_node_process_testing_state(force_authoring).await;
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();
Expand Down

0 comments on commit 61c77d4

Please sign in to comment.