Skip to content

Commit 4e6513d

Browse files
xbeghersComp0teost-ptk
authored
Tests2.0 (#1151)
* Fix issue with old secret keys with 128 length * Add timestamp to initiated deploys * Release 1.14.2 version * Add Devnet network * Add Casper Network API version checking * Update Signature request page for Casper2.0 * Update redirection to cspr.live * Populate account info with data from accounts and contacts * Rename Deploys to Transaction for Casper 2.0 * Disable Buy CSPR for Safari * Update transfers and auction actions to Casper 2.0 * Add Integration network support * Update HttpHandler usage * Add validators minAmount, maxAmount and reserved slots handling * Update casper-js-sdk and casper-wallet-core * Update casper-wallet-core * Fix Deploy to Transaction renaming * Fix arguments parsing * Update casper-wallet-core lib * Update casper-wallet-core and casper-js-sdk libs * Fix delegation amount during redelegation flow * Remove redundant isSafariExtension util * Improve max delegation amount formatting * Refactor validator error messages to include headers (#1138) * fixes for tests on 2.0 branch * jest fix * jest fix * jest fix * fixes for tests * changes related to issue with RPC * fix: jest.config.js and jest.tsconfig.json * jest fix * added skip * fixes and improvements without fix for failu transfers * merge with develop * fix for fail transfers flow improvement of selectors removing unnecessary lines * cleaning code a bit for erc20 transfer test --------- Co-authored-by: Dmytro Vynnyk <[email protected]> Co-authored-by: Ostap Piatkovskyi <[email protected]>
1 parent 9963506 commit 4e6513d

21 files changed

+635
-74
lines changed

e2e-tests/constants.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { Page } from '@playwright/test';
12
import path from 'path';
23

4+
export const newPassword = 'this is new password';
35
export const vaultPassword = '3hQqzYn4C7Y8rEZTVEZb';
46
export const twentyFourWordsSecretPhrase =
57
'hold matrix spider subway bottom jazz charge fire lawn valley stay coil moral hospital dream cycle multiply december agree huge major tower devote old';
@@ -20,7 +22,8 @@ export const torusSecretKeyHex =
2022
export const ACCOUNT_NAMES = {
2123
defaultFirstAccountName: 'Account 1',
2224
defaultSecondAccountName: 'Account 2',
23-
createdAccountName: 'New account 1',
25+
createdAccountName: 'First New Account',
26+
createdAccountName2: 'Second New account ',
2427
importedPemAccountName: 'Imported pem account',
2528
renamedAccountName: 'Renamed account',
2629
importedCerAccountName: 'Imported cer account',
@@ -53,7 +56,9 @@ export const IMPORTED_TORUS_ACCOUNT = {
5356
truncatedPublicKey: '02029...ffd4f',
5457
mediumTruncatedPublicKey: '02029fcc5b...65182ffd4f'
5558
};
56-
59+
export function accountSettingLocator(accountName: string) {
60+
return `xpath=//div[contains(@class, 'sc-hLBbgP') and contains(@class, 'fYMUrO')]//span[text()='${accountName}']/ancestor::div[contains(@class, 'sc-hLBbgP')]/following-sibling::div[@data-testid='popover-children-container']`;
61+
}
5762
export const DEFAULT_FIRST_ACCOUNT = {
5863
accountName: ACCOUNT_NAMES.defaultFirstAccountName,
5964
publicKey:
@@ -102,8 +107,8 @@ export const VALIDATOR_FOR_STAKE = {
102107

103108
export const NEW_VALIDATOR_FOR_STAKE = {
104109
publicKey:
105-
'01ad002e37667f90aa982396ebdfcc7d3eea99731241eaad8a0dc20f453f72975a',
106-
truncatedPublicKey: '01ad...975a'
110+
'01c8be540a643e6c9df283dd2d2d6be67748f69a3c7bb6cf34471c899b8e858c9a',
111+
truncatedPublicKey: '01c8...8c9a'
107112
};
108113

109114
export const URLS = {
@@ -117,21 +122,24 @@ export const RPC_RESPONSE = {
117122
jsonrpc: '2.0',
118123
id: 1717761373590,
119124
result: {
120-
api_version: '1.5.6',
121-
deploy_hash: 'deploy hash'
125+
api_version: '2.0.0',
126+
transaction_hash: {
127+
Version1:
128+
'9de32b7f6d79e559cb3f7b94250a605739de803d98ec681cc4a4b7dc8604fdae'
129+
}
122130
}
123131
})
124132
},
125133
failure: {
126134
status: 500,
127135
body: JSON.stringify({
128-
jsonrpc: '2.0',
129-
id: 1717761373590,
130-
error: {
131-
code: '',
132-
data: 'Error description',
133-
message: 'Error message'
134-
}
136+
sourceErr: {
137+
code: -32016,
138+
data: 'error description',
139+
message: 'error message'
140+
},
141+
id: 1,
142+
jsonrpc: '2.0'
135143
})
136144
}
137145
};

e2e-tests/fixtures.ts

Lines changed: 157 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import {
2-
test as base,
3-
chromium,
42
type BrowserContext,
5-
Page
3+
Page,
4+
test as base,
5+
chromium
66
} from '@playwright/test';
77
import path from 'path';
88

99
import {
1010
DEFAULT_FIRST_ACCOUNT,
11+
DEFAULT_SECOND_ACCOUNT,
1112
PLAYGROUND_URL,
13+
RPC_RESPONSE,
14+
URLS,
15+
newPassword,
1216
vaultPassword
1317
} from './constants';
1418

@@ -34,13 +38,24 @@ export const test = base.extend<{
3438
await context.close();
3539
},
3640
extensionId: async ({ context }, use) => {
37-
let [background] = context.serviceWorkers();
41+
let background = context.serviceWorkers()[0];
42+
43+
if (!background) {
44+
try {
45+
background = await context.waitForEvent('serviceworker', {
46+
timeout: 5000
47+
});
48+
} catch (error) {
49+
throw new Error('Service worker did not register in time.');
50+
}
51+
}
3852

3953
if (!background) {
40-
background = await context.waitForEvent('serviceworker');
54+
throw new Error('Failed to retrieve the service worker.');
4155
}
4256

43-
const extensionId = background.url().split('/')[2];
57+
// Extract extension ID from the worker URL (if it's a Chrome extension)
58+
const extensionId = new URL(background.url()).host;
4459

4560
await use(extensionId);
4661
}
@@ -212,6 +227,13 @@ export const popup = test.extend<{
212227
createAccount: (newAccountName: string) => Promise<void>;
213228
connectAccounts: () => Promise<void>;
214229
addContact: () => Promise<void>;
230+
providePassword: (popupPage?: Page) => Promise<void>;
231+
setWrongPasswordFiveTimes: (popupPage?: Page) => Promise<void>;
232+
changePassword: (popupPage?: Page) => Promise<void>;
233+
provideNewPassword: (popupPage?: Page) => Promise<void>;
234+
unlockVaultNewPassword: (popupPage?: Page) => Promise<void>;
235+
setWrongPassword: (popupPage?: Page) => Promise<void>;
236+
sendCsprTokens: (popupPage?: Page) => Promise<void>;
215237
}>({
216238
popupPage: async ({ extensionId, page }, use) => {
217239
await page.goto(`chrome-extension://${extensionId}/popup.html`);
@@ -225,6 +247,7 @@ export const popup = test.extend<{
225247
.getByPlaceholder('Password', { exact: true })
226248
.fill(vaultPassword);
227249
await currentPage.getByRole('button', { name: 'Unlock wallet' }).click();
250+
await page.waitForLoadState('networkidle');
228251
};
229252

230253
await use(unlockVault);
@@ -271,6 +294,59 @@ export const popup = test.extend<{
271294

272295
await use(connectAccounts);
273296
},
297+
sendCsprTokens: async ({ page }, use) => {
298+
const sendCsprTokens = async (popupPage?: Page) => {
299+
const currentPage = popupPage || page;
300+
await currentPage.route(URLS.rpc, route =>
301+
route.fulfill(RPC_RESPONSE.success)
302+
);
303+
304+
await new Promise(r => setTimeout(r, 5000));
305+
306+
await currentPage.getByText('Send').click();
307+
308+
await currentPage.getByRole('button', { name: 'Next' }).click();
309+
310+
await currentPage
311+
.getByPlaceholder('Public key or name', { exact: true })
312+
.fill(DEFAULT_SECOND_ACCOUNT.publicKey);
313+
314+
await currentPage
315+
.getByText(DEFAULT_SECOND_ACCOUNT.mediumTruncatedPublicKey, {
316+
exact: true
317+
})
318+
.click();
319+
320+
await currentPage.getByRole('button', { name: 'Next' }).click();
321+
322+
await currentPage.getByRole('button', { name: 'Next' }).click();
323+
324+
// Scroll to the bottom
325+
await currentPage.evaluate(() => {
326+
const container = document.querySelector('#ms-container');
327+
328+
container?.scrollTo(0, 1000);
329+
});
330+
331+
await currentPage.getByRole('button', { name: 'Confirm send' }).click();
332+
await currentPage.waitForLoadState('networkidle');
333+
await currentPage.getByRole('button', { name: 'Done' }).click();
334+
};
335+
await use(sendCsprTokens);
336+
},
337+
338+
unlockVaultNewPassword: async ({ page }, use) => {
339+
const unlockVaultNewPassword = async (popupPage?: Page) => {
340+
const currentPage = popupPage || page;
341+
342+
await currentPage
343+
.getByPlaceholder('Password', { exact: true })
344+
.fill(newPassword);
345+
await currentPage.getByRole('button', { name: 'Unlock wallet' }).click();
346+
};
347+
348+
await use(unlockVaultNewPassword);
349+
},
274350
addContact: async ({ page }, use) => {
275351
const addContact = async () => {
276352
await page.getByTestId('menu-open-icon').click();
@@ -291,7 +367,81 @@ export const popup = test.extend<{
291367
};
292368

293369
await use(addContact);
370+
},
371+
372+
providePassword: async ({ page }, use) => {
373+
const providePassword = async (popupPage?: Page) => {
374+
const currentPage = popupPage || page;
375+
376+
await currentPage
377+
.getByPlaceholder('Password', { exact: true })
378+
.fill(vaultPassword);
379+
await currentPage.getByRole('button', { name: 'Continue' }).click();
380+
};
381+
382+
await use(providePassword);
383+
},
384+
provideNewPassword: async ({ page }, use) => {
385+
const provideNewPassword = async (popupPage?: Page) => {
386+
const currentPage = popupPage || page;
387+
388+
await currentPage
389+
.getByPlaceholder('Password', { exact: true })
390+
.fill(newPassword);
391+
await currentPage.getByRole('button', { name: 'Continue' }).click();
392+
};
393+
394+
await use(provideNewPassword);
395+
},
396+
changePassword: async ({ page }, use) => {
397+
const changePassword = async (popupPage?: Page) => {
398+
const currentPage = popupPage || page;
399+
400+
await currentPage
401+
.getByPlaceholder('Password', { exact: true })
402+
.fill(newPassword);
403+
await currentPage.getByPlaceholder('Confirm password').fill(newPassword);
404+
405+
await currentPage.getByRole('button', { name: 'Continue' }).click();
406+
407+
await page.waitForTimeout(2000);
408+
};
409+
410+
await use(changePassword);
411+
},
412+
setWrongPassword: async ({ page }, use) => {
413+
const changePassword = async (popupPage?: Page) => {
414+
const currentPage = popupPage || page;
415+
416+
await currentPage
417+
.getByPlaceholder('Password', { exact: true })
418+
.fill(newPassword);
419+
await currentPage
420+
.getByPlaceholder('Confirm password')
421+
.fill(vaultPassword);
422+
423+
await currentPage.getByRole('button', { name: 'Continue' }).click();
424+
425+
await page.waitForTimeout(2000);
426+
};
427+
428+
await use(changePassword);
429+
},
430+
431+
setWrongPasswordFiveTimes: async ({ page }, use) => {
432+
const setWrongPasswordFiveTimes = async (popupPage?: Page) => {
433+
const currentPage = popupPage || page;
434+
435+
await currentPage
436+
.getByPlaceholder('Password', { exact: true })
437+
.fill('wrong password');
438+
439+
for (let i = 0; i < 5; i++) {
440+
await currentPage.getByRole('button', { name: 'Continue' }).click();
441+
}
442+
};
443+
444+
await use(setWrongPasswordFiveTimes);
294445
}
295446
});
296-
297447
export const popupExpect = popup.expect;

e2e-tests/onboarding-flow/confirm-secret-phrase-flow.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { onboardingExpect, onboarding } from '../fixtures';
21
import { DEFAULT_FIRST_ACCOUNT } from '../constants';
2+
import { onboarding, onboardingExpect } from '../fixtures';
33

44
onboarding.describe('Onboarding UI: confirm secret phrase flow', () => {
55
onboarding(
@@ -30,6 +30,19 @@ onboarding.describe('Onboarding UI: confirm secret phrase flow', () => {
3030
await onboardingExpect(
3131
page.getByText(DEFAULT_FIRST_ACCOUNT.accountName)
3232
).toBeVisible();
33+
34+
//Fresh account should have empty balances, no nft or deploy history
35+
await onboardingExpect(page.getByText('NFTs')).toBeVisible();
36+
37+
await page.getByText('NFTs').click();
38+
39+
await onboardingExpect(
40+
await page.getByText('No NFT tokens')
41+
).toBeVisible();
42+
43+
await page.getByText('Deploys').click();
44+
45+
await onboardingExpect(await page.getByText('No activity')).toBeVisible();
3346
}
3447
);
3548

0 commit comments

Comments
 (0)