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
1 change: 0 additions & 1 deletion system-tests/tests/smoke/cre/v2_vault_don_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ func allowlistRequest(t *testing.T, owner string, request jsonrpc.Request[json.R
require.NoError(t, err, "failed to allowlist request")

framework.L.Info().Msgf("Allowlisting request digest at contract %s, for owner: %s, digestHexStr: %s", wfRegistryContract.Address().Hex(), owner, requestDigest)
time.Sleep(6 * time.Second) // allowlist syncer polls every 5s; one tick + margin
allowedList, err := wfRegistryContract.GetAllowlistedRequests(&bind.CallOpts{}, big.NewInt(0), big.NewInt(100))
require.NoError(t, err, "failed to validate allowlisted request")
for _, req := range allowedList {
Expand Down
61 changes: 49 additions & 12 deletions system-tests/tests/smoke/cre/v2_vault_don_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -56,20 +57,56 @@ func FetchVaultPublicKey(t *testing.T, gatewayURL string) (publicKey string) {
}

func sendVaultRequestToGateway(t *testing.T, gatewayURL string, requestBody []byte) (statusCode int, body []byte) {
const maxRetries = 7
const retryInterval = 2 * time.Second

framework.L.Info().Msgf("Request Body: %s", string(requestBody))
req, err := http.NewRequestWithContext(t.Context(), "POST", gatewayURL, bytes.NewBuffer(requestBody))
require.NoError(t, err, "failed to create request")

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
for attempt := range maxRetries + 1 {
req, err := http.NewRequestWithContext(t.Context(), "POST", gatewayURL, bytes.NewBuffer(requestBody))
require.NoError(t, err, "failed to create request")

req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
require.NoError(t, err, "failed to execute request")

client := &http.Client{}
resp, err := client.Do(req)
require.NoError(t, err, "failed to execute request")
defer resp.Body.Close()
body, err = io.ReadAll(resp.Body)
resp.Body.Close()
require.NoError(t, err, "failed to read http response body")
statusCode = resp.StatusCode

body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "failed to read http response body")
framework.L.Info().Msgf("HTTP Response Body: %s", string(body))
return resp.StatusCode, body
framework.L.Info().Msgf("HTTP Response Body: %s", string(body))

if !isGatewayNotAllowlistedError(body) {
return statusCode, body
}

if attempt < maxRetries {
framework.L.Warn().Msgf("Request not yet allowlisted, retrying in %s (attempt %d/%d)...", retryInterval, attempt+1, maxRetries)
time.Sleep(retryInterval)
}
}

return statusCode, body
}

// isGatewayNotAllowlistedError checks whether the response is a gateway-level
// "request not allowlisted" rejection (method is empty, error code -32600).
// Node-level rejections (method is set, code -32603) have a different format
// and must not be retried because the gateway has already consumed the request.
func isGatewayNotAllowlistedError(body []byte) bool {
var resp struct {
Method string `json:"method"`
Error *struct {
Message string `json:"message"`
} `json:"error"`
}
if json.Unmarshal(body, &resp) != nil {
return false
}
return resp.Method == "" && resp.Error != nil &&
strings.Contains(resp.Error.Message, "request not allowlisted")
}
Loading