Skip to content

Commit

Permalink
Tests for GraphQL Cancun fields (hyperledger#5975)
Browse files Browse the repository at this point in the history
* Tests for GraphQL Cancun fields

Add tests for GraphQL fields added to support cancun.
Also, re-work test case inclusion code and update tests impacted by
adding a new block to the chain.

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>

* unneeded deltas in genesis file

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>

---------

Signed-off-by: Danno Ferrin <danno.ferrin@swirldslabs.com>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
2 people authored and Gabriel-Trintinalia committed Oct 20, 2023
1 parent 872c36e commit 6717b57
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
*/
package org.hyperledger.besu.ethereum.api.graphql;

import static com.google.common.base.Preconditions.checkState;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

import com.google.common.base.Charsets;
Expand All @@ -30,80 +37,30 @@

public class EthGraphQLHttpBySpecTest extends AbstractEthGraphQLHttpServiceTest {

public static Stream<Arguments> specs() {
return Stream.of(
Arguments.of("eth_blockNumber"),
Arguments.of("eth_call_Block8"),
Arguments.of("eth_call_Block8_invalidHexBytesData"),
Arguments.of("eth_call_BlockLatest"),
Arguments.of("eth_call_from_contract"),
Arguments.of("eth_estimateGas_transfer"),
Arguments.of("eth_estimateGas_noParams"),
Arguments.of("eth_estimateGas_contractDeploy"),
Arguments.of("eth_estimateGas_from_contract"),
Arguments.of("eth_gasPrice"),
Arguments.of("eth_getBalance_0x19"),
Arguments.of("eth_getBalance_invalidAccountBlockNumber"),
Arguments.of("eth_getBalance_invalidAccountLatest"),
Arguments.of("eth_getBalance_latest"),
Arguments.of("eth_getBalance_toobig_bn"),
Arguments.of("eth_getBalance_without_addr"),
Arguments.of("eth_getBlock_byHash"),
Arguments.of("eth_getBlock_byHash_InvalidHexBytes32Hash"),
Arguments.of("eth_getBlock_byHashInvalid"),
Arguments.of("eth_getBlock_byNumber"),
Arguments.of("eth_getBlock_byNumberInvalid"),
Arguments.of("eth_getBlock_wrongParams"),
Arguments.of("eth_getBlockTransactionCount_byHash"),
Arguments.of("eth_getBlockTransactionCount_byNumber"),
Arguments.of("eth_getCode"),
Arguments.of("eth_getCode_noCode"),
Arguments.of("eth_getLogs_emptyListParam"),
Arguments.of("eth_getLogs_matchTopic"),
Arguments.of("eth_getLogs_matchAnyTopic"),
Arguments.of("eth_getLogs_range"),
Arguments.of("eth_getStorageAt"),
Arguments.of("eth_getStorageAt_illegalRangeGreaterThan"),
Arguments.of("eth_getTransaction_byBlockHashAndIndex"),
Arguments.of("eth_getTransaction_byBlockNumberAndIndex"),
Arguments.of("eth_getTransaction_byBlockNumberAndInvalidIndex"),
Arguments.of("eth_getTransaction_byHash"),
Arguments.of("eth_getTransaction_byHashNull"),
Arguments.of("eth_getTransactionCount"),
Arguments.of("eth_getTransactionReceipt"),
Arguments.of("eth_sendRawTransaction_contractCreation"),
Arguments.of("eth_sendRawTransaction_messageCall"),
Arguments.of("eth_sendRawTransaction_nonceTooLow"),
Arguments.of("eth_sendRawTransaction_transferEther"),
Arguments.of("eth_sendRawTransaction_unsignedTransaction"),
Arguments.of("eth_syncing"),
Arguments.of("graphql_blocks_byFrom"),
Arguments.of("graphql_blocks_byRange"),
Arguments.of("graphql_blocks_byWrongRange"),
Arguments.of("graphql_pending"),
Arguments.of("graphql_tooComplex"),
Arguments.of("graphql_tooComplexSchema"),
Arguments.of("graphql_variable_address"),
Arguments.of("graphql_variable_bytes"),
Arguments.of("graphql_variable_bytes32"),
Arguments.of("graphql_variable_long"),
Arguments.of("block_withdrawals_pre_shanghai"),
Arguments.of("block_withdrawals"),
Arguments.of("eth_getTransaction_type2"),
Arguments.of("eth_getBlock_shanghai"));
@SuppressWarnings("StreamResourceLeak")
public static Stream<Arguments> specs() throws IOException, URISyntaxException {
final URL url =
EthGraphQLHttpBySpecTest.class.getResource(
"/org/hyperledger/besu/ethereum/api/graphql/eth_blockNumber.json");
checkState(url != null, "Cannot find test directory org/hyperledger/besu/ethereum/api/graphql");
final Path dir = Paths.get(url.toURI()).getParent();
return Files.list(dir)
.map(Path::getFileName)
.map(Path::toString)
.filter(p -> p.endsWith(".json"))
.filter(p -> !p.contains("genesis"))
.map(Arguments::of);
}

@ParameterizedTest(name = "{index}: {0}")
@MethodSource("specs")
public void graphQLCallWithSpecFile(final String specFileName) throws Exception {
void graphQLCallWithSpecFile(final String specFileName) throws Exception {
graphQLCall(specFileName);
}

private void graphQLCall(final String name) throws IOException {
final String testSpecFile = name + ".json";
final String json =
Resources.toString(
EthGraphQLHttpBySpecTest.class.getResource(testSpecFile), Charsets.UTF_8);
Resources.toString(EthGraphQLHttpBySpecTest.class.getResource(name), Charsets.UTF_8);
final JsonObject spec = new JsonObject(json);
final String rawRequestBody = spec.getString("request");
final String rawVariables = spec.getString("variables");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"response": {
"data": {
"block": {
"number": "0x21"
"number": "0x22"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"response": {
"data": {
"block": {
"number": "0x21",
"number": "0x22",
"call": {
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
"status": "0x1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"response": {
"data": {
"block": {
"number": "0x21",
"number": "0x22",
"call": {
"data": "0x",
"status": "0x1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"response": {
"data": {
"gasPrice": "0x1",
"maxPriorityFeePerGas": "0x0"
"maxPriorityFeePerGas": "0x3b9aca00"
}
},
"statusCode": 200
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"request": "{ block(number:\"0x22\") { account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { balance } } }",
"request": "{ block(number:\"0x220\") { account(address: \"0x6295ee1b4f6dd65047762f924ecd367c17eabf8f\") { balance } } }",
"response": {
"errors": [
{
"message": "Exception while fetching data (/block) : Block number 34 was not found",
"message": "Exception while fetching data (/block) : Block number 544 was not found",
"locations": [
{
"line": 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"request": "{block (number: 34) { baseFeePerGas difficulty extraData miner { address } mixHash nonce stateRoot totalDifficulty withdrawalsRoot withdrawals { address amount index validator } blobGasUsed excessBlobGas transactions { maxFeePerBlobGas blobGasUsed blobGasPrice } }} ",
"response":{
"data": {
"block":{
"baseFeePerGas":"0x3437004a",
"difficulty":"0x0",
"extraData":"0x",
"miner": {
"address":"0x0000000000000000000000000000000000000000"
},
"mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce":"0x0000000000000000",
"stateRoot":"0x34727aff24d1c51cd63fdc14515b15ddaa156fa0671c58a96c72b1553819945d",
"totalDifficulty":"0x427c00",
"withdrawalsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"withdrawals":[],
"blobGasUsed":"0x40000",
"excessBlobGas":"0x0",
"transactions":[{"maxFeePerBlobGas":"0x3b9aca00","blobGasUsed":"0x40000","blobGasPrice":"0x1"}]
}
}
},
"statusCode": 200
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"data": {
"pending": {
"account": {
"transactionCount": "0x21"
"transactionCount": "0x22"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
},
{
"number": "0x21"
},
{
"number": "0x22"
}
]
}
Expand Down
Binary file modified testutil/src/main/resources/hive/testBlockchain.blocks
Binary file not shown.
3 changes: 2 additions & 1 deletion testutil/src/main/resources/hive/testGenesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"ethash": {
},
"londonBlock": 33,
"shanghaiTime": 1444660030
"shanghaiTime": 1444660030,
"cancunTime": 1444660040
},
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
Expand Down

0 comments on commit 6717b57

Please sign in to comment.