Skip to content

Commit 4df1da5

Browse files
Align test specification with bitcoinkernel.h exported symbols (#7)
- Standardize test parameters to match C function signatures and names - Restructure response format with improved success/error semantics - Remove test cases for unexported errors and flags (not in bitcoinkernel.h) - Add response validation unit tests - Update handler specification to reflect new response structure Co-authored-by: stickies-v <stickies-v@protonmail.com>
2 parents 3b7e4de + e8ddf75 commit 4df1da5

File tree

10 files changed

+590
-323
lines changed

10 files changed

+590
-323
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
- name: Build
2121
run: make build
2222

23-
- name: Run tests against mock handler
23+
- name: Run tests
2424
run: make test

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ mock-handler:
1919
go build -o $(MOCK_HANDLER_BIN) ./cmd/mock-handler
2020

2121
test:
22+
@echo "Running runner unit tests..."
23+
go test ./runner/...
2224
@echo "Running conformance tests with mock handler..."
2325
$(RUNNER_BIN) -handler $(MOCK_HANDLER_BIN)
2426

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ make runner
5656

5757
### Testing the Runner
5858

59-
Build and test the runner using the mock handler:
59+
Build and test the runner:
6060

6161
```bash
6262
# Build both runner and mock handler
6363
make build
6464

65-
# Run the test runner against the mock handler
65+
# Run runner unit tests and integration tests with mock handler
6666
make test
6767
```

cmd/mock-handler/main.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ func handleRequest(line string, testIndex map[string]string) error {
8181
resp := runner.Response{
8282
ID: req.ID,
8383
Error: &runner.Error{
84-
Type: "Handler",
85-
Variant: "UnknownTest",
84+
Code: &runner.ErrorCode{
85+
Type: "Handler",
86+
Member: "UNKNOWN_TEST",
87+
},
8688
},
8789
}
8890
return writeResponse(resp)
@@ -94,8 +96,10 @@ func handleRequest(line string, testIndex map[string]string) error {
9496
resp := runner.Response{
9597
ID: req.ID,
9698
Error: &runner.Error{
97-
Type: "Handler",
98-
Variant: "LoadError",
99+
Code: &runner.ErrorCode{
100+
Type: "Handler",
101+
Member: "LOAD_ERROR",
102+
},
99103
},
100104
}
101105
return writeResponse(resp)
@@ -113,8 +117,10 @@ func handleRequest(line string, testIndex map[string]string) error {
113117
resp := runner.Response{
114118
ID: req.ID,
115119
Error: &runner.Error{
116-
Type: "Handler",
117-
Variant: "TestNotFound",
120+
Code: &runner.ErrorCode{
121+
Type: "Handler",
122+
Member: "TEST_NOT_FOUND",
123+
},
118124
},
119125
}
120126
return writeResponse(resp)
@@ -125,18 +131,20 @@ func handleRequest(line string, testIndex map[string]string) error {
125131
resp := runner.Response{
126132
ID: req.ID,
127133
Error: &runner.Error{
128-
Type: "Handler",
129-
Variant: "MethodMismatch",
134+
Code: &runner.ErrorCode{
135+
Type: "Handler",
136+
Member: "METHOD_MISMATCH",
137+
},
130138
},
131139
}
132140
return writeResponse(resp)
133141
}
134142

135143
// Build response based on expected result
136144
return writeResponse(runner.Response{
137-
ID: req.ID,
138-
Success: testCase.Expected.Success,
139-
Error: testCase.Expected.Error,
145+
ID: req.ID,
146+
Result: testCase.Expected.Result,
147+
Error: testCase.Expected.Error,
140148
})
141149
}
142150

docs/handler-spec.md

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,32 @@ Handlers communicate with the test runner via **stdin/stdout**:
2424
**Fields:**
2525
- `id` (string, required): Unique identifier for this request
2626
- `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 `{}`)
27+
- `params` (object, optional): Method-specific parameters
2828

2929
### Response
3030

3131
```json
3232
{
3333
"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",
34+
"result": null,
4835
"error": {
49-
"type": "error_category",
50-
"variant": "specific_error"
36+
"code": {
37+
"type": "error_type",
38+
"member": "ERROR_MEMBER_NAME"
39+
}
5140
}
5241
}
5342
```
5443

55-
**Error response fields:**
44+
**Fields:**
5645
- `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
46+
- `result` (any, optional): The return value, or `null` for void/nullptr operations. Must be `null` on error
47+
- `error` (object, optional): Error details. Must be `null` on success. An empty object `{}` is used to indicate an error is raised without further details, it is NOT equivalent to `null`
48+
- `code` (object, optional): Error code details
49+
- `type` (string, required): Error type (e.g., "btck_ScriptVerifyStatus")
50+
- `member` (string, required): Specific error member (e.g., "ERROR_INVALID_FLAGS_COMBINATION")
51+
52+
**Note:** Throughout this protocol, an omitted field is semantically equivalent to `null`.
6153

6254
## Handler Requirements
6355

@@ -74,43 +66,49 @@ The conformance tests are organized into suites, each testing a specific aspect
7466
### Script Verification Success Cases
7567
**File:** [`script_verify_success.json`](../testdata/script_verify_success.json)
7668

77-
Tests valid Bitcoin script verification scenarios across different transaction types.
69+
Test cases where the script verification operation executes successfully and returns a boolean result (true for valid scripts, false for invalid scripts).
7870

79-
**Method:** `script_pubkey.verify`
71+
**Method:** `btck_script_pubkey_verify`
8072

8173
**Expected Response Format:**
8274
```json
8375
{
8476
"id": "test-id",
85-
"success": {}
77+
"result": true
78+
}
79+
```
80+
or
81+
```json
82+
{
83+
"id": "test-id",
84+
"result": false
8685
}
8786
```
8887

8988
### Script Verification Error Cases
9089
**File:** [`script_verify_errors.json`](../testdata/script_verify_errors.json)
9190

92-
Tests error handling for invalid script verification scenarios.
91+
Test cases where the verification operation fails to determine validity of the script due to bad user input.
9392

94-
**Method:** `script_pubkey.verify`
93+
**Method:** `btck_script_pubkey_verify`
9594

9695
**Expected Response Format:**
9796
```json
9897
{
9998
"id": "test-id",
99+
"result": null,
100100
"error": {
101-
"type": "ScriptVerify",
102-
"variant": "ErrorVariant"
101+
"code": {
102+
"type": "btck_ScriptVerifyStatus",
103+
"member": "ERROR_MEMBER_NAME"
104+
}
103105
}
104106
}
105107
```
106108

107-
**Error Variants:**
109+
**Error Members:**
108110

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. |
111+
| Member | Description |
112+
|--------|-------------|
113+
| `ERROR_INVALID_FLAGS_COMBINATION` | Invalid or inconsistent verification flags were provided. This occurs when the supplied `script_verify_flags` combination violates internal consistency rules. |
114+
| `ERROR_SPENT_OUTPUTS_REQUIRED` | Spent outputs are required but were not provided (e.g., for Taproot verification). |

0 commit comments

Comments
 (0)