Files
nym/nym-wallet/src/context/delegationQuery.test.ts
T
Tommy Verrall 959a986e2c PR review comments
- Add `historical_node_identity` to `DelegationWithEverything` and populate via `lookup_historical_node_identity` in `delegate.rs` so search works after unbond.
- `searchDelegations` searches `historical_node_identity` and guards null/empty `node_identity` with optional chaining.
- Acceptance tests: historical identity search, bonded-unbonding vs synthetic branch semantics, empty-identity search safety.
- Fix linting
2026-06-08 12:23:00 +02:00

53 lines
2.0 KiB
TypeScript

import { getAllPendingDelegations, getDelegationSummary } from 'src/requests';
import { fetchDelegationSummaryQuery } from './delegationQuery';
jest.mock('src/utils', () => ({
decCoinToDisplay: jest.fn((coin: { amount: string; denom: string }) => coin),
}));
jest.mock('src/requests', () => ({
getDelegationSummary: jest.fn(),
getAllPendingDelegations: jest.fn(),
}));
const mockedGetDelegationSummary = getDelegationSummary as jest.MockedFunction<typeof getDelegationSummary>;
const mockedGetAllPendingDelegations = getAllPendingDelegations as jest.MockedFunction<typeof getAllPendingDelegations>;
describe('fetchDelegationSummaryQuery', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('includes unbonded delegations in totals and keeps pending events on new nodes separate', async () => {
mockedGetDelegationSummary.mockResolvedValue({
delegations: [
{
mix_id: 42,
node_identity: 'unbonded:42',
amount: { amount: '1000000', denom: 'unym' },
unclaimed_rewards: { amount: '50000', denom: 'unym' },
mixnode_is_unbonding: true,
},
],
total_delegations: { amount: '1000000', denom: 'unym' },
total_rewards: { amount: '50000', denom: 'unym' },
} as unknown as Awaited<ReturnType<typeof getDelegationSummary>>);
mockedGetAllPendingDelegations.mockResolvedValue([
{
node_identity: 'new-node-identity',
event: { mix_id: 99, kind: 'Delegate', address: 'n1test' },
},
] as Awaited<ReturnType<typeof getAllPendingDelegations>>);
const result = await fetchDelegationSummaryQuery();
expect(result.delegations).toHaveLength(2);
expect(result.delegations[0]).toMatchObject({ mix_id: 42, node_identity: 'unbonded:42' });
expect(result.pendingDelegations).toHaveLength(1);
expect(result.totalDelegations.amount).toBe('1000000');
expect(result.totalRewards.amount).toBe('50000');
expect(result.totalDelegationsAndRewards.amount).toBe('1050000.000000');
});
});