Skip to content

Commit

Permalink
servers-mock: Change create_actors_grpc parameter to BridgeConfig.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Dec 9, 2024
1 parent d6c9559 commit a6cbf15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
5 changes: 0 additions & 5 deletions core/src/mock/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ pub fn get_test_config(configuration_file: &str) -> Result<BridgeConfig, BridgeE
config.db_name = env_config.db_name;
};

#[cfg(test)]
{
config.port = 0;
}

Ok(config)
}

Expand Down
20 changes: 12 additions & 8 deletions core/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Utilities for operator and verifier servers.
use crate::aggregator;
use crate::aggregator::Aggregator;
use crate::database::Database;
use crate::mock::database::create_test_config_with_thread_name;
use crate::rpc::clementine::clementine_aggregator_server::ClementineAggregatorServer;
use crate::rpc::clementine::clementine_operator_server::ClementineOperatorServer;
Expand Down Expand Up @@ -347,20 +348,19 @@ pub async fn create_watchtower_grpc_server(
// #[tracing::instrument(ret(level = tracing::Level::TRACE))]
#[allow(clippy::type_complexity)] // Enabling tracing::instrument causes this.
pub async fn create_actors_grpc(
config_name: &str,
config: BridgeConfig,
number_of_watchtowers: u32,
) -> (
Vec<(std::net::SocketAddr,)>, // Verifier clients
Vec<(std::net::SocketAddr,)>, // Operator clients
(std::net::SocketAddr,), // Aggregator client
Vec<(std::net::SocketAddr,)>, // Watchtower clients
) {
let config = create_test_config_with_thread_name(config_name, None).await;
let start_port = 17000;
let start_port = config.port;
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url,
config.bitcoin_rpc_user,
config.bitcoin_rpc_password,
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
config.bitcoin_rpc_password.clone(),
)
.await;
let all_verifiers_secret_keys = config.all_verifiers_secret_keys.clone().unwrap_or_else(|| {
Expand All @@ -374,9 +374,13 @@ pub async fn create_actors_grpc(
// println!("Port: {}", port);
let i = i.to_string();
let rpc = rpc.clone();
let mut config_with_new_db = config.clone();
async move {
let config_with_new_db =
create_test_config_with_thread_name(config_name, Some(&i.to_string())).await;
config_with_new_db.db_name += &i;
Database::initialize_database(&config_with_new_db)
.await
.unwrap();

let verifier = create_verifier_grpc_server(
BridgeConfig {
secret_key: *sk,
Expand Down
13 changes: 6 additions & 7 deletions core/tests/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ use bitcoin::{Address, Amount, Txid};
use bitcoincore_rpc::RpcApi;
use clementine_core::errors::BridgeError;
use clementine_core::extended_rpc::ExtendedRpc;
use clementine_core::mock::database::create_test_config_with_thread_name;
use clementine_core::rpc::clementine::clementine_aggregator_client::ClementineAggregatorClient;
use clementine_core::rpc::clementine::{self, DepositParams};
use clementine_core::servers::create_actors_grpc;
use clementine_core::utils::{initialize_logger, SECP};
use clementine_core::utils::{SECP};
use clementine_core::{traits::rpc::OperatorRpcClient, user::User};
use common::run_single_deposit;
use secp256k1::SecretKey;
Expand Down Expand Up @@ -145,9 +146,8 @@ async fn withdrawal_fee_too_low() {
#[should_panic]
#[serial_test::serial]
async fn double_calling_setip() {
initialize_logger(5).unwrap();
let (_verifiers, _operators, aggregator, _watchtowers) =
create_actors_grpc("test_config.toml", 0).await;
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let (_verifiers, _operators, aggregator, _watchtowers) = create_actors_grpc(config, 0).await;

let x: Uri = format!("http://{}", aggregator.0).parse().unwrap();

Expand All @@ -169,9 +169,8 @@ async fn double_calling_setip() {
#[tokio::test]
#[serial_test::serial]
async fn grpc_flow() {
initialize_logger(5).unwrap();
let (_verifiers, _operators, aggregator, _watchtowers) =
create_actors_grpc("test_config.toml", 0).await;
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let (_verifiers, _operators, aggregator, _watchtowers) = create_actors_grpc(config, 0).await;

let x: Uri = format!("http://{}", aggregator.0).parse().unwrap();

Expand Down

0 comments on commit a6cbf15

Please sign in to comment.