Skip to content

Commit

Permalink
[MINOR] Block number param additional test (hyperledger#5918)
Browse files Browse the repository at this point in the history
* add test for hex vs decimal block parameter

Signed-off-by: Sally MacFarlane <[email protected]>

* typo

Signed-off-by: Sally MacFarlane <[email protected]>

---------

Signed-off-by: Sally MacFarlane <[email protected]>
  • Loading branch information
macfarla authored Sep 21, 2023
1 parent db8bd9d commit 277424d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 277424d

Please sign in to comment.