refactor: remove Transaction and add DatabaseProvider to stages (#3034)

Co-authored-by: Georgios Konstantopoulos <me@gakonst.com>
This commit is contained in:
joshieDo
2023-06-12 23:37:58 +01:00
committed by GitHub
parent cfdd88d392
commit f55d88b8c4
58 changed files with 2326 additions and 2109 deletions

View File

@ -6,9 +6,9 @@ use crate::{
};
use reth_db::mdbx::test_utils::create_test_rw_db;
use reth_primitives::{BlockBody, SealedBlock};
use reth_provider::Transaction;
use reth_provider::ShareableDatabase;
use reth_stages::{stages::ExecutionStage, ExecInput, Stage};
use std::{collections::BTreeMap, ffi::OsStr, fs, ops::Deref, path::Path, sync::Arc};
use std::{collections::BTreeMap, ffi::OsStr, fs, path::Path, sync::Arc};
/// A handler for the blockchain test suite.
#[derive(Debug)]
@ -75,19 +75,21 @@ impl Case for BlockchainTestCase {
// Create the database
let db = create_test_rw_db();
let mut transaction = Transaction::new(db.as_ref())?;
let factory =
ShareableDatabase::new(db.as_ref(), Arc::new(case.network.clone().into()));
let mut provider = factory.provider_rw().unwrap();
// Insert test state
reth_provider::insert_canonical_block(
transaction.deref(),
provider.tx_ref(),
SealedBlock::new(case.genesis_block_header.clone().into(), BlockBody::default()),
None,
)?;
case.pre.write_to_db(transaction.deref())?;
case.pre.write_to_db(provider.tx_ref())?;
let mut last_block = None;
for block in case.blocks.iter() {
last_block = Some(block.write_to_db(transaction.deref())?);
last_block = Some(block.write_to_db(provider.tx_ref())?);
}
// Call execution stage
@ -103,7 +105,7 @@ impl Case for BlockchainTestCase {
// ignore error
let _ = stage
.execute(
&mut transaction,
&mut provider,
ExecInput { target: last_block, checkpoint: None },
)
.await;
@ -118,13 +120,13 @@ impl Case for BlockchainTestCase {
}
Some(RootOrState::State(state)) => {
for (&address, account) in state.iter() {
account.assert_db(address, transaction.deref())?;
account.assert_db(address, provider.tx_ref())?;
}
}
None => println!("No post-state"),
}
transaction.close();
drop(provider);
}
Ok(())
}