Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Lldenaurois committed Sep 1, 2021
1 parent 77b3527 commit c31dc3f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ opt-level = 3
panic = "unwind"

[features]
default = [ "disputes" ]
runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ]
try-runtime = [ "polkadot-cli/try-runtime" ]
disputes = [ "polkadot-cli/disputes" ]
Expand Down
44 changes: 40 additions & 4 deletions node/service/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ impl TestChainStorage {
if minimum_block_number >= block.number {
break
}
if self.approved_blocks.contains(&block_hash) {
if !self.approved_blocks.contains(&block_hash) {
highest_approved_ancestor = None;
descriptions.clear();
} else {
if highest_approved_ancestor.is_none() {
highest_approved_ancestor = Some((block_hash, block.number));
}
Expand All @@ -174,9 +177,6 @@ impl TestChainStorage {
block_hash,
candidates: vec![], // not relevant for any test cases
});
} else {
highest_approved_ancestor = None;
descriptions.clear();
}
block_hash = *block.parent_hash();
}
Expand Down Expand Up @@ -497,6 +497,37 @@ struct CaseVars {
expected_finality_target_result: Option<Hash>,
}

/// ```raw
/// genesis -- 0xA1 --- 0xA2 --- 0xA3 --- 0xA4(!avail) --- 0xA5(!avail)
/// \
/// `- 0xB2
/// ```
fn chain_undisputed() -> CaseVars {
let head: Hash = ChainBuilder::GENESIS_HASH;
let mut builder = ChainBuilder::new();

let a1 = builder.fast_forward_approved(0xA0, head, 1);
let a2 = builder.fast_forward_approved(0xA0, a1, 2);
let a3 = builder.fast_forward_approved(0xA0, a2, 3);
let a4 = builder.fast_forward(0xA0, a3, 4);
let a5 = builder.fast_forward(0xA0, a4, 5);

let b1 = builder.fast_forward_approved(0xB0, a1, 2);
let b2 = builder.fast_forward_approved(0xB0, b1, 3);
let b3 = builder.fast_forward_approved(0xB0, b2, 4);

builder.set_heads(vec![a5, b3]);

CaseVars {
chain: builder.init(),
target_block: a1,
best_chain_containing_block: Some(a5),
highest_approved_ancestor_block: Some(a3),
undisputed_chain: Some(a3),
expected_finality_target_result: Some(a3),
}
}

/// ```raw
/// genesis -- 0xA1 --- 0xA2 --- 0xA3(disputed) --- 0xA4(!avail) --- 0xA5(!avail)
/// \
Expand Down Expand Up @@ -702,6 +733,11 @@ fn chain_6() -> CaseVars {
}
}

#[test]
fn chain_sel_undisputed() {
run_specialized_test_w_harness(chain_undisputed);
}

#[test]
fn chain_sel_0() {
run_specialized_test_w_harness(chain_0);
Expand Down

0 comments on commit c31dc3f

Please sign in to comment.