ethclient: fix BlockNumber (#21565)

It didn't actually work because it called a method that doesn't
exist. This fixes it also adds a test.

Co-authored-by: Felix Lange <fjl@twurst.com>
pull/21571/head
Mason Fischer 4 years ago committed by GitHub
parent 0185ee0993
commit cf2a77af28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ethclient/ethclient.go
  2. 16
      ethclient/ethclient_test.go

@ -91,7 +91,7 @@ func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl
// BlockNumber returns the most recent block number
func (ec *Client) BlockNumber(ctx context.Context) (uint64, error) {
var result hexutil.Uint64
err := ec.c.CallContext(ctx, &result, "eth_getBlockNumber", nil)
err := ec.c.CallContext(ctx, &result, "eth_blockNumber")
return uint64(result), err
}

@ -352,3 +352,19 @@ func TestChainID(t *testing.T) {
t.Fatalf("ChainID returned wrong number: %+v", id)
}
}
func TestBlockNumber(t *testing.T) {
backend, _ := newTestBackend(t)
client, _ := backend.Attach()
defer backend.Close()
defer client.Close()
ec := NewClient(client)
blockNumber, err := ec.BlockNumber(context.Background())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if blockNumber != 1 {
t.Fatalf("BlockNumber returned wrong number: %d", blockNumber)
}
}

Loading…
Cancel
Save