From f9754e3d6e6ad5dca8d2341ef4c135f15cab1512 Mon Sep 17 00:00:00 2001 From: Ruslan Tushov Date: Mon, 5 Aug 2024 16:44:08 +0500 Subject: [PATCH] grandpa reorg test (#2167) Signed-off-by: turuslan Co-authored-by: kamilsa --- test/core/blockchain/block_tree_test.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/core/blockchain/block_tree_test.cpp b/test/core/blockchain/block_tree_test.cpp index bad306ed9d..bb98ff2d8e 100644 --- a/test/core/blockchain/block_tree_test.cpp +++ b/test/core/blockchain/block_tree_test.cpp @@ -244,9 +244,13 @@ struct BlockTreeTest : public testing::Test { return {hash, header}; } + uint32_t state_nonce_ = 0; BlockHash addHeaderToRepository(const BlockHash &parent, BlockNumber number) { + Hash256 state; + memcpy(state.data(), &state_nonce_, sizeof(state_nonce_)); + ++state_nonce_; return std::get<0>(addHeaderToRepositoryAndGet( - parent, number, {}, SlotType::SecondaryPlain)); + parent, number, state, SlotType::SecondaryPlain)); } BlockHash addHeaderToRepository(const BlockHash &parent, @@ -788,6 +792,11 @@ TEST_F(BlockTreeTest, GetBestChain_TwoChains) { ASSERT_OUTCOME_SUCCESS(best_info, block_tree_->getBestContaining(T_hash)); ASSERT_EQ(best_info.hash, D2_hash); + + // test grandpa best chain selection when target block is not on best chain + // /~https://github.com/paritytech/polkadot-sdk/pull/5153 + // /~https://github.com/paritytech/polkadot-sdk/blob/776e95748901b50ff2833a7d27ea83fd91fbf9d1/substrate/client/consensus/grandpa/src/tests.rs#L1823-L1931 + EXPECT_EQ(block_tree_->getBestContaining(C1_hash).value().hash, C1_hash); } /**