Remove Leading Zeros from TransactionPendingResult (#3776)

* test + fix

Signed-off-by: Frank Li <b439988l@gmail.com>

* spotless

Signed-off-by: Frank Li <b439988l@gmail.com>

* typo

Signed-off-by: Frank Li <b439988l@gmail.com>

Co-authored-by: Frank Li <b439988l@gmail.com>
pull/3778/head
Joe Clapis 3 years ago committed by GitHub
parent 9ef9ff4980
commit fd007357cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java
  2. 26
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/TxPoolBesuPendingTransactionsTest.java

@ -84,8 +84,8 @@ public class TransactionPendingResult implements TransactionResult {
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();

@ -31,6 +31,7 @@ import org.hyperledger.besu.ethereum.eth.transactions.sorter.GasPricePendingTran
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;
@ -74,6 +75,31 @@ public class TxPoolBesuPendingTransactionsTest {
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 =

Loading…
Cancel
Save