Skip to content
Open
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
2 changes: 1 addition & 1 deletion bin/node/src/commands/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl BootstrapCommand {
let genesis_block =
read_bootstrap_genesis_block(self.genesis_block_file.as_deref(), self.network).await?;
let genesis_commitment = genesis_block.inner().header().commitment();
State::bootstrap(genesis_block, &self.data_directory)?;
State::bootstrap(genesis_block, &self.data_directory).await?;
tracing::info!(
target: crate::LOG_TARGET,
{
Expand Down
4 changes: 3 additions & 1 deletion bin/stress-test/src/seeding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ pub async fn seed_store_with_readers(
);
let genesis_block = genesis_state.into_block().expect("genesis block should be created");
let genesis_header = genesis_block.inner().header().clone();
State::bootstrap(genesis_block, &data_directory).expect("store should bootstrap");
State::bootstrap(genesis_block, &data_directory)
.await
.expect("store should bootstrap");

let (state, mut block_writer, writer_task) = load_state(data_directory.clone()).await;

Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
#[tokio::test]
async fn block_producer_starts_with_store_state() {
let data_directory = tempfile::tempdir().expect("tempdir should be created");
bootstrap_store(data_directory.path());
bootstrap_store(data_directory.path()).await;
let (state, block_writer, proof_writer) = State::for_tests(data_directory.path()).await;

let block_producer = Sequencer {
Expand All @@ -47,7 +47,7 @@ async fn block_producer_starts_with_store_state() {
assert_eq!(status.chain_tip, BlockNumber::GENESIS);
}

fn bootstrap_store(path: &std::path::Path) {
async fn bootstrap_store(path: &std::path::Path) {
let signer = random_secret_key();
let genesis_state = GenesisState::new(
vec![],
Expand All @@ -58,5 +58,5 @@ fn bootstrap_store(path: &std::path::Path) {
);
let genesis_block = genesis_state.into_block().expect("genesis block should be created");

State::bootstrap(genesis_block, path).expect("store should bootstrap");
State::bootstrap(genesis_block, path).await.expect("store should bootstrap");
}
13 changes: 7 additions & 6 deletions crates/rpc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl TestStore {

async fn start() -> Self {
let data_directory = new_tempdir();
let genesis_commitment = Self::bootstrap(&data_directory);
let genesis_commitment = Self::bootstrap(&data_directory).await;
let (state, ..) = State::for_tests(&data_directory).await;
Self {
state,
Expand All @@ -103,14 +103,14 @@ impl TestStore {
}
}

fn bootstrap(path: &std::path::Path) -> Word {
async fn bootstrap(path: &std::path::Path) -> Word {
let config = GenesisConfig::default();
let (genesis_state, _) = config.into_state().unwrap();
let genesis_block =
genesis_state.clone().into_block().expect("genesis block should be created");
let genesis_commitment = genesis_block.inner().header().commitment();

State::bootstrap(genesis_block, path).expect("store should bootstrap");
State::bootstrap(genesis_block, path).await.expect("store should bootstrap");

genesis_commitment
}
Expand Down Expand Up @@ -504,7 +504,8 @@ async fn rpc_rejects_post_deployment_network_account_tx() {
miden_node_store::test_support::seed_network_account(
&store.data_directory_path().join("miden-store.sqlite3"),
network_account_id,
);
)
.await;

// Build a non-deployment tx for that account.
let (account, _) = build_test_account([0; 32]);
Expand Down Expand Up @@ -626,7 +627,7 @@ async fn start_source_rpc(
) -> (RpcClient, TestStore) {
let store = TestStore::start().await;
let block_producer_dir = new_tempdir();
TestStore::bootstrap(&block_producer_dir);
TestStore::bootstrap(&block_producer_dir).await;
let (block_producer_state, ..) = State::for_tests(&block_producer_dir).await;
let state = Arc::clone(&store.state);

Expand Down Expand Up @@ -1102,7 +1103,7 @@ async fn start_rpc_with_options(
) -> (RpcClient, std::net::SocketAddr, TestStore) {
let store = TestStore::start().await;
let block_producer_dir = new_tempdir();
TestStore::bootstrap(&block_producer_dir);
TestStore::bootstrap(&block_producer_dir).await;
let (block_producer_state, ..) = State::for_tests(&block_producer_dir).await;
let state = Arc::clone(&store.state);

Expand Down
4 changes: 2 additions & 2 deletions crates/store/src/account_state_forest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use miden_protocol::{EMPTY_WORD, Word};
use thiserror::Error;

use crate::COMPONENT;
pub use crate::db::models::queries::HISTORICAL_BLOCK_RETENTION;
use crate::db::models::queries::{PrecomputedPublicAccountState, PrecomputedPublicAccountStates};
pub use crate::db::HISTORICAL_BLOCK_RETENTION;
use crate::db::{PrecomputedPublicAccountState, PrecomputedPublicAccountStates};
use crate::errors::AccountStateForestUpdateError;

#[cfg(test)]
Expand Down
16 changes: 0 additions & 16 deletions crates/store/src/db/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,5 @@ pub fn verify_latest_schema(database_filepath: &Path) -> std::result::Result<(),
Ok(())
}

#[cfg(test)]
pub(crate) fn test_connection() -> diesel::SqliteConnection {
use diesel::{Connection, SqliteConnection};

let temp_dir = tempfile::tempdir().expect("failed to create temp directory");
let database_filepath = temp_dir.path().join("test.sqlite3");
bootstrap_database(&database_filepath).expect("database should bootstrap");

let conn = SqliteConnection::establish(
database_filepath.to_str().expect("temp database path should be valid UTF-8"),
)
.expect("temp file sqlite should always work");
let _kept_dir = temp_dir.keep();
conn
}

#[cfg(test)]
mod tests;
65 changes: 26 additions & 39 deletions crates/store/src/db/migrations/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use std::process::Command;

use anyhow::{Context, Result, ensure};
use diesel::connection::SimpleConnection;
use diesel::query_dsl::methods::{OrderDsl, SelectDsl};
use diesel::{Connection, ExpressionMethods, RunQueryDsl, SqliteConnection};
use diesel::{Connection, SqliteConnection};
use miden_node_db::migration::{SchemaHash, SchemaHashes};

use super::*;
use crate::db::models::queries::VALID_FOREVER;
use crate::db::schema;
use crate::db::TestDb;
use crate::db::queries::VALID_FOREVER;

const EXPECTED_SCHEMA_HASHES: [SchemaHash; 4] = [
SchemaHash::from_hex("cc92cb332410e6f63036b52cf953acb446c142d5c0fbbdbd6d3b4f466510b210"),
Expand Down Expand Up @@ -60,33 +59,25 @@ fn migration_004_validity_intervals_backfills_valid_until() -> Result<()> {

migrate_database(&database_filepath)?;

let mut conn = SqliteConnection::establish(database_path_str)?;
let db = TestDb::open(&database_filepath);

let accounts: Vec<(i64, i64)> = OrderDsl::order(
SelectDsl::select(
schema::accounts::table,
(schema::accounts::block_num, schema::accounts::valid_until),
),
schema::accounts::block_num.asc(),
)
.load(&mut conn)?;
let accounts = db.read::<_, DatabaseError, _>(|tx| {
tx.query(
"SELECT block_num, valid_until FROM accounts ORDER BY block_num ASC",
&[],
|row| Ok((row.get::<i64>(0)?, row.get::<i64>(1)?)),
)
})?;
pretty_assertions::assert_eq!(accounts, vec![(1, 5), (5, VALID_FOREVER)]);

let vault: Vec<(Vec<u8>, i64, i64)> = OrderDsl::order(
SelectDsl::select(
schema::account_vault_assets::table,
(
schema::account_vault_assets::vault_key,
schema::account_vault_assets::block_num,
schema::account_vault_assets::valid_until,
),
),
(
schema::account_vault_assets::vault_key.asc(),
schema::account_vault_assets::block_num.asc(),
),
)
.load(&mut conn)?;
let vault = db.read::<_, DatabaseError, _>(|tx| {
tx.query(
"SELECT vault_key, block_num, valid_until FROM account_vault_assets \
ORDER BY vault_key ASC, block_num ASC",
&[],
|row| Ok((row.get::<Vec<u8>>(0)?, row.get::<i64>(1)?, row.get::<i64>(2)?)),
)
})?;
pretty_assertions::assert_eq!(
vault,
vec![
Expand All @@ -96,17 +87,13 @@ fn migration_004_validity_intervals_backfills_valid_until() -> Result<()> {
]
);

let storage: Vec<(i64, i64)> = OrderDsl::order(
SelectDsl::select(
schema::account_storage_map_values::table,
(
schema::account_storage_map_values::block_num,
schema::account_storage_map_values::valid_until,
),
),
schema::account_storage_map_values::block_num.asc(),
)
.load(&mut conn)?;
let storage = db.read::<_, DatabaseError, _>(|tx| {
tx.query(
"SELECT block_num, valid_until FROM account_storage_map_values ORDER BY block_num ASC",
&[],
|row| Ok((row.get::<i64>(0)?, row.get::<i64>(1)?)),
)
})?;
pretty_assertions::assert_eq!(storage, vec![(1, 5), (5, VALID_FOREVER)]);

Ok(())
Expand Down
Loading
Loading