Skip to content

Commit b8a51e3

Browse files
committed
Fix test
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 489aa27 commit b8a51e3

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

stackslib/src/chainstate/stacks/db/blocks.rs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ impl StacksChainState {
757757

758758
/// Get all stacks block headers. Great for testing!
759759
pub fn get_all_staging_block_headers(blocks_conn: &DBConn) -> Result<Vec<StagingBlock>, Error> {
760-
let sql = "SELECT * FROM staging_blocks ORDER BY height".to_string();
761-
query_rows::<StagingBlock, _>(blocks_conn, &sql, NO_PARAMS).map_err(Error::DBError)
760+
let sql = "SELECT * FROM staging_blocks ORDER BY height";
761+
query_rows::<StagingBlock, _>(blocks_conn, sql, NO_PARAMS).map_err(Error::DBError)
762762
}
763763

764764
/// Get a list of all microblocks' hashes, and their anchored blocks' hashes
@@ -929,7 +929,7 @@ impl StacksChainState {
929929
table: &str,
930930
block_hash: &BlockHeaderHash,
931931
) -> Result<Option<Vec<u8>>, Error> {
932-
let sql = format!("SELECT block_data FROM {} WHERE block_hash = ?1", table);
932+
let sql = format!("SELECT block_data FROM {table} WHERE block_hash = ?1");
933933
let args = [&block_hash];
934934
let mut blobs = StacksChainState::load_block_data_blobs(block_conn, &sql, &args)?;
935935
let len = blobs.len();
@@ -982,10 +982,10 @@ impl StacksChainState {
982982
consensus_hash: &ConsensusHash,
983983
block_hash: &BlockHeaderHash,
984984
) -> Result<Option<StagingBlock>, Error> {
985-
let sql = "SELECT * FROM staging_blocks WHERE anchored_block_hash = ?1 AND consensus_hash = ?2 AND orphaned = 0 AND processed = 0".to_string();
985+
let sql = "SELECT * FROM staging_blocks WHERE anchored_block_hash = ?1 AND consensus_hash = ?2 AND orphaned = 0 AND processed = 0";
986986
let args = params![block_hash, consensus_hash];
987987
let mut rows =
988-
query_rows::<StagingBlock, _>(block_conn, &sql, args).map_err(Error::DBError)?;
988+
query_rows::<StagingBlock, _>(block_conn, sql, args).map_err(Error::DBError)?;
989989
let len = rows.len();
990990
match len {
991991
0 => Ok(None),
@@ -1330,22 +1330,18 @@ impl StacksChainState {
13301330

13311331
let sql = if start_seq == last_seq {
13321332
// takes the same arguments as the range case below, but will
1333-
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence == ?2 AND sequence == ?3 AND orphaned = 0 ORDER BY sequence ASC".to_string()
1333+
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence == ?2 AND sequence == ?3 AND orphaned = 0 ORDER BY sequence ASC"
13341334
} else {
1335-
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence >= ?2 AND sequence < ?3 AND orphaned = 0 ORDER BY sequence ASC".to_string()
1335+
"SELECT * FROM staging_microblocks WHERE index_block_hash = ?1 AND sequence >= ?2 AND sequence < ?3 AND orphaned = 0 ORDER BY sequence ASC"
13361336
};
13371337

13381338
let args = params![parent_index_block_hash, start_seq, last_seq];
13391339
let staging_microblocks =
1340-
query_rows::<StagingMicroblock, _>(blocks_conn, &sql, args).map_err(Error::DBError)?;
1340+
query_rows::<StagingMicroblock, _>(blocks_conn, sql, args).map_err(Error::DBError)?;
13411341

13421342
if staging_microblocks.is_empty() {
13431343
// haven't seen any microblocks that descend from this block yet
1344-
test_debug!(
1345-
"No microblocks built on {} up to {}",
1346-
&parent_index_block_hash,
1347-
last_seq
1348-
);
1344+
test_debug!("No microblocks built on {parent_index_block_hash} up to {last_seq}");
13491345
return Ok(None);
13501346
}
13511347

@@ -9444,49 +9440,50 @@ pub mod test {
94449440
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[0], blocks[0]);
94459441

94469442
// process and store blocks 1 and N, as well as microblocks in-between
9447-
for (i, block) in blocks.iter().skip(1).enumerate() {
9443+
let len = blocks.len();
9444+
for i in 1..len {
94489445
// this is what happens at the end of append_block()
94499446
// store block to staging and process it
94509447
assert!(StacksChainState::load_staging_block_data(
94519448
chainstate.db(),
94529449
&chainstate.blocks_path,
94539450
&consensus_hashes[i],
9454-
&block.block_hash()
9451+
&blocks[i].block_hash()
94559452
)
94569453
.unwrap()
94579454
.is_none());
94589455
store_staging_block(
94599456
&mut chainstate,
94609457
&consensus_hashes[i],
9461-
block,
9458+
blocks[i],
94629459
&consensus_hashes[0],
94639460
1,
94649461
2,
94659462
);
9466-
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], block);
9463+
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], blocks[i]);
94679464

94689465
set_block_processed(
94699466
&mut chainstate,
94709467
&consensus_hashes[i],
9471-
&block.block_hash(),
9468+
&blocks[i].block_hash(),
94729469
true,
94739470
);
94749471

94759472
// set different parts of this stream as confirmed
94769473
set_microblocks_processed(
94779474
&mut chainstate,
94789475
&consensus_hashes[i],
9479-
&block.block_hash(),
9480-
&block.header.parent_microblock,
9476+
&blocks[i].block_hash(),
9477+
&blocks[i].header.parent_microblock,
94819478
);
94829479

9483-
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[i], block);
9480+
assert_block_stored_not_staging(&mut chainstate, &consensus_hashes[i], blocks[i]);
94849481

94859482
let mblocks_confirmed = StacksChainState::load_processed_microblock_stream_fork(
94869483
chainstate.db(),
94879484
&consensus_hashes[0],
94889485
&blocks[0].block_hash(),
9489-
&block.header.parent_microblock,
9486+
&blocks[i].header.parent_microblock,
94909487
)
94919488
.unwrap()
94929489
.unwrap();
@@ -9562,24 +9559,24 @@ pub mod test {
95629559
}
95639560

95649561
// store blocks to staging
9565-
for (i, block) in blocks.iter().enumerate() {
9562+
for i in 0..blocks.len() {
95669563
assert!(StacksChainState::load_staging_block_data(
95679564
chainstate.db(),
95689565
&chainstate.blocks_path,
95699566
&consensus_hashes[i],
9570-
&block.block_hash()
9567+
&blocks[i].block_hash()
95719568
)
95729569
.unwrap()
95739570
.is_none());
95749571
store_staging_block(
95759572
&mut chainstate,
95769573
&consensus_hashes[i],
9577-
block,
9574+
&blocks[i],
95789575
&parent_consensus_hashes[i],
95799576
1,
95809577
2,
95819578
);
9582-
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], block);
9579+
assert_block_staging_not_processed(&mut chainstate, &consensus_hashes[i], &blocks[i]);
95839580
}
95849581

95859582
// reject block 1

0 commit comments

Comments
 (0)