Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

tests: continue converting tests to use CommitteeFixture #918

Merged
merged 17 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions config/tests/snapshots/config_tests__committee.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ expression: committee
---
{
"authorities": {
"ildi4hrBzbOHBELHe0w69Yx87bh3nQJw5tTx4vc2fXQ=": {
"O6EMZUvkFG2rPW2rgLPOJM4323x0XCslMgXWL5Z7ALM=": {
"stake": 1,
"primary": {
"primary_to_primary": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_primary": "/ip4/127.0.0.1/tcp/0/http"
}
},
"rvP0pLjsod/DQzYb+OQ2vULeklnAS4MU644gVN1ugqs=": {
"gznZnDM7s6J3/reAuNRsrDDNzZBQ2+I1+4zGe5HBsGo=": {
"stake": 1,
"primary": {
"primary_to_primary": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_primary": "/ip4/127.0.0.1/tcp/0/http"
}
},
"ucbuFjDvPnERRKZI2wa7sihPcnTPvuU//O5QPMGkkgA=": {
"nUdhahjfIDkwfwZCImAliLUqaq6qe2/oxrTZ66inh7E=": {
"stake": 1,
"primary": {
"primary_to_primary": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_primary": "/ip4/127.0.0.1/tcp/0/http"
}
},
"zGIzLjS7LVzWn2Dvuyo2y5FsfrRYMB6jZjbE27ASvYg=": {
"ucbuFjDvPnERRKZI2wa7sihPcnTPvuU//O5QPMGkkgA=": {
"stake": 1,
"primary": {
"primary_to_primary": "/ip4/127.0.0.1/tcp/0/http",
Expand Down
8 changes: 4 additions & 4 deletions config/tests/snapshots/config_tests__worker_cache.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: worker_cache
---
{
"workers": {
"ildi4hrBzbOHBELHe0w69Yx87bh3nQJw5tTx4vc2fXQ=": {
"O6EMZUvkFG2rPW2rgLPOJM4323x0XCslMgXWL5Z7ALM=": {
"0": {
"transactions": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_worker": "/ip4/127.0.0.1/tcp/0/http",
Expand All @@ -26,7 +26,7 @@ expression: worker_cache
"primary_to_worker": "/ip4/127.0.0.1/tcp/0/http"
}
},
"rvP0pLjsod/DQzYb+OQ2vULeklnAS4MU644gVN1ugqs=": {
"gznZnDM7s6J3/reAuNRsrDDNzZBQ2+I1+4zGe5HBsGo=": {
"0": {
"transactions": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_worker": "/ip4/127.0.0.1/tcp/0/http",
Expand All @@ -48,7 +48,7 @@ expression: worker_cache
"primary_to_worker": "/ip4/127.0.0.1/tcp/0/http"
}
},
"ucbuFjDvPnERRKZI2wa7sihPcnTPvuU//O5QPMGkkgA=": {
"nUdhahjfIDkwfwZCImAliLUqaq6qe2/oxrTZ66inh7E=": {
"0": {
"transactions": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_worker": "/ip4/127.0.0.1/tcp/0/http",
Expand All @@ -70,7 +70,7 @@ expression: worker_cache
"primary_to_worker": "/ip4/127.0.0.1/tcp/0/http"
}
},
"zGIzLjS7LVzWn2Dvuyo2y5FsfrRYMB6jZjbE27ASvYg=": {
"ucbuFjDvPnERRKZI2wa7sihPcnTPvuU//O5QPMGkkgA=": {
"0": {
"transactions": "/ip4/127.0.0.1/tcp/0/http",
"worker_to_worker": "/ip4/127.0.0.1/tcp/0/http",
Expand Down
2 changes: 1 addition & 1 deletion executor/tests/consensus_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async fn test_internal_consensus_output() {
// nodes logs.
let _guard = setup_tracing();

let mut cluster = Cluster::new(None, None, None, true);
let mut cluster = Cluster::new(None, true);

// start the cluster
cluster.start(Some(4), Some(1), None).await;
Expand Down
83 changes: 61 additions & 22 deletions primary/src/tests/block_waiter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use mockall::*;
use network::PrimaryToWorkerNetwork;
use std::{collections::HashMap, sync::Arc};
use test_utils::{
certificate, fixture_batch_with_transactions, fixture_header_builder,
fixture_header_with_payload, keys, resolve_name_committee_and_worker_cache,
PrimaryToWorkerMockServer,
fixture_batch_with_transactions, fixture_payload, CommitteeFixture, PrimaryToWorkerMockServer,
};
use tokio::{
sync::{oneshot, watch},
Expand All @@ -32,11 +30,19 @@ use types::{
#[tokio::test]
async fn test_successfully_retrieve_block() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let author = fixture.authorities().next().unwrap();
let name = fixture.authorities().nth(1).unwrap().public_key();

// AND store certificate
let header = fixture_header_with_payload(2);
let certificate = certificate(&header);
let header = author
.header_builder(&committee)
.payload(fixture_payload(2))
.build(author.keypair())
.unwrap();
let certificate = fixture.certificate(&header);
let block_id = certificate.digest();

// AND spawn a new blocks waiter
Expand Down Expand Up @@ -139,9 +145,12 @@ async fn test_successfully_retrieve_block() {
#[tokio::test]
async fn test_successfully_retrieve_multiple_blocks() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let author = fixture.authorities().next().unwrap();
let name = fixture.authorities().nth(1).unwrap().public_key();

let key = keys(None).pop().unwrap();
let mut block_ids = Vec::new();
let mut expected_batch_messages = HashMap::new();
let worker_id = 0;
Expand All @@ -155,7 +164,7 @@ async fn test_successfully_retrieve_multiple_blocks() {
let common_batch_2 = fixture_batch_with_transactions(10);

for i in 0..10 {
let mut builder = fixture_header_builder();
let mut builder = author.header_builder(&committee);

let batch_1 = fixture_batch_with_transactions(10);
let batch_2 = fixture_batch_with_transactions(10);
Expand Down Expand Up @@ -228,9 +237,9 @@ async fn test_successfully_retrieve_multiple_blocks() {
// sort the batches to make sure that the response is the expected one.
batches.sort_by(|a, b| a.id.cmp(&b.id));

let header = builder.build(&key).unwrap();
let header = builder.build(author.keypair()).unwrap();

let certificate = certificate(&header);
let certificate = fixture.certificate(&header);
certificates.push(certificate.clone());

block_ids.push(certificate.digest());
Expand Down Expand Up @@ -341,11 +350,19 @@ async fn test_successfully_retrieve_multiple_blocks() {
#[tokio::test]
async fn test_one_pending_request_for_block_at_time() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let author = fixture.authorities().next().unwrap();
let name = fixture.authorities().nth(1).unwrap().public_key();

// AND store certificate
let header = fixture_header_with_payload(2);
let certificate = certificate(&header);
let header = author
.header_builder(&committee)
.payload(fixture_payload(2))
.build(author.keypair())
.unwrap();
let certificate = fixture.certificate(&header);
let block_id = certificate.digest();

// AND
Expand Down Expand Up @@ -419,11 +436,19 @@ async fn test_one_pending_request_for_block_at_time() {
#[tokio::test]
async fn test_unlocking_pending_get_block_request_after_response() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let author = fixture.authorities().next().unwrap();
let name = fixture.authorities().nth(1).unwrap().public_key();

// AND store certificate
let header = fixture_header_with_payload(2);
let certificate = certificate(&header);
let header = author
.header_builder(&committee)
.payload(fixture_payload(2))
.build(author.keypair())
.unwrap();
let certificate = fixture.certificate(&header);
let block_id = certificate.digest();

// AND spawn a new blocks waiter
Expand Down Expand Up @@ -488,11 +513,19 @@ async fn test_unlocking_pending_get_block_request_after_response() {
#[tokio::test]
async fn test_batch_timeout() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let author = fixture.authorities().next().unwrap();
let name = fixture.authorities().nth(1).unwrap().public_key();

// AND store certificate
let header = fixture_header_with_payload(2);
let certificate = certificate(&header);
let header = author
.header_builder(&committee)
.payload(fixture_payload(2))
.build(author.keypair())
.unwrap();
let certificate = fixture.certificate(&header);
let block_id = certificate.digest();

// AND spawn a new blocks waiter
Expand Down Expand Up @@ -559,7 +592,10 @@ async fn test_batch_timeout() {
#[tokio::test]
async fn test_return_error_when_certificate_is_missing() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let name = fixture.authorities().nth(1).unwrap().public_key();

// AND create a certificate but don't store it
let certificate = Certificate::default();
Expand Down Expand Up @@ -622,7 +658,10 @@ async fn test_return_error_when_certificate_is_missing() {
#[tokio::test]
async fn test_return_error_when_certificate_is_missing_when_get_blocks() {
// GIVEN
let (name, committee, worker_cache) = resolve_name_committee_and_worker_cache();
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let name = fixture.authorities().nth(1).unwrap().public_key();

// AND create a certificate but don't store it
let certificate = Certificate::default();
Expand Down
51 changes: 24 additions & 27 deletions primary/src/tests/certificate_waiter_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ use fastcrypto::{traits::KeyPair, Hash, SignatureService};
use network::{PrimaryNetwork, PrimaryToWorkerNetwork};
use prometheus::Registry;
use std::{collections::BTreeSet, sync::Arc, time::Duration};
use test_utils::{
certificate, fixture_headers_round, keys, pure_committee_from_keys,
shared_worker_cache_from_keys,
};
use test_utils::CommitteeFixture;
use tokio::sync::watch;
use types::{Certificate, PrimaryMessage, ReconfigureNotification, Round};

#[tokio::test]
async fn process_certificate_missing_parents_in_reverse() {
let mut k = keys(None);
let committee = pure_committee_from_keys(&k);
let worker_cache = shared_worker_cache_from_keys(&k);
let kp = k.pop().unwrap();
let network_key = kp.copy().private().0.to_bytes();
let name = kp.public().clone();
let signature_service = SignatureService::new(kp);
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let primary = fixture.authorities().next().unwrap();
let network_key = primary.keypair().copy().private().0.to_bytes();
let name = primary.public_key();
let signature_service = SignatureService::new(primary.keypair().copy());

// kept empty
let (_tx_reconfigure, rx_reconfigure) =
Expand Down Expand Up @@ -138,9 +135,9 @@ async fn process_certificate_missing_parents_in_reverse() {
for i in 0..rounds {
let parents: BTreeSet<_> = current_round
.into_iter()
.map(|header| certificate(&header).digest())
.map(|header| fixture.certificate(&header).digest())
.collect();
(_, current_round) = fixture_headers_round(i, &parents);
(_, current_round) = fixture.headers_round(i, &parents);
headers.extend(current_round.clone());
}

Expand All @@ -150,17 +147,17 @@ async fn process_certificate_missing_parents_in_reverse() {
}

// sanity-check
assert!(headers.len() == keys(None).len() * rounds as usize); // note we don't include genesis
assert!(headers.len() == fixture.authorities().count() * rounds as usize); // note we don't include genesis

// the `rev()` below is important, as we want to test anti-topological arrival
#[allow(clippy::needless_collect)]
let ids: Vec<_> = headers
.iter()
.map(|header| certificate(header).digest())
.map(|header| fixture.certificate(header).digest())
.collect();
for header in headers.into_iter().rev() {
tx_primary_messages
.send(PrimaryMessage::Certificate(certificate(&header)))
.send(PrimaryMessage::Certificate(fixture.certificate(&header)))
.await
.unwrap();
}
Expand All @@ -175,13 +172,13 @@ async fn process_certificate_missing_parents_in_reverse() {

#[tokio::test]
async fn process_certificate_check_gc_fires() {
let mut k = keys(None);
let committee = pure_committee_from_keys(&k);
let worker_cache = shared_worker_cache_from_keys(&k);
let kp = k.pop().unwrap();
let network_key = kp.copy().private().0.to_bytes();
let name = kp.public().clone();
let signature_service = SignatureService::new(kp);
let fixture = CommitteeFixture::builder().randomize_ports(true).build();
let committee = fixture.committee();
let worker_cache = fixture.shared_worker_cache();
let primary = fixture.authorities().next().unwrap();
let network_key = primary.keypair().copy().private().0.to_bytes();
let name = primary.public_key();
let signature_service = SignatureService::new(primary.keypair().copy());

// kept empty
let (_tx_reconfigure, rx_reconfigure) =
Expand Down Expand Up @@ -292,9 +289,9 @@ async fn process_certificate_check_gc_fires() {
for i in 0..rounds {
let parents: BTreeSet<_> = current_round
.into_iter()
.map(|header| certificate(&header).digest())
.map(|header| fixture.certificate(&header).digest())
.collect();
(_, current_round) = fixture_headers_round(i, &parents);
(_, current_round) = fixture.headers_round(i, &parents);
headers.extend(current_round.clone());
}

Expand All @@ -304,11 +301,11 @@ async fn process_certificate_check_gc_fires() {
}

// sanity-check
assert!(headers.len() == keys(None).len() * rounds as usize); // note we don't include genesis
assert!(headers.len() == fixture.authorities().count() * rounds as usize); // note we don't include genesis

// Just send the last header, the causal certificate completion cannot complete
let header = headers.last().unwrap();
let cert = certificate(header);
let cert = fixture.certificate(header);
let id = cert.digest();

tx_primary_messages
Expand Down
Loading