Skip to content

Latest commit

 

History

History
60 lines (38 loc) · 5.98 KB

debugging.md

File metadata and controls

60 lines (38 loc) · 5.98 KB

Debugging tests

Run the project's tests under a real debugger: breakpoints in your own .ts files, stepping, call stack, variables and watches. It works like Eclipse's "Debug As → JUnit Test" and is built on vitest and the Node inspector.

Use it

  1. Open a test file (for example test/payment.test.ts) and click the gutter next to a line number, or press F9 on the line. A red dot marks the breakpoint. Right-click → Toggle breakpoint works too.
  2. Press F5 (or Run → Debug tests in this file, or right-click the file in the Explorer → Debug tests in this file, or the Debug buttons in the Tests view; Debug this test runs only the selected test).
  3. When the run reaches a breakpoint the editor opens at that line (yellow arrow and highlighted line) and the Tests view shows the state: the debugger lives inside it, next to the results, so there is one place for running, debugging and reading results.
Key Action
F5 Start (on a test file) / Continue
F10 Step over
F11 Step into
Shift+F11 Step out
Shift+F5 Stop
F9 Toggle breakpoint on the cursor line

While a session is open the Tests view shows the controls (continue, step over / into / out, restart, stop), the call stack (click a frame to jump to it), the variables of the selected frame (click the arrows to expand objects) and watch expressions (re-evaluated at every stop). Always available there: the list of breakpoints, an option to pause when an exception is thrown (only for code in your project, not the libraries' own caught errors), and the test output. Every test and file row has a bug button to debug just that one.

Good to know

  • Breakpoints are remembered per project and follow their lines while you edit. A breakpoint on a line without code moves to the next line that has code; the Tests view lists where it really stops.
  • Test and hook timeouts are switched off while debugging, otherwise a test paused for a few seconds would fail with "Test timed out".
  • Stepping skips library code (node_modules and Node internals).
  • The Tests view is a normal dockable view: left by default so the editor stays next to it; its dock controls can move it to the right or open it as a wide tab, and Reset panel layout puts it back.

How it works

packages/ide-server/src/debug.ts starts vitest run --inspect-brk (single worker, no file parallelism) and attaches to the worker over the Chrome DevTools Protocol. Vitest runs transformed code, so every script's inline source map is read and breakpoints and stack frames are translated between your original file and the code V8 runs. Breakpoints are placed just before each script runs (instrumentation breakpoint), so even top-level code is stopped on. The IDE talks to it through /api/debug/events (server-sent events) and /api/debug/command.

Needs vitest installed in the project (the HardKas templates ship it), the project's own Node dependencies (npm install) and a trusted folder: the debugger runs the project's tests, so in restricted mode it does not start (UNTRUSTED_WORKSPACE).

This part debugs the project's TypeScript tests. SilverScript contracts have their own debugger, below.

Debugging SilverScript contracts

Run one entry of a .sil contract on the Kaspa script engine, line by line: current line in the editor, constructor arguments, call arguments, locals, the script stack, and expressions you evaluate.

Use it

  1. Open the contract and the SilverScript compiler view. Fill the constructor arguments box ([{"kind":"pubkey","value":"0x…"},{"kind":"int","value":1000}]). Show the dev accounts' public keys lists the simnet dev accounts' keys to paste into pubkey arguments. Left empty, a contract whose constructor parameters are all pubkey is compiled with the dev accounts' keys (the first parameter alice's, the second bob's, as Deploy & Run proposes); the values are written to <name>.constructor-args.json next to the contract and the Console says which were used. Any other parameter type has no default: the compile stops and says which values are missing.
  2. In SilverScript debugger, pick the entry and fill its arguments. A sig argument is signed by a simnet dev account you choose.
  3. Click the gutter of the .sil file to set breakpoints (the same red dots as for tests), then Debug. It stops on the first line.
  4. Use Continue (to the next breakpoint), Over, Into, Out, Opcode (one script opcode) and Stop. Eval evaluates an expression with the current values (currentBalance - withdrawSompi).

It ends either with The entry ran to the end: every require passed, or Rejected at line N on the require that failed, with the values at that point.

What it checks, and what it does not

It runs the contract's logic on a test transaction: one input locked to this contract (5000 sompi) and one output back to it, unless the contract says otherwise. That shows whether your requires accept these arguments. It does not show that a node would accept a real spend (fees, mass, real UTXOs): for that, deploy and spend on the local node from Deploy & Run.

The runner

The engine is cli-debugger from kaspanet/silverscript v1.0.0. Upstream publishes no binary, so build it yourself (cargo build --release -p cli-debugger) and put it at ~/.hardkas/toolchains/cli-debugger/1.0.0/, or set HARDKAS_SILVER_RUNNER to it. HardKas cannot verify a local build, so the IDE runs it only after you approve that exact file (its SHA-256 is kept in ~/.hardkas-ide/settings.json); a different binary asks again.

Signatures are made by the project's own @hardkas/core, as hardkas silver test makes them, and only with simnet dev accounts. The project needs its Node dependencies (npm install) and a trusted folder.

packages/ide-server/src/silverDebug.ts drives the runner's interactive prompt; the IDE talks to it through /api/silver-debug/*. Breakpoints added during a session reach the runner; removing one takes effect on the next session (the runner cannot remove breakpoints).