-
Notifications
You must be signed in to change notification settings - Fork 19
test: add Cashu Fault Lab mint recovery lane #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Egge21M
wants to merge
3
commits into
master
Choose a base branch
from
agent/cashu-fault-lab-mint-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| name: cashu-fault-lab | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| paths: | ||
| - 'test/fault-lab/**' | ||
| - '.github/workflows/cashu-fault-lab.yml' | ||
|
|
||
| jobs: | ||
| mint-response-lost: | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 20 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v5 | ||
|
|
||
| - name: Setup Bun | ||
| uses: oven-sh/setup-bun@v2 | ||
| with: | ||
| bun-version: 1.3.11 | ||
|
|
||
| - name: Setup Node.js for Cashu Fault Lab | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 24 | ||
|
|
||
| - name: Install dependencies | ||
| run: bun install --frozen-lockfile | ||
|
|
||
| - name: Test lifecycle adapter contract | ||
| run: bun run test:fault-lab:adapter | ||
|
|
||
| - name: Run mint response-loss scenario | ||
| run: bun run test:fault-lab:mint-response-lost | ||
| env: | ||
| COCO_FAULT_LAB_REPORT: artifacts/fault-lab/mint-response-lost.json | ||
|
|
||
| - name: Upload redacted Fault Lab report | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: cashu-fault-lab-mint-response-lost | ||
| path: artifacts/fault-lab/mint-response-lost.json | ||
| if-no-files-found: ignore | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Cashu Fault Lab integration | ||
|
|
||
| This optional integration runs Coco against the experimental | ||
| [`cashu-fault-lab`](https://github.com/GautamBytes/cashu-fault-lab) wallet lifecycle suite. It is | ||
| test tooling, not a runtime dependency or release certification gate. | ||
|
|
||
| The first lane covers `mint-response-lost`: mintd commits a NUT-04 issuance, the official Fault Lab | ||
| gateway drops that response, and Coco must converge on one successful operation with the original | ||
| output plan and a 64 sat wallet credit. | ||
|
|
||
| ## Run | ||
|
|
||
| Prerequisites: | ||
|
|
||
| - Bun and the repository dependencies (`bun install --frozen-lockfile`) | ||
| - Node.js 24 (required by `cashu-fault-lab@0.2.0`) | ||
| - Docker with Compose | ||
|
|
||
| ```bash | ||
| bun run test:fault-lab:mint-response-lost | ||
| ``` | ||
|
|
||
| The script starts pinned mintd and Fault Lab containers, launches the test-only Coco lifecycle | ||
| adapter on `127.0.0.1:4103`, runs the published Fault Lab CLI, and removes its containers and | ||
| temporary SQLite database afterward. Set `COCO_FAULT_LAB_REPORT` to retain the redacted JSON report: | ||
|
|
||
| ```bash | ||
| COCO_FAULT_LAB_REPORT=artifacts/fault-lab/mint-response-lost.json \ | ||
| bun run test:fault-lab:mint-response-lost | ||
| ``` | ||
|
|
||
| The adapter currently advertises only `mint` and process durability. Restart scenarios require a | ||
| generic external-adapter restart hook in Fault Lab or a Coco-specific driver. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { afterEach, describe, expect, it } from 'bun:test'; | ||
| import { mkdtemp, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { startCocoLifecycleAdapter, type RunningCocoLifecycleAdapter } from './adapter.ts'; | ||
|
|
||
| const CONTROL_TOKEN = 'coco-fault-lab-test-token'; | ||
| const MINT_URL = 'http://127.0.0.1:4300'; | ||
|
|
||
| describe('Coco Fault Lab lifecycle HTTP adapter', () => { | ||
| let adapter: RunningCocoLifecycleAdapter | undefined; | ||
| let temporaryDirectory: string | undefined; | ||
|
|
||
| afterEach(async () => { | ||
| await adapter?.stop(); | ||
| if (temporaryDirectory !== undefined) { | ||
| await rm(temporaryDirectory, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| it('exposes an authenticated, resettable mint lifecycle wallet', async () => { | ||
| temporaryDirectory = await mkdtemp(join(tmpdir(), 'coco-fault-lab-')); | ||
| adapter = await startCocoLifecycleAdapter({ | ||
| controlToken: CONTROL_TOKEN, | ||
| databasePath: join(temporaryDirectory, 'coco.sqlite'), | ||
| host: '127.0.0.1', | ||
| mintId: 'mintd-local', | ||
| mintUrl: MINT_URL, | ||
| port: 0, | ||
| unit: 'sat', | ||
| }); | ||
|
|
||
| const capabilities = await request(adapter.url, '/v1/lifecycle/capabilities'); | ||
| expect(capabilities).toMatchObject({ | ||
| schemaVersion: 1, | ||
| implementation: { id: 'coco', language: 'typescript' }, | ||
| operations: ['mint'], | ||
| durability: 'process', | ||
| recovery: ['quote_state', 'nut09_restore'], | ||
| mints: [{ id: 'mintd-local', implementation: 'mintd' }], | ||
| }); | ||
|
|
||
| expect( | ||
| await request(adapter.url, '/v1/lifecycle/reset', { | ||
| method: 'POST', | ||
| body: JSON.stringify({ seed: 'wallet-lifecycle-v1:mint-response-lost' }), | ||
| }), | ||
| ).toEqual({ ok: true }); | ||
|
|
||
| expect(await request(adapter.url, '/v1/lifecycle/wallet')).toEqual({ | ||
| walletId: 'coco', | ||
| mint: MINT_URL, | ||
| unit: 'sat', | ||
| balances: { available: 0, reserved: 0, recoverable: 0 }, | ||
| proofs: [], | ||
| }); | ||
| }); | ||
|
|
||
| it('rejects lifecycle requests without the control token', async () => { | ||
| temporaryDirectory = await mkdtemp(join(tmpdir(), 'coco-fault-lab-')); | ||
| adapter = await startCocoLifecycleAdapter({ | ||
| controlToken: CONTROL_TOKEN, | ||
| databasePath: join(temporaryDirectory, 'coco.sqlite'), | ||
| host: '127.0.0.1', | ||
| mintId: 'mintd-local', | ||
| mintUrl: MINT_URL, | ||
| port: 0, | ||
| unit: 'sat', | ||
| }); | ||
|
|
||
| const response = await fetch(`${adapter.url}/v1/lifecycle/capabilities`); | ||
|
|
||
| expect(response.status).toBe(401); | ||
| expect(await response.json()).toEqual({ | ||
| code: 'UNAUTHORIZED', | ||
| message: 'A valid adapter control token is required', | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| async function request(origin: string, path: string, init: RequestInit = {}): Promise<unknown> { | ||
| const headers = new Headers(init.headers); | ||
| headers.set('authorization', `Bearer ${CONTROL_TOKEN}`); | ||
| if (init.body !== undefined) headers.set('content-type', 'application/json'); | ||
| const response = await fetch(`${origin}${path}`, { ...init, headers }); | ||
| expect(response.status).toBe(200); | ||
| return response.json(); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For pull requests that modify only
packages/core/**, includingMintOperationServiceor the NUT-09 recovery handlers this scenario is intended to validate, this workflow is skipped because its path filter includes only the Fault Lab files and its own YAML. Consequently, the external response-loss regression test does not protect the production recovery changes it targets; include the relevant core and storage package paths in this trigger.Useful? React with 👍 / 👎.