-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathfreighterApiIntegration.test.ts
More file actions
419 lines (348 loc) · 13.1 KB
/
Copy pathfreighterApiIntegration.test.ts
File metadata and controls
419 lines (348 loc) · 13.1 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
import { expect, test, expectPageToHaveScreenshot } from "./test-fixtures";
import { TEST_TOKEN_ADDRESS } from "./helpers/test-token";
import { loginToTestAccount } from "./helpers/login";
import { allowDapp } from "./helpers/allowDapp";
import {
stubAccountBalances,
stubAccountHistory,
stubIsSac,
stubScanDapp,
stubTokenDetails,
stubTokenPrices,
} from "./helpers/stubs";
import { Page } from "@playwright/test";
const TX_TO_SIGN =
"AAAAAgAAAADLvQoIbFw9k0tgjZoOrLTuJJY9kHFYp/YAEAlt/xirbAAAAGQAAAfjAAAOpQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAABngBTmbmUycqG2cAMHcomSR80dRzGtKzxM6gb3yySD5AAAAAAAAAAAAvrwgAAAAAAAAAAA";
const SIGNED_TX =
"AAAAAgAAAADLvQoIbFw9k0tgjZoOrLTuJJY9kHFYp/YAEAlt/xirbAAAAGQAAAfjAAAOpQAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAABngBTmbmUycqG2cAMHcomSR80dRzGtKzxM6gb3yySD5AAAAAAAAAAAAvrwgAAAAAAAAAAB/xirbAAAAEBWgE2DhhukpAdJTOhBxvuvePAJH+gBbD3hQQljuidQbTFDMEyak7c2fOjyK2moqVhf3AUpCIMSlALglwFXumQH";
const AUTH_ENTRY_TO_SIGN =
"AAAACc7gMC1ZhE0yvcqRXIID3USzP7t+3BkFHqN6vt8o7NRyGVzFh1h1V3oANBPZAAAAAAAAAAGhRTk9qFLakLcWsi5wS6hhHr80ka5WABdo/8hF7QmS3QAAAARzd2FwAAAABAAAABIAAAAB0kc/9lM7RuxEsaiiUFR+T89kG7IOUk1U0cXCIDkTDesAAAASAAAAAZ+9o35h9wEnNl2hiVZHRJxsDoO3altsu023K1kAex/nAAAACgAAAAAAAAAAAAAAAAADDUAAAAAKAAAAAAAAAAAAAAAAAAGGoAAAAAEAAAAAAAAAAdJHP/ZTO0bsRLGoolBUfk/PZBuyDlJNVNHFwiA5Ew3rAAAACHRyYW5zZmVyAAAAAwAAABIAAAAAAAAAAFVmR/NPwhQJzrxxqVrqFZ83Hy9HmP4trSdB/dX7sAZjAAAAEgAAAAGhRTk9qFLakLcWsi5wS6hhHr80ka5WABdo/8hF7QmS3QAAAAoAAAAAAAAAAAAAAAAAAw1AAAAAAA==";
const SIGNED_AUTH_ENTRY = JSON.stringify({
type: "Buffer",
data: [
165, 67, 16, 42, 244, 165, 43, 189, 159, 221, 121, 137, 153, 150, 203, 45,
93, 57, 72, 249, 253, 123, 201, 63, 246, 111, 81, 64, 229, 182, 24, 57, 169,
81, 159, 223, 75, 150, 86, 14, 192, 5, 222, 178, 110, 148, 104, 60, 1, 82,
246, 212, 89, 84, 175, 233, 209, 21, 193, 126, 172, 179, 162, 3,
],
});
const MSG_TO_SIGN = "Hello, World!";
const SIGNED_MSG =
'"v6NmJHPZ5jUzZzphmTAb4/2Yv18mXFLmzjnwgDmqKR6Rq7/HQB6YxcUbxtBYNtBxccmPq2PB+7EBwOL3nuwQAQ=="';
test.skip("should sign transaction when allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await loginToTestAccount({ page, extensionId });
await allowDapp({ page });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const txPopupPromise = page.context().waitForEvent("page");
await pageTwo.goto(
"https://docs.freighter.app/docs/playground/signTransaction",
);
await pageTwo.getByRole("textbox").first().fill(TX_TO_SIGN);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo.getByText("Sign Transaction XDR").click();
const txPopup = await txPopupPromise;
await expect(txPopup.getByText("Confirm Transaction")).toBeVisible();
await expect(txPopup.getByText("GDF3…ZEFY")).toBeVisible();
await expect(txPopup.getByText("-5")).toBeVisible();
await expectPageToHaveScreenshot({
page: txPopup,
screenshot: "sign-transaction.png",
});
await txPopup.getByRole("button", { name: "Confirm" }).click();
});
// TODO: Add domain not allowed to SignTransaction when warning is redesigned
test.skip("should not sign transaction when not allowed", async ({
page,
extensionId,
}) => {
await loginToTestAccount({ page, extensionId });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const txPopupPromise = page.context().waitForEvent("page");
await pageTwo.goto(
"https://docs.freighter.app/docs/playground/signTransaction",
);
await pageTwo.getByRole("textbox").first().fill(TX_TO_SIGN);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo.getByText("Sign Transaction XDR").click();
const txPopup = await txPopupPromise;
await expect(
txPopup.getByText(
"docs.freighter.app is not currently connected to Freighter",
),
).toBeVisible();
await expect(txPopup.getByTestId("sign-transaction-sign")).toBeDisabled();
await expectPageToHaveScreenshot({
page: txPopup,
screenshot: "domain-not-allowed-sign-transaction.png",
});
});
test.skip("should sign auth entry when allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await loginToTestAccount({ page, extensionId });
await allowDapp({ page });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto(
"https://docs.freighter.app/docs/playground/signAuthEntry",
);
await pageTwo.getByRole("textbox").first().fill(AUTH_ENTRY_TO_SIGN);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo
.getByText("Sign Authorization Entry XDR")
.click({ force: true });
const popup = await popupPromise;
await expect(popup.getByText("Confirm Authorization").first()).toBeVisible();
await expectPageToHaveScreenshot({
page: popup,
screenshot: "sign-auth-entry.png",
});
await popup.getByRole("button", { name: "Confirm" }).click();
await expect(pageTwo.getByRole("textbox").nth(3)).toHaveText(
SIGNED_AUTH_ENTRY,
);
});
test.skip("should not sign auth entry when not allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await loginToTestAccount({ page, extensionId });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto(
"https://docs.freighter.app/docs/playground/signAuthEntry",
);
await pageTwo.getByRole("textbox").first().fill(AUTH_ENTRY_TO_SIGN);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo
.getByText("Sign Authorization Entry XDR")
.click({ force: true });
const popup = await popupPromise;
await expect(popup.getByText("Confirm Authorization").first()).toBeVisible();
await expect(
popup.getByText(
"docs.freighter.app is not currently connected to Freighter",
),
).toBeVisible();
await expect(
popup.getByTestId("sign-auth-entry-approve-button"),
).toBeDisabled();
await expectPageToHaveScreenshot({
page: popup,
screenshot: "domain-not-allowed-sign-auth-entry.png",
});
});
test.skip("should sign message when allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await loginToTestAccount({ page, extensionId });
await allowDapp({ page });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto("https://docs.freighter.app/docs/playground/signMessage");
await pageTwo.getByRole("textbox").first().fill(MSG_TO_SIGN);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo.getByText("Sign message").click();
const popup = await popupPromise;
await expect(popup.getByText(MSG_TO_SIGN)).toBeVisible();
await expectPageToHaveScreenshot({
page: popup,
screenshot: "sign-message.png",
});
await popup.getByTestId("sign-message-approve-button").click();
await expect(pageTwo.getByRole("textbox").nth(3)).toHaveText(SIGNED_MSG);
await expect(pageTwo.getByRole("textbox").nth(4)).toHaveValue(
"GDF32CQINROD3E2LMCGZUDVMWTXCJFR5SBYVRJ7WAAIAS3P7DCVWZEFY",
);
});
test.skip("should not sign message when not allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await loginToTestAccount({ page, extensionId });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto("https://docs.freighter.app/docs/playground/signMessage");
await pageTwo.getByRole("textbox").first().fill(MSG_TO_SIGN);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo.getByText("Sign message").click({ force: true });
const popup = await popupPromise;
await expect(
popup.getByText(
"docs.freighter.app is not currently connected to Freighter",
),
).toBeVisible();
await expect(popup.getByTestId("sign-message-approve-button")).toBeDisabled();
await expectPageToHaveScreenshot({
page: popup,
screenshot: "domain-not-allowed-sign-message.png",
});
});
test.skip("should add token when allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(context);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await stubIsSac(context);
await loginToTestAccount({ page, extensionId });
await allowDapp({ page });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto("https://docs.freighter.app/docs/playground/addToken");
await pageTwo.getByRole("textbox").first().fill(TEST_TOKEN_ADDRESS);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo.getByText("Add Token").click();
const popup = await popupPromise;
await expect(popup.getByText("E2E Token")).toBeDefined();
await expectPageToHaveScreenshot({
page: popup,
screenshot: "add-token.png",
});
await popup.getByTestId("add-token-approve").click();
await expect(pageTwo.getByRole("textbox").nth(2)).toHaveText(
"Token info successfully sent.",
);
});
test.skip("should not add token when not allowed", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(context);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await stubIsSac(context);
await loginToTestAccount({ page, extensionId });
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto("https://docs.freighter.app/docs/playground/addToken");
await pageTwo.getByRole("textbox").first().fill(TEST_TOKEN_ADDRESS);
await pageTwo
.getByRole("textbox")
.nth(1)
.fill("Test SDF Network ; September 2015");
await pageTwo.getByText("Add Token").click({ force: true });
const popup = await popupPromise;
await expect(
popup.getByText(
"docs.freighter.app is not currently connected to Freighter",
),
).toBeVisible();
await expect(popup.getByTestId("add-token-approve")).toBeDisabled();
await expectPageToHaveScreenshot({
page: popup,
screenshot: "domain-not-allowed-add-token.png",
});
});
test.skip("should get public key when logged out", async ({
page,
extensionId,
context,
}) => {
await stubTokenDetails(page);
await stubAccountBalances(page);
await stubAccountHistory(page);
await stubTokenPrices(page);
await stubScanDapp(context);
await loginToTestAccount({ page, extensionId });
await page.getByTestId("account-options-dropdown").click();
await page.getByText("Settings").click();
await page.getByText("Log Out").click();
await expect(page.getByText("Welcome back")).toBeVisible();
// open a second tab and go to docs playground
const pageTwo = await page.context().newPage();
await pageTwo.waitForLoadState();
const popupPromise = page.context().waitForEvent("page");
await pageTwo.goto(
"https://docs.freighter.app/docs/playground/requestAccess",
);
await pageTwo.getByText("Request Access").click();
const popup = await popupPromise;
await expect(popup.getByText("Welcome back")).toBeVisible();
await popup.locator("#password-input").fill("My-password123");
await popup.getByRole("button", { name: "Unlock" }).click();
await expect(popup.getByText("Connection Request")).toBeVisible();
await popup.getByTestId("grant-access-connect-button").click();
await expect(pageTwo.getByRole("textbox").first()).toHaveValue(
"GDF32CQINROD3E2LMCGZUDVMWTXCJFR5SBYVRJ7WAAIAS3P7DCVWZEFY",
);
});