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>
This commit is contained in:
Mason Fischer 2020-09-15 05:29:51 -04:00 committed by GitHub
parent 0185ee0993
commit cf2a77af28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

@ -91,7 +91,7 @@ func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl
// BlockNumber returns the most recent block number // BlockNumber returns the most recent block number
func (ec *Client) BlockNumber(ctx context.Context) (uint64, error) { func (ec *Client) BlockNumber(ctx context.Context) (uint64, error) {
var result hexutil.Uint64 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 return uint64(result), err
} }

@ -352,3 +352,19 @@ func TestChainID(t *testing.T) {
t.Fatalf("ChainID returned wrong number: %+v", id) 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)
}
}