Skip to content
Merged
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
18 changes: 18 additions & 0 deletions app/stream/[id]/__tests__/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,24 @@ describe('StreamPage (app/stream/[id]/page.tsx)', () => {
expect(container.textContent).toContain('Stream not found.');
});

it('surfaces the underlying error instead of "Stream not found" when the address lookup fails', async () => {
mockUseWallet.mockReturnValue({
publicKey: 'GWALLET',
connected: true,
} as unknown as ReturnType<typeof useWallet>);
mockAddr.mockRejectedValue(new Error('rpc down'));

await act(async () => {
root.render(React.createElement(StreamPage));
await Promise.resolve();
await Promise.resolve();
await Promise.resolve();
});

expect(container.textContent).toContain('rpc down');
expect(container.textContent).not.toContain('Stream not found');
});

it('derives isSender/isRecipient correctly and renders StreamActions once loaded', async () => {
mockUseWallet.mockReturnValue({
publicKey: 'GSENDER',
Expand Down
4 changes: 2 additions & 2 deletions lib/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ describe('getStreamAddress', () => {
expect(await getStreamAddress(SENDER, 999n)).toBeNull();
});

it('returns null (not throw) when the underlying call rejects', async () => {
it('lets failures propagate so callers can tell "not found" from "RPC down"', async () => {
mockSimulateReadOnly.mockRejectedValue(new Error('rpc down'));
const { getStreamAddress } = await import('./stream.js');
expect(await getStreamAddress(SENDER, 1n)).toBeNull();
await expect(getStreamAddress(SENDER, 1n)).rejects.toThrow('rpc down');
});
});

Expand Down
26 changes: 13 additions & 13 deletions lib/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ export async function getStreamAddress(
options?: { signal?: AbortSignal },
): Promise<string | null> {
if (isMock()) return MOCK_ADDRESSES[streamId.toString()] ?? null;
try {
const result = await simulateReadOnly(
source,
FACTORY()!,
'stream_address',
[nativeToScVal(streamId, { type: 'u64' })],
options,
);
if (result.switch().name === 'scvVoid') return null;
return Address.fromScVal(result).toString();
} catch {
return null;
}
const result = await simulateReadOnly(
source,
FACTORY()!,
'stream_address',
[nativeToScVal(streamId, { type: 'u64' })],
options,
);
// scvVoid is DripFactory::stream_address returning Option::None — the only
// case that means "this stream ID does not exist". RPC/network failures and
// a misconfigured factory env var must propagate so callers don't mistake
// an outage for a missing stream.
if (result.switch().name === 'scvVoid') return null;
return Address.fromScVal(result).toString();
}

/**
Expand Down