Skip to content

Commit 4956376

Browse files
authored
feat: add a new set of integration tests for construction endpoints (#583)
* feat: add integration testing for Rosetta API construction endpoints - Introduced a new Python validator for testing Rosetta construction API endpoints, supporting snapshot testing and OpenAPI schema validation. - Updated GitHub Actions workflow to set up Python 3.12 and install necessary dependencies. - Added README documentation for usage instructions and features of the new validator. * fix: integration tests with network flexibility - Added support for specifying network IDs in integration tests via the `--network-id` parameter, allowing for dynamic replacement of `{{networkId}}` placeholders. - Updated README to document new network flexibility features and usage examples. - Modified the integration test script to handle network ID replacements in API calls, defaulting to 'preprod' if not specified. - Improved CI/CD integration by ensuring proper exit codes based on test results. * refactor: update network identifier in integration test JSON files - Replaced hardcoded 'preprod' network identifier with a dynamic placeholder '{{networkId}}' in multiple integration test JSON files for improved flexibility. - Ensures consistency across test cases and aligns with recent changes to support dynamic network configurations. * refactor: expand VOLATILE_FIELDS in integration tests - Added 'options.transaction_size' to the VOLATILE_FIELDS dictionary in the construction API integration test to ensure proper handling of devkit differences
1 parent 73871a4 commit 4956376

File tree

313 files changed

+80156
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

313 files changed

+80156
-0
lines changed

.github/workflows/integration-test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ jobs:
2727
PGPASSWORD=$DB_SECRET psql -h localhost -p 5432 -d $DB_NAME -U $DB_USER -f temp.sql
2828
- name: "Install newman"
2929
run: npm install -g newman
30+
- name: "Setup Python"
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: '3.12'
34+
- name: "Install uv"
35+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
3036
# - name: "Install mesh-cli"
3137
# run: curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s
3238

@@ -36,6 +42,13 @@ jobs:
3642

3743
- name: "Run tests"
3844
run: newman run ./postmanTests/rosetta-java.postman_collection.json -e postmanTests/Rosetta-java-env.postman_environment.json -r cli
45+
- name: "Run construction API tests with schema validation"
46+
run: |
47+
cd ./tests/integration
48+
~/.local/bin/uv run test_construction_api.py \
49+
-u http://localhost:8082 \
50+
--network-id devkit \
51+
--openapi ../../api/src/main/resources/rosetta-specifications-1.4.15/api.yaml
3952
- name: "Run rosetta check:data tests"
4053
run: ./bin/rosetta-cli check:data --configuration-file ./rosetta-cli-tests/data/byron_sample.json
4154
- name: "Tear down environment"

tests/integration/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Python cache
2+
__pycache__/
3+
*.pyc
4+
5+
# Test outputs
6+
results.txt
7+
*.test.log

tests/integration/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# Rosetta API Construction Integration Test Validator
2+
3+
A integration testing tool for Rosetta API construction endpoints. It validates live API responses against both:
4+
- Snapshot expectations stored in JSON test files, and
5+
- The OpenAPI schema (when available) for structural correctness.
6+
7+
## What is Snapshot Testing?
8+
9+
This validator implements snapshot testing - it compares actual API responses against previously captured "snapshots" of expected behavior. When the API behavior changes, tests fail, alerting you to potential regressions or the need to update snapshots.
10+
11+
## Quick Start
12+
13+
### Option 1: Basic Mode (No Environment Setup)
14+
Run snapshot testing without schema validation - no dependencies needed:
15+
16+
```bash
17+
# Test all files with default parallel execution (10 workers)
18+
python3 test_construction_api.py
19+
20+
# Test specific endpoint with more workers for faster execution
21+
python3 test_construction_api.py parse/ -j 20
22+
23+
# Note: Schema validation will be skipped in this mode
24+
```
25+
26+
### Option 2: Full Mode with uv (Includes Schema Validation)
27+
For full features including OpenAPI schema validation:
28+
29+
```bash
30+
# Install uv if you don't have it
31+
curl -LsSf https://astral.sh/uv/install.sh | sh
32+
33+
# Run the validator with full features (uv handles environment automatically)
34+
uv run test_construction_api.py
35+
36+
# Run with specific options and increased parallelism
37+
uv run test_construction_api.py parse/ -v -j 15
38+
uv run test_construction_api.py -o results.txt -j 20
39+
```
40+
41+
That's it! The `uv run` command automatically:
42+
- Creates a virtual environment (if needed)
43+
- Installs all dependencies (pyyaml, jsonschema)
44+
- Runs the script with full schema validation enabled
45+
46+
## Features
47+
48+
- **Parallel execution**: Run tests in parallel with configurable workers (10x+ speedup)
49+
- **Snapshot testing**: Detects API response changes against stored expectations
50+
- **Network flexibility**: Support for different networks via `{{networkId}}` placeholders and `--network-id` parameter
51+
- **Schema validation**: Validates responses against OpenAPI spec (when using uv environment)
52+
- **Two modes**: Basic (Python only) or Full (with uv for schema validation)
53+
- **CLI interface**: Flexible path/pattern matching
54+
- **Detailed error reporting**: Shows actual API error details
55+
- **HTTP status validation**: Robust error detection using status codes
56+
- **File output**: Save results to file with `-o` option
57+
- **Dynamic field handling**: Ignores expected volatile fields (TTL, signatures)
58+
- **Execution timing**: Total test suite execution time tracking
59+
- **CI/CD integration**: Proper exit codes for continuous integration pipelines
60+
61+
## Detailed Usage Examples
62+
63+
### With uv (Full Features)
64+
```bash
65+
# Test all files with schema validation
66+
uv run test_construction_api.py
67+
68+
# Test specific endpoint
69+
uv run test_construction_api.py parse/
70+
71+
# Test with wildcards
72+
uv run test_construction_api.py "parse/native_assets/*.json"
73+
uv run test_construction_api.py "*/withdrawals/*.json"
74+
75+
# Test specific file
76+
uv run test_construction_api.py parse/native_assets/multiple_assets_different_policies.json
77+
78+
# Use specific network (for CI/CD with different networks)
79+
uv run test_construction_api.py --network-id devkit
80+
uv run test_construction_api.py -n preprod
81+
82+
# Run with increased parallelism (20 workers instead of default 10)
83+
uv run test_construction_api.py -j 20
84+
85+
# Run single-threaded (useful for debugging)
86+
uv run test_construction_api.py -j 1
87+
88+
# Output to file
89+
uv run test_construction_api.py -o results.txt
90+
91+
# Custom API URL
92+
uv run test_construction_api.py -u http://localhost:8080
93+
94+
# Verbose output
95+
uv run test_construction_api.py -v # verbose prints schema details per test
96+
97+
# Combine options for CI/CD environment
98+
uv run test_construction_api.py --network-id devkit -v -u http://localhost:8080 -o results.txt -j 15
99+
```
100+
101+
### Without uv (Basic Mode)
102+
```bash
103+
# Same commands work with python3 directly (no schema validation)
104+
python3 test_construction_api.py
105+
python3 test_construction_api.py parse/ -v
106+
python3 test_construction_api.py --network-id devkit # for CI/CD with devkit network
107+
python3 test_construction_api.py --no-schema # explicitly skip schema
108+
python3 test_construction_api.py -j 20 # parallel execution with 20 workers
109+
```
110+
111+
## CLI Options
112+
113+
- `[paths/patterns...]` - Test file paths or patterns (positional, optional)
114+
- `-o <file>` - Output results to file instead of stdout
115+
- `-u <url>` - Rosetta API URL (default: `http://localhost:8082`)
116+
- `-n, --network-id <id>` - Network ID to replace {{networkId}} placeholders (e.g., 'devkit', 'preprod', 'mainnet'). Defaults to 'preprod' when placeholders are found.
117+
- `-v, --verbose` - Show detailed output for each test
118+
- `-j, --workers <n>` - Number of parallel workers for test execution (default: 10)
119+
- `--openapi <path>` - OpenAPI spec file (YAML or JSON). Defaults to `api.yaml` next to the script
120+
- `--no-schema` - Disable schema validation (snapshot-only)
121+
- `--schema-details` - Force schema summary (redundant with `-v`, which enables it)
122+
123+
## Requirements
124+
125+
- Python 3.6+
126+
- Running Rosetta API (configure via `-u` option)
127+
- Test files in JSON format
128+
- For schema validation: `uv` (installs pyyaml & jsonschema automatically)
129+
130+
## Test File Structure
131+
132+
Each test file should contain:
133+
- `request_body`: The API request payload
134+
- Either `expected_response` (success) or `expected_error` (failure)
135+
- Test metadata (name, description)
136+
137+
## Exit Codes
138+
139+
- `0`: All tests passed
140+
- `1`: One or more tests failed or connection error
141+
142+
## What It Validates
143+
144+
The script validates all Rosetta construction flow endpoints:
145+
- `/construction/derive`
146+
- `/construction/preprocess`
147+
- `/construction/metadata`
148+
- `/construction/payloads`
149+
- `/construction/parse`
150+
- `/construction/combine`
151+
- `/construction/hash`
152+
- `/construction/submit`
153+
154+
For each test, it compares the actual API response against the expected response, accounting for dynamic fields like TTL and signatures.
155+
156+
If schema validation is enabled and the OpenAPI spec is available, it also validates the structure of the response (and error responses) against the schema. Schema failures are reported alongside snapshot diffs and will mark the test as failed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"test_name": "combined stake and drep delegation combine",
3+
"description": "Combine test for Payloads for combined stake and drep delegation",
4+
"request_body": {
5+
"network_identifier": {
6+
"blockchain": "cardano",
7+
"network": "{{networkId}}"
8+
},
9+
"unsigned_transaction": "827902006135303064393031303238313832353832303666323766643863636138333561663231663361633337356261633630316639376561643735663265373931343362646637316665326334626530343365386630303031383138323538333930303866303735636264663264316437663334616639613161366232373664383463643762343939633830636166363231376431316336663030336631623261653562343263396466346534613435386262663964623061663766373163343633366264383337623131306261343738303231613030323638336137303231613030303734333139303331613035666363663865303464393031303238323833303238323030353831633366316232616535623432633964663465346134353862626639646230616637663731633436333662643833376231313062613437383032353831633162323638663463626133666161376533366438613063633461646361323039366662383536313139343132656537333330663639326235383330393832303035383163336631623261653562343263396466346534613435386262663964623061663766373163343633366264383337623131306261343738303238323030353831636637323035306161323532636363366266373537343731383439313063306239333836323938313637363536663933356436623663323661a16a6f7065726174696f6e7384a5746f7065726174696f6e5f6964656e746966696572a165696e64657800676163636f756e74a16761646472657373786c616464725f7465737431717a38737768396137746761307536326c78733664766e6b6d707864306479656571783237637368367977783771706c72763477746470766e68367766667a63683075616b7a68683775777976643461736461337a7a61793071707163706c77683066616d6f756e74a26863757272656e6379a26673796d626f6c6341444168646563696d616c73066576616c7565682d333030303030306b636f696e5f6368616e6765a26f636f696e5f6964656e746966696572a16a6964656e7469666965727842366632376664386363613833356166323166336163333735626163363031663937656164373566326537393134336264663731666532633462653034336538663a306b636f696e5f616374696f6e6a636f696e5f7370656e74647479706565696e707574a4746f7065726174696f6e5f6964656e746966696572a165696e64657801676163636f756e74a16761646472657373786c616464725f7465737431717a38737768396137746761307536326c78733664766e6b6d707864306479656571783237637368367977783771706c72763477746470766e68367766667a63683075616b7a68683775777976643461736461337a7a61793071707163706c77683066616d6f756e74a26863757272656e6379a26673796d626f6c6341444168646563696d616c73066576616c756567323532343037316474797065666f7574707574a4746f7065726174696f6e5f6964656e746966696572a165696e64657802676163636f756e74a1676164647265737378407374616b655f746573743175716c336b3268396b736b666d613879353376746837776d70746d6c77387a78783637637837633370776a38737173367a6c307772686d65746164617461a2727374616b696e675f63726564656e7469616ca2696865785f62797465737840666462656538366137303263343964323366343561623830653639376239336563343862373434643566343133656635396333333863336637623264326465386a63757276655f747970656c6564776172647332353531396d706f6f6c5f6b65795f686173687838316232363866346362613366616137653336643861306363346164636132303936666238353631313934313265653733333066363932623564747970656f7374616b6544656c65676174696f6ea4746f7065726174696f6e5f6964656e746966696572a165696e64657803676163636f756e74a1676164647265737378407374616b655f746573743175716c336b3268396b736b666d613879353376746837776d70746d6c77387a78783637637837633370776a38737173367a6c307772686d65746164617461a2727374616b696e675f63726564656e7469616ca2696865785f62797465737840666462656538366137303263343964323366343561623830653639376239336563343862373434643566343133656635396333333863336637623264326465386a63757276655f747970656c6564776172647332353531396464726570a2626964783866373230353061613235326363633662663735373437313834393130633062393338363239383136373635366639333564366236633236616474797065686b65795f6861736864747970657264526570566f746544656c65676174696f6e",
10+
"signatures": [
11+
{
12+
"signing_payload": {
13+
"account_identifier": {
14+
"address": "stake_test1uql3k2h9kskfma8y53vth7wmptmlw8zxx67cx7c3pwj8sqs6zl0wr"
15+
},
16+
"hex_bytes": "b6a2574c3192529f8c7d8f0f7ce671e6b4e05faae144b156f0f2fd9ba85b165f",
17+
"signature_type": "ed25519"
18+
},
19+
"public_key": {
20+
"hex_bytes": "fdbee86a702c49d23f45ab80e697b93ec48b744d5f413ef59c338c3f7b2d2de8",
21+
"curve_type": "edwards25519"
22+
},
23+
"signature_type": "ed25519",
24+
"hex_bytes": "a7c16ed6684938b3865765f269408e250f4fd201c1c6f5564aaedeb26535146504c9c270da7c3042214079fd679496380283864416cc8fe12185c93f65b9977f"
25+
},
26+
{
27+
"signing_payload": {
28+
"account_identifier": {
29+
"address": "addr_test1qz8swh9a7tga0u62lxs6dvnkmpxd0dyeeqx27csh6ywx7qplrv4wtdpvnh6wffzch0uakzhh7uwyvd4asda3zzay0qpqcplwh0"
30+
},
31+
"hex_bytes": "b6a2574c3192529f8c7d8f0f7ce671e6b4e05faae144b156f0f2fd9ba85b165f",
32+
"signature_type": "ed25519"
33+
},
34+
"public_key": {
35+
"hex_bytes": "7a7049b2ce743e11b8b3bfae650530fe54b5154a854f16e9500d2bf850e525eb",
36+
"curve_type": "edwards25519"
37+
},
38+
"signature_type": "ed25519",
39+
"hex_bytes": "c27fcb4e968214d13635fa5b9f96ca8904371cc4668d6990c5502eeb44eb6dec47be8ed603b4b4264dc10fd7e0f254b9cb72c2a2a5d57df2c0bb12c3b2113714"
40+
}
41+
]
42+
},
43+
"expected_response": {
44+
"signed_transaction": "827903a638346135303064393031303238313832353832303666323766643863636138333561663231663361633337356261633630316639376561643735663265373931343362646637316665326334626530343365386630303031383138323538333930303866303735636264663264316437663334616639613161366232373664383463643762343939633830636166363231376431316336663030336631623261653562343263396466346534613435386262663964623061663766373163343633366264383337623131306261343738303231613030323638336137303231613030303734333139303331613035666363663865303464393031303238323833303238323030353831633366316232616535623432633964663465346134353862626639646230616637663731633436333662643833376231313062613437383032353831633162323638663463626133666161376533366438613063633461646361323039366662383536313139343132656537333330663639326235383330393832303035383163336631623261653562343263396466346534613435386262663964623061663766373163343633366264383337623131306261343738303238323030353831636637323035306161323532636363366266373537343731383439313063306239333836323938313637363536663933356436623663323661613130306439303130323832383235383230666462656538366137303263343964323366343561623830653639376239336563343862373434643566343133656635396333333863336637623264326465383538343061376331366564363638343933386233383635373635663236393430386532353066346664323031633163366635353634616165646562323635333531343635303463396332373064613763333034323231343037396664363739343936333830323833383634343136636338666531323138356339336636356239393737663832353832303761373034396232636537343365313162386233626661653635303533306665353462353135346138353466313665393530306432626638353065353235656235383430633237666362346539363832313464313336333566613562396639366361383930343337316363343636386436393930633535303265656234346562366465633437626538656436303362346234323634646331306664376530663235346239636237326332613261356435376466326330626231326333623231313337313466356636a16a6f7065726174696f6e7384a5746f7065726174696f6e5f6964656e746966696572a165696e64657800676163636f756e74a16761646472657373786c616464725f7465737431717a38737768396137746761307536326c78733664766e6b6d707864306479656571783237637368367977783771706c72763477746470766e68367766667a63683075616b7a68683775777976643461736461337a7a61793071707163706c77683066616d6f756e74a26863757272656e6379a26673796d626f6c6341444168646563696d616c73066576616c7565682d333030303030306b636f696e5f6368616e6765a26f636f696e5f6964656e746966696572a16a6964656e7469666965727842366632376664386363613833356166323166336163333735626163363031663937656164373566326537393134336264663731666532633462653034336538663a306b636f696e5f616374696f6e6a636f696e5f7370656e74647479706565696e707574a4746f7065726174696f6e5f6964656e746966696572a165696e64657801676163636f756e74a16761646472657373786c616464725f7465737431717a38737768396137746761307536326c78733664766e6b6d707864306479656571783237637368367977783771706c72763477746470766e68367766667a63683075616b7a68683775777976643461736461337a7a61793071707163706c77683066616d6f756e74a26863757272656e6379a26673796d626f6c6341444168646563696d616c73066576616c756567323532343037316474797065666f7574707574a4746f7065726174696f6e5f6964656e746966696572a165696e64657802676163636f756e74a1676164647265737378407374616b655f746573743175716c336b3268396b736b666d613879353376746837776d70746d6c77387a78783637637837633370776a38737173367a6c307772686d65746164617461a2727374616b696e675f63726564656e7469616ca2696865785f62797465737840666462656538366137303263343964323366343561623830653639376239336563343862373434643566343133656635396333333863336637623264326465386a63757276655f747970656c6564776172647332353531396d706f6f6c5f6b65795f686173687838316232363866346362613366616137653336643861306363346164636132303936666238353631313934313265653733333066363932623564747970656f7374616b6544656c65676174696f6ea4746f7065726174696f6e5f6964656e746966696572a165696e64657803676163636f756e74a1676164647265737378407374616b655f746573743175716c336b3268396b736b666d613879353376746837776d70746d6c77387a78783637637837633370776a38737173367a6c307772686d65746164617461a2727374616b696e675f63726564656e7469616ca2696865785f62797465737840666462656538366137303263343964323366343561623830653639376239336563343862373434643566343133656635396333333863336637623264326465386a63757276655f747970656c6564776172647332353531396464726570a2626964783866373230353061613235326363633662663735373437313834393130633062393338363239383136373635366639333564366236633236616474797065686b65795f6861736864747970657264526570566f746544656c65676174696f6e"
45+
}
46+
}

0 commit comments

Comments
 (0)