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
14 changes: 14 additions & 0 deletions backend/src/controllers/stream.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,20 @@ export const topUpStreamHandler = async (req: Request, res: Response) => {
return res.status(403).json({ error: 'Only the stream sender may top up this stream' });
}

if (stream.isPaused) {
return res.status(409).json({
error: 'Conflict',
message: 'Cannot top up a paused stream',
});
}

if (!stream.isActive) {
return res.status(409).json({
error: 'Conflict',
message: 'Cannot top up an inactive stream',
});
}

const txHash = await topUpStream(streamId, amount, callerAddress);

const newDeposited = (BigInt(stream.depositedAmount) + amount).toString();
Expand Down
16 changes: 16 additions & 0 deletions backend/tests/integration/top-up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ describe('POST /v1/streams/:streamId/top-up', () => {
expect(res.status).toBe(403);
});

it('returns 409 when stream is inactive', async () => {
vi.mocked(mockPrisma.stream.findUnique).mockResolvedValue({
...mockStream,
isActive: false,
isPaused: false,
} as any);

const res = await request(app)
.post('/v1/streams/42/top-up')
.set('Authorization', 'Bearer dummy')
.send({ amount: '1000' });

expect(res.status).toBe(409);
expect(topUpStream).not.toHaveBeenCalled();
});

it('updates depositedAmount in DB on success', async () => {
await request(app)
.post('/v1/streams/42/top-up')
Expand Down
Loading
Loading