# Writing a testcase for graphql
I'm adding a testcase for EIP-4844 which will be shipped in the Cancun hardfork. The graphql schema will change to include the additional fields in the block and transaction data structures. Refer to https://github.com/ethereum/execution-apis/pull/468 for the schema changes.
The graphql simulator https://github.com/ethereum/hive/tree/master/simulators/ethereum/graphql comes with a chain. However this chain does not include 4844 blocks. So we need to update the chain and add new blocks + txes. For that we use https://github.com/s1na/graphqltestgen.
## graphqltestgen
This tool is used to **extend** an existing chain which at first consisted of only frontier blocks and later extended with post-merge blocks. The benefit here is we can test the response at fork boundaries too.
It takes in a genesis configuration assumed to be at `./genesis.json` and the RLP-serialized list of blocks at `./chain.rlp`. Note: you need to modify the code to implement the kind of block you want to add. The new chain will be written to `./newchain.rlp`.
Note since the merge forks happen after a given timestamp. Since the new block should be Cancun, the genesis file must be modified with a value for `"cancunTime"`. To calculate the value, we need to know the timestamp of the last block. This is because the chain generator will automatically assign `parentBlock + 10` as the timestamp of any new block. So I print the current header with `go run main.go head` to find out the latest timestamp.
So now on to the block generation logic. For a cancun block it looks roughly like this:
```go=
blocks, _ := core.GenerateChain(config, head, chain.Engine(), node.db, 1, func(i int, b *core.BlockGen) {
b.SetPoS()
tx, err := types.SignTx(types.NewTx(&types.BlobTx{
Nonce: b.TxNonce(address),
Gas: 50000,
GasTipCap: uint256.NewInt(params.GWei),
GasFeeCap: new(uint256.Int).Mul(uint256.NewInt(3), uint256.NewInt(params.GWei)),
To: dest,
Data: common.FromHex("0x12a7b914"),
BlobFeeCap: uint256.NewInt(params.GWei),
BlobHashes: []common.Hash{{1}, {1, 2}},
}), signer, key)
if err != nil {
utils.Fatalf("error: %v\n", err)
}
b.SetBlobGas(2 * params.BlobTxBlobGasPerBlob)
b.AddTx(tx)
})
```
Now run the main command `go run main.go` and the extended chain will be written to `newchain.rlp`. This + the updated genesis file will be used in Hive to test against.
## Filling the test
The schema has been modified to add fields to `Block` and `Transaction` resources. The following query should capture all of these new fields:
```graphql=
{block (number: 34) {
baseFeePerGas
difficulty
extraData
miner { address }
mixHash
nonce
stateRoot
totalDifficulty
withdrawalsRoot
withdrawals { address amount index validator }
blobGasUsed
excessBlobGas
transactions {
maxFeePerBlobGas
blobGasUsed
blobGasPrice
}
}}
```
So that we don't have to fill in the values for all these fields manually, `graphqltestgen` offers a feature to issue this query against geth and return the response. It creates a private geth network based on the given genesis and chain and it needs a compiled geth binary. Save the query in `request.gql`, then:
```terminal
./graphqltestgen --chain newchain.rlp fill --bin /path/to/geth
```
This will write the query response in `response.gql`. Note we have to use the newly generated chain here as it contains the blob txes. Now we can create a testcase in the Hive simulator with request and response.