mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
Add testing for finding terminal block
This commit is contained in:
@@ -307,7 +307,7 @@ impl ExecutionLayer {
|
|||||||
.await?
|
.await?
|
||||||
.ok_or(ApiError::ExecutionHeadBlockNotFound)?;
|
.ok_or(ApiError::ExecutionHeadBlockNotFound)?;
|
||||||
|
|
||||||
self.execution_blocks().await.put(block.parent_hash, block);
|
self.execution_blocks().await.put(block.block_hash, block);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if block.total_difficulty >= self.terminal_total_difficulty() {
|
if block.total_difficulty >= self.terminal_total_difficulty() {
|
||||||
@@ -447,11 +447,20 @@ mod test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn move_to_block_prior_to_terminal_block(self) -> Self {
|
||||||
|
{
|
||||||
|
let mut block_gen = self.server.execution_block_generator().await;
|
||||||
|
let target_block = block_gen.terminal_block_number.checked_sub(1).unwrap();
|
||||||
|
block_gen.set_clock_for_block_number(target_block)
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn move_to_terminal_block(self) -> Self {
|
pub async fn move_to_terminal_block(self) -> Self {
|
||||||
{
|
{
|
||||||
let mut block_gen = self.server.execution_block_generator().await;
|
let mut block_gen = self.server.execution_block_generator().await;
|
||||||
block_gen.seconds_since_genesis =
|
let target_block = block_gen.terminal_block_number;
|
||||||
block_gen.terminal_block_number * block_gen.block_interval_secs;
|
block_gen.set_clock_for_block_number(target_block)
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@@ -485,6 +494,29 @@ mod test {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn finds_valid_terminal_block_hash() {
|
async fn finds_valid_terminal_block_hash() {
|
||||||
|
SingleEngineTester::new()
|
||||||
|
.move_to_block_prior_to_terminal_block()
|
||||||
|
.await
|
||||||
|
.with_terminal_block_number(|el, _| async move {
|
||||||
|
assert_eq!(
|
||||||
|
el.get_pow_block_hash_at_total_difficulty().await.unwrap(),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.move_to_terminal_block()
|
||||||
|
.await
|
||||||
|
.with_terminal_block_number(|el, terminal_block_number| async move {
|
||||||
|
assert_eq!(
|
||||||
|
el.get_pow_block_hash_at_total_difficulty().await.unwrap(),
|
||||||
|
Some(block_number_to_hash(terminal_block_number))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn verifies_valid_terminal_block_hash() {
|
||||||
SingleEngineTester::new()
|
SingleEngineTester::new()
|
||||||
.move_to_terminal_block()
|
.move_to_terminal_block()
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ impl ExecutionBlockGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_clock_for_block_number(&mut self, number: u64) {
|
||||||
|
self.seconds_since_genesis = number
|
||||||
|
.checked_mul(self.block_interval_secs)
|
||||||
|
.expect("overflow setting clock");
|
||||||
|
}
|
||||||
|
|
||||||
pub fn increment_seconds_since_genesis(&mut self, inc: u64) {
|
pub fn increment_seconds_since_genesis(&mut self, inc: u64) {
|
||||||
self.seconds_since_genesis += inc;
|
self.seconds_since_genesis += inc;
|
||||||
}
|
}
|
||||||
@@ -159,7 +165,6 @@ mod test {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let next_i = i + 1;
|
let next_i = i + 1;
|
||||||
dbg!(next_i);
|
|
||||||
assert!(generator.block_by_number(next_i).is_none());
|
assert!(generator.block_by_number(next_i).is_none());
|
||||||
assert!(generator
|
assert!(generator
|
||||||
.block_by_hash(block_number_to_hash(next_i))
|
.block_by_hash(block_number_to_hash(next_i))
|
||||||
|
|||||||
Reference in New Issue
Block a user