|
| 1 | +# Handler Specification |
| 2 | + |
| 3 | +This document defines the protocol that handler binaries must implement to be compatible with the conformance test runner. |
| 4 | + |
| 5 | +## Communication Protocol |
| 6 | + |
| 7 | +Handlers communicate with the test runner via **stdin/stdout**: |
| 8 | +- **Input**: JSON requests on stdin (one per line) |
| 9 | +- **Output**: JSON responses on stdout (one per line) |
| 10 | +- **Lifecycle**: Handler starts, processes requests until stdin closes, then exits |
| 11 | + |
| 12 | +## Message Format |
| 13 | + |
| 14 | +### Request |
| 15 | + |
| 16 | +```json |
| 17 | +{ |
| 18 | + "id": "unique-request-id", |
| 19 | + "method": "method_name", |
| 20 | + "params": { /* method-specific parameters */ } |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +**Fields:** |
| 25 | +- `id` (string, required): Unique identifier for this request |
| 26 | +- `method` (string, required): The operation to perform. Each unique method must be implemented by the handler to exercise the corresponding binding API operation. |
| 27 | +- `params` (object, required): Method-specific parameters (can be `null` or `{}`) |
| 28 | + |
| 29 | +### Response |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "id": "unique-request-id", |
| 34 | + "success": { /* method-specific result */ } |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +**Success response fields:** |
| 39 | +- `id` (string, required): Must match the request ID |
| 40 | +- `success` (any, required): Method-specific result data. Must be present on success (can be empty `{}`) |
| 41 | +- `error` (null or omitted): Must not be present on success |
| 42 | + |
| 43 | +### Error Response |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "id": "unique-request-id", |
| 48 | + "error": { |
| 49 | + "type": "error_category", |
| 50 | + "variant": "specific_error" |
| 51 | + } |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +**Error response fields:** |
| 56 | +- `id` (string, required): Must match the request ID |
| 57 | +- `success` (null or omitted): Must not be present on error |
| 58 | +- `error` (object, required): Error details |
| 59 | + - `type` (string, required): Error category/type |
| 60 | + - `variant` (string, optional): Specific error variant within the type. Whether the runner expects this field depends on the specific test case |
| 61 | + |
| 62 | +## Handler Requirements |
| 63 | + |
| 64 | +1. **Input Processing**: Read JSON requests line-by-line from stdin |
| 65 | +2. **Response Order**: Responses must match request order (process sequentially) |
| 66 | +3. **ID Matching**: Response `id` must exactly match the request `id` |
| 67 | +4. **Error Handling**: Return error responses for invalid requests or failed operations |
| 68 | +5. **Exit Behavior**: Exit cleanly when stdin closes |
| 69 | + |
| 70 | +## Test Suites and Expected Responses |
| 71 | + |
| 72 | +The conformance tests are organized into suites, each testing a specific aspect of the Bitcoin Kernel bindings. Test files are located in [`../testdata/`](../testdata/). |
| 73 | + |
| 74 | +### Script Verification Success Cases |
| 75 | +**File:** [`script_verify_success.json`](../testdata/script_verify_success.json) |
| 76 | + |
| 77 | +Tests valid Bitcoin script verification scenarios across different transaction types. |
| 78 | + |
| 79 | +**Method:** `script_pubkey.verify` |
| 80 | + |
| 81 | +**Expected Response Format:** |
| 82 | +```json |
| 83 | +{ |
| 84 | + "id": "test-id", |
| 85 | + "success": {} |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### Script Verification Error Cases |
| 90 | +**File:** [`script_verify_errors.json`](../testdata/script_verify_errors.json) |
| 91 | + |
| 92 | +Tests error handling for invalid script verification scenarios. |
| 93 | + |
| 94 | +**Method:** `script_pubkey.verify` |
| 95 | + |
| 96 | +**Expected Response Format:** |
| 97 | +```json |
| 98 | +{ |
| 99 | + "id": "test-id", |
| 100 | + "error": { |
| 101 | + "type": "ScriptVerify", |
| 102 | + "variant": "ErrorVariant" |
| 103 | + } |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +**Error Variants:** |
| 108 | + |
| 109 | +| Variant | Description | |
| 110 | +|---------|-------------| |
| 111 | +| `TxInputIndex` | The specified input index is out of bounds. The `input_index` parameter is greater than or equal to the number of inputs in the transaction. | |
| 112 | +| `InvalidFlags` | Invalid verification flags were provided. The flags parameter contains bits that don't correspond to any defined verification flag. | |
| 113 | +| `InvalidFlagsCombination` | Invalid or inconsistent verification flags were provided. This occurs when the supplied `script_verify_flags` combination violates internal consistency rules. | |
| 114 | +| `SpentOutputsMismatch` | The spent_outputs array length doesn't match the input count. When spent_outputs is non-empty, it must contain exactly one output for each input in the transaction. | |
| 115 | +| `SpentOutputsRequired` | Spent outputs are required but were not provided. | |
| 116 | +| `Invalid` | Script verification failed. | |
0 commit comments