Skip to content

Commit

Permalink
refactor: remove old integration tests (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Aug 12, 2024
1 parent 96c92b6 commit ae731de
Show file tree
Hide file tree
Showing 17 changed files with 10 additions and 107,723 deletions.
119 changes: 9 additions & 110 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ redis = "=0.26.0"
rocksdb = { version = "=0.22.0", features = ["multi-threaded-cf"] }
sqlx = { version = "=0.7.4", features = ["runtime-tokio", "postgres", "bigdecimal", "time"] }

# containers
testcontainers = "=0.15.0"
testcontainers-modules = { version = "=0.3.5", features = ["postgres"] }

# test
fake = { version = "=2.9.2", features = ["chrono", "derive"] }

Expand Down
34 changes: 1 addition & 33 deletions src/bin/importer_offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,22 @@
//! arrive.
use std::cmp::min;
use std::fs;
use std::sync::Arc;

use anyhow::anyhow;
use futures::try_join;
use futures::StreamExt;
use itertools::Itertools;
use stratus::config::ImporterOfflineConfig;
use stratus::eth::executor::Executor;
use stratus::eth::miner::Miner;
use stratus::eth::miner::MinerMode;
use stratus::eth::primitives::Block;
use stratus::eth::primitives::BlockNumber;
use stratus::eth::primitives::ExternalBlock;
use stratus::eth::primitives::ExternalReceipt;
use stratus::eth::primitives::ExternalReceipts;
use stratus::eth::storage::ExternalRpcStorage;
use stratus::eth::storage::InMemoryPermanentStorage;
use stratus::ext::spawn_named;
use stratus::ext::spawn_thread;
use stratus::ext::to_json_string_pretty;
use stratus::log_and_err;
use stratus::utils::calculate_tps_and_bpm;
use stratus::utils::DropTimer;
Expand Down Expand Up @@ -57,9 +52,6 @@ async fn run(config: ImporterOfflineConfig) -> anyhow::Result<()> {
let miner = config.miner.init_with_mode(MinerMode::External, Arc::clone(&storage))?;
let executor = config.executor.init(Arc::clone(&storage), Arc::clone(&miner));

// init block snapshots to export
let block_snapshots = config.export_snapshot.into_iter().map_into().collect();

// init block range
let block_start = match config.block_start {
Some(start) => BlockNumber::from(start),
Expand All @@ -85,7 +77,7 @@ async fn run(config: ImporterOfflineConfig) -> anyhow::Result<()> {
});

let block_importer = spawn_thread("block-importer", || {
if let Err(e) = execute_block_importer(executor, miner, backlog_rx, block_snapshots) {
if let Err(e) = execute_block_importer(executor, miner, backlog_rx) {
tracing::error!(reason = ?e, "'block-importer' task failed");
}
});
Expand All @@ -109,7 +101,6 @@ fn execute_block_importer(
miner: Arc<Miner>,
// data
mut backlog_rx: mpsc::Receiver<BacklogTask>,
blocks_to_export_snapshot: Vec<BlockNumber>,
) -> anyhow::Result<()> {
const TASK_NAME: &str = "external-block-executor";
let _timer = DropTimer::start("importer-offline::execute_block_importer");
Expand Down Expand Up @@ -160,9 +151,6 @@ fn execute_block_importer(

// mine and save block
let mined_block = miner.mine_external()?;
if blocks_to_export_snapshot.contains(&mined_block.number()) {
export_snapshot(&block, &receipts, &mined_block)?;
}
miner.commit(mined_block.clone())?;
}

Expand Down Expand Up @@ -259,23 +247,3 @@ async fn block_number_to_stop(rpc_storage: &Arc<dyn ExternalRpcStorage>) -> anyh
Err(e) => Err(e),
}
}

// -----------------------------------------------------------------------------
// Snapshot exporter
// -----------------------------------------------------------------------------
fn export_snapshot(external_block: &ExternalBlock, external_receipts: &ExternalReceipts, mined_block: &Block) -> anyhow::Result<()> {
// generate snapshot
let state_snapshot = InMemoryPermanentStorage::dump_snapshot(mined_block.compact_account_changes());
let receipts_snapshot = external_receipts.filter_block(external_block.number());

// create dir
let dir = format!("tests/fixtures/snapshots/{}/", mined_block.number());
fs::create_dir_all(&dir)?;

// write json
fs::write(format!("{}/block.json", dir), to_json_string_pretty(external_block))?;
fs::write(format!("{}/receipts.json", dir), to_json_string_pretty(&receipts_snapshot))?;
fs::write(format!("{}/snapshot.json", dir), to_json_string_pretty(&state_snapshot))?;

Ok(())
}
4 changes: 0 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ pub struct ImporterOfflineConfig {
#[arg(short = 'b', long = "blocks-by-fetch", env = "BLOCKS_BY_FETCH", default_value = "10000")]
pub blocks_by_fetch: usize,

/// Export selected blocks to fixtures snapshots to be used in tests.
#[arg(long = "export-snapshot", env = "EXPORT_SNAPSHOT", value_delimiter = ',')]
pub export_snapshot: Vec<u64>,

#[clap(flatten)]
pub executor: ExecutorConfig,

Expand Down
36 changes: 0 additions & 36 deletions src/eth/storage/inmemory/inmemory_permanent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::eth::primitives::BlockFilter;
use crate::eth::primitives::BlockNumber;
use crate::eth::primitives::Bytes;
use crate::eth::primitives::CodeHash;
use crate::eth::primitives::ExecutionAccountChanges;
use crate::eth::primitives::Hash;
use crate::eth::primitives::LogFilter;
use crate::eth::primitives::LogMined;
Expand Down Expand Up @@ -66,41 +65,6 @@ impl InMemoryPermanentStorage {
self.state.write().unwrap()
}

// -------------------------------------------------------------------------
// Snapshot methods
// -------------------------------------------------------------------------

/// Dump a snapshot of an execution previous state that can be used in tests.
pub fn dump_snapshot(changes: Vec<ExecutionAccountChanges>) -> InMemoryPermanentStorageState {
let mut state = InMemoryPermanentStorageState::default();
for change in changes {
// save account
let mut account = InMemoryPermanentAccount::new_empty(change.address);
account.balance = InMemoryHistory::new_at_zero(change.balance.take_original().unwrap_or_default());
account.nonce = InMemoryHistory::new_at_zero(change.nonce.take_original().unwrap_or_default());
account.bytecode = InMemoryHistory::new_at_zero(change.bytecode.take_original().unwrap_or_default());

// save slots
for (index, slot) in change.slots {
let slot = slot.take_original().unwrap_or_default();
let slot_history = InMemoryHistory::new_at_zero(slot);
account.slots.insert(index, slot_history);
}

state.accounts.insert(change.address, account);
}
state
}

/// Creates a new InMemoryPermanentStorage from a snapshot dump.
pub fn from_snapshot(state: InMemoryPermanentStorageState) -> Self {
tracing::info!("creating inmemory permanent storage from snapshot");
Self {
state: RwLock::new(state),
block_number: AtomicU64::new(0),
}
}

// -------------------------------------------------------------------------
// State methods
// -------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit ae731de

Please sign in to comment.