From 2b0aa25a5a983392925aaad8d2700d0afc3e431a Mon Sep 17 00:00:00 2001 From: Ty J Everett Date: Thu, 5 Nov 2026 16:32:43 -0800 Subject: [PATCH 1/2] Retain small incoming payments and require affirmative acceptance receipts --- .github/workflows/payment-checks.yml | 46 +++++++++++++++++++ frontend/src/components/PaymentList.tsx | 3 +- frontend/src/utils/paymentCompatibility.ts | 10 ++-- .../utils/paymentCompatibilitySafety.test.ts | 39 ++++++++++++++++ 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/payment-checks.yml create mode 100644 frontend/src/utils/paymentCompatibilitySafety.test.ts diff --git a/.github/workflows/payment-checks.yml b/.github/workflows/payment-checks.yml new file mode 100644 index 0000000..9398135 --- /dev/null +++ b/.github/workflows/payment-checks.yml @@ -0,0 +1,46 @@ +name: Payment source checks +on: + pull_request: + push: + branches: [master] +permissions: + contents: read +jobs: + payments: + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: frontend + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-node@v6 + with: + node-version: '24.22.1' + cache: npm + cache-dependency-path: frontend/package-lock.json + - run: npm ci --ignore-scripts + - run: npx tsc --noEmit + - run: npm test -- --reporter=json --outputFile=payment-test-results.json + - name: Require complete passing source coverage + run: | + node --input-type=module - <<'JS' + import assert from 'node:assert/strict' + import fs from 'node:fs' + const report = JSON.parse(fs.readFileSync('payment-test-results.json', 'utf8')) + assert.equal(report.success, true) + assert.equal(report.numFailedTests, 0) + assert.equal(report.numPendingTests, 0) + assert.equal(report.numTodoTests, 0) + assert(report.numPassedTests >= 28) + const safety = report.testResults.find(result => result.name.endsWith('/paymentCompatibilitySafety.test.ts')) + assert(safety && safety.assertionResults.length === 9) + assert(safety.assertionResults.every(result => result.status === 'passed')) + JS + - run: npm run build + - uses: actions/upload-artifact@v6 + if: always() + with: + name: payment-source-results + path: frontend/payment-test-results.json + if-no-files-found: warn diff --git a/frontend/src/components/PaymentList.tsx b/frontend/src/components/PaymentList.tsx index 2d827c5..51ed09f 100644 --- a/frontend/src/components/PaymentList.tsx +++ b/frontend/src/components/PaymentList.tsx @@ -162,6 +162,7 @@ const PaymentList: React.FC = ({ payments = [], onUpdatePaymen + {payment.token.amount < 2000 && Too small to return after the fee. Accept it to keep the funds.} = ({ payments = [], onUpdatePaymen color='secondary' variant='outlined' size='small' - disabled={isBulkAccepting || !!processingMap[payment.messageId]} + disabled={isBulkAccepting || !!processingMap[payment.messageId] || !Number.isSafeInteger(payment.token.amount) || payment.token.amount < 2000} > {processingMap[payment.messageId] === 'reject' ? ( <> diff --git a/frontend/src/utils/paymentCompatibility.ts b/frontend/src/utils/paymentCompatibility.ts index c2a7daf..11f5ebe 100644 --- a/frontend/src/utils/paymentCompatibility.ts +++ b/frontend/src/utils/paymentCompatibility.ts @@ -23,7 +23,8 @@ export function prepareIncomingPayment(payment: IncomingPayment): { } function assertPaymentAccepted(result: unknown): void { - if (typeof result === 'string' || result == null || typeof result !== 'object') { + if (typeof result === 'string' || result == null || typeof result !== 'object' || + (result as { paymentResult?: { accepted?: unknown } }).paymentResult?.accepted !== true) { throw new Error(typeof result === 'string' ? result : 'The wallet did not confirm the payment.') } } @@ -40,12 +41,13 @@ export async function rejectIncomingPayment(payment: IncomingPayment): Promise

({ acceptPayment: vi.fn(), rejectPayment: vi.fn(), sendPayment: vi.fn() })) +vi.mock('./peerPayClient', () => ({ peerPayClient: client })) +import { acceptIncomingPayment, rejectIncomingPayment } from './paymentCompatibility' + +// Unfunded bytes are used only by the format parser. No wallet or service runs. +const transaction = new Transaction() +transaction.addOutput({ satoshis: 1000, lockingScript: LockingScript.fromHex('51') }) +const incoming = (amount = 1000) => ({ + messageId: 'lab-fixture', sender: '02' + '11'.repeat(32), + token: { amount, transaction: transaction.toAtomicBEEF(), customInstructions: { derivationPrefix: 'AQ==', derivationSuffix: 'Ag==' } } +}) +beforeEach(() => vi.resetAllMocks()) +describe('retaining funds when accepting or returning a payment is unsafe', () => { + it.each([1000, 1999])('keeps a %i-satoshi payment queued instead of acknowledging without a credit or refund', async amount => { + await expect(rejectIncomingPayment(incoming(amount))).rejects.toThrow('too small to return') + expect(client.rejectPayment).not.toHaveBeenCalled() + expect(client.acceptPayment).not.toHaveBeenCalled() + expect(client.sendPayment).not.toHaveBeenCalled() + }) + it.each([undefined, 'failed', {}, { paymentResult: {} }, { paymentResult: { accepted: false } }])('requires an affirmative wallet receipt before removing an incoming row: %j', async result => { + client.acceptPayment.mockResolvedValue(result) + await expect(acceptIncomingPayment(incoming())).rejects.toThrow() + }) + it('retains legacy BEEF compatibility when the wallet confirms acceptance', async () => { + client.acceptPayment.mockResolvedValue({ paymentResult: { accepted: true } }) + const payment = incoming() + payment.token.transaction = transaction.toBEEF() + await expect(acceptIncomingPayment(payment)).resolves.toBe('legacy-converted') + expect(Transaction.fromAtomicBEEF(client.acceptPayment.mock.calls[0][0].token.transaction).id('hex')).toBe(transaction.id('hex')) + }) + it('does not fund a return from unrelated balance after a negative acceptance receipt', async () => { + client.acceptPayment.mockResolvedValue({ paymentResult: { accepted: false } }) + await expect(rejectIncomingPayment(incoming(5000))).rejects.toThrow() + expect(client.sendPayment).not.toHaveBeenCalled() + expect(client.rejectPayment).not.toHaveBeenCalled() + }) +}) From cd4bc98066cad5e9ec482ecce511ebe5620c3e4c Mon Sep 17 00:00:00 2001 From: Ty J Everett Date: Thu, 5 Nov 2026 16:35:51 -0800 Subject: [PATCH 2/2] Reuse existing PeerPay verification for complete payment regression reports --- .github/workflows/deploy.yaml | 24 ++++++++++++++- .github/workflows/payment-checks.yml | 46 ---------------------------- 2 files changed, 23 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/payment-checks.yml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 8783c1e..957d04b 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -31,7 +31,22 @@ jobs: cache: npm cache-dependency-path: frontend/package-lock.json - run: npm ci - - run: npm test + - run: npm test -- --reporter=json --outputFile=payment-test-results.json + - name: Require complete passing payment source coverage + run: | + node --input-type=module - <<'JS' + import assert from 'node:assert/strict' + import fs from 'node:fs' + const report = JSON.parse(fs.readFileSync('payment-test-results.json', 'utf8')) + assert.equal(report.success, true) + assert.equal(report.numFailedTests, 0) + assert.equal(report.numPendingTests, 0) + assert.equal(report.numTodoTests, 0) + assert(report.numPassedTests >= 28) + const safety = report.testResults.find(result => result.name.endsWith('/paymentCompatibilitySafety.test.ts')) + assert(safety && safety.assertionResults.length === 9) + assert(safety.assertionResults.every(result => result.status === 'passed')) + JS - run: npx tsc --noEmit - run: npm run build - name: Bound startup JavaScript @@ -44,6 +59,13 @@ jobs: } JS + - uses: actions/upload-artifact@v6 + if: always() + with: + name: payment-source-results + path: frontend/payment-test-results.json + if-no-files-found: warn + deploy: name: Verify and deploy if: github.event_name != 'pull_request' diff --git a/.github/workflows/payment-checks.yml b/.github/workflows/payment-checks.yml deleted file mode 100644 index 9398135..0000000 --- a/.github/workflows/payment-checks.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Payment source checks -on: - pull_request: - push: - branches: [master] -permissions: - contents: read -jobs: - payments: - runs-on: ubuntu-latest - timeout-minutes: 10 - defaults: - run: - working-directory: frontend - steps: - - uses: actions/checkout@v6 - - uses: actions/setup-node@v6 - with: - node-version: '24.22.1' - cache: npm - cache-dependency-path: frontend/package-lock.json - - run: npm ci --ignore-scripts - - run: npx tsc --noEmit - - run: npm test -- --reporter=json --outputFile=payment-test-results.json - - name: Require complete passing source coverage - run: | - node --input-type=module - <<'JS' - import assert from 'node:assert/strict' - import fs from 'node:fs' - const report = JSON.parse(fs.readFileSync('payment-test-results.json', 'utf8')) - assert.equal(report.success, true) - assert.equal(report.numFailedTests, 0) - assert.equal(report.numPendingTests, 0) - assert.equal(report.numTodoTests, 0) - assert(report.numPassedTests >= 28) - const safety = report.testResults.find(result => result.name.endsWith('/paymentCompatibilitySafety.test.ts')) - assert(safety && safety.assertionResults.length === 9) - assert(safety.assertionResults.every(result => result.status === 'passed')) - JS - - run: npm run build - - uses: actions/upload-artifact@v6 - if: always() - with: - name: payment-source-results - path: frontend/payment-test-results.json - if-no-files-found: warn