Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/tempo/server/Session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,32 @@ describe.runIf(isLocalnet)('session', () => {
).rejects.toThrow('close voucher amount must be >')
})

test('allows zero close for an untouched channel', async () => {
const { channelId, serializedTransaction } = await createSignedOpenTransaction(10000000n)
const server = createServer()

await openServerChannel(server, channelId, serializedTransaction)

const receipt = await server.verify({
credential: {
challenge: makeChallenge({ id: 'challenge-zero-close', channelId }),
payload: {
action: 'close' as const,
channelId,
cumulativeAmount: '0',
signature: await signTestVoucher(channelId, 0n),
},
},
request: makeRequest(),
})

expect(receipt.status).toBe('success')

const ch = await store.getChannel(channelId)
expect(ch).not.toBeNull()
expect(ch!.finalized).toBe(true)
})

test('rejects close exceeding on-chain deposit', async () => {
const { channelId, serializedTransaction } = await createSignedOpenTransaction(10000000n)
const server = createServer()
Expand Down
4 changes: 3 additions & 1 deletion src/tempo/server/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,9 @@ async function handleClose(
reason: `close voucher amount must be >= ${channel.spent} (spent)`,
})
}
if (voucher.cumulativeAmount <= onChain.settled) {
const isUntouchedZeroClose =
voucher.cumulativeAmount === 0n && channel.spent === 0n && onChain.settled === 0n
if (!isUntouchedZeroClose && voucher.cumulativeAmount <= onChain.settled) {
throw new VerificationFailedError({
reason: `close voucher amount must be > ${onChain.settled} (on-chain settled)`,
})
Expand Down