Skip to content

Commit

Permalink
Remove Leading Zeros from TransactionPendingResult (hyperledger#3776)
Browse files Browse the repository at this point in the history
* test + fix

Signed-off-by: Frank Li <[email protected]>

* spotless

Signed-off-by: Frank Li <[email protected]>

* typo

Signed-off-by: Frank Li <[email protected]>

Co-authored-by: Frank Li <[email protected]>
  • Loading branch information
jclapis and frankisawesome authored Apr 29, 2022
1 parent 9ef9ff4 commit fd00735
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public TransactionPendingResult(final Transaction transaction) {
this.from = transaction.getSender().toString();
this.gas = Quantity.create(transaction.getGasLimit());
this.maxPriorityFeePerGas =
transaction.getMaxPriorityFeePerGas().map(Wei::toHexString).orElse(null);
this.maxFeePerGas = transaction.getMaxFeePerGas().map(Wei::toHexString).orElse(null);
transaction.getMaxPriorityFeePerGas().map(Wei::toShortHexString).orElse(null);
this.maxFeePerGas = transaction.getMaxFeePerGas().map(Wei::toShortHexString).orElse(null);
this.gasPrice = transaction.getGasPrice().map(Quantity::create).orElse(maxFeePerGas);
this.hash = transaction.getHash().toString();
this.input = transaction.getPayload().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -74,6 +75,31 @@ public void shouldReturnPendingTransactions() {
assertThat(result.size()).isEqualTo(4);
}

@Test
public void pendingTransactionsGasPricesDoNotHaveLeadingZeroes() {
final JsonRpcRequestContext request =
new JsonRpcRequestContext(
new JsonRpcRequest(
JSON_RPC_VERSION, TXPOOL_PENDING_TRANSACTIONS_METHOD, new Object[] {100}));

final JsonRpcSuccessResponse actualResponse = (JsonRpcSuccessResponse) method.response(request);
final Set<TransactionPendingResult> result =
(Set<TransactionPendingResult>) actualResponse.getResult();

assertThat(result)
.extracting(TransactionPendingResult::getGasPrice)
.filteredOn(Objects::nonNull)
.allSatisfy(p -> assertThat(p).doesNotContain("0x0"));
assertThat(result)
.extracting(TransactionPendingResult::getMaxFeePerGas)
.filteredOn(Objects::nonNull)
.allSatisfy(p -> assertThat(p).doesNotContain("0x0"));
assertThat(result)
.extracting(TransactionPendingResult::getMaxPriorityFeePerGas)
.filteredOn(Objects::nonNull)
.allSatisfy(p -> assertThat(p).doesNotContain("0x0"));
}

@Test
public void shouldReturnPendingTransactionsWithLimit() {
final JsonRpcRequestContext request =
Expand Down

0 comments on commit fd00735

Please sign in to comment.