Skip to content

Commit

Permalink
Update eth call post 1559 (#2445)
Browse files Browse the repository at this point in the history
Signed-off-by: Karim TAAM <karim.t2am@gmail.com>
  • Loading branch information
matkt authored Jun 21, 2021
1 parent e92c9bc commit 87e8770
Show file tree
Hide file tree
Showing 20 changed files with 616 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.BlockImporter;
import org.hyperledger.besu.ethereum.core.PrivacyParameters;
import org.hyperledger.besu.ethereum.core.ProtocolScheduleFixture;
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.eth.manager.EthPeers;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
Expand Down Expand Up @@ -76,8 +75,8 @@ public Map<String, JsonRpcMethod> methods() {
final MutableBlockchain blockchain = createInMemoryBlockchain(importer.getGenesisBlock());
final ProtocolContext context = new ProtocolContext(blockchain, stateArchive, null);

final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
for (final Block block : importer.getBlocks()) {
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
final ProtocolSpec protocolSpec =
protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
Expand Down Expand Up @@ -127,7 +126,7 @@ public Map<String, JsonRpcMethod> methods() {
peerDiscovery,
blockchainQueries,
synchronizer,
ProtocolScheduleFixture.MAINNET,
protocolSchedule,
filterManager,
transactionPool,
miningCoordinator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
Expand Down Expand Up @@ -200,6 +200,142 @@ public void shouldReturnSuccessWithGasPriceTooHighNotStrict() {
assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnErrorWithGasPriceTooHigh() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
null,
Wei.fromHexString("0x10000000000000"),
null,
null,
null,
Bytes.fromHexString("0x12a7b914"),
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, JsonRpcError.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnSuccessWithValidGasPrice() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
null,
Wei.fromHexString("0x10"),
null,
null,
null,
Bytes.fromHexString("0x12a7b914"),
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(
null, "0x0000000000000000000000000000000000000000000000000000000000000001");

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnErrorWithGasPriceAndEmptyBalance() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xdeadbeef00000000000000000000000000000000"),
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
null,
Wei.fromHexString("0x10"),
null,
null,
null,
Bytes.fromHexString("0x12a7b914"),
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcErrorResponse(null, JsonRpcError.TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE);

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnSuccessWithZeroGasPriceAndEmptyBalance() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xdeadbeef00000000000000000000000000000000"),
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
null,
Wei.fromHexString("0x0"),
null,
null,
null,
Bytes.fromHexString("0x12a7b914"),
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(
null, "0x0000000000000000000000000000000000000000000000000000000000000001");

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnSuccessWithoutGasPriceAndEmptyBalance() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xdeadbeef00000000000000000000000000000000"),
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
null,
null,
null,
null,
null,
Bytes.fromHexString("0x12a7b914"),
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(
null, "0x0000000000000000000000000000000000000000000000000000000000000001");

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnSuccessWithInvalidGasPricingAndEmptyBalance() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xdeadbeef00000000000000000000000000000000"),
Address.fromHexString("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
null,
null,
Wei.fromHexString("0x0A"),
null,
null,
Bytes.fromHexString("0x12a7b914"),
null);
final JsonRpcRequestContext request = requestWithParams(callParameter, "latest");
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(
null, "0x0000000000000000000000000000000000000000000000000000000000000001");

final JsonRpcResponse response = method.response(request);

assertThat(response).isEqualToComparingFieldByField(expectedResponse);
}

@Test
public void shouldReturnEmptyHashResultForCallWithOnlyToField() {
final JsonCallParameter callParameter =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.methods;
package org.hyperledger.besu.ethereum.api.jsonrpc.methods.fork.frontier;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Loading

0 comments on commit 87e8770

Please sign in to comment.