Skip to content

Commit

Permalink
feat: get block returns null for non existing blocks (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasyl-ivanchuk authored Nov 10, 2023
1 parent a74c39c commit 668a2cf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/node/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa

Ok(Some(block))
}
None => Err(into_jsrpc_error(Web3Error::NoBlock)),
None => Ok(None),
}
})
}
Expand Down Expand Up @@ -451,7 +451,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa

Ok(Some(block))
}
None => Err(into_jsrpc_error(Web3Error::NoBlock)),
None => Ok(None),
}
})
}
Expand Down Expand Up @@ -1365,13 +1365,15 @@ mod tests {
}

#[tokio::test]
async fn test_get_block_by_hash_produces_no_block_error_for_non_existing_block() {
async fn test_get_block_by_hash_returns_none_for_non_existing_block() {
let node = InMemoryNode::<HttpForkSource>::default();

let expected_err = into_jsrpc_error(Web3Error::NoBlock);
let result = node.get_block_by_hash(H256::repeat_byte(0x01), false).await;
let result = node
.get_block_by_hash(H256::repeat_byte(0x01), false)
.await
.expect("failed fetching block by hash");

assert_eq!(expected_err, result.unwrap_err());
assert!(result.is_none());
}

#[tokio::test]
Expand Down Expand Up @@ -1514,15 +1516,15 @@ mod tests {
}

#[tokio::test]
async fn test_get_block_by_number_produces_no_block_error_for_non_existing_block() {
async fn test_get_block_by_number_returns_none_for_non_existing_block() {
let node = InMemoryNode::<HttpForkSource>::default();

let expected_err = into_jsrpc_error(Web3Error::NoBlock);
let result = node
.get_block_by_number(BlockNumber::Number(U64::from(42)), false)
.await;
.await
.expect("failed fetching block by number");

assert_eq!(expected_err, result.unwrap_err());
assert!(result.is_none());
}

#[tokio::test]
Expand Down

0 comments on commit 668a2cf

Please sign in to comment.