Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeiannucci committed Oct 8, 2024
1 parent ce1043e commit 0f8f8e4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
48 changes: 47 additions & 1 deletion sequencer/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@ mod persistence_tests {
data::{DaProposal, QuorumProposal, VidDisperseShare, ViewNumber},
event::{EventType, HotShotAction, LeafInfo},
message::Proposal,
simple_certificate::QuorumCertificate,
simple_certificate::{QuorumCertificate, UpgradeCertificate},
simple_vote::UpgradeProposalData,
traits::{node_implementation::ConsensusTime, EncodeBytes},
vid::vid_scheme,
};
use jf_vid::VidScheme;
use sequencer_utils::test_utils::setup_test;
use testing::TestablePersistence;
use vbs::version::Version;

use super::*;

Expand Down Expand Up @@ -469,6 +471,50 @@ mod persistence_tests {
);
}

#[async_std::test]
pub async fn test_upgrade_certificate<P: TestablePersistence>() {
setup_test();

let tmp = P::tmp_storage().await;
let storage = P::connect(&tmp).await;

// Test get upgrade certificate
assert_eq!(storage.load_upgrade_certificate().await.unwrap(), None);

let upgrade_data = UpgradeProposalData {
old_version: Version { major: 0, minor: 1 },
new_version: Version { major: 1, minor: 0 },
decide_by: ViewNumber::genesis(),
new_version_hash: Default::default(),
old_version_last_view: ViewNumber::genesis(),
new_version_first_view: ViewNumber::genesis(),
};

let decide_upgrade_certificate = UpgradeCertificate::<SeqTypes>::new(
upgrade_data.clone(),
upgrade_data.commit(),
ViewNumber::genesis(),
Default::default(),
Default::default(),
);
storage
.store_upgrade_certificate(Some(decide_upgrade_certificate.clone()))
.await
.unwrap();

let res = storage.load_upgrade_certificate().await.unwrap();
let view_number = res.unwrap().view_number;
assert_eq!(view_number, ViewNumber::genesis());

let new_view_number_for_certificate = ViewNumber::new(50);
let mut new_upgrade_certificate = decide_upgrade_certificate.clone();
new_upgrade_certificate.view_number = new_view_number_for_certificate;

let res = storage.load_upgrade_certificate().await.unwrap();
let view_number = res.unwrap().view_number;
assert_eq!(view_number, new_view_number_for_certificate);
}

#[async_std::test]
pub async fn test_decide_with_failing_event_consumer<P: TestablePersistence>() {
#[derive(Clone, Copy, Debug)]
Expand Down
4 changes: 0 additions & 4 deletions sequencer/src/persistence/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,6 @@ async fn collect_garbage(
)
.await?;

// Cleanup upgrade certificate, should only be 1
tx.execute("DELETE FROM upgrade_certificate where id <= $1", [&(0i32)])
.await?;

// Exclude from the decide event any leaves which have definitely already been processed. We may
// have selected an already-processed leaf because the oldest leaf -- the last leaf processed in
// the previous decide event -- remained in the database to serve as the anchor leaf, so our
Expand Down

0 comments on commit 0f8f8e4

Please sign in to comment.