Skip to content

Commit

Permalink
[Testcase] Add sequencer accumulator test cases (#1941)
Browse files Browse the repository at this point in the history
* update last_sequencer_info

* add sequencer acumulator test caese

* fixup testcases

* remove last order update
  • Loading branch information
baichuan3 authored Jun 19, 2024
1 parent 11b00a3 commit ddaaa15
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
13 changes: 7 additions & 6 deletions crates/rooch-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ impl RoochDB {
None,
)?))?;

let rooch_store = RoochStore::new(StoreInstance::new_db_instance(RocksDB::new(
rooch_store_dir,
rooch_store::StoreMeta::get_column_family_names().to_vec(),
config.rocksdb_config(false),
None,
)?))?;
let rooch_store =
RoochStore::new_with_instance(StoreInstance::new_db_instance(RocksDB::new(
rooch_store_dir,
rooch_store::StoreMeta::get_column_family_names().to_vec(),
config.rocksdb_config(false),
None,
)?))?;

let indexer_store = IndexerStore::new(indexer_store_dir.clone())?;
let indexer_reader = IndexerReader::new(indexer_store_dir)?;
Expand Down
5 changes: 3 additions & 2 deletions crates/rooch-sequencer/src/actor/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ impl SequencerActor {

let sequencer_info =
SequencerInfo::new(tx.sequence_info.tx_order, self.tx_accumulator.get_info());
self.rooch_store.save_sequencer_info(sequencer_info)?;
self.rooch_store
.save_sequencer_info(sequencer_info.clone())?;
self.rooch_store.save_transaction(tx.clone())?;
info!("sequencer tx: {} order: {:?}", hash, tx_order);
self.last_sequencer_info.last_order = tx_order;
self.last_sequencer_info = sequencer_info;
Ok(tx)
}
}
Expand Down
24 changes: 23 additions & 1 deletion crates/rooch-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ use crate::meta_store::{MetaDBStore, MetaStore};
use crate::transaction_store::{TransactionDBStore, TransactionStore};
use accumulator::AccumulatorTreeStore;
use anyhow::Result;
use moveos_config::store_config::RocksdbConfig;
use moveos_config::DataDirPath;
use moveos_types::h256::H256;
use once_cell::sync::Lazy;
use raw_store::rocks::RocksDB;
use raw_store::{ColumnFamilyName, StoreInstance};
use rooch_types::sequencer::SequencerInfo;
use rooch_types::transaction::LedgerTransaction;
use std::fmt::{Debug, Display, Formatter};
use std::path::Path;
use std::sync::Arc;

pub mod accumulator_store;
pub mod meta_store;
#[cfg(test)]
mod tests;
pub mod transaction_store;

// pub const DEFAULT_PREFIX_NAME: ColumnFamilyName = "default";
Expand Down Expand Up @@ -52,7 +58,17 @@ pub struct RoochStore {
}

impl RoochStore {
pub fn new(instance: StoreInstance) -> Result<Self> {
pub fn new(db_path: &Path) -> Result<Self> {
let instance = StoreInstance::new_db_instance(RocksDB::new(
db_path,
StoreMeta::get_column_family_names().to_vec(),
RocksdbConfig::default(),
None,
)?);
Self::new_with_instance(instance)
}

pub fn new_with_instance(instance: StoreInstance) -> Result<Self> {
let store = Self {
transaction_store: TransactionDBStore::new(instance.clone()),
meta_store: MetaDBStore::new(instance.clone()),
Expand All @@ -63,6 +79,12 @@ impl RoochStore {
Ok(store)
}

pub fn mock_rooch_store() -> Result<(Self, DataDirPath)> {
let tmpdir = moveos_config::temp_dir();
//The testcases should hold the tmpdir to prevent the tmpdir from being deleted.
Ok((Self::new(tmpdir.path())?, tmpdir))
}

pub fn get_transaction_store(&self) -> &TransactionDBStore {
&self.transaction_store
}
Expand Down
4 changes: 4 additions & 0 deletions crates/rooch-store/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

mod test_accumulator;
25 changes: 25 additions & 0 deletions crates/rooch-store/src/tests/test_accumulator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::RoochStore;
use accumulator::node_index::NodeIndex;
use accumulator::{AccumulatorNode, AccumulatorTreeStore};
use moveos_types::h256::H256;

#[test]
fn test_accumulator_store() {
let (rooch_store, _) = RoochStore::mock_rooch_store().unwrap();

let acc_node = AccumulatorNode::new_leaf(NodeIndex::from_inorder_index(1), H256::random());
let node_hash = acc_node.hash();
rooch_store
.transaction_accumulator_store
.save_node(acc_node.clone())
.unwrap();
let acc_node2 = rooch_store
.transaction_accumulator_store
.get_node(node_hash)
.unwrap()
.unwrap();
assert_eq!(acc_node, acc_node2);
}

0 comments on commit ddaaa15

Please sign in to comment.