mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 15:47:58 +00:00
Finalized should be before best (#14308)
* Finalized block should not be after best block * Remove unwrap * Apply code review suggestion Co-authored-by: Koute <koute@users.noreply.github.com> * Add test --------- Co-authored-by: Koute <koute@users.noreply.github.com>
This commit is contained in:
@@ -2001,3 +2001,41 @@ fn use_dalek_ext_works() {
|
||||
.verify_ed25519(a1.hash(), zero_ed_sig(), zero_ed_pub(), vec![])
|
||||
.unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn finalize_after_best_block_updates_best() {
|
||||
let mut client = substrate_test_runtime_client::new();
|
||||
|
||||
// G -> A1
|
||||
let a1 = client.new_block(Default::default()).unwrap().build().unwrap().block;
|
||||
block_on(client.import(BlockOrigin::Own, a1.clone())).unwrap();
|
||||
|
||||
// A1 -> A2
|
||||
let a2 = client
|
||||
.new_block_at(a1.hash(), Default::default(), false)
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
block_on(client.import(BlockOrigin::Own, a2.clone())).unwrap();
|
||||
|
||||
// A2 -> A3
|
||||
let a3 = client
|
||||
.new_block_at(a2.hash(), Default::default(), false)
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block;
|
||||
let (header, extrinsics) = a3.clone().deconstruct();
|
||||
let mut import_params = BlockImportParams::new(BlockOrigin::Own, header);
|
||||
import_params.body = Some(extrinsics);
|
||||
import_params.fork_choice = Some(ForkChoiceStrategy::Custom(false));
|
||||
block_on(client.import_block(import_params)).unwrap();
|
||||
|
||||
assert_eq!(client.chain_info().best_hash, a2.hash());
|
||||
|
||||
client.finalize_block(a3.hash(), None).unwrap();
|
||||
|
||||
assert_eq!(client.chain_info().finalized_hash, a3.hash());
|
||||
assert_eq!(client.chain_info().best_hash, a3.hash());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user