Skip to content

Commit

Permalink
there were two duplicate create_responder test methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Jun 28, 2024
1 parent a15d8f7 commit 0a0a118
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 28 deletions.
29 changes: 5 additions & 24 deletions teos/src/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,12 @@ mod tests {
use crate::dbm::DBM;
use crate::rpc_errors;
use crate::test_utils::{
create_carrier, generate_dummy_appointment, generate_dummy_appointment_with_user,
generate_uuid, get_last_n_blocks, get_random_breach, get_random_tracker, get_random_tx,
store_appointment_and_its_user, Blockchain, MockedServerQuery, DURATION, EXPIRY_DELTA,
SLOTS, START_HEIGHT,
create_responder_with_query, generate_dummy_appointment,
generate_dummy_appointment_with_user, generate_uuid, get_random_breach, get_random_tracker,
get_random_tx, store_appointment_and_its_user, Blockchain, MockedServerQuery, DURATION,
EXPIRY_DELTA, SLOTS, START_HEIGHT,
};

use teos_common::constants::IRREVOCABLY_RESOLVED;
use teos_common::test_utils::get_random_user_id;

impl TransactionTracker {
Expand Down Expand Up @@ -548,24 +547,6 @@ mod tests {
}
}

async fn create_responder(
chain: &mut Blockchain,
gatekeeper: Arc<Gatekeeper>,
dbm: Arc<Mutex<DBM>>,
query: MockedServerQuery,
) -> Responder {
let height = if chain.tip().height < IRREVOCABLY_RESOLVED {
chain.tip().height
} else {
IRREVOCABLY_RESOLVED
};

let carrier = create_carrier(query, chain.tip().height);
let last_n_blocks = get_last_n_blocks(chain, height as usize).await;

Responder::new(&last_n_blocks, chain.tip().height, carrier, gatekeeper, dbm)
}

async fn init_responder_with_chain_and_dbm(
mocked_query: MockedServerQuery,
chain: &mut Blockchain,
Expand All @@ -578,7 +559,7 @@ mod tests {
EXPIRY_DELTA,
dbm.clone(),
);
create_responder(chain, Arc::new(gk), dbm, mocked_query).await
create_responder_with_query(chain, Arc::new(gk), dbm, mocked_query).await
}

async fn init_responder(mocked_query: MockedServerQuery) -> Responder {
Expand Down
18 changes: 14 additions & 4 deletions teos/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,28 @@ pub(crate) fn create_carrier(query: MockedServerQuery, height: u32) -> Carrier {
)
}

pub(crate) async fn create_responder(
pub(crate) async fn create_responder_with_query(
chain: &mut Blockchain,
gatekeeper: Arc<Gatekeeper>,
dbm: Arc<Mutex<DBM>>,
query: MockedServerQuery,
) -> Responder {
let height = chain.tip().height;
// For the local TxIndex logic to be sound, our index needs to have, at least, IRREVOCABLY_RESOLVED blocks
debug_assert!(height >= IRREVOCABLY_RESOLVED);
let carrier = create_carrier(MockedServerQuery::Regular, height);
let last_n_blocks = get_last_n_blocks(chain, IRREVOCABLY_RESOLVED as usize).await;

Responder::new(&last_n_blocks, height, carrier, gatekeeper, dbm)
let carrier = create_carrier(query, chain.tip().height);
let last_n_blocks = get_last_n_blocks(chain, height as usize).await;

Responder::new(&last_n_blocks, chain.tip().height, carrier, gatekeeper, dbm)
}

pub(crate) async fn create_responder(
chain: &mut Blockchain,
gatekeeper: Arc<Gatekeeper>,
dbm: Arc<Mutex<DBM>>,
) -> Responder {
create_responder_with_query(chain, gatekeeper, dbm, MockedServerQuery::Regular).await
}

pub(crate) async fn create_watcher(
Expand Down

0 comments on commit 0a0a118

Please sign in to comment.