Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Jul 2, 2023
1 parent 3599e0e commit e088a05
Show file tree
Hide file tree
Showing 9 changed files with 1,270 additions and 1,783 deletions.
16 changes: 14 additions & 2 deletions teos/src/api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,10 @@ mod tests_methods {
use super::*;

use crate::extended_appointment::UUID;
use crate::test_utils::{generate_dummy_appointment, ApiConfig, DURATION, SLOTS};
use crate::responder::ConfirmationStatus;
use crate::test_utils::{
generate_dummy_appointment, get_random_breach, ApiConfig, DURATION, SLOTS,
};

use teos_common::test_utils::get_random_user_id;
use teos_common::{cryptography, UserId};
Expand Down Expand Up @@ -806,6 +809,7 @@ mod tests_methods {

// Register
let (user_sk, user_pk) = cryptography::get_random_keypair();
let user_id = UserId(user_pk);
request_to_api::<common_msgs::RegisterRequest, common_msgs::RegisterResponse>(
Endpoint::Register,
common_msgs::RegisterRequest {
Expand All @@ -818,10 +822,18 @@ mod tests_methods {

// Add the appointment to the Responder so it counts as triggered
let appointment = generate_dummy_appointment(None).inner;
let uuid = UUID::new(appointment.locator, user_id);
let signature = cryptography::sign(&appointment.to_vec(), &user_sk).unwrap();
internal_api
.get_watcher()
.add_random_tracker_to_responder(UUID::new(appointment.locator, UserId(user_pk)));
.add_appointment(appointment.clone(), signature.clone())
.unwrap();
internal_api.get_watcher().get_responder().add_tracker(
uuid,
get_random_breach(),
user_id,
ConfirmationStatus::ConfirmedIn(100),
);

// Try to add it via the http API
assert_eq!(
Expand Down
33 changes: 20 additions & 13 deletions teos/src/api/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,10 @@ mod tests_private_api {
use bitcoin::hashes::Hash;
use bitcoin::Txid;

use crate::extended_appointment::UUID;
use crate::responder::{ConfirmationStatus, TransactionTracker};
use crate::test_utils::{
create_api, generate_dummy_appointment, generate_dummy_appointment_with_user,
generate_uuid, get_random_tx, DURATION, SLOTS, START_HEIGHT,
get_random_tx, DURATION, SLOTS, START_HEIGHT,
};
use crate::watcher::Breach;

Expand Down Expand Up @@ -491,9 +490,7 @@ mod tests_private_api {
let (internal_api, _s) = create_api().await;

// Add data to the Responser so we can retrieve it later on
internal_api
.watcher
.add_random_tracker_to_responder(generate_uuid());
internal_api.watcher.add_random_tracker_to_responder();

let response = internal_api
.get_all_appointments(Request::new(()))
Expand Down Expand Up @@ -593,7 +590,7 @@ mod tests_private_api {
);
internal_api
.watcher
.add_dummy_tracker_to_responder(generate_uuid(), &tracker);
.add_dummy_tracker_to_responder(&tracker);
}

let locator = Locator::new(dispute_tx.txid());
Expand Down Expand Up @@ -660,9 +657,7 @@ mod tests_private_api {

// And the Responder
for _ in 0..3 {
internal_api
.watcher
.add_random_tracker_to_responder(generate_uuid());
internal_api.watcher.add_random_tracker_to_responder();
}

let response = internal_api
Expand Down Expand Up @@ -791,8 +786,10 @@ mod tests_public_api {
use super::*;

use crate::extended_appointment::UUID;
use crate::responder::ConfirmationStatus;
use crate::test_utils::{
create_api, create_api_with_config, generate_dummy_appointment, ApiConfig, DURATION, SLOTS,
create_api, create_api_with_config, generate_dummy_appointment, get_random_breach,
ApiConfig, DURATION, SLOTS,
};
use teos_common::cryptography::{self, get_random_keypair};

Expand Down Expand Up @@ -1012,16 +1009,26 @@ mod tests_public_api {
let user_id = UserId(user_pk);
internal_api.watcher.register(user_id).unwrap();

// Add a tracker to the responder to simulate it being triggered.
let appointment = generate_dummy_appointment(None).inner;
let uuid = UUID::new(appointment.locator, user_id);
let user_signature = cryptography::sign(&appointment.to_vec(), &user_sk).unwrap();
internal_api
.watcher
.add_random_tracker_to_responder(UUID::new(appointment.locator, user_id));
.add_appointment(appointment.clone(), user_signature.clone())
.unwrap();
internal_api.watcher.get_responder().add_tracker(
uuid,
get_random_breach(),
user_id,
ConfirmationStatus::ConfirmedIn(100),
);

// Try to add it again using the API.
match internal_api
.add_appointment(Request::new(common_msgs::AddAppointmentRequest {
appointment: Some(appointment.clone().into()),
signature: user_signature.clone(),
appointment: Some(appointment.into()),
signature: user_signature,
}))
.await
{
Expand Down
Loading

0 comments on commit e088a05

Please sign in to comment.