Skip to content

Commit a8ad5f0

Browse files
committed
wip: db maintenance cleanup and tests
1 parent 8a74a59 commit a8ad5f0

File tree

7 files changed

+240
-33
lines changed

7 files changed

+240
-33
lines changed

crates/db/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ tracing.workspace = true
2929
futures-util = "0.3.31"
3030
tokio.workspace = true
3131
auto_impl = "1.3.0"
32+
33+
[dev-dependencies]
34+
serde_json.workspace = true
35+
reth-db = { workspace = true, features = ["test-utils"] }
36+
reth-exex-test-utils.workspace = true

crates/db/src/convert.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Type conversion traits and implementations for converting between Reth, Alloy, and Signet types.
22
//!
3-
//! This module provides a set of conversion traits that enable seamless interoperability
4-
//! between different type systems used in the Ethereum ecosystem:
3+
//! This module provides a set of conversion traits that enable seamless
4+
//! interoperability between different type systems used in the Ethereum
5+
//! ecosystem:
56
//!
67
//! - **Reth types**: Core primitives from the Reth Ethereum client
78
//! - **Alloy types**: Modern Ethereum types from the Alloy framework

crates/db/src/provider.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,31 +104,6 @@ where
104104
.map_err(Into::into)
105105
}
106106

107-
/// Increase the balance of an account.
108-
fn mint_eth(&self, address: Address, amount: U256) -> ProviderResult<Account> {
109-
let mut account = self.basic_account(&address)?.unwrap_or_default();
110-
account.balance = account.balance.saturating_add(amount);
111-
self.tx_ref().put::<PlainAccountState>(address, account)?;
112-
trace!(%address, balance = %account.balance, "minting ETH");
113-
Ok(account)
114-
}
115-
116-
/// Decrease the balance of an account.
117-
fn burn_eth(&self, address: Address, amount: U256) -> ProviderResult<Account> {
118-
let mut account = self.basic_account(&address)?.unwrap_or_default();
119-
if amount > account.balance {
120-
warn!(
121-
balance = %account.balance,
122-
amount = %amount,
123-
"burning more than balance"
124-
);
125-
}
126-
account.balance = account.balance.saturating_sub(amount);
127-
self.tx_ref().put::<PlainAccountState>(address, account)?;
128-
trace!(%address, balance = %account.balance, "burning ETH");
129-
Ok(account)
130-
}
131-
132107
fn insert_signet_header(
133108
&self,
134109
header: Zenith::BlockHeader,

crates/db/src/traits.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ pub trait RuWriter {
3131
/// Get the latest journal hash from the DB.
3232
fn latest_journal_hash(&self) -> ProviderResult<B256>;
3333

34-
/// Increase the balance of an account.
35-
fn mint_eth(&self, address: Address, amount: U256) -> ProviderResult<Account>;
36-
37-
/// Decrease the balance of an account.
38-
fn burn_eth(&self, address: Address, amount: U256) -> ProviderResult<Account>;
39-
4034
/// Store a zenith header in the DB
4135
fn insert_signet_header(
4236
&self,

crates/db/tests/common/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use alloy::genesis::Genesis;
2+
use reth::{
3+
chainspec::ChainSpec,
4+
providers::{ProviderFactory, providers::StaticFileProvider},
5+
};
6+
use reth_db::test_utils::{create_test_rw_db, create_test_static_files_dir};
7+
use reth_exex_test_utils::TmpDB as TmpDb;
8+
use signet_node_types::SignetNodeTypes;
9+
use std::sync::{Arc, OnceLock};
10+
11+
static GENESIS_JSON: &str = include_str!("../../../../tests/artifacts/local.genesis.json");
12+
13+
static SPEC: OnceLock<Arc<ChainSpec>> = OnceLock::new();
14+
15+
/// Returns a chain spec for tests.
16+
pub fn chain_spec() -> Arc<ChainSpec> {
17+
SPEC.get_or_init(|| {
18+
let genesis: Genesis = serde_json::from_str(GENESIS_JSON).expect("valid genesis json");
19+
Arc::new(genesis.into())
20+
})
21+
.clone()
22+
}
23+
24+
/// Create a provider factory with a chain spec
25+
pub fn create_test_provider_factory() -> ProviderFactory<SignetNodeTypes<TmpDb>> {
26+
let (static_dir, _) = create_test_static_files_dir();
27+
let db = create_test_rw_db();
28+
ProviderFactory::new(
29+
db,
30+
chain_spec(),
31+
StaticFileProvider::read_write(static_dir.keep()).expect("static file provider"),
32+
)
33+
}

crates/db/tests/db.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[path = "./common/mod.rs"]
2+
mod test_common;
3+
4+
use signet_db::RuWriter;
5+
6+
#[test]
7+
fn test_ru_writer() {
8+
let factory = test_common::create_test_provider_factory();
9+
10+
let writer = factory.provider_rw().unwrap();
11+
12+
dbg!(writer.last_block_number().unwrap());
13+
}

tests/artifacts/local.genesis.json

Lines changed: 186 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)