[Feature] machine-readable input/output mode
As a first step towards allowing Clarinet to be integrated in different tools (like a VSCode extension), we should have the ability for Clarinet to switch to a machine-readable input/output mode. Open to suggestions, but it could be as simple as just using JSON.
Additionally, if Clarinet were to be able to emit the result of every call to mineBlock as it happens, then an extension could use that for indexing and display.
Example: the VSCode extension could invoke clarinet test in JSON I/O mode and have:
- A pane that displays the blocks (and maybe transactions).
- A pane that displays the assets as they change over time.
- A pane that show the tests with pass/fail, including any events.
Tons of possibilities...
Normal I/O mode stdout:
running 4 tests
test Ensure that thing A <...> ... ok (154ms)
test Ensure that thing B <...> ... ok (154ms)
test Ensure that thing C <...> ... ok (154ms)
test Ensure that thing D ... FAILED (151ms)
failures:
test Ensure that thing D
Error: Expected false, got true
JSON I/O mode stdout (empty newlines for readability):
{"event": "test-start", "testCount": 4}
{"event": "new-block", "height": 1, "receipts": [ { "result": "(ok true)", "events": [] } ] }
{"event": "test-result", "test": "Ensure that thing A", "file": "my-contract.clar", "pass": true, "ms": 154}
{"event": "new-block", "height": 2, "receipts": [ { "result": "(ok true)", "events": [] } ] }
{"event": "test-result", "test": "Ensure that thing B", "file": "my-contract.clar", "pass": true, "ms": 154}
{"event": "new-block", "height": 3, "receipts": [ { "result": "(ok true)", "events":[{"type":"stx_transfer_event","stx_transfer_event":{"sender":"ST123","recipient":"ST345","amount":"10"}}]}]}
{"event": "test-result", "test": "Ensure that thing C", "file": "my-contract.clar", "pass": true, "ms": 154}
{"event": "new-block", "height": 4, "receipts": [ { "result": "(ok true)", "events": [] } ] }
{"event": "test-result", "test": "Ensure that thing D", "file": "my-contract.clar", "pass": false, "ms": 151, "expected": "u100", "got": "u200", "stackTrace": "..."}
The same would go for clarinet console. Useful if we want to add the ability for interactive programming in the VSCode extension. (::get_assets_maps gives back JSON instead of an ASCII table.)
Normal:
>> (contract-call? .my-contract something u100)
(ok true)
>> ::get_assets_maps
+------------------------------------------------------+---------+
| Address | STX |
+------------------------------------------------------+---------+
| ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE (deployer) | 1000000 |
+------------------------------------------------------+---------+
| ST1J4G6RR643BCG8G8SR6M2D9Z9KXT2NJDRK3FBTK (wallet_1) | 1000000 |
JSON:
>> {"clar": "(contract-call? .my-contract something u100)", "id": 50}
{"event": "clar-result", "result": "(ok true)", "id": 50}
>> {"cmd": "get_assets_map", "id": 51}
{"event": "cmd-result", "result": [{ "address": "ST1HT...", "name": "deployer", "stx": 1000000 }, { "address": "ST1HT...", "name": "wallet_1", "stx": 1000000 }], "id": 51}
Thoughts? Open to suggestions and comments. I can probably also take (part of) this on myself once/if we decide on a format.
I understand that the Foundation will be working on this issue, so assigning it to you @MarvinJanssen. Thanks!
Thanks @lgalabru!
Now that we have a solid way architecture for building components via WASM (ie. latest clarity VSCode 1.0), I'll close this issue.