Skip to content

Commit 4f10463

Browse files
test(bitcoind_rpc): add no_agreement_point test
Co-authored-by: Steve Myers <[email protected]>
1 parent a73dac2 commit 4f10463

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

crates/bitcoind_rpc/tests/test_emitter.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,3 +757,56 @@ fn mempool_during_reorg() -> anyhow::Result<()> {
757757

758758
Ok(())
759759
}
760+
761+
/// If blockchain re-org includes the start height, emit new start height block
762+
///
763+
/// 1. mine 101 blocks
764+
/// 2. emmit blocks 99a, 100a
765+
/// 3. invalidate blocks 99a, 100a, 101a
766+
/// 4. mine new blocks 99b, 100b, 101b
767+
/// 5. emmit block 99b
768+
///
769+
/// The block hash of 99b should be different than 99a, but their previous block hashes should
770+
/// be the same.
771+
#[test]
772+
fn no_agreement_point() -> anyhow::Result<()> {
773+
const PREMINE_COUNT: usize = 101;
774+
775+
let env = TestEnv::new()?;
776+
777+
// start height is 99
778+
let mut emitter = Emitter::new(&env.client, (PREMINE_COUNT - 2) as u32);
779+
780+
// mine 101 blocks
781+
env.mine_blocks(PREMINE_COUNT, None)?;
782+
783+
// emit block 99a
784+
let (_, block_header_99a) = emitter.next_header()?.expect("block 99a header");
785+
let block_hash_99a = block_header_99a.block_hash();
786+
let block_hash_98a = block_header_99a.prev_blockhash;
787+
788+
// emit block 100a
789+
let (_, block_header_100a) = emitter.next_header()?.expect("block 100a header");
790+
let block_hash_100a = block_header_100a.block_hash();
791+
792+
// get hash for block 101a
793+
let block_hash_101a = env.client.get_block_hash(101)?;
794+
795+
// invalidate blocks 99a, 100a, 101a
796+
env.client.invalidate_block(&block_hash_99a)?;
797+
env.client.invalidate_block(&block_hash_100a)?;
798+
env.client.invalidate_block(&block_hash_101a)?;
799+
800+
// mine new blocks 99b, 100b, 101b
801+
env.mine_blocks(3, None)?;
802+
803+
// emit block header 99b
804+
let (_, block_header_99b) = emitter.next_header()?.expect("block 99b header");
805+
let block_hash_99b = block_header_99b.block_hash();
806+
let block_hash_98b = block_header_99b.prev_blockhash;
807+
808+
assert_ne!(block_hash_99a, block_hash_99b);
809+
assert_eq!(block_hash_98a, block_hash_98b);
810+
811+
Ok(())
812+
}

0 commit comments

Comments
 (0)