-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathwallet.spec.ts
More file actions
199 lines (165 loc) · 6.23 KB
/
wallet.spec.ts
File metadata and controls
199 lines (165 loc) · 6.23 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { test, type BrowserContext } from '@playwright/test';
import { WalletPage } from './shared/pages/WalletPage';
import { WalletValidator } from './shared/validators/WalletValidator';
import { ModalPage } from './shared/pages/ModalPage';
import { ModalValidator } from './shared/validators/ModalValidator';
import { DEFAULT_CHAIN_NAME, TEST_CHAINS } from './shared/constants';
let modalPage: ModalPage;
let modalValidator: ModalValidator;
let walletPage: WalletPage;
let walletValidator: WalletValidator;
let context: BrowserContext;
// -- Setup --------------------------------------------------------------------
const sampleWalletTest = test.extend<{ library: string }>({
library: ['wagmi', { option: true }]
});
sampleWalletTest.describe.configure({ mode: 'serial' });
sampleWalletTest.beforeAll(async ({ browser }) => {
context = await browser.newContext();
const browserPage = await context.newPage();
modalPage = new ModalPage(browserPage);
walletPage = new WalletPage(await context.newPage());
modalValidator = new ModalValidator(browserPage);
walletValidator = new WalletValidator(walletPage.page);
await modalPage.load();
await modalPage.qrCodeFlow(modalPage, walletPage);
await modalValidator.expectConnected();
});
sampleWalletTest.afterAll(async () => {
await modalPage.page.close();
});
// -- Tests --------------------------------------------------------------------
/**
* Connection Tests
* Tests the basic connection functionality including:
* - Page refresh behavior
* - Network switching
* - Disconnection flows
*/
sampleWalletTest('it should be connected instantly after page refresh', async () => {
await modalPage.page.reload();
await modalValidator.expectToBeConnectedInstantly();
});
/**
* Network Tests
* Tests network-related functionality including:
* - Disabled networks visibility
* - Network switching
* - Network persistence after refresh
*/
sampleWalletTest('it should switch networks and sign', async () => {
const chains = [TEST_CHAINS.POLYGON, TEST_CHAINS.ETHEREUM];
async function processChain(index: number) {
if (index >= chains.length) {
return;
}
const chainName = chains[index] ?? DEFAULT_CHAIN_NAME;
// -- Switch network --------------------------------------------------------
const chainNameOnWalletPage = chainName;
await modalPage.openAccountModal();
await modalPage.goToNetworks();
await modalPage.switchNetwork(chainName);
await modalValidator.expectSwitchedNetwork(chainName);
await modalPage.closeModal();
// -- Sign ------------------------------------------------------------------
await modalPage.sign();
await walletValidator.expectReceivedSign({ chainName: chainNameOnWalletPage });
await walletPage.handleRequest({ accept: true });
await modalValidator.expectAcceptedSign();
await processChain(index + 1);
}
await processChain(0);
});
sampleWalletTest('it should show last connected network after refreshing', async () => {
await modalPage.openAccountModal();
await modalPage.goToNetworks();
await modalPage.switchNetwork(TEST_CHAINS.POLYGON);
await modalValidator.expectSwitchedNetwork(TEST_CHAINS.POLYGON);
await modalPage.closeModal();
await modalPage.page.reload();
await modalPage.openAccountModal();
await modalValidator.expectSwitchedNetwork(TEST_CHAINS.POLYGON);
await modalPage.closeModal();
});
/**
* Signing Tests
* Tests message signing functionality including:
* - Successful signing flow
* - Rejection flow
*/
sampleWalletTest('it should reject sign', async () => {
await modalPage.sign();
await walletValidator.expectReceivedSign({ chainName: TEST_CHAINS.POLYGON });
await walletPage.handleRequest({ accept: false });
await modalValidator.expectRejectedSign();
});
/**
* Activity Screen Tests
* Tests the Activity screen behavior including:
* - Loader visibility on first visit
* - Loader behavior on subsequent visits
* - Loader behavior after network changes
*/
sampleWalletTest('shows loader behavior on first visit to Activity screen', async () => {
// First visit to Activity screen
await modalPage.openAccountModal();
await modalPage.goToActivity();
await modalPage.expectLoaderVisible();
await modalPage.expectLoaderHidden();
// Second visit to Activity screen
await modalPage.goBack();
await modalPage.goToActivity();
await modalPage.expectLoaderHidden();
// Third visit after closing the modal
await modalPage.closeModal();
await modalPage.openAccountModal();
await modalPage.goToActivity();
await modalPage.expectLoaderHidden();
await modalPage.closeModal();
});
sampleWalletTest('shows loader behavior after network change in Activity screen', async () => {
await modalPage.openAccountModal();
// Change network
await modalPage.goToNetworks();
await modalPage.switchNetwork(TEST_CHAINS.ETHEREUM);
await modalValidator.expectSwitchedNetwork(TEST_CHAINS.ETHEREUM);
// Visit Activity screen after network change
await modalPage.goToActivity();
await modalPage.expectLoaderVisible();
await modalPage.expectLoaderHidden();
// Second visit after network change
await modalPage.goBack();
await modalPage.goToActivity();
await modalPage.expectLoaderHidden();
await modalPage.closeModal();
});
/**
* Disconnection Tests
* Tests various disconnection scenarios including:
* - Hook-based disconnection
* - Wallet-initiated disconnection
* - Manual disconnection
*/
sampleWalletTest('it should disconnect using hook', async () => {
await modalValidator.expectConnected();
await modalPage.clickHookDisconnectButton();
await modalValidator.expectDisconnected();
});
sampleWalletTest(
'it should disconnect and close modal when disconnecting from wallet',
async () => {
await modalValidator.expectDisconnected();
await modalPage.qrCodeFlow(modalPage, walletPage);
await modalValidator.expectConnected();
await modalPage.openAccountModal();
await walletPage.disconnectConnection();
await modalValidator.expectModalNotVisible();
await walletPage.page.waitForTimeout(500);
}
);
sampleWalletTest('it should disconnect as expected', async () => {
await modalPage.qrCodeFlow(modalPage, walletPage);
await modalValidator.expectConnected();
await modalPage.disconnect();
await modalValidator.expectDisconnected();
});