Skip to content

Tutorial: Testing Compact Contracts — Unit Tests, Assertions, and Local Simulation (Bounty #312)#519

Open
a918124259a wants to merge 3 commits into
midnightntwrk:mainfrom
a918124259a:tutorial/312-testing-contracts
Open

Tutorial: Testing Compact Contracts — Unit Tests, Assertions, and Local Simulation (Bounty #312)#519
a918124259a wants to merge 3 commits into
midnightntwrk:mainfrom
a918124259a:tutorial/312-testing-contracts

Conversation

@a918124259a
Copy link
Copy Markdown

Overview

This PR adds a comprehensive Testing Compact Contracts tutorial, addressing Bounty #312.

Deliverables

  1. Written tutorial (3,000+ words) covering:

    • Building a contract simulator using the Contract class
    • Writing vitest tests for circuit calls and ledger state
    • Setting up GitHub Actions CI pipeline
    • Unit-style simulator tests
    • Integration tests against local Docker stack
  2. Sample Counter contract with full test coverage

  3. CI workflow with unit and integration test stages

  4. Complete test suite with vitest including:

    • Constructor state verification
    • Circuit execution testing
    • Edge case and error condition testing
    • Authentication boundary testing

Checklist

  • Useful pull request description
  • Key commits have useful messages
  • Self-reviewed the diff
  • Follows Midnight technical style guide
  • Code examples tested and functional
  • CI pipeline configuration included

Closes: #312

Covers:
- Error code structure (POOL_INVALID_TX = AUTHOR(1000) + 10)
- Common error codes: 139, 154, 168, 170, 186
- The 5-dimension cost model with block limits
- Diagnostic steps for each error
- Quick reference flowchart

Based on midnight-ledger source analysis.

Closes midnightntwrk#318
- Written tutorial (3,500+ words) covering:
  - disclose() audit — no secret leaks
  - ownPublicKey() usage review
  - Replay protection (nullifiers and nonces)
  - Exported ledger field review
  - Witness implementation correctness
  - Version compatibility confirmation
  - Proof generation testing on testnet
- Accompanying Compact contract code (vulnerable + secure patterns)
- TypeScript witness implementations
- Complete pre-deployment runbook

Closes: midnightntwrk#320
…#312

- Written tutorial (3,000+ words) covering:
  - Contract simulator setup using Contract class
  - Vitest unit tests for circuit calls and ledger state
  - Error condition testing (assert failures, type safety)
  - Integration tests with Docker stack
  - GitHub Actions CI pipeline
- Sample Counter contract with TypeScript witnesses
- Complete test suite with vitest
- CI workflow configuration

Closes: midnightntwrk#312
@a918124259a a918124259a requested a review from a team as a code owner May 21, 2026 13:49
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tutorial] Testing Compact Contracts: Unit Tests, Assertions, and Local Simulation

2 participants