From 0b83ab501168939472fe73df264efb26fc6529ca Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Thu, 5 Oct 2023 22:48:30 -0600 Subject: [PATCH] Tests for GraphQL Cancun fields (#5975) * 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 * unneeded deltas in genesis file Signed-off-by: Danno Ferrin --------- Signed-off-by: Danno Ferrin Co-authored-by: Sally MacFarlane --- .../api/graphql/EthGraphQLHttpBySpecTest.java | 87 +++++------------- .../ethereum/api/graphql/eth_blockNumber.json | 2 +- .../api/graphql/eth_call_BlockLatest.json | 2 +- .../api/graphql/eth_call_from_contract.json | 2 +- .../ethereum/api/graphql/eth_gasPrice.json | 2 +- .../api/graphql/eth_getBalance_toobig_bn.json | 4 +- .../api/graphql/eth_getBlock_cancun.json | 25 +++++ .../api/graphql/eth_getTransactionCount.json | 2 +- .../api/graphql/graphql_blocks_byFrom.json | 3 + .../main/resources/hive/testBlockchain.blocks | Bin 24039 -> 24815 bytes .../src/main/resources/hive/testGenesis.json | 3 +- 11 files changed, 59 insertions(+), 73 deletions(-) create mode 100644 ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBlock_cancun.json diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/EthGraphQLHttpBySpecTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/EthGraphQLHttpBySpecTest.java index bc1e3c84bc6..4cd31646007 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/EthGraphQLHttpBySpecTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/graphql/EthGraphQLHttpBySpecTest.java @@ -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; @@ -30,80 +37,30 @@ public class EthGraphQLHttpBySpecTest extends AbstractEthGraphQLHttpServiceTest { - public static Stream 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 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"); diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_blockNumber.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_blockNumber.json index 247ec0146e5..35b79c9ab7b 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_blockNumber.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_blockNumber.json @@ -3,7 +3,7 @@ "response": { "data": { "block": { - "number": "0x21" + "number": "0x22" } } }, diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_BlockLatest.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_BlockLatest.json index 9b5bb2fd89c..bd133f0f060 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_BlockLatest.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_BlockLatest.json @@ -3,7 +3,7 @@ "response": { "data": { "block": { - "number": "0x21", + "number": "0x22", "call": { "data": "0x0000000000000000000000000000000000000000000000000000000000000001", "status": "0x1" diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_from_contract.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_from_contract.json index 211a97be18f..dea5433a856 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_from_contract.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_call_from_contract.json @@ -3,7 +3,7 @@ "response": { "data": { "block": { - "number": "0x21", + "number": "0x22", "call": { "data": "0x", "status": "0x1" diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_gasPrice.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_gasPrice.json index 744e7ea98b9..40b8bf0fa0d 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_gasPrice.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_gasPrice.json @@ -3,7 +3,7 @@ "response": { "data": { "gasPrice": "0x1", - "maxPriorityFeePerGas": "0x0" + "maxPriorityFeePerGas": "0x3b9aca00" } }, "statusCode": 200 diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBalance_toobig_bn.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBalance_toobig_bn.json index cbc24c848e1..ef45299e915 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBalance_toobig_bn.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBalance_toobig_bn.json @@ -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, diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBlock_cancun.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBlock_cancun.json new file mode 100644 index 00000000000..3b9c0039152 --- /dev/null +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getBlock_cancun.json @@ -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 +} \ No newline at end of file diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getTransactionCount.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getTransactionCount.json index a1fc9e307c2..3bacae05c80 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getTransactionCount.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/eth_getTransactionCount.json @@ -4,7 +4,7 @@ "data": { "pending": { "account": { - "transactionCount": "0x21" + "transactionCount": "0x22" } } } diff --git a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/graphql_blocks_byFrom.json b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/graphql_blocks_byFrom.json index 800542adbc0..33046a3a548 100644 --- a/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/graphql_blocks_byFrom.json +++ b/ethereum/api/src/test/resources/org/hyperledger/besu/ethereum/api/graphql/graphql_blocks_byFrom.json @@ -14,6 +14,9 @@ }, { "number": "0x21" + }, + { + "number": "0x22" } ] } diff --git a/testutil/src/main/resources/hive/testBlockchain.blocks b/testutil/src/main/resources/hive/testBlockchain.blocks index 480efc87d9fcf4bb02cebf943897e5fec7d18226..8504fd7a8c4f6d2ce1a0de17a65ed7319c1df72e 100644 GIT binary patch delta 329 zcmV-P0k;0ML z1qpZ%lfe`slR#S)Vl;Ak|0L1H9M(VF6j56h-KrIDpl2LdscdqwRX7=xU7!|bA7fxr zX{2h<#jS;wb6KZHnoTQ3sD;dEzstvUIq zo?ikv%$tL=kq!d^5P%|sU*E8TTOx#38^ck6pp(G@Ad~7`3IsGa07{XcAqIm4004lX zlfeQY7Wlllx&!#P0U?Atn#ur#vd~@tg2PagpcoYofP@mKxfH;JJDSP>_(GtO!5{;m z0Rof30v<(xplaY@Ed8W9n?_3zw1^yU!sNn5GtY^;;CVFKWy7vX&Y%)ghpw_B>`@a8 b`JBD0@=MgHfss$H)}JL#N