-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse-send.submit-message.test.ts
More file actions
83 lines (72 loc) · 2.22 KB
/
use-send.submit-message.test.ts
File metadata and controls
83 lines (72 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { renderHook, act, waitFor } from '@testing-library/react';
import { Amount } from '@/types/amount';
import type { AssetInfo } from '@/types/asset';
import type { ChainConfig } from '@/services/chain-config';
const { mockSubmitWeb3Transfer, mockFetchWeb3Fee } = vi.hoisted(() => ({
mockSubmitWeb3Transfer: vi.fn(),
mockFetchWeb3Fee: vi.fn(),
}));
vi.mock('./use-send.web3', async () => {
const actual = await vi.importActual<typeof import('./use-send.web3')>('./use-send.web3');
return {
...actual,
fetchWeb3Fee: mockFetchWeb3Fee,
submitWeb3Transfer: mockSubmitWeb3Transfer,
validateWeb3Address: vi.fn(() => null),
};
});
import { useSend } from './use-send';
const mockAsset: AssetInfo = {
assetType: 'TRX',
name: 'Tron',
amount: Amount.fromRaw('100000000', 6, 'TRX'),
decimals: 6,
};
const mockChainConfig = {
id: 'tron',
name: 'Tron',
symbol: 'TRX',
decimals: 6,
chainKind: 'tron',
} as ChainConfig;
describe('useSend submit message propagation', () => {
beforeEach(() => {
vi.clearAllMocks();
mockFetchWeb3Fee.mockResolvedValue({
amount: Amount.fromRaw('1000', 6, 'TRX'),
symbol: 'TRX',
});
});
it('returns and stores detailed submit error message for web3 transfer', async () => {
const detailedMessage = 'Broadcast failed: SIGERROR';
mockSubmitWeb3Transfer.mockResolvedValue({
status: 'error',
message: detailedMessage,
});
const { result } = renderHook(() =>
useSend({
initialAsset: mockAsset,
useMock: false,
walletId: 'wallet-1',
fromAddress: 'TFromAddress',
chainConfig: mockChainConfig,
}),
);
act(() => {
result.current.setToAddress('TToAddress');
result.current.setAmount(Amount.fromRaw('100000', 6, 'TRX'));
});
let submitResult: Awaited<ReturnType<typeof result.current.submit>>;
await act(async () => {
submitResult = await result.current.submit('wallet-lock');
});
expect(submitResult).toEqual({
status: 'error',
message: detailedMessage,
});
await waitFor(() => {
expect(result.current.state.errorMessage).toBe(detailedMessage);
});
});
});