Skip to content

Commit

Permalink
db2/BigTableEthRaw: fallback for unsupported method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tangui-Bitfly committed Oct 15, 2024
1 parent dcfaba1 commit 7d0b7c6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backend/pkg/commons/db2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
var ttl = 2 * time.Second

var ErrNotFoundInCache = fmt.Errorf("cannot find hash in cache")
var ErrMethodNotSupported = fmt.Errorf("methode not supported")

type EthClient interface {
ethereum.ChainReader
Expand Down Expand Up @@ -52,6 +53,7 @@ func (r WithFallback) RoundTrip(request *http.Request) (*http.Response, error) {
var e1 *json.SyntaxError
if !errors.As(err, &e1) &&
!errors.Is(err, ErrNotFoundInCache) &&
!errors.Is(err, ErrMethodNotSupported) &&
!errors.Is(err, store.ErrNotFound) {
return nil, err
}
Expand Down Expand Up @@ -169,6 +171,8 @@ func (r *BigTableEthRaw) handle(ctx context.Context, message *jsonrpcMessage) (*
if err != nil {
return nil, err
}
default:
return nil, ErrMethodNotSupported
}
var resp jsonrpcMessage
_ = json.Unmarshal(respBody, &resp)
Expand Down
8 changes: 8 additions & 0 deletions backend/pkg/commons/db2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ func TestBigTableClientWithFallback(t *testing.T) {
}
ethClient := ethclient.NewClient(rpcClient)

balance, err := ethClient.BalanceAt(context.Background(), common.Address{}, big.NewInt(tt.block.BlockNumber))
if err != nil {
t.Fatal(err)
}
if balance == nil {
t.Errorf("empty balance")
}

block, err := ethClient.BlockByNumber(context.Background(), big.NewInt(tt.block.BlockNumber))
if err != nil {
t.Fatalf("BlockByNumber() error = %v", err)
Expand Down

0 comments on commit 7d0b7c6

Please sign in to comment.