From a3e55e3bb87a2c3402190e6038ba2b72d6789c15 Mon Sep 17 00:00:00 2001 From: Hoang Trinh Date: Tue, 19 Dec 2023 10:53:28 +0700 Subject: [PATCH] feat: expose block number (#7) --- client.go | 4 ++++ ethrpc_test.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/client.go b/client.go index 040f0ec..7f18d31 100644 --- a/client.go +++ b/client.go @@ -55,6 +55,10 @@ func (c *Client) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, return c.ethClient.EstimateGas(ctx, msg) } +func (c *Client) GetBlockNumber(ctx context.Context) (uint64, error) { + return c.ethClient.BlockNumber(ctx) +} + func (c *Client) R() *Request { r := &Request{ client: c, diff --git a/ethrpc_test.go b/ethrpc_test.go index 9e193e8..40ed0fc 100644 --- a/ethrpc_test.go +++ b/ethrpc_test.go @@ -1,6 +1,7 @@ package ethrpc import ( + "context" "fmt" "math/big" "testing" @@ -23,6 +24,13 @@ func (ts *RPCTestSuite) SetupTest() { ts.client = rpcClient } +func (ts *RPCTestSuite) TestGetBlockNumber() { + blockNumber, err := ts.client.GetBlockNumber(context.Background()) + + ts.Require().NoError(err) + ts.Require().NotEqual(0, blockNumber) +} + func (ts *RPCTestSuite) TestTryAggregate() { type TradeInfo struct { Reserve0 *big.Int