Publish Chain 138 RPC capability metadata
This commit is contained in:
@@ -46,6 +46,29 @@ type testTokenList struct {
|
||||
} `json:"tokens"`
|
||||
}
|
||||
|
||||
type testCapabilitiesCatalog struct {
|
||||
Name string `json:"name"`
|
||||
GeneratedBy string `json:"generatedBy"`
|
||||
ChainID int `json:"chainId"`
|
||||
ChainName string `json:"chainName"`
|
||||
RPCURL string `json:"rpcUrl"`
|
||||
HTTP struct {
|
||||
SupportedMethods []string `json:"supportedMethods"`
|
||||
UnsupportedMethods []string `json:"unsupportedMethods"`
|
||||
Notes []string `json:"notes"`
|
||||
} `json:"http"`
|
||||
Tracing struct {
|
||||
SupportedMethods []string `json:"supportedMethods"`
|
||||
UnsupportedMethods []string `json:"unsupportedMethods"`
|
||||
Notes []string `json:"notes"`
|
||||
} `json:"tracing"`
|
||||
WalletSupport struct {
|
||||
WalletAddEthereumChain bool `json:"walletAddEthereumChain"`
|
||||
WalletWatchAsset bool `json:"walletWatchAsset"`
|
||||
Notes []string `json:"notes"`
|
||||
} `json:"walletSupport"`
|
||||
}
|
||||
|
||||
func setupConfigHandler() http.Handler {
|
||||
server := NewServer(nil, 138)
|
||||
mux := http.NewServeMux()
|
||||
@@ -53,6 +76,15 @@ func setupConfigHandler() http.Handler {
|
||||
return server.addMiddleware(mux)
|
||||
}
|
||||
|
||||
func containsString(items []string, want string) bool {
|
||||
for _, item := range items {
|
||||
if item == want {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestConfigNetworksEndpointProvidesWalletMetadata(t *testing.T) {
|
||||
handler := setupConfigHandler()
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/config/networks", nil)
|
||||
@@ -148,6 +180,38 @@ func TestConfigTokenListEndpointProvidesOptionalMetadata(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigCapabilitiesEndpointProvidesRPCCapabilityMatrix(t *testing.T) {
|
||||
handler := setupConfigHandler()
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/config/capabilities", nil)
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d", w.Code)
|
||||
}
|
||||
|
||||
var payload testCapabilitiesCatalog
|
||||
if err := json.Unmarshal(w.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("failed to parse capabilities payload: %v", err)
|
||||
}
|
||||
|
||||
if payload.ChainID != 138 || payload.ChainName == "" || payload.RPCURL == "" || payload.GeneratedBy == "" {
|
||||
t.Fatal("expected populated chain-level capability metadata")
|
||||
}
|
||||
if !payload.WalletSupport.WalletAddEthereumChain || !payload.WalletSupport.WalletWatchAsset {
|
||||
t.Fatal("expected wallet support flags to be true")
|
||||
}
|
||||
if !containsString(payload.HTTP.SupportedMethods, "eth_feeHistory") {
|
||||
t.Fatal("expected eth_feeHistory support to be documented")
|
||||
}
|
||||
if !containsString(payload.HTTP.UnsupportedMethods, "eth_maxPriorityFeePerGas") {
|
||||
t.Fatal("expected missing eth_maxPriorityFeePerGas support to be documented")
|
||||
}
|
||||
if !containsString(payload.Tracing.SupportedMethods, "trace_block") {
|
||||
t.Fatal("expected trace_block support to be documented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigEndpointsSupportOptionsPreflight(t *testing.T) {
|
||||
handler := setupConfigHandler()
|
||||
req := httptest.NewRequest(http.MethodOptions, "/api/config/token-list", nil)
|
||||
|
||||
Reference in New Issue
Block a user