This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Simon Paitrault <[email protected]>
- Loading branch information
Showing
6 changed files
with
223 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
use std::sync::Arc; | ||
|
||
use libp2p::PeerId; | ||
use prost::Message; | ||
use rstest::rstest; | ||
use test_log::test; | ||
use tokio::sync::{mpsc, oneshot}; | ||
use topos_core::api::grpc::tce::v1::{double_echo_request, DoubleEchoRequest, Echo, Gossip, Ready}; | ||
use topos_crypto::{messages::MessageSigner, validator_id::ValidatorId}; | ||
use topos_tce_storage::{store::WriteStore, types::PendingResult}; | ||
use topos_test_sdk::{ | ||
certificates::create_certificate_chain, | ||
constants::{SOURCE_SUBNET_ID_1, TARGET_SUBNET_ID_1}, | ||
}; | ||
|
||
use crate::AppContext; | ||
|
||
use super::setup_test; | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
async fn handle_new_certificate( | ||
#[future] setup_test: ( | ||
AppContext, | ||
mpsc::Receiver<topos_p2p::Command>, | ||
Arc<MessageSigner>, | ||
), | ||
) { | ||
let (mut context, mut p2p_receiver, message_signer) = setup_test.await; | ||
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1); | ||
let certificate = certificates.pop().unwrap().certificate; | ||
|
||
let (sender, receiver) = oneshot::channel(); | ||
|
||
context | ||
.on_api_event(topos_tce_api::RuntimeEvent::CertificateSubmitted { | ||
certificate: Box::new(certificate), | ||
sender, | ||
}) | ||
.await; | ||
|
||
let response = receiver.await; | ||
|
||
assert!(matches!(response, Ok(Ok(PendingResult::InPending(_))))); | ||
} | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
async fn handle_certificate_in_precedence_pool( | ||
#[future] setup_test: ( | ||
AppContext, | ||
mpsc::Receiver<topos_p2p::Command>, | ||
Arc<MessageSigner>, | ||
), | ||
) { | ||
let (mut context, mut p2p_receiver, message_signer) = setup_test.await; | ||
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 2); | ||
let certificate = certificates.pop().unwrap().certificate; | ||
|
||
let (sender, receiver) = oneshot::channel(); | ||
|
||
context | ||
.on_api_event(topos_tce_api::RuntimeEvent::CertificateSubmitted { | ||
certificate: Box::new(certificate), | ||
sender, | ||
}) | ||
.await; | ||
|
||
let response = receiver.await; | ||
|
||
assert!(matches!(response, Ok(Ok(PendingResult::AwaitPrecedence)))); | ||
} | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
async fn handle_certificate_already_delivered( | ||
#[future] setup_test: ( | ||
AppContext, | ||
mpsc::Receiver<topos_p2p::Command>, | ||
Arc<MessageSigner>, | ||
), | ||
) { | ||
let (mut context, mut p2p_receiver, message_signer) = setup_test.await; | ||
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1); | ||
let certificate_delivered = certificates.pop().unwrap(); | ||
|
||
_ = context | ||
.validator_store | ||
.insert_certificate_delivered(&certificate_delivered) | ||
.await | ||
.unwrap(); | ||
|
||
let certificate = certificate_delivered.certificate; | ||
|
||
let (sender, receiver) = oneshot::channel(); | ||
|
||
context | ||
.on_api_event(topos_tce_api::RuntimeEvent::CertificateSubmitted { | ||
certificate: Box::new(certificate), | ||
sender, | ||
}) | ||
.await; | ||
|
||
let response = receiver.await; | ||
|
||
assert!(matches!(response, Ok(Ok(PendingResult::AlreadyDelivered)))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use std::sync::Arc; | ||
|
||
use libp2p::PeerId; | ||
use prost::Message; | ||
use rstest::rstest; | ||
use test_log::test; | ||
use tokio::sync::mpsc; | ||
use topos_core::api::grpc::tce::v1::{double_echo_request, DoubleEchoRequest, Echo, Gossip, Ready}; | ||
use topos_crypto::{messages::MessageSigner, validator_id::ValidatorId}; | ||
use topos_test_sdk::{ | ||
certificates::create_certificate_chain, | ||
constants::{SOURCE_SUBNET_ID_1, TARGET_SUBNET_ID_1}, | ||
}; | ||
|
||
use crate::AppContext; | ||
|
||
use super::setup_test; | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
async fn handle_gossip( | ||
#[future] setup_test: ( | ||
AppContext, | ||
mpsc::Receiver<topos_p2p::Command>, | ||
Arc<MessageSigner>, | ||
), | ||
) { | ||
let (mut context, mut p2p_receiver, message_signer) = setup_test.await; | ||
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1); | ||
let certificate = certificates.pop().unwrap().certificate; | ||
|
||
let msg = DoubleEchoRequest { | ||
request: Some(double_echo_request::Request::Gossip(Gossip { | ||
certificate: Some(certificate.into()), | ||
})), | ||
}; | ||
context | ||
.on_net_event(topos_p2p::Event::Gossip { | ||
from: PeerId::random(), | ||
data: msg.encode_to_vec(), | ||
}) | ||
.await; | ||
} | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
async fn handle_echo( | ||
#[future] setup_test: ( | ||
AppContext, | ||
mpsc::Receiver<topos_p2p::Command>, | ||
Arc<MessageSigner>, | ||
), | ||
) { | ||
let (mut context, mut p2p_receiver, message_signer) = setup_test.await; | ||
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1); | ||
let certificate = certificates.pop().unwrap().certificate; | ||
let validator_id: ValidatorId = message_signer.public_address.into(); | ||
|
||
let msg = DoubleEchoRequest { | ||
request: Some(double_echo_request::Request::Echo(Echo { | ||
certificate_id: Some(certificate.id.into()), | ||
signature: Some(message_signer.sign_message(&[]).ok().unwrap().into()), | ||
validator_id: Some(validator_id.into()), | ||
})), | ||
}; | ||
context | ||
.on_net_event(topos_p2p::Event::Gossip { | ||
from: PeerId::random(), | ||
data: msg.encode_to_vec(), | ||
}) | ||
.await; | ||
} | ||
|
||
#[rstest] | ||
#[test(tokio::test)] | ||
async fn handle_ready( | ||
#[future] setup_test: ( | ||
AppContext, | ||
mpsc::Receiver<topos_p2p::Command>, | ||
Arc<MessageSigner>, | ||
), | ||
) { | ||
let (mut context, mut p2p_receiver, message_signer) = setup_test.await; | ||
let mut certificates = create_certificate_chain(SOURCE_SUBNET_ID_1, &[TARGET_SUBNET_ID_1], 1); | ||
let certificate = certificates.pop().unwrap().certificate; | ||
let validator_id: ValidatorId = message_signer.public_address.into(); | ||
|
||
let msg = DoubleEchoRequest { | ||
request: Some(double_echo_request::Request::Ready(Ready { | ||
certificate_id: Some(certificate.id.into()), | ||
signature: Some(message_signer.sign_message(&[]).ok().unwrap().into()), | ||
validator_id: Some(validator_id.into()), | ||
})), | ||
}; | ||
context | ||
.on_net_event(topos_p2p::Event::Gossip { | ||
from: PeerId::random(), | ||
data: msg.encode_to_vec(), | ||
}) | ||
.await; | ||
} |