From e9752aaa041fdf23f8c6df47d557f0f026feace8 Mon Sep 17 00:00:00 2001 From: Mister-EA Date: Fri, 7 Apr 2023 13:41:04 +0200 Subject: [PATCH] ethclient, graphql: update test cases --- ethclient/ethclient_test.go | 19 +++++++++++++++---- graphql/graphql_test.go | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ethclient/ethclient_test.go b/ethclient/ethclient_test.go index b488487620..842c17abcc 100644 --- a/ethclient/ethclient_test.go +++ b/ethclient/ethclient_test.go @@ -38,6 +38,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb/memorydb" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" ) @@ -415,10 +416,20 @@ func testHeader(t *testing.T, chain []*types.Block, client *rpc.Client) { if !errors.Is(err, tt.wantErr) { t.Fatalf("HeaderByNumber(%v) error = %q, want %q", tt.block, err, tt.wantErr) } - if got != nil && got.Number != nil && got.Number.Sign() == 0 { - got.Number = big.NewInt(0) // hack to make DeepEqual work + + gotBytes, err := rlp.EncodeToBytes(got) + if err != nil { + t.Fatalf("Error serializing received block header.") + } + wantBytes, _ := rlp.EncodeToBytes(tt.want) + if err != nil { + t.Fatalf("Error serializing wanted block header.") } - if !reflect.DeepEqual(got, tt.want) { + + // Instead of comparing the Header's compare the serialized bytes, + // because reflect.DeepEqual(*types.Header, *types.Header) sometimes + // returns false even though the underlying field values are exactly the same. + if !reflect.DeepEqual(gotBytes, wantBytes) { t.Fatalf("HeaderByNumber(%v)\n = %v\nwant %v", tt.block, got, tt.want) } }) @@ -579,7 +590,7 @@ func testStatusFunctions(t *testing.T, client *rpc.Client) { if err != nil { t.Fatalf("unexpected error: %v", err) } - if gasPrice.Cmp(big.NewInt(1000000042)) != 0 { + if gasPrice.Cmp(big.NewInt(1000000000)) != 0 { t.Fatalf("unexpected gas price: %v", gasPrice) } diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index a0b7979069..4d709d50d2 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -177,7 +177,7 @@ func TestGraphQLBlockSerializationEIP2718(t *testing.T) { }{ { body: `{"query": "{block {number transactions { from { address } to { address } value hash type accessList { address storageKeys } index}}}"}`, - want: `{"data":{"block":{"number":1,"transactions":[{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x64","hash":"0xd864c9d7d37fade6b70164740540c06dd58bb9c3f6b46101908d6339db6a6a7b","type":0,"accessList":[],"index":0},{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x32","hash":"0x19b35f8187b4e15fb59a9af469dca5dfa3cd363c11d372058c12f6482477b474","type":1,"accessList":[{"address":"0x0000000000000000000000000000000000000dad","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000"]}],"index":1}]}}}`, + want: `{"data":{"block":{"number":1,"transactions":[{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x64","hash":"0xe7418d03e2ece5fcd277c49bf9d8b7b9d43a9e27731d56a6496eb9e54d504202","type":0,"accessList":[],"index":0},{"from":{"address":"0x71562b71999873db5b286df957af199ec94617f7"},"to":{"address":"0x0000000000000000000000000000000000000dad"},"value":"0x32","hash":"0x0f32fec26e145116d7927ce74dfa64334682747459481246cde86e68d3091679","type":1,"accessList":[{"address":"0x0000000000000000000000000000000000000dad","storageKeys":["0x0000000000000000000000000000000000000000000000000000000000000000"]}],"index":1}]}}}`, code: 200, }, } {