From 834d45819d5743a67ea68ebc42f6a7acd1451c88 Mon Sep 17 00:00:00 2001 From: Sero <69639595+Seroxdesign@users.noreply.github.com> Date: Wed, 19 Jun 2024 05:03:55 -0400 Subject: [PATCH] unlock for fixture (: keplr --- wallets/keplr/.env | 0 wallets/keplr/src/KeplrWallet.ts | 2 +- .../src/fixtureActions/unlockForFixtures.ts | 4 ++-- wallets/keplr/src/fixtures/keplrFixtures.ts | 20 ++++++++++--------- .../keplr/src/pages/LockPage/actions/index.ts | 3 ++- .../pages/LockPage/actions/unlockWallet.ts | 11 ++++++++++ wallets/keplr/src/pages/LockPage/page.ts | 9 +++++++-- .../src/pages/LockPage/selectors/index.ts | 4 ++-- .../keplr/test/playwright/getAddress.spec.ts | 18 ++++++++--------- wallets/keplr/test/synpress.ts | 2 +- 10 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 wallets/keplr/.env create mode 100644 wallets/keplr/src/pages/LockPage/actions/unlockWallet.ts diff --git a/wallets/keplr/.env b/wallets/keplr/.env new file mode 100644 index 000000000..e69de29bb diff --git a/wallets/keplr/src/KeplrWallet.ts b/wallets/keplr/src/KeplrWallet.ts index abefb94b8..412f85a70 100644 --- a/wallets/keplr/src/KeplrWallet.ts +++ b/wallets/keplr/src/KeplrWallet.ts @@ -28,7 +28,7 @@ export class KeplrWallet { async setupWallet( { secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string }, ) { - const wallet = await this.lockPage.unlock(secretWordsOrPrivateKey, password) + const wallet = await this.lockPage.importWallet(secretWordsOrPrivateKey, password) return wallet; } diff --git a/wallets/keplr/src/fixtureActions/unlockForFixtures.ts b/wallets/keplr/src/fixtureActions/unlockForFixtures.ts index 72ad671ee..5b0c07fc7 100644 --- a/wallets/keplr/src/fixtureActions/unlockForFixtures.ts +++ b/wallets/keplr/src/fixtureActions/unlockForFixtures.ts @@ -1,8 +1,8 @@ import type { Page } from '@playwright/test'; import { LockPage } from '../pages/LockPage/page' -export default async function unlockForFixtures(page: Page, seedPhrase: string, password: string) { +export default async function unlockForFixtures(page: Page, password: string) { const lockpage = new LockPage(page) - const wallet = await lockpage.unlock(seedPhrase, password) + const wallet = await lockpage.unlock(password) return wallet; } \ No newline at end of file diff --git a/wallets/keplr/src/fixtures/keplrFixtures.ts b/wallets/keplr/src/fixtures/keplrFixtures.ts index 744ddf441..6a3bb7aa0 100644 --- a/wallets/keplr/src/fixtures/keplrFixtures.ts +++ b/wallets/keplr/src/fixtures/keplrFixtures.ts @@ -14,6 +14,7 @@ import fs from 'fs-extra' import { persistLocalStorage } from '../fixtureActions/persistLocalStorage' import { getExtensionId } from '../fixtureActions' import { prepareExtension } from '@synthetixio/synpress-utils' +import unlockForFixtures from '../fixtureActions/unlockForFixtures' type KeplrFixtures = { _contextPath: string @@ -78,28 +79,29 @@ export const keplrFixtures = (walletSetup: ReturnType, _keplrPage = context.pages()[0] as Page - await _keplrPage.goto('chrome-extension://' + extensionId + '/register.html') - + await _keplrPage.goto(`chrome-extension://${extensionId}/popup.html`) + await unlockForFixtures(_keplrPage, PASSWORD) + await use(context) - await context.close() + }, + keplrPage: async ({ context: _ }, use) => { + await use(_keplrPage); }, extensionId: async ({ context }, use) => { const extensionId = await getExtensionId(context, 'Keplr') await use(extensionId) }, - page: async ({ page }, use) => { - await page.goto('https://wallet.keplr.app/') - await use(page) - }, keplr: async ({ context, extensionId }, use) => { const keplrWallet = new KeplrWallet(_keplrPage, context, PASSWORD, extensionId) await use(keplrWallet) }, - keplrPage: async ({ context: _ }, use) => { - await use(_keplrPage!); + + page: async ({ page }, use) => { + await page.goto('https://wallet.keplr.app/') + await use(page) }, }) } \ No newline at end of file diff --git a/wallets/keplr/src/pages/LockPage/actions/index.ts b/wallets/keplr/src/pages/LockPage/actions/index.ts index e4edd0f6f..c2828e215 100644 --- a/wallets/keplr/src/pages/LockPage/actions/index.ts +++ b/wallets/keplr/src/pages/LockPage/actions/index.ts @@ -1 +1,2 @@ -export * from './importWallet'; \ No newline at end of file +export * from './importWallet'; +export * from './unlockWallet'; \ No newline at end of file diff --git a/wallets/keplr/src/pages/LockPage/actions/unlockWallet.ts b/wallets/keplr/src/pages/LockPage/actions/unlockWallet.ts new file mode 100644 index 000000000..b503eae75 --- /dev/null +++ b/wallets/keplr/src/pages/LockPage/actions/unlockWallet.ts @@ -0,0 +1,11 @@ +import { onboardingElements } from "../selectors"; +import type { Page } from "@playwright/test"; + +export async function unlockWallet(page: Page, password: string) { + await page.waitForLoadState('domcontentloaded'); + const passwordField = page.locator(onboardingElements.passwordInput); + await passwordField.fill(password); + const button = await page.$('button[type="submit"].sc-ciZhAO.kaxPjU'); + button?.click(); + return true; +} \ No newline at end of file diff --git a/wallets/keplr/src/pages/LockPage/page.ts b/wallets/keplr/src/pages/LockPage/page.ts index 40119b143..57b0eb34f 100644 --- a/wallets/keplr/src/pages/LockPage/page.ts +++ b/wallets/keplr/src/pages/LockPage/page.ts @@ -1,6 +1,7 @@ import type { Page } from '@playwright/test' import { onboardingElements } from './selectors' import { importWallet } from './actions' +import { unlockWallet } from './actions' export class LockPage { static readonly selectors = onboardingElements @@ -12,7 +13,11 @@ export class LockPage { this.page = page } - async unlock(seedPhrase: string, password: string) { - await importWallet(this.page, seedPhrase, password) + async unlock(password: string) { + await unlockWallet(this.page, password) + } + + async importWallet(secretWordsOrPrivateKey: string, password: string) { + await importWallet(this.page, secretWordsOrPrivateKey, password) } } diff --git a/wallets/keplr/src/pages/LockPage/selectors/index.ts b/wallets/keplr/src/pages/LockPage/selectors/index.ts index 0fdc0dea2..51bf03d63 100644 --- a/wallets/keplr/src/pages/LockPage/selectors/index.ts +++ b/wallets/keplr/src/pages/LockPage/selectors/index.ts @@ -14,8 +14,8 @@ export const onboardingElements = { phraseSelectChain: 'Select Chains', phraseAccountCreated: 'Account Created!', walletInput: 'input[name="name"]:focus', - passwordInput: 'input[name="password"]', - confirmPasswordInput: 'input[name="confirmPassword"]', + passwordInput: '.sc-kLLXSd.aOXjF', + confirmPasswordInput: '.sc-ciZhAO.hUwRuH', submitWalletDataButton: 'button[type="submit"]', submitChainButton: 'button[type="button"]', finishButton: 'button[type="button"]', diff --git a/wallets/keplr/test/playwright/getAddress.spec.ts b/wallets/keplr/test/playwright/getAddress.spec.ts index b7afa7fee..0ac88330e 100644 --- a/wallets/keplr/test/playwright/getAddress.spec.ts +++ b/wallets/keplr/test/playwright/getAddress.spec.ts @@ -1,8 +1,16 @@ -import { PASSWORD, SEED_PHRASE } from '../../src' +// import { PASSWORD, SEED_PHRASE } from '../../src' import synpress from '../synpress' const test = synpress +// test('should import wallet', async ({ keplr }) => { +// try { +// await keplr.setupWallet({ secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD }) +// } catch (error) { +// console.error('Error:', error) +// } +// }) + test('should create address', async ({ keplr }) => { try { await keplr.getWalletAddress() @@ -10,11 +18,3 @@ test('should create address', async ({ keplr }) => { console.error('Error:', error) } }) - -test('should import wallet', async ({ keplr }) => { - try { - await keplr.setupWallet({ secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD }) - } catch (error) { - console.error('Error:', error) - } -}) \ No newline at end of file diff --git a/wallets/keplr/test/synpress.ts b/wallets/keplr/test/synpress.ts index 411630841..634589cd2 100644 --- a/wallets/keplr/test/synpress.ts +++ b/wallets/keplr/test/synpress.ts @@ -3,4 +3,4 @@ import { keplrFixtures } from "../src"; import connectedKeplrSetup from "./wallet-setup/connected-keplr.setup"; console.log('connectedKeplrSetup', connectedKeplrSetup, connectedKeplrSetup.hash) -export default testWithSynpress(keplrFixtures(connectedKeplrSetup)) \ No newline at end of file +export default testWithSynpress(keplrFixtures(connectedKeplrSetup, 1000)) \ No newline at end of file