Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions ethrpc/ethrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ func TestDebugTraceTransaction(t *testing.T) {
require.NotEmpty(t, payload)
}*/

func TestDoRequest_SeqChainHealth(t *testing.T) {
p, err := ethrpc.NewProvider("https://dev-nodes.sequence.app/polygon")
require.NoError(t, err)

result, err := ethrpc.DoRequest(context.Background(), p, "seq_chainHealth")
require.NoError(t, err)
require.NotNil(t, result)

// Expect isHealthy to be true
isHealthy, ok := result["isHealthy"].(bool)
require.True(t, ok, "expected isHealthy to be a bool")
assert.True(t, isHealthy, "expected isHealthy to be true")

// Expect expiresAt to be present as a string (RFC3339 timestamp)
expiresAt, ok := result["expiresAt"].(string)
require.True(t, ok, "expected expiresAt to be a string")
assert.NotEmpty(t, expiresAt)
}

func TestFetchBlockWithInvalidVRS(t *testing.T) {
url := "https://rpc.telos.net"
// url := "https://node.mainnet.etherlink.com"
Expand Down
16 changes: 16 additions & 0 deletions ethrpc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,19 @@ type DebugInterface interface {
DebugTraceBlockByHash(ctx context.Context, blockHash common.Hash) ([]*TransactionDebugTrace, error)
DebugTraceTransaction(ctx context.Context, txHash common.Hash) (*CallDebugTrace, error)
}

// DoRequest is a helper for sending a custom JSON-RPC method to a provider
// and decoding the response into a map[string]any.
//
// Usage:
//
// result, err := ethrpc.DoRequest(ctx, provider, "seq_chainHealth")
// result, err := ethrpc.DoRequest(ctx, provider, "custom_method", arg1, arg2)
func DoRequest(ctx context.Context, provider Interface, method string, args ...any) (map[string]any, error) {
var result map[string]any
_, err := provider.Do(ctx, NewCallBuilder[map[string]any](method, nil, args...).Into(&result))
if err != nil {
return nil, err
}
return result, nil
}
Loading