Skip to content

Commit

Permalink
mock_macro: Use create_test_config_with_thread_name in everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Dec 12, 2024
1 parent 7402354 commit 190d071
Show file tree
Hide file tree
Showing 18 changed files with 580 additions and 598 deletions.
49 changes: 0 additions & 49 deletions core/src/bin/all_servers.rs

This file was deleted.

52 changes: 27 additions & 25 deletions core/src/database/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,9 @@ impl Database {
#[cfg(test)]
mod tests {
use super::Database;
use crate::{config::BridgeConfig, initialize_database, utils::initialize_logger};
use crate::{
mock::database::create_test_config_with_thread_name,
create_test_config_with_thread_name,
musig2::{nonce_pair, MuSigAggNonce, MuSigPubNonce, MuSigSecNonce},
ByteArray32, EVMAddress, UTXO,
};
Expand All @@ -996,10 +997,11 @@ mod tests {
use risc0_zkvm::Receipt;
use secp256k1::{constants::SCHNORR_SIGNATURE_SIZE, rand::rngs::OsRng};
use secp256k1::{schnorr, Secp256k1};
use std::{env, thread};

#[tokio::test]
async fn save_get_timeout_tx_sigs() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let database = Database::new(&config).await.unwrap();

let signatures: Vec<schnorr::Signature> = (0..0x45)
Expand All @@ -1018,7 +1020,7 @@ mod tests {

#[tokio::test]
async fn test_database_gets_previously_saved_operator_take_signature() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let database = Database::new(&config).await.unwrap();

let deposit_outpoint = OutPoint::null();
Expand Down Expand Up @@ -1056,7 +1058,7 @@ mod tests {

#[tokio::test]
async fn test_save_and_get_deposit_info() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let database = Database::new(&config).await.unwrap();

let secp = Secp256k1::new();
Expand Down Expand Up @@ -1089,7 +1091,7 @@ mod tests {

#[tokio::test]
async fn test_nonces_1() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();
let secp = Secp256k1::new();

Expand Down Expand Up @@ -1134,7 +1136,7 @@ mod tests {

#[tokio::test]
async fn test_nonces_2() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();
let secp = Secp256k1::new();

Expand Down Expand Up @@ -1178,7 +1180,7 @@ mod tests {

#[tokio::test]
async fn test_nonces_3() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();
let secp = Secp256k1::new();

Expand Down Expand Up @@ -1226,7 +1228,7 @@ mod tests {

#[tokio::test]
async fn test_get_pub_nonces_1() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();
let secp = Secp256k1::new();

Expand Down Expand Up @@ -1259,7 +1261,7 @@ mod tests {

#[tokio::test]
async fn test_get_pub_nonces_2() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();
let outpoint = OutPoint {
txid: Txid::from_byte_array([1u8; 32]),
Expand All @@ -1271,7 +1273,7 @@ mod tests {

#[tokio::test]
async fn test_operators_kickoff_utxo_1() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let outpoint = OutPoint {
Expand All @@ -1296,7 +1298,7 @@ mod tests {

#[tokio::test]
async fn test_operators_kickoff_utxo_2() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let outpoint = OutPoint {
Expand All @@ -1309,7 +1311,7 @@ mod tests {

#[tokio::test]
async fn test_verifiers_kickoff_utxos_1() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let outpoint = OutPoint {
Expand Down Expand Up @@ -1346,7 +1348,7 @@ mod tests {

#[tokio::test]
async fn test_verifiers_kickoff_utxos_2() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let outpoint = OutPoint {
Expand All @@ -1359,7 +1361,7 @@ mod tests {

#[tokio::test]
async fn test_operators_funding_utxo_1() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let utxo = UTXO {
Expand All @@ -1381,7 +1383,7 @@ mod tests {

#[tokio::test]
async fn test_operators_funding_utxo_2() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let db_utxo = db.get_funding_utxo(None).await.unwrap();
Expand All @@ -1391,7 +1393,7 @@ mod tests {

#[tokio::test]
async fn test_deposit_kickoff_generator_tx_0() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let raw_hex = "02000000000101eb87b1a80d47b7f5bd5082b77653f5ca37e566951742b80c361875ba0e5c478f0a00000000fdffffff0ca086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca3a086010000000000225120b23da6d2e0390018b953f7d74e3582da4da30fd0fd157cc84a2d2753003d1ca35c081777000000002251202a64b1ee3375f3bb4b367b8cb8384a47f73cf231717f827c6c6fbbf5aecf0c364a010000000000002200204ae81572f06e1b88fd5ced7a1a000945432e83e1551e6f721ee9c00b8cc33260014005a41e6f4a4bcfcc5cd3ef602687215f97c18949019a491df56af7413c5dce9292ba3966edc4564a39d9bc0d6c0faae19030f1cedf4d931a6cdc57cc5b83c8ef00000000".to_string();
Expand Down Expand Up @@ -1437,7 +1439,7 @@ mod tests {

#[tokio::test]
async fn test_deposit_kickoff_generator_tx_2() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let txid = Txid::from_byte_array([1u8; 32]);
Expand All @@ -1447,7 +1449,7 @@ mod tests {

#[tokio::test]
async fn test_deposit_kickoff_generator_tx_1() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let raw_hex = "01000000000101308d840c736eefd114a8fad04cb0d8338b4a3034a2b517250e5498701b25eb360100000000fdffffff02401f00000000000022512024985a1ab5724a5164ae5e0026b3e7e22031e83948eedf99d438b866857946b81f7e000000000000225120f7298da2a2be5b6e02a076ff7d35a1fe6b54a2bc7938c1c86bede23cadb7d9650140ad2fdb01ec5e2772f682867c8c6f30697c63f622e338f7390d3abc6c905b9fd7e96496fdc34cb9e872387758a6a334ec1307b3505b73121e0264fe2ba546d78ad11b0d00".to_string();
Expand Down Expand Up @@ -1497,7 +1499,7 @@ mod tests {

#[tokio::test]
async fn test_deposit_kickoff_generator_tx_3() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let txid = Txid::from_byte_array([1u8; 32]);
Expand All @@ -1507,7 +1509,7 @@ mod tests {

#[tokio::test]
async fn save_get_new_block() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let block = block::Block {
Expand Down Expand Up @@ -1536,7 +1538,7 @@ mod tests {

#[tokio::test]
async fn get_block_header() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let block = block::Block {
Expand Down Expand Up @@ -1573,7 +1575,7 @@ mod tests {

#[tokio::test]
pub async fn get_latest_chain_proof_height() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

let mut block = block::Block {
Expand Down Expand Up @@ -1629,7 +1631,7 @@ mod tests {

#[tokio::test]
pub async fn save_get_block_proof() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

// Save dummy block.
Expand Down Expand Up @@ -1673,7 +1675,7 @@ mod tests {

#[tokio::test]
pub async fn get_non_proven_block() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let db = Database::new(&config).await.unwrap();

assert!(db.get_non_proven_block(None).await.is_err());
Expand Down Expand Up @@ -1749,7 +1751,7 @@ mod tests {

#[tokio::test]
async fn save_get_winternitz_public_key() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let database = Database::new(&config).await.unwrap();

let wpk: winternitz::PublicKey = vec![[0x45; 20]];
Expand Down
13 changes: 6 additions & 7 deletions core/src/database/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,14 @@ impl Database {

#[cfg(test)]
mod tests {
use crate::{
config::BridgeConfig,
database::Database,
mock::{common, database::create_test_config_with_thread_name},
};
use crate::create_test_config_with_thread_name;
use crate::{config::BridgeConfig, database::Database};
use crate::{initialize_database, utils::initialize_logger};
use std::{env, thread};

#[tokio::test]
async fn valid_database_connection() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);

Database::new(&config).await.unwrap();
}
Expand All @@ -159,7 +158,7 @@ mod tests {

#[tokio::test]
async fn create_drop_database() {
let mut config = common::get_test_config("test_config.toml").unwrap();
let mut config = create_test_config_with_thread_name!("test_config.toml", None);
config.db_name = "create_drop_database".to_string();

// Drop database (clear previous test run artifacts) and check that
Expand Down
20 changes: 12 additions & 8 deletions core/src/header_chain_prover/blockgazer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,19 @@ impl HeaderChainProver {
#[cfg(test)]
mod tests {
use crate::{
config::BridgeConfig, database::Database, initialize_database, utils::initialize_logger,
};
use crate::{
create_test_config_with_thread_name,
extended_rpc::ExtendedRpc,
header_chain_prover::{
blockgazer::{BlockFetchStatus, BATCH_DEEPNESS, BATCH_DEEPNESS_SAFETY_BARRIER},
HeaderChainProver,
},
mock::database::create_test_config_with_thread_name,
};
use bitcoin::BlockHash;
use bitcoincore_rpc::RpcApi;
use std::{env, thread};

async fn mine_and_save_blocks(prover: &HeaderChainProver, height: u64) -> Vec<BlockHash> {
let mut fork_block_hashes = Vec::new();
Expand Down Expand Up @@ -253,7 +257,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn check_for_new_blocks_uptodate() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down Expand Up @@ -287,7 +291,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn check_for_new_blocks_fallen_behind_single() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down Expand Up @@ -328,7 +332,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn check_for_new_blocks_fallen_behind_multiple() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down Expand Up @@ -359,7 +363,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn check_for_new_blocks_fork_and_mine_new() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down Expand Up @@ -391,7 +395,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn sync_blockchain_single_block() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down Expand Up @@ -425,7 +429,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn sync_blockchain_multiple_blocks() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down Expand Up @@ -459,7 +463,7 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn sync_blockchain_multiple_blocks_with_fork() {
let config = create_test_config_with_thread_name("test_config.toml", None).await;
let config = create_test_config_with_thread_name!("test_config.toml", None);
let rpc = ExtendedRpc::new(
config.bitcoin_rpc_url.clone(),
config.bitcoin_rpc_user.clone(),
Expand Down
Loading

0 comments on commit 190d071

Please sign in to comment.