diff --git a/system-tests/tests/smoke/cre/v2_vault_don_test.go b/system-tests/tests/smoke/cre/v2_vault_don_test.go index ff709c8d9f9..2bb459ed8bb 100644 --- a/system-tests/tests/smoke/cre/v2_vault_don_test.go +++ b/system-tests/tests/smoke/cre/v2_vault_don_test.go @@ -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 { diff --git a/system-tests/tests/smoke/cre/v2_vault_don_test_helpers.go b/system-tests/tests/smoke/cre/v2_vault_don_test_helpers.go index a9a493e2e8a..1b3976c857c 100644 --- a/system-tests/tests/smoke/cre/v2_vault_don_test_helpers.go +++ b/system-tests/tests/smoke/cre/v2_vault_don_test_helpers.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "net/http" + "strings" "testing" "time" @@ -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") }