Skip to content

Commit

Permalink
Use Long for block number
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Nov 24, 2020
1 parent cd7e560 commit f1fe93c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions graphql/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ var (

type Long uint64

func (b Long) String() string {
return string(b)
}

// ImplementsGraphQLType returns true if Long implements the provided GraphQL type.
func (b Long) ImplementsGraphQLType(name string) bool { return name == "Long" }

Expand Down Expand Up @@ -442,13 +438,13 @@ func (b *Block) resolveReceipts(ctx context.Context) ([]*types.Receipt, error) {
return b.receipts, nil
}

func (b *Block) Number(ctx context.Context) (hexutil.Uint64, error) {
func (b *Block) Number(ctx context.Context) (Long, error) {
header, err := b.resolveHeader(ctx)
if err != nil {
return 0, err
return Long(0), err
}

return hexutil.Uint64(header.Number.Uint64()), nil
return Long(header.Number.Uint64()), nil
}

func (b *Block) Hash(ctx context.Context) (common.Hash, error) {
Expand Down
4 changes: 2 additions & 2 deletions graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestGraphQLHTTPOnSamePort_GQLRequest_Successful(t *testing.T) {
if err != nil {
t.Fatalf("could not read from response body: %v", err)
}
expected := "{\"data\":{\"block\":{\"number\":\"0x0\"}}}"
expected := "{\"data\":{\"block\":{\"number\":0}}}"
assert.Equal(t, expected, string(bodyBytes))
}

Expand All @@ -85,7 +85,7 @@ func TestGraphQLBlockSerialization(t *testing.T) {
if err != nil {
t.Fatalf("could not read from response body: %v", err)
}
expected := "{\"data\":{\"block\":{\"number\":\"0x0\",\"gasUsed\":0,\"gasLimit\":5000}}}"
expected := "{\"data\":{\"block\":{\"number\":0,\"gasUsed\":0,\"gasLimit\":5000}}}"
assert.Equal(t, expected, string(bodyBytes))
}

Expand Down

0 comments on commit f1fe93c

Please sign in to comment.