Skip to content

Commit

Permalink
Add tests to transactionReceiptsByBlockHash
Browse files Browse the repository at this point in the history
Signed-off-by: Wetitpig <[email protected]>
  • Loading branch information
Wetitpig committed Dec 7, 2024
1 parent bf3128f commit 2cfaa1c
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,40 @@ public void getOmmerCountForLatestBlock() {
assertThat(result).contains(targetBlock.getBody().getOmmers().size());
}

@Test
public void getTransactionReceiptsByHash() {
final BlockchainWithData data = setupBlockchain(3);
final BlockchainQueries queries = data.blockchainQueries;

final Block targetBlock = data.blockData.get(1).block;

final Optional<List<TransactionReceiptWithMetadata>> receipts =
queries.transactionReceiptsByBlockHash(targetBlock.getHash());
assertThat(receipts).isNotEmpty();

receipts
.get()
.forEach(
receipt -> {
final long gasUsed = receipt.getGasUsed();

assertThat(gasUsed)
.isEqualTo(
targetBlock.getHeader().getGasUsed()
/ targetBlock.getBody().getTransactions().size());
});
}

@Test
public void getTransactionReceiptsByInvalidHash() {
final BlockchainWithData data = setupBlockchain(3);
final BlockchainQueries queries = data.blockchainQueries;

final Optional<List<TransactionReceiptWithMetadata>> result =
queries.transactionReceiptsByBlockHash(gen.hash());
assertThat(result).isEmpty();
}

@Test
public void logsShouldBeFlaggedAsRemovedWhenBlockIsNotInCanonicalChain() {
// create initial blockchain
Expand Down

0 comments on commit 2cfaa1c

Please sign in to comment.