Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql: add test case for eip-4844 fields #894

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clients/go-ethereum/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go-ethereum
7 changes: 7 additions & 0 deletions simulators/ethereum/graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# GraphQL

This simulator tests the GraphQL endpoint of Ethereum clients to validate they are following the [specification](https://github.com/ethereum/execution-apis/tree/main#graphql).

## Adding a test

This step-by-step [example](https://notes.ethereum.org/@s1na/By9rdtex6) shows how to add a new test to the GraphQL simulator.
43 changes: 41 additions & 2 deletions simulators/ethereum/graphql/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,66 @@ module github.com/ethereum/hive/simulators/ethereum/graphql

go 1.18

require github.com/ethereum/hive v0.0.0-20230919110229-d58aec4a3eb5
require (
github.com/ethereum/go-ethereum v1.13.1
github.com/ethereum/hive v0.0.0-20230919110229-d58aec4a3eb5
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/VictoriaMetrics/fastcache v1.12.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.9.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v0.0.0-20230906160148-46873a6a7a06 // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.10.0 // indirect
github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/ethereum/go-ethereum v1.13.1 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/getsentry/sentry-go v0.18.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad // indirect
golang.org/x/mod v0.11.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
325 changes: 325 additions & 0 deletions simulators/ethereum/graphql/go.sum

Large diffs are not rendered by default.

65 changes: 44 additions & 21 deletions simulators/ethereum/graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ import (
"strings"
"sync"

"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/hive/hivesim"
)

func main() {
var (
genesisPath = "./init/testGenesis.json"
genesis = loadGenesis(genesisPath)
params = getParameters(genesis)
)

suite := hivesim.Suite{
Name: "graphql",
Description: `Test suite covering the graphql API surface.
Expand All @@ -29,28 +36,11 @@ The GraphQL tests were initially imported from the Besu codebase.`,
Description: `This is a meta-test. It launches the client with the test chain
and reads the test case files. The individual test cases are run as sub-tests against
the client launched by this test.`,
Parameters: hivesim.Params{
// The graphql chain comes from the Besu codebase, and is built on Frontier.
"HIVE_CHAIN_ID": "1",
"HIVE_GRAPHQL_ENABLED": "1",
"HIVE_ALLOW_UNPROTECTED_TX": "1",
"HIVE_FORK_FRONTIER": "0",
"HIVE_FORK_HOMESTEAD": "33",
"HIVE_FORK_TANGERINE": "33",
"HIVE_FORK_SPURIOUS": "33",
"HIVE_FORK_BYZANTIUM": "33",
"HIVE_FORK_CONSTANTINOPLE": "33",
"HIVE_FORK_PETERSBURG": "33",
"HIVE_FORK_ISTANBUL": "33",
"HIVE_FORK_MUIR_GLACIER": "33",
"HIVE_FORK_BERLIN": "33",
"HIVE_FORK_LONDON": "33",
"HIVE_MERGE_BLOCK_ID": "33",
"HIVE_TERMINAL_TOTAL_DIFFICULTY": "4357120",
"HIVE_SHANGHAI_TIMESTAMP": "1444660030",
},
Parameters: params,
Files: map[string]string{
"/genesis.json": "./init/testGenesis.json",
// The chain has originated from the Besu client. It consisted of Frontier blocks.
// It has been since extended with post-merge blocks.
"/genesis.json": genesisPath,
"/chain.rlp": "./init/testBlockchain.blocks",
},
Run: graphqlTest,
Expand Down Expand Up @@ -217,3 +207,36 @@ func reindentJSON(text string) (string, bool) {
indented, _ := json.MarshalIndent(&obj, "", " ")
return string(indented), true
}

func loadGenesis(path string) core.Genesis {
contents, err := os.ReadFile(path)
if err != nil {
panic(fmt.Errorf("can't to read genesis file: %v", err))
}
var genesis core.Genesis
if err := json.Unmarshal(contents, &genesis); err != nil {
panic(fmt.Errorf("can't parse genesis JSON: %v", err))
}
return genesis
}

func getParameters(genesis core.Genesis) hivesim.Params {
return hivesim.Params{
"HIVE_CHAIN_ID": genesis.Config.ChainID.String(),
"HIVE_GRAPHQL_ENABLED": "1",
"HIVE_ALLOW_UNPROTECTED_TX": "1",
"HIVE_FORK_FRONTIER": "0",
"HIVE_FORK_HOMESTEAD": genesis.Config.HomesteadBlock.String(),
"HIVE_FORK_TANGERINE": genesis.Config.EIP150Block.String(),
"HIVE_FORK_SPURIOUS": genesis.Config.EIP155Block.String(),
"HIVE_FORK_BYZANTIUM": genesis.Config.ByzantiumBlock.String(),
"HIVE_FORK_CONSTANTINOPLE": genesis.Config.ConstantinopleBlock.String(),
"HIVE_FORK_PETERSBURG": genesis.Config.PetersburgBlock.String(),
"HIVE_FORK_ISTANBUL": genesis.Config.IstanbulBlock.String(),
"HIVE_FORK_MUIR_GLACIER": genesis.Config.MuirGlacierBlock.String(),
"HIVE_FORK_BERLIN": genesis.Config.BerlinBlock.String(),
"HIVE_FORK_LONDON": genesis.Config.LondonBlock.String(),
"HIVE_TERMINAL_TOTAL_DIFFICULTY": genesis.Config.TerminalTotalDifficulty.String(),
"HIVE_SHANGHAI_TIMESTAMP": fmt.Sprintf("%d", *genesis.Config.ShanghaiTime),
}
}
Binary file modified simulators/ethereum/graphql/init/testBlockchain.blocks
Binary file not shown.
22 changes: 20 additions & 2 deletions simulators/ethereum/graphql/init/testGenesis.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
{
"config" : {},
"config" : {
"chainId": 1,
"frontierBlock": 0,
"homesteadBlock": 33,
"eip150Block": 33,
"eip155Block" : 33,
"eip158Block" : 33,
"byzantiumBlock" : 33,
"constantinopleBlock" : 33,
"petersburgBlock" : 33,
"istanbulBlock" : 33,
"muirGlacierBlock": 33,
"berlinBlock" : 33,
"londonBlock" : 33,
"terminalTotalDifficulty": 4357120,
"shanghaiTime": 1444660030,
"cancunTime": 1444660040,
"terminalTotalDifficultyPassed": true
},
"coinbase" : "0x8888f1f195afa192cfee860698584c030f4c9db1",
"difficulty" : "0x020000",
"extraData" : "0x42",
Expand All @@ -13,4 +31,4 @@
"balance" : "0x09184e72a000"
}
}
}
}
25 changes: 25 additions & 0 deletions simulators/ethereum/graphql/testcases/51_eth_getBlock_4844.json
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 } }} ",
"responses":[{
"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
}