patched testing tool
This commit is contained in:
parent
8e26f51eb6
commit
7f7d5975d4
|
|
@ -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
|
The test tool requires the PHP GD and OpenSSL extensions in addition to the
|
||||||
Contractless Skein and Falcon modules.
|
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
|
## Initial Endpoints
|
||||||
|
|
||||||
All responses use JSON. Successful responses contain `success: true` and a
|
All responses use JSON. Successful responses contain `success: true` and a
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,11 @@ declare(strict_types=1);
|
||||||
|
|
||||||
use Contractless\Api\Tools\FalconSigner;
|
use Contractless\Api\Tools\FalconSigner;
|
||||||
use Contractless\Api\Tools\TestWalletLoader;
|
use Contractless\Api\Tools\TestWalletLoader;
|
||||||
|
use Contractless\Api\ApplicationFactory;
|
||||||
|
use Contractless\Rpc\Client;
|
||||||
use Contractless\Rpc\Crypto\NativeCrypto;
|
use Contractless\Rpc\Crypto\NativeCrypto;
|
||||||
|
use Contractless\Rpc\Protocol\HandshakeProof;
|
||||||
|
use Contractless\Rpc\Transport\StreamTransport;
|
||||||
|
|
||||||
if (PHP_SAPI !== 'cli') {
|
if (PHP_SAPI !== 'cli') {
|
||||||
http_response_code(404);
|
http_response_code(404);
|
||||||
|
|
@ -99,6 +103,58 @@ try {
|
||||||
} catch (JsonException) {
|
} catch (JsonException) {
|
||||||
echo $body . PHP_EOL;
|
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);
|
exit($status >= 200 && $status < 300 ? 0 : 1);
|
||||||
} catch (Throwable $error) {
|
} catch (Throwable $error) {
|
||||||
fwrite(STDERR, 'API test failed: ' . $error->getMessage() . PHP_EOL);
|
fwrite(STDERR, 'API test failed: ' . $error->getMessage() . PHP_EOL);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue