Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions __tests__/priceStore.cadence.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { SelectServerEnum } from '../app/AppState';
import { getZecPrice } from '../app/walletBackend';
import { mockInfo } from '../__mocks__/dataMocks/mockInfo';
import { INITIAL_MIXNET_VIEW } from '../app/walletBackend/transforms/mixnetView';

const price = getZecPrice as jest.MockedFunction<typeof getZecPrice>;

Expand Down Expand Up @@ -92,11 +93,21 @@ test('turning Nym on mid-session fetches at once', async () => {
price.mockResolvedValue({ price: 42, error: '' });
const setZecPrice = jest.fn();

const view = render(driverUi(makeCtx({ nym: false }), setZecPrice));
const view = render(
driverUi(
makeCtx({ nym: false, mixnetView: INITIAL_MIXNET_VIEW }),
setZecPrice,
),
);
await jest.advanceTimersByTimeAsync(10_000);
expect(price).not.toHaveBeenCalled();

view.rerender(driverUi(makeCtx({ nym: true }), setZecPrice));
view.rerender(
driverUi(
makeCtx({ nym: true, mixnetView: INITIAL_MIXNET_VIEW }),
setZecPrice,
),
);
await jest.advanceTimersByTimeAsync(0);
expect(price).toHaveBeenCalledTimes(1);
});
Expand Down
7 changes: 4 additions & 3 deletions __tests__/priceStore.lifecycle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,15 @@ test('rapid app hops inside the cooldown do not multiply fetches', async () => {
expect(price).toHaveBeenCalledTimes(1);
});

test('without the Nym selection no price traffic exists', async () => {
test('Nym off while the route still serves stays off clearnet', async () => {
jest.useFakeTimers();
price.mockResolvedValue({ price: 42, error: '' });
const setZecPrice = jest.fn();
seedDeps(setZecPrice);

// USD may even be the seeded default; the currency authorizes nothing.
render(fetcherUi(makeCtx({ nym: false }), setZecPrice));
render(
fetcherUi(makeCtx({ nym: false, mixnetView: READY_VIEW }), setZecPrice),
);
await jest.advanceTimersByTimeAsync(61_000);
fireAppState('background');
fireAppState('active');
Expand Down
31 changes: 30 additions & 1 deletion __tests__/priceStore.trafficGuards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ const DIED_VIEW: MixnetView = {
reconnecting: false,
};

const UNKNOWN_VIEW: MixnetView = {
statusKey: 'mixnet.status.unknown',
socks5Addr: null,
narration: null,
sendBlocked: true,
recovery: 'reenable',
reconnecting: false,
};

const price = getZecPrice as jest.MockedFunction<typeof getZecPrice>;

type Ctx = typeof defaultAppContextLoaded;
Expand Down Expand Up @@ -144,7 +153,12 @@ test('a withdrawn opt-in stops the mid-flight retry', async () => {
const view = render(surfaceUi(makeCtx(), setZecPrice));
await waitFor(() => expect(price).toHaveBeenCalledTimes(1));

view.rerender(surfaceUi(makeCtx({ nym: false }), setZecPrice)); // Nym off
view.rerender(
surfaceUi(
makeCtx({ nym: false, mixnetView: INITIAL_MIXNET_VIEW }),
setZecPrice,
),
);
land({ price: -1, error: 'refused' });
await flush();

Expand Down Expand Up @@ -204,6 +218,21 @@ test('a switch-off fetches the price over clearnet', async () => {
);
});

test('a switch-off whose disable rejected still fetches over clearnet', async () => {
price.mockResolvedValue({ price: 42, error: '' });
const setZecPrice = jest.fn();

render(
surfaceUi(
makeCtx({ nym: false, mixnetView: UNKNOWN_VIEW }),
setZecPrice,
),
);
await waitFor(() =>
expect(setZecPrice).toHaveBeenCalledWith(42, expect.any(Number)),
);
});

test('opting in with the transport still off emits no clearnet fetch', async () => {
price.mockResolvedValue({ price: 42, error: '' });
const setZecPrice = jest.fn();
Expand Down
10 changes: 6 additions & 4 deletions components/Components/priceFetcherStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,13 @@ function surfaceMayFetch(): boolean {
}

function priceTrafficConsented(): boolean {
if (deps === undefined) return false;
if (deps.nymSelected) {
return deps.mixnetStatusKey !== 'mixnet.status.off';
}
return (
deps !== undefined &&
(deps.nymSelected
? deps.mixnetStatusKey !== 'mixnet.status.off'
: deps.mixnetStatusKey === 'mixnet.status.off')
deps.mixnetStatusKey !== 'mixnet.status.ready' &&
Comment thread
dorianvp marked this conversation as resolved.
Outdated
deps.mixnetStatusKey !== 'mixnet.status.bootstrapping'
);
}

Expand Down
Loading