Skip to content

Commit 0737c5a

Browse files
andresilvanathanwhit
authored andcommitted
sc-client-db: add test for reverting finalized blocks (paritytech#14205)
1 parent 3365e3c commit 0737c5a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

client/db/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,6 +3913,38 @@ pub(crate) mod tests {
39133913
assert_eq!(1, backend.blockchain.leaves.read().highest_leaf().unwrap().0);
39143914
}
39153915

3916+
#[test]
3917+
fn revert_finalized_blocks() {
3918+
let pruning_modes = [BlocksPruning::Some(10), BlocksPruning::KeepAll];
3919+
3920+
// we will create a chain with 11 blocks, finalize block #8 and then
3921+
// attempt to revert 5 blocks.
3922+
for pruning_mode in pruning_modes {
3923+
let backend = Backend::<Block>::new_test_with_tx_storage(pruning_mode, 1);
3924+
3925+
let mut parent = Default::default();
3926+
for i in 0..=10 {
3927+
parent = insert_block(&backend, i, parent, None, Default::default(), vec![], None)
3928+
.unwrap();
3929+
}
3930+
3931+
assert_eq!(backend.blockchain().info().best_number, 10);
3932+
3933+
let block8 = backend.blockchain().hash(8).unwrap().unwrap();
3934+
backend.finalize_block(block8, None).unwrap();
3935+
backend.revert(5, true).unwrap();
3936+
3937+
match pruning_mode {
3938+
// we can only revert to blocks for which we have state, if pruning is enabled
3939+
// then the last state available will be that of the latest finalized block
3940+
BlocksPruning::Some(_) =>
3941+
assert_eq!(backend.blockchain().info().finalized_number, 8),
3942+
// otherwise if we're not doing state pruning we can revert past finalized blocks
3943+
_ => assert_eq!(backend.blockchain().info().finalized_number, 5),
3944+
}
3945+
}
3946+
}
3947+
39163948
#[test]
39173949
fn test_no_duplicated_leaves_allowed() {
39183950
let backend: Backend<Block> = Backend::new_test(10, 10);

0 commit comments

Comments
 (0)