@@ -161,6 +161,43 @@ func TestGraphQLBlockSerialization(t *testing.T) {
161
161
}
162
162
}
163
163
164
+ // Tests that a graphQL request is successfully handled when graphql is enabled on the specified endpoint
165
+ func TestGraphQLTransactionSerialization (t * testing.T ) {
166
+ stack := createNode (t , true , true )
167
+ defer stack .Close ()
168
+ // start node
169
+ if err := stack .Start (); err != nil {
170
+ t .Fatalf ("could not start node: %v" , err )
171
+ }
172
+
173
+ for i , tt := range []struct {
174
+ body string
175
+ want string
176
+ code int
177
+ }{
178
+ {
179
+ body : `{"query":"{ transaction(hash: \"0x22f565cfeb33d5e6f81c8923ef0633a49fef0848a089a6d8564b655d5605fb13\") { gas gasUsed gasPrice maxFeePerGas maxPriorityFeePerGas effectiveGasPrice index from { address } to { address } value inputData block { transactionCount baseFeePerGas } status type }}"}` ,
180
+ want : `{"data":{"transaction":{"gas":"0xc350","gasUsed":22604,"gasPrice":"0xa","maxFeePerGas":"0x7530","maxPriorityFeePerGas":"0xa","effectiveGasPrice":"0xa","index":2,"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x32","inputData":"0x","block":{"transactionCount":3,"baseFeePerGas":"0x0"},"status":1,"type":2}}}` ,
181
+ code : 200 ,
182
+ },
183
+ } {
184
+ resp , err := http .Post (fmt .Sprintf ("%s/graphql" , stack .HTTPEndpoint ()), "application/json" , strings .NewReader (tt .body ))
185
+ if err != nil {
186
+ t .Fatalf ("could not post: %v" , err )
187
+ }
188
+ bodyBytes , err := ioutil .ReadAll (resp .Body )
189
+ if err != nil {
190
+ t .Fatalf ("could not read from response body: %v" , err )
191
+ }
192
+ if have := string (bodyBytes ); have != tt .want {
193
+ t .Errorf ("testcase %d %s,\n have:\n %v\n want:\n %v" , i , tt .body , have , tt .want )
194
+ }
195
+ if tt .code != resp .StatusCode {
196
+ t .Errorf ("testcase %d %s,\n wrong statuscode, have: %v, want: %v" , i , tt .body , resp .StatusCode , tt .code )
197
+ }
198
+ }
199
+ }
200
+
164
201
func TestGraphQLBlockSerializationEIP2718 (t * testing.T ) {
165
202
stack := createNode (t , true , true )
166
203
defer stack .Close ()
@@ -176,7 +213,7 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) {
176
213
}{
177
214
{
178
215
body : `{"query": "{block {number transactions { from { address } to { address } value hash type accessList { address storageKeys } index}}}"}` ,
179
- want : `{"data":{"block":{"number":1,"transactions":[{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x64","hash":"0x46933b8a43e70320bb41910f015c4b2aded1caaba32b55b56054e4d1811d06d6","type":0,"accessList":[],"index":0},{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x32","hash":"0x03682ed7cc9cf9e9fa3bb6f58a62d6a350c09ec4d22b71b884503ae469e8640b","type":1,"accessList":[{"address":"0x0000000000000000000000000000000000000dad","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000"]}],"index":1}]}}}` ,
216
+ want : `{"data":{"block":{"number":1,"transactions":[{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x64","hash":"0x46933b8a43e70320bb41910f015c4b2aded1caaba32b55b56054e4d1811d06d6","type":0,"accessList":[],"index":0},{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x32","hash":"0x03682ed7cc9cf9e9fa3bb6f58a62d6a350c09ec4d22b71b884503ae469e8640b","type":1,"accessList":[{"address":"0x0000000000000000000000000000000000000dad","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000"]}],"index":1},{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x32","hash":"0x22f565cfeb33d5e6f81c8923ef0633a49fef0848a089a6d8564b655d5605fb13","type":2,"accessList":[],"index":2} ]}}}` ,
180
217
code : 200 ,
181
218
},
182
219
} {
@@ -330,13 +367,23 @@ func createGQLServiceWithTransactions(t *testing.T, stack *node.Node) {
330
367
StorageKeys : []common.Hash {{0 }},
331
368
}},
332
369
})
370
+ dynamicTx , _ := types .SignNewTx (key , signer , & types.DynamicFeeTx {
371
+ ChainID : ethConf .Genesis .Config .ChainID ,
372
+ Nonce : uint64 (2 ),
373
+ To : & dad ,
374
+ Gas : 50000 ,
375
+ GasFeeCap : big .NewInt (30000 ),
376
+ GasTipCap : big .NewInt (10 ),
377
+ Value : big .NewInt (50 ),
378
+ })
333
379
334
380
// Create some blocks and import them
335
381
chain , _ := core .GenerateChain (params .IstanbulEHFTestChainConfig , ethBackend .BlockChain ().Genesis (),
336
382
mockEngine .NewFaker (), ethBackend .ChainDb (), 1 , func (i int , b * core.BlockGen ) {
337
383
b .SetCoinbase (common.Address {1 })
338
384
b .AddTx (legacyTx )
339
385
b .AddTx (envelopTx )
386
+ b .AddTx (dynamicTx )
340
387
})
341
388
342
389
_ , err = ethBackend .BlockChain ().InsertChain (chain )
0 commit comments