From 277424d8a15d74b83b420d9aa100a4272466e445 Mon Sep 17 00:00:00 2001 From: Sally MacFarlane Date: Fri, 22 Sep 2023 00:42:59 +1000 Subject: [PATCH] [MINOR] Block number param additional test (#5918) * add test for hex vs decimal block parameter Signed-off-by: Sally MacFarlane * typo Signed-off-by: Sally MacFarlane --------- Signed-off-by: Sally MacFarlane --- .../methods/EthGetBlockByNumberTest.java | 4 +-- .../parameters/BlockParameterTest.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java index 2d3390e7f30..8eafb35f730 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetBlockByNumberTest.java @@ -82,9 +82,9 @@ public void setUp() { 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)); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockParameterTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockParameterTest.java index 3e8d534e70f..015a217bc28 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockParameterTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/BlockParameterTest.java @@ -114,6 +114,34 @@ public void longShouldReturnLongNumberValue() { 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");