forked from cerc-io/plugeth
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:
parent
0185ee0993
commit
cf2a77af28
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user