Skip to content

Commit

Permalink
ethclient, graphql: update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-EA committed Apr 11, 2023
1 parent 76ccc72 commit e9752aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
})
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
} {
Expand Down

0 comments on commit e9752aa

Please sign in to comment.