Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EmptyDb useable #228

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 11 additions & 10 deletions firewood/src/v2/emptydb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ use super::propose::{Proposal, ProposalBase};
/// An EmptyDb is a simple implementation of api::Db
/// that doesn't store any data. It contains a single
/// HistoricalImpl that has no keys or values
#[derive(Debug, Default)]
struct EmptyDb {
root: Arc<HistoricalImpl>,
}
#[derive(Debug)]
pub struct EmptyDb;

/// HistoricalImpl is always empty, and there is only one,
/// since nothing can be committed to an EmptyDb.
#[derive(Debug, Default)]
struct HistoricalImpl;
#[derive(Debug)]
pub struct HistoricalImpl;

/// This is the hash of the [EmptyDb] root
const ROOT_HASH: [u8; 32] = [0; 32];
Expand All @@ -29,7 +27,7 @@ impl Db for EmptyDb {

async fn revision(&self, hash_key: HashKey) -> Result<Arc<Self::Historical>, Error> {
if hash_key == ROOT_HASH {
Ok(self.root.clone())
Ok(HistoricalImpl.into())
} else {
Err(Error::HashNotFound { provided: hash_key })
}
Expand All @@ -44,7 +42,10 @@ impl Db for EmptyDb {
K: KeyType,
V: ValueType,
{
Ok(Proposal::new(ProposalBase::View(self.root.clone()), data))
Ok(Proposal::new(
ProposalBase::View(HistoricalImpl.into()),
data,
))
}
}

Expand Down Expand Up @@ -82,7 +83,7 @@ mod tests {

#[tokio::test]
async fn basic_proposal() -> Result<(), Error> {
let db = Arc::new(EmptyDb::default());
let db = Arc::new(EmptyDb);

let batch = vec![
BatchOp::Put {
Expand All @@ -103,7 +104,7 @@ mod tests {

#[tokio::test]
async fn nested_proposal() -> Result<(), Error> {
let db = Arc::new(EmptyDb::default());
let db = Arc::new(EmptyDb);

// create proposal1 which adds key "k" with value "v" and deletes "z"
let batch = vec![
Expand Down
2 changes: 1 addition & 1 deletion firewood/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pub mod api;
pub mod db;
pub mod propose;

#[cfg(test)]
// #[cfg(test)]
pub mod emptydb;
Loading