From 7f7d5975d4336fe58c3f72ff0f167a083079c2d3 Mon Sep 17 00:00:00 2001 From: viraladmin <00purple@gmail.com> Date: Mon, 27 Jul 2026 16:51:32 -0600 Subject: [PATCH] patched testing tool --- README.md | 4 ++++ tools/test_api.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/README.md b/README.md index a0a700d..79fbb8f 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,10 @@ nonzero exit status when the HTTP request fails. The test tool requires the PHP GD and OpenSSL extensions in addition to the Contractless Skein and Falcon modules. +If the HTTP API returns `503`, the tool also tests every RPC endpoint from the +local `api.env` directly. It prints the real transport, handshake, or protocol +error to the terminal without exposing that diagnostic through the public API. + ## Initial Endpoints All responses use JSON. Successful responses contain `success: true` and a diff --git a/tools/test_api.php b/tools/test_api.php index 07e6642..8bf6cb1 100644 --- a/tools/test_api.php +++ b/tools/test_api.php @@ -4,7 +4,11 @@ declare(strict_types=1); use Contractless\Api\Tools\FalconSigner; use Contractless\Api\Tools\TestWalletLoader; +use Contractless\Api\ApplicationFactory; +use Contractless\Rpc\Client; use Contractless\Rpc\Crypto\NativeCrypto; +use Contractless\Rpc\Protocol\HandshakeProof; +use Contractless\Rpc\Transport\StreamTransport; if (PHP_SAPI !== 'cli') { http_response_code(404); @@ -99,6 +103,58 @@ try { } catch (JsonException) { echo $body . PHP_EOL; } + + if ($status === 503) { + fwrite( + STDERR, + "The API returned 503. Testing each configured RPC endpoint directly:\n", + ); + $config = ApplicationFactory::configuration($projectRoot); + $proof = new HandshakeProof($wallet['public_key'], $signature); + foreach ($config->rpcNodes as $name => $node) { + try { + $client = new Client( + new StreamTransport( + host: $node['host'], + port: $node['port'], + timeout: $config->rpcTimeout, + ), + $crypto, + $proof, + ); + $reply = $client->blockHeight(); + if (strlen($reply) !== 4) { + throw new RuntimeException( + "Block-height reply contained " . strlen($reply) . ' bytes.', + ); + } + $height = unpack('Vheight', $reply); + fwrite( + STDERR, + sprintf( + "[%s] %s:%d succeeded at height %u\n", + $name, + $node['host'], + $node['port'], + (int) ($height['height'] ?? 0), + ), + ); + } catch (Throwable $endpointError) { + fwrite( + STDERR, + sprintf( + "[%s] %s:%d failed: %s: %s\n", + $name, + $node['host'], + $node['port'], + $endpointError::class, + $endpointError->getMessage(), + ), + ); + } + } + } + exit($status >= 200 && $status < 300 ? 0 : 1); } catch (Throwable $error) { fwrite(STDERR, 'API test failed: ' . $error->getMessage() . PHP_EOL);