diff --git a/ethrpc/ethrpc_test.go b/ethrpc/ethrpc_test.go index 036a1d85..866b0c55 100644 --- a/ethrpc/ethrpc_test.go +++ b/ethrpc/ethrpc_test.go @@ -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" diff --git a/ethrpc/interface.go b/ethrpc/interface.go index 16060239..5803c001 100644 --- a/ethrpc/interface.go +++ b/ethrpc/interface.go @@ -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 +}