Skip to content

Commit

Permalink
minor
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Aug 30, 2023
1 parent a24e6c3 commit 887c461
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func cacheKeyBlockNum(chainID *big.Int, num *big.Int) string {
}

func (m *Monitor) fetchRawBlockByNumber(ctx context.Context, num *big.Int) ([]byte, error) {
m.log.Debugf("ethmonitor: fetchBlockByNumber is calling origin for number %s", num)
m.log.Debugf("ethmonitor: fetchRawBlockByNumber is calling origin for number %s", num)
maxErrAttempts, errAttempts := 3, 0 // quick retry in case of short-term node connection failures

var blockPayload []byte
Expand Down
30 changes: 30 additions & 0 deletions ethrpc/ethrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,33 @@ func TestETHRPC(t *testing.T) {
assert.Equal(t, uint64(38470000), header.Number.Uint64())
})
}

func TestRaw(t *testing.T) {
p, err := ethrpc.NewProvider("https://nodes.sequence.app/polygon")
// p, err := ethrpc.NewProvider("http://localhost:8887/polygon")
require.NoError(t, err)

// block exists
{
ctx := context.Background()
payload, err := p.RawBlockByNumber(ctx, big.NewInt(38470000))

require.NoError(t, err)
require.NotEmpty(t, payload)

var block *types.Block
err = ethrpc.IntoBlock(payload, &block)
require.NoError(t, err)
require.Equal(t, uint64(38470000), block.NumberU64())
}

// block does not exist
{
ctx := context.Background()
n, _ := big.NewInt(0).SetString("ffffffffffff", 16)
payload, err := p.RawBlockByNumber(ctx, n)

require.True(t, errors.Is(err, ethereum.NotFound))
require.Empty(t, payload)
}
}

0 comments on commit 887c461

Please sign in to comment.