Skip to content

Commit

Permalink
consensus-logic, test-utils: fixed broken tests due to simplified con…
Browse files Browse the repository at this point in the history
…text type
  • Loading branch information
delbonis committed Feb 2, 2025
1 parent 8213a1a commit b65dd92
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 29 deletions.
34 changes: 10 additions & 24 deletions crates/consensus-logic/src/csm/client_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ mod tests {
use strata_rocksdb::test_utils::get_common_db;
use strata_state::{l1::L1BlockId, operation};
use strata_test_utils::{
bitcoin::{gen_l1_chain, get_btc_chain},
bitcoin::{gen_l1_chain, get_btc_chain, BtcChainSegment},
l2::{gen_client_state, gen_params},
ArbitraryGenerator,
};
Expand All @@ -504,18 +504,21 @@ mod tests {
use crate::genesis;

pub struct DummyEventContext {
// nothing
chainseg: BtcChainSegment,
}

impl DummyEventContext {
pub fn new() -> Self {
Self {}
Self {
chainseg: get_btc_chain(),
}
}
}

impl EventContext for DummyEventContext {
fn get_l1_block_manifest(&self, height: u64) -> Result<L1BlockManifest, Error> {
Ok(ArbitraryGenerator::new().generate())
let rec = self.chainseg.get_block_record(height as u32);
Ok(L1BlockManifest::new(rec, height))
}

fn get_l2_block_data(&self, blkid: &L2BlockId) -> Result<L2BlockBundle, Error> {
Expand All @@ -538,12 +541,7 @@ mod tests {
state_assertions: Box<dyn Fn(&ClientState)>, // Closure to verify state after all events
}

fn run_test_cases(
test_cases: &[TestCase],
state: &mut ClientState,
database: &impl Database,
params: &Params,
) {
fn run_test_cases(test_cases: &[TestCase], state: &mut ClientState, params: &Params) {
let context = DummyEventContext::new();

for case in test_cases {
Expand Down Expand Up @@ -574,31 +572,19 @@ mod tests {

#[test]
fn test_genesis() {
let database = get_common_db();
let params = gen_params();
let mut state = gen_client_state(Some(&params));

let horizon = params.rollup().horizon_l1_height;
let genesis = params.rollup().genesis_l1_height;

let chain = get_btc_chain();
let l1_chain = chain.get_block_manifests(horizon as u32, 10);
let l1_verification_state =
chain.get_verification_state(genesis as u32 + 1, &MAINNET.clone().into());

let genesis_block = genesis::make_genesis_block(&params);
let genesis_blockid = genesis_block.header().get_blockid();

let l1_db = database.l1_db();
for (i, b) in l1_chain.iter().enumerate() {
l1_db
.put_block_data(
i as u64 + horizon,
L1BlockManifest::new(b.clone(), 0),
Vec::new(),
)
.expect("test: insert blocks");
}
let l1_chain = chain.get_block_records(horizon as u32, 10);
let blkids: Vec<L1BlockId> = l1_chain.iter().map(|b| b.block_hash()).collect();

let test_cases = [
Expand Down Expand Up @@ -743,6 +729,6 @@ mod tests {
},
];

run_test_cases(&test_cases, &mut state, database.as_ref(), &params);
run_test_cases(&test_cases, &mut state, &params);
}
}
6 changes: 3 additions & 3 deletions crates/test-utils/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl BtcChainSegment {
}
}

pub fn get_block_manifest(&self, height: u32) -> L1BlockRecord {
pub fn get_block_record(&self, height: u32) -> L1BlockRecord {
let header = self.get_header(height);
L1BlockRecord::new(
header.block_hash().into(),
Expand All @@ -126,10 +126,10 @@ impl BtcChainSegment {
)
}

pub fn get_block_manifests(&self, from_height: u32, len: usize) -> Vec<L1BlockRecord> {
pub fn get_block_records(&self, from_height: u32, len: usize) -> Vec<L1BlockRecord> {
let mut blocks = Vec::with_capacity(len);
for i in 0..len {
let block = self.get_block_manifest(from_height + i as u32);
let block = self.get_block_record(from_height + i as u32);
blocks.push(block);
}
blocks
Expand Down
2 changes: 1 addition & 1 deletion crates/test-utils/src/l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ pub fn get_genesis_chainstate() -> Chainstate {
// Build the genesis block and genesis consensus states.
let gblock = make_genesis_block(&params);
let pregenesis_mfs =
vec![get_btc_chain().get_block_manifest(params.rollup().horizon_l1_height as u32)];
vec![get_btc_chain().get_block_record(params.rollup().horizon_l1_height as u32)];
make_genesis_chainstate(&gblock, pregenesis_mfs, &params)
}
2 changes: 1 addition & 1 deletion crates/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod evm_ee;
pub mod l2;

/// The default buffer size for the `ArbitraryGenerator`.
const ARB_GEN_LEN: usize = 16_384;
const ARB_GEN_LEN: usize = 65_536;

pub struct ArbitraryGenerator {
buf: Vec<u8>, // Persistent buffer
Expand Down

0 comments on commit b65dd92

Please sign in to comment.