Skip to content

Commit

Permalink
h
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jun 17, 2024
1 parent 3cf42d9 commit 5baf24d
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 50 deletions.
1 change: 0 additions & 1 deletion packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export const cliEntrypoint = async () => {
}

const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug)
console.log('force', flags.force, 'compiledWalletSetupDirPath', compiledWalletSetupDirPath, 'extensionNames', extensionNames)
for (const extensionName of extensionNames) {
await createCache(compiledWalletSetupDirPath, () => prepareExtension(extensionName), flags.force); // Pass extensionName
}
Expand Down
1 change: 0 additions & 1 deletion wallets/keplr/src/KeplrWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class KeplrWallet {
page: Page,
) {
const homePage = new HomePage(page)
console.log('homePage', homePage, 1)
const walletAddress = await homePage.getWalletAddress()
return walletAddress;
}
Expand Down
8 changes: 8 additions & 0 deletions wallets/keplr/src/fixtureActions/unlockForFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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) {
const lockpage = new LockPage(page)
const wallet = await lockpage.unlock(seedPhrase, password)
return wallet;
}
44 changes: 19 additions & 25 deletions wallets/keplr/src/fixtures/keplrFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type Page, chromium } from '@playwright/test'

import { test as base } from '@playwright/test'
import { KeplrWallet } from '../KeplrWallet'
import { PASSWORD, SEED_PHRASE } from '../utils'
import { PASSWORD } from '../utils'
import {
CACHE_DIR_NAME,
createTempContextDir,
Expand All @@ -13,6 +13,7 @@ import {
import fs from 'fs-extra'
import { persistLocalStorage } from '../fixtureActions/persistLocalStorage'
import { prepareExtension, getExtensionId } from '../fixtureActions'
//import unlockForFixtures from '../fixtureActions/unlockForFixtures'

type KeplrFixtures = {
_contextPath: string
Expand All @@ -24,18 +25,17 @@ type KeplrFixtures = {
let _keplrPage: Page

export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>, slowMo = 0) => {
console.log('walletSetup', walletSetup)
return base.extend<KeplrFixtures>({
_contextPath: async ({ browserName }, use, testInfo) => {
const contextDir = await createTempContextDir(browserName, testInfo.testId)
await use(contextDir)
await removeTempContextDir(contextDir)
},
context: async ({ context: currentContext, _contextPath }, use) => {
console.log('walletSetup', walletSetup, process.cwd(), CACHE_DIR_NAME)
const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, '3dbe6a44c47cff706d19', 'context')
console.log('cacheDirPath', cacheDirPath)
const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, 'dbfc33f5185f468a2b25')
if (!(await fs.exists(cacheDirPath))) {
throw new Error(`Cache for ${walletSetup.hash} does not exist. Create it first!`)
throw new Error(`Cache for ${cacheDirPath} does not exist. Create it first!`)
}

// Copying the cache to the temporary context directory.
Expand All @@ -44,7 +44,6 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,
const keplrPath = await prepareExtension()
// We don't need the `--load-extension` arg since the extension is already loaded in the cache.
const browserArgs = [`--disable-extensions-except=${keplrPath}`]
console.log('keplrPath', keplrPath)
if (process.env.HEADLESS) {
browserArgs.push('--headless=new')

Expand All @@ -56,43 +55,38 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,
const context = await chromium.launchPersistentContext(_contextPath, {
headless: false,
args: browserArgs,
slowMo: process.env.HEADLESS ? 0 : slowMo
slowMo: process.env.HEADLESS ? 0 : 100000,
})


console.log("Cookies before login:", await context.cookies());
console.log('1')
const { cookies, origins } = await currentContext.storageState()

console.log('2')
if (cookies) {
await context.addCookies(cookies)
}
console.log('3', use)
if (origins && origins.length > 0) {
await persistLocalStorage(origins, context)
}

const extensionId = await getExtensionId(context, 'keplr')

_keplrPage = await context.newPage() as Page

await _keplrPage.goto('chrome-extension://' + extensionId + '/popup.html')

await use(context)

await context.close()
// console.log('4')
// // console.log('context', context, origins, cookies, currentContext, walletSetup)
// await use(context)
// console.log('5')
// await context.close()
// console.log('6')
},
page: async ({ context }, use) => {
const page = await context.newPage()
const extensionId = await getExtensionId(context, 'keplr')
await page.goto(`chrome-extension://${extensionId}/register.html`)

await use(page)
},
keplrPage: async ({ context: _ }, use) => {
await use(_keplrPage)
keplrPage: async ({ context }, use) => {
const keplrPage = await context.newPage();
await use(keplrPage);
},
keplr: async ({ context }, use) => {
const extensionId = await getExtensionId(context, 'keplr')
const keplrWallet = new KeplrWallet(_keplrPage, context, extensionId, PASSWORD)
await keplrWallet.setupWallet(_keplrPage, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD })
await use(keplrWallet)
},
})
Expand Down
27 changes: 14 additions & 13 deletions wallets/keplr/src/pages/LockPage/actions/importWallet.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { onboardingElements } from "../selectors";
import type { Page } from "@playwright/test";
import { sleep } from "../../../utils/helpers";

export async function importWallet(page: Page, secretWords: string, password: string) {
await page.waitForLoadState('domcontentloaded');

const importButton = await page.getByText(onboardingElements.importRecoveryPhraseButton);

await importButton.click();
const useButton = await page.getByText(onboardingElements.useRecoveryPhraseButton);
await useButton.click();
Expand All @@ -13,26 +16,24 @@ export async function importWallet(page: Page, secretWords: string, password: st
const inputFields = page.locator(onboardingElements.phraseInput);
const inputCount = await inputFields.count();
for (let i = 0; i < inputCount; i++) {
if (!wordsArray[i]) {
return;
}
const inputField = inputFields.nth(i);
await inputField.fill(wordsArray[i]!);
if (wordsArray[i]){
await inputField.fill(wordsArray[i]!);
}
}
const submitPhraseButton = await page.getByText(onboardingElements.submitPhraseButton);
const submitPhraseButton = await page.getByRole('button', { name: 'Import', exact: true });
await submitPhraseButton.click();
const walletInput = await page.locator(onboardingElements.walletInput);
await walletInput.fill(onboardingElements.walletName);
const passwordInput = await page.locator(onboardingElements.passwordInput);
await passwordInput.fill(password);
const confirmPasswordInput = await page.locator(onboardingElements.confirmPasswordInput);
await confirmPasswordInput.fill(password);
const submitWalletDataButton = await page.getByText(onboardingElements.submitWalletDataButton);
const submitWalletDataButton = await page.getByRole('button', { name: 'Next', exact: true });
await submitWalletDataButton.click();
const submitChainButton = await page.getByText(onboardingElements.submitChainButton);
await submitChainButton.click();
const phraseAccountCreated = await page.getByText(onboardingElements.phraseAccountCreated);
await phraseAccountCreated.click();
const finishButton = await page.getByText(onboardingElements.finishButton);
await finishButton.click();
}
const submitChainButton = await page.getByRole('button', { name: 'Save', exact: true });
await submitChainButton.click();
sleep(2000);
await page.close();
}

2 changes: 1 addition & 1 deletion wallets/keplr/src/pages/LockPage/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export const onboardingElements = {
submitChainButton: 'button[type="button"]',
finishButton: 'button[type="button"]',
textAreaSelector: 'textbox',
submitPhraseButton: 'button[type="submit"]',
submitPhraseButton: '.sc-bZkfAO jGdbNJ',
};
17 changes: 13 additions & 4 deletions wallets/keplr/test/playwright/getAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import test from '../synpress'
const { expect } = test
//const { expect } = test
import { getExtensionId } from '../../src/fixtureActions'
import { PASSWORD, SEED_PHRASE } from '../../src'

test.only('should get address', async ({ context, keplr }) => {
const extensionId = await getExtensionId(context, 'keplr')
console.log('6')
const page = await context.newPage()
console.log('7')
await keplr.setupWallet(page, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD })
console.log('8')
await page.goto(`chrome-extension://${extensionId}/popup.html`)
await keplr.getWalletAddress(page)

test.only('should get address', async ({ page, keplr }) => {
console.log('page', page, keplr)
expect(await keplr.getWalletAddress(page)).toBeTruthy()
})
2 changes: 0 additions & 2 deletions wallets/keplr/test/synpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ import { testWithSynpress } from "@synthetixio/synpress-core";
import { keplrFixtures } from "../src";
import connectedSetup from "./wallet-setup/connected-keplr.setup";

console.log('testWithSynpress', testWithSynpress, keplrFixtures, connectedSetup)

export default testWithSynpress(keplrFixtures(connectedSetup))
6 changes: 3 additions & 3 deletions wallets/keplr/test/wallet-setup/connected-keplr.setup.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { defineWalletSetup } from "@synthetixio/synpress-cache";
import { KeplrWallet } from "../../src";
import { getExtensionId, prepareExtension } from "../../src/fixtureActions";
import { getExtensionId } from "../../src/fixtureActions";

const SEED_PHRASE = 'orbit bench unit task food shock brand bracket domain regular warfare company announce wheel grape trust sphere boy doctor half guard ritual three ecology'
const PASSWORD = 'Test1234'

export default defineWalletSetup(PASSWORD, async (context, lockPage) => {
await prepareExtension()
const extensionId = await getExtensionId(context, 'keplr')
const keplr = new KeplrWallet(lockPage, context, PASSWORD, extensionId)

const page = await context.newPage()
await page.goto(`chrome-extension://${extensionId}/register.html`)
const keplr = new KeplrWallet(page, context, PASSWORD, extensionId)
await keplr.setupWallet(page, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD})
})

0 comments on commit 5baf24d

Please sign in to comment.