-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created minimal packet of ctrl methods; deleted xdefi
- Loading branch information
Showing
16 changed files
with
311 additions
and
139 deletions.
There are no files selected for viewing
10 changes: 5 additions & 5 deletions
10
...ages/wallets/src/xdefi/xdefi.constants.ts → packages/wallets/src/ctrl/ctrl.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { CommonWalletConfig } from '../wallets.constants'; | ||
|
||
export const XDEFI_COMMON_CONFIG: CommonWalletConfig = { | ||
WALLET_NAME: 'xdefi', | ||
CONNECTED_WALLET_NAME: 'XDEFI', | ||
export const CTRL_COMMON_CONFIG: CommonWalletConfig = { | ||
WALLET_NAME: 'ctrl', | ||
CONNECTED_WALLET_NAME: 'Ctrl', | ||
RPC_URL_PATTERN: 'https://mainnet.infura.io/v3/**', | ||
STORE_EXTENSION_ID: 'hmeobnfnfcmdkdcmlblgagmfpfboieaf', | ||
CONNECT_BUTTON_NAME: 'XDEFI', | ||
CONNECT_BUTTON_NAME: 'Ctrl', | ||
SIMPLE_CONNECT: false, | ||
EXTENSION_START_PATH: '/app.html', | ||
EXTENSION_START_PATH: '/popup.html', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { WalletPage } from '../wallet.page'; | ||
import { test, BrowserContext, Page } from '@playwright/test'; | ||
import { WalletConfig } from '../wallets.constants'; | ||
import { LoginPage, OnboardingPage, WalletOperations } from './pages'; | ||
import { closeUnnecessaryPages } from './helper'; | ||
|
||
export class CtrlPage implements WalletPage { | ||
page: Page | undefined; | ||
onboardingPage: OnboardingPage; | ||
loginPage: LoginPage; | ||
|
||
constructor( | ||
private browserContext: BrowserContext, | ||
private extensionUrl: string, | ||
public config: WalletConfig, | ||
) {} | ||
|
||
/** Init all page objects Classes included to wallet */ | ||
async initLocators() { | ||
this.page = await this.browserContext.newPage(); | ||
this.onboardingPage = new OnboardingPage( | ||
this.page, | ||
this.browserContext, | ||
this.extensionUrl, | ||
this.config, | ||
); | ||
this.loginPage = new LoginPage(this.page, this.config); | ||
} | ||
|
||
/** Open the home page of the wallet extension */ | ||
async goto() { | ||
await this.page.goto( | ||
this.extensionUrl + this.config.COMMON.EXTENSION_START_PATH, | ||
); | ||
} | ||
|
||
/** Navigate to home page of OXK Wallet extension: | ||
* - open the wallet extension | ||
* - unlock extension (if needed) | ||
* - cancel awaited transactions (if needed) | ||
*/ | ||
async navigate() { | ||
await test.step('Navigate to Ctrl', async () => { | ||
await this.initLocators(); | ||
await this.goto(); | ||
await this.loginPage.unlock(); | ||
// await this.walletOperations.cancelAllTxInQueue(); | ||
}); | ||
} | ||
|
||
async setup() { | ||
await test.step('Setup', async () => { | ||
await this.initLocators(); | ||
if (await this.onboardingPage.isNeedToGoThroughOnboarding()) { | ||
await this.onboardingPage.firstTimeSetup(); | ||
await this.goto(); | ||
await this.onboardingPage.closeWalletTour(); | ||
await this.onboardingPage.createWalletPassword(); | ||
} | ||
await closeUnnecessaryPages(this.browserContext); | ||
}); | ||
} | ||
|
||
/** Click `Connect` button */ | ||
async connectWallet(page: Page) { | ||
await test.step('Connect OKX wallet', async () => { | ||
const operationPage = new WalletOperations(page); | ||
await operationPage.connectBtn.waitFor({ | ||
state: 'visible', | ||
timeout: 10000, | ||
}); | ||
await operationPage.connectBtn.click(); | ||
// need wait the page to be closed after the extension is connected | ||
await new Promise<void>((resolve) => { | ||
operationPage.page.on('close', () => { | ||
resolve(); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
importKey(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
assertTxAmount(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
confirmTx(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
cancelTx(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
approveTokenTx(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
openLastTxInEthplorer(): Promise<Page> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
getTokenBalance(): Promise<number> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
confirmAddTokenToWallet(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
assertReceiptAddress(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
getWalletAddress(): Promise<string> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
setupNetwork(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
addNetwork(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
changeNetwork(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
changeWalletAccountByName(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
changeWalletAccountByAddress(): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
isWalletAddressExist(): Promise<boolean> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { BrowserContext } from '@playwright/test'; | ||
|
||
export async function closeUnnecessaryPages(browserContext: BrowserContext) { | ||
const pages = browserContext.pages().slice(1); | ||
for (const page of pages) { | ||
await page.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './ctrl.page'; | ||
export * from './ctrl.constants'; | ||
export * from './helper'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './onboarding.page'; | ||
export * from './login.page'; | ||
export * from './walletOperations.page'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Locator, Page, test } from '@playwright/test'; | ||
import { WalletConfig } from '../../wallets.constants'; | ||
|
||
export class LoginPage { | ||
page: Page; | ||
unlockBtn: Locator; | ||
passwordInput: Locator; | ||
homeBtn: Locator; | ||
|
||
constructor(page: Page, public config: WalletConfig) { | ||
this.page = page; | ||
this.unlockBtn = this.page.getByTestId('unlock-btn'); | ||
this.passwordInput = this.page.locator('input[type="password"]'); | ||
} | ||
|
||
async unlock() { | ||
await test.step('Unlock wallet', async () => { | ||
try { | ||
await this.unlockBtn.waitFor({ state: 'visible', timeout: 2000 }); | ||
await this.passwordInput.fill(this.config.PASSWORD); | ||
await this.unlockBtn.click(); | ||
await this.homeBtn.waitFor({ state: 'visible' }); | ||
} catch { | ||
console.log('The Wallet unlocking is not needed'); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { BrowserContext, Locator, Page, test } from '@playwright/test'; | ||
import { WalletConfig } from '../../wallets.constants'; | ||
|
||
export class OnboardingPage { | ||
page: Page; | ||
alreadyHaveWalletBtn: Locator; | ||
importRecoveryPhraseBtn: Locator; | ||
passwordInput: Locator; | ||
nextBtn: Locator; | ||
importBtn: Locator; | ||
closeTourBtn: Locator; | ||
notNowBtn: Locator; | ||
createPasswordBtn: Locator; | ||
confirmPasswordBtn: Locator; | ||
|
||
constructor( | ||
page: Page, | ||
private browserContext: BrowserContext, | ||
private extensionUrl: string, | ||
public config: WalletConfig, | ||
) { | ||
this.page = page; | ||
this.alreadyHaveWalletBtn = this.page.getByTestId( | ||
'i-already-have-a-wallet-btn', | ||
); | ||
this.importRecoveryPhraseBtn = this.page.getByText( | ||
'Import with Recovery Phrase', | ||
); | ||
this.passwordInput = this.page.locator('input[type="password"]'); | ||
this.nextBtn = this.page.getByTestId('next-btn'); | ||
this.importBtn = this.page.getByTestId('import-btn'); | ||
this.closeTourBtn = this.page.locator( | ||
'[testID="home-page-tour-close-icon"]', | ||
); | ||
this.notNowBtn = this.page.getByText('Not now'); | ||
this.createPasswordBtn = this.page.getByText('create a password'); | ||
this.confirmPasswordBtn = this.page.getByTestId('button'); | ||
} | ||
|
||
async isNeedToGoThroughOnboarding() { | ||
return await test.step('Open the onboarding page', async () => { | ||
// Need to open onboarding page cause the extension does not redirect from home url automatically | ||
await this.page.goto( | ||
this.extensionUrl + '/tabs/onboarding.html#onboarding', | ||
); | ||
|
||
const btn = this.page.getByTestId('i-already-have-a-wallet-btn'); | ||
try { | ||
await btn.waitFor({ | ||
state: 'visible', | ||
timeout: 5000, | ||
}); | ||
} catch { | ||
console.log('Onboarding process is not needed'); | ||
} | ||
return btn.isVisible(); | ||
}); | ||
} | ||
|
||
async firstTimeSetup() { | ||
await test.step('First time set up', async () => { | ||
// Need to wait some time for button enabling | ||
await this.page.waitForTimeout(1000); | ||
await this.alreadyHaveWalletBtn.click({ force: true }); | ||
|
||
await test.step('Import wallet with recovery phrase', async () => { | ||
await this.importRecoveryPhraseBtn.click(); | ||
const seedWords = this.config.SECRET_PHRASE.split(' '); | ||
for (let i = 0; i < seedWords.length; i++) { | ||
await this.passwordInput.nth(i).fill(seedWords[i]); | ||
} | ||
await this.nextBtn.click(); | ||
await this.importBtn.waitFor({ state: 'visible', timeout: 60000 }); | ||
await this.importBtn.click(); | ||
await this.nextBtn.click(); | ||
}); | ||
}); | ||
} | ||
|
||
async closeWalletTour() { | ||
await test.step('Close wallet tour', async () => { | ||
await this.closeTourBtn.waitFor({ state: 'visible', timeout: 2000 }); | ||
await this.closeTourBtn.click(); | ||
await this.notNowBtn.waitFor({ state: 'visible', timeout: 2000 }); | ||
await this.notNowBtn.click({ force: true }); | ||
}); | ||
} | ||
|
||
async createWalletPassword() { | ||
await test.step('Create wallet password', async () => { | ||
await this.createPasswordBtn.click(); | ||
await this.passwordInput.nth(0).fill(this.config.PASSWORD); | ||
await this.passwordInput.nth(1).fill(this.config.PASSWORD); | ||
await this.confirmPasswordBtn.click(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Locator, Page } from '@playwright/test'; | ||
|
||
export class WalletOperations { | ||
page: Page; | ||
connectBtn: Locator; | ||
|
||
constructor(page: Page) { | ||
this.page = page; | ||
this.connectBtn = this.page.getByTestId('connect-dapp-button'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.