Skip to content

Commit

Permalink
unlock for fixture (: keplr
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jun 19, 2024
1 parent 8f6e1e4 commit 834d458
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 27 deletions.
Empty file added wallets/keplr/.env
Empty file.
2 changes: 1 addition & 1 deletion wallets/keplr/src/KeplrWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions wallets/keplr/src/fixtureActions/unlockForFixtures.ts
Original file line number Diff line number Diff line change
@@ -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;
}
20 changes: 11 additions & 9 deletions wallets/keplr/src/fixtures/keplrFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,28 +79,29 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,

_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)
},
})
}
3 changes: 2 additions & 1 deletion wallets/keplr/src/pages/LockPage/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './importWallet';
export * from './importWallet';
export * from './unlockWallet';
11 changes: 11 additions & 0 deletions wallets/keplr/src/pages/LockPage/actions/unlockWallet.ts
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 7 additions & 2 deletions wallets/keplr/src/pages/LockPage/page.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
4 changes: 2 additions & 2 deletions wallets/keplr/src/pages/LockPage/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]',
Expand Down
18 changes: 9 additions & 9 deletions wallets/keplr/test/playwright/getAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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()
} catch (error) {
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)
}
})
2 changes: 1 addition & 1 deletion wallets/keplr/test/synpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
export default testWithSynpress(keplrFixtures(connectedKeplrSetup, 1000))

0 comments on commit 834d458

Please sign in to comment.