forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPCBuilder.test.tsx
More file actions
130 lines (109 loc) · 3.56 KB
/
Copy pathRPCBuilder.test.tsx
File metadata and controls
130 lines (109 loc) · 3.56 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { RPCBuilder } from './RPCBuilder';
import { RequestType } from '../types';
// Mock dependencies
vi.mock('framer-motion', () => ({
motion: {
div: ({ children, className }: any) => <div className={className}>{children}</div>
}
}));
vi.mock('@mysten/dapp-kit', () => ({
useSignAndExecuteTransaction: () => ({
mutateAsync: vi.fn()
})
}));
const { mockAppStore, mockWallet } = vi.hoisted(() => ({
mockAppStore: {
tabs: [],
activeTabId: null,
network: 'testnet',
envVariables: [],
getSnapshot: () => ({ envVariables: [] }),
finalizeRequest: vi.fn(),
addToHistory: vi.fn(),
pushLog: vi.fn(),
},
mockWallet: {
currentWallet: { family: 'sui', address: '0x123' },
openModal: vi.fn(),
}
}));
vi.mock('@/lib/store', () => ({
useAppStore: () => mockAppStore,
appStore: mockAppStore
}));
vi.mock('@/wallet', () => ({
useWallet: () => mockWallet
}));
vi.mock('../components/RequestPanel/RequestPanel', () => ({
RequestPanel: ({ onExecute }: any) => (
<div data-testid="request-panel">
<button onClick={onExecute}>Execute Request</button>
</div>
)
}));
vi.mock('../components/SignTransactionModal', () => ({
SignTransactionModal: ({ isOpen, onExecute }: any) => isOpen ? (
<div data-testid="sign-modal">
<button onClick={onExecute} data-testid="sign-confirm">Confirm Sign</button>
</div>
) : null
}));
vi.mock('../services/suiService', () => ({
executeSuiRpc: vi.fn(),
looksLikeSuiNs: vi.fn().mockReturnValue(false),
resolveSuiAddress: vi.fn(),
simulateMoveCall: vi.fn(),
signAndExecuteMoveCall: vi.fn().mockResolvedValue({ result: 'ok', duration: 100, status: 200 }),
SuiRpcError: class SuiRpcError extends Error {}
}));
vi.mock('@/lib/terminalLog', () => ({
ensureTerminalOpen: vi.fn(),
logCommandToTerminal: vi.fn(),
}));
vi.mock('@/lib/hooksEngine', () => ({
runHooks: vi.fn().mockResolvedValue(undefined),
}));
describe('RPCBuilder Execution Flows', () => {
beforeEach(() => {
vi.clearAllMocks();
mockAppStore.tabs = [
{
id: 'tab-1',
data: {
type: RequestType.TRANSACTION,
moveParams: { packageId: '0x1', module: 'm', function: 'f', typeArguments: [], arguments: [] },
hooks: {}
}
}
] as any;
mockAppStore.activeTabId = 'tab-1' as any;
});
it('bypasses mainnet warning on testnet and executes directly', async () => {
mockAppStore.network = 'testnet';
render(<RPCBuilder />);
// Open SignModal
fireEvent.click(screen.getByText('Execute Request'));
// Click execute in SignModal
fireEvent.click(screen.getByTestId('sign-confirm'));
// Verify mainnet warning is NOT shown
expect(screen.queryByText('Mainnet Execution Warning')).not.toBeInTheDocument();
});
it('shows mainnet warning when network is mainnet', async () => {
mockAppStore.network = 'mainnet';
render(<RPCBuilder />);
// Open SignModal
fireEvent.click(screen.getByText('Execute Request'));
// Click execute in SignModal
fireEvent.click(screen.getByTestId('sign-confirm'));
// Verify mainnet warning IS shown
expect(screen.getByText('Mainnet Execution Warning')).toBeInTheDocument();
// Confirm execution
fireEvent.click(screen.getByText('Confirm & Execute'));
await waitFor(() => {
expect(screen.queryByText('Mainnet Execution Warning')).not.toBeInTheDocument();
});
});
});