[MINOR] Block number param additional test (#5918)

* add test for hex vs decimal block parameter

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

* typo

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>

---------

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/5923/head
Sally MacFarlane 1 year ago committed by GitHub
parent db8bd9d2af
commit 277424d8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java
  2. 28
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockParameterTest.java

@ -82,9 +82,9 @@ public class EthGetBlockByNumberTest {
blockchain.appendBlock(block, receipts);
}
BlockHeader lastestHeader = blockchain.getChainHeadBlock().getHeader();
BlockHeader latestHeader = blockchain.getChainHeadBlock().getHeader();
when(worldStateArchive.isWorldStateAvailable(
lastestHeader.getStateRoot(), lastestHeader.getHash()))
latestHeader.getStateRoot(), latestHeader.getHash()))
.thenReturn(Boolean.TRUE);
blockchainQueries = spy(new BlockchainQueries(blockchain, worldStateArchive));

@ -114,6 +114,34 @@ public class BlockParameterTest {
assertThat(blockParameter.isSafe()).isFalse();
}
@Test
public void numberStringShouldReturnLongNumberValue() {
final BlockParameter blockParameter = new BlockParameter("55");
assertThat(blockParameter.getNumber()).isPresent();
assertThat(blockParameter.getNumber().get()).isEqualTo(55L);
assertThat(blockParameter.isNumeric()).isTrue();
assertThat(blockParameter.isEarliest()).isFalse();
assertThat(blockParameter.isFinalized()).isFalse();
assertThat(blockParameter.isLatest()).isFalse();
assertThat(blockParameter.isPending()).isFalse();
assertThat(blockParameter.isSafe()).isFalse();
}
@Test
public void hexShouldReturnLongNumberValue() {
final BlockParameter blockParameter = new BlockParameter("0x55");
assertThat(blockParameter.getNumber()).isPresent();
assertThat(blockParameter.getNumber().get()).isEqualTo(85L);
assertThat(blockParameter.isNumeric()).isTrue();
assertThat(blockParameter.isEarliest()).isFalse();
assertThat(blockParameter.isFinalized()).isFalse();
assertThat(blockParameter.isLatest()).isFalse();
assertThat(blockParameter.isPending()).isFalse();
assertThat(blockParameter.isSafe()).isFalse();
}
@Test
public void upperCaseStringShouldBeHandled() {
final BlockParameter blockParameter = new BlockParameter("LATEST");

Loading…
Cancel
Save