Skip to content

Commit

Permalink
hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSero committed Jun 17, 2024
1 parent c5cec19 commit fd48092
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 47 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"private": true,
"scripts": {
"build": "turbo build",
"build:cache": "turbo build:cache --filter=@synthetixio/synpress-metamask -- -m",
"build:cache:keplr": "turbo build:cache --filter=@synthetixio/synpress-keplr -- -k",
"build:cache": "turbo build:cache --filter=@synthetixio/synpress-metamask",
"build:cache:keplr": "turbo build:cache --filter=@synthetixio/synpress-keplr",
"docs:build": "turbo docs:build --filter=docs",
"format": "biome format . --write",
"format:check": "biome format . --error-on-warnings",
Expand Down
8 changes: 4 additions & 4 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const cliEntrypoint = async () => {
.helpOption(undefined, 'Display help for command')
.addHelpText('afterAll', `\n${footer}\n`)
.parse(process.argv)

console.log(WALLET_SETUP_DIR_NAME, program.args[0])
let walletSetupDir = program.args[0]
if (!walletSetupDir) {
walletSetupDir = path.join(process.cwd(), 'test', WALLET_SETUP_DIR_NAME)
Expand Down Expand Up @@ -67,8 +67,8 @@ export const cliEntrypoint = async () => {
}
let extensionNames = extensionsToSetup()

if (!extensionNames) {
extensionNames = ['MetaMask']
if (!extensionNames.length) {
extensionNames = ['Keplr']
}

if (os.platform() === 'win32') {
Expand All @@ -84,7 +84,7 @@ 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
12 changes: 11 additions & 1 deletion wallets/keplr/src/KeplrWallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type BrowserContext, type Page } from '@playwright/test'
import { LockPage } from './pages/LockPage/page'
import { HomePage } from './pages/HomePage/page'

export class KeplrWallet {
seedPhrase = ''
Expand Down Expand Up @@ -37,11 +38,20 @@ export class KeplrWallet {
* @param password. The password to set.
*/
async setupWallet(
page: any,
page: Page,
{ secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string },
) {
const lockpage = new LockPage(page)
const wallet = await lockpage.unlock(secretWordsOrPrivateKey, password)
return wallet;
}

async getWalletAddress(
page: Page,
) {
const homePage = new HomePage(page)
console.log('homePage', homePage, 1)
const walletAddress = await homePage.getWalletAddress()
return walletAddress;
}
}
12 changes: 6 additions & 6 deletions wallets/keplr/src/cypress/setupTasks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PASSWORD, SEED_PHRASE } from "../utils"
import { getKeplrWallet } from "./initKeplrWallet"
// import { PASSWORD, SEED_PHRASE } from "../utils"
// import { getKeplrWallet } from "./initKeplrWallet"

export default function setupTasks(on: Cypress.PluginEvents) {
on('task', {
importWallet: async function () {
const keplrWallet = getKeplrWallet()
if (keplrWallet) {
await keplrWallet.setupWallet(null, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD })
}
// const keplrWallet = getKeplrWallet()
// if (keplrWallet) {
// await keplrWallet.setupWallet(null, { secretWordsOrPrivateKey: SEED_PHRASE, password: PASSWORD })
// }
return true
}
})
Expand Down
12 changes: 7 additions & 5 deletions wallets/keplr/src/fixtures/keplrFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { prepareExtension, getExtensionId } from '../fixtureActions'
type KeplrFixtures = {
_contextPath: string
keplr: KeplrWallet
extensionId: string
keplrPage: Page
extensionId: string
}

let _keplrPage: Page
Expand All @@ -31,7 +31,8 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,
await removeTempContextDir(contextDir)
},
context: async ({ context: currentContext, _contextPath }, use) => {
const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash)
console.log('walletSetup', walletSetup, process.cwd(), CACHE_DIR_NAME)
const cacheDirPath = path.join(process.cwd(), CACHE_DIR_NAME, walletSetup.hash, 'context')
if (!(await fs.exists(cacheDirPath))) {
throw new Error(`Cache for ${walletSetup.hash} does not exist. Create it first!`)
}
Expand Down Expand Up @@ -79,15 +80,16 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,
},
page: async ({ context }, use) => {
const page = await context.newPage()

await page.goto('/')
const extensionId = await getExtensionId(context, 'keplr')
await page.goto(`chrome-extension://${extensionId}/register.html`)

await use(page)
},
keplrPage: async ({ context: _ }, use) => {
await use(_keplrPage)
},
keplr: async ({ context, extensionId }, use) => {
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
33 changes: 12 additions & 21 deletions wallets/keplr/src/pages/HomePage/actions/getWalletAddress.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import type { Page } from '@playwright/test';
import { homePageElements } from '../selectors';

export const getWalletAddress = async (page: Page) => {
console.log('getWalletAddress', page);
// return await playwright.waitAndGetValue(homePageElements.walletAddress);
// playwright.switchToKeplrWindow();
// await module.exports.goToHome();
// const newTokensSelctorExists =
// await playwright.waitForAndCheckElementExistence(
// homePageElements.newTokensFoundSelector,
// );

// if (newTokensSelctorExists) {
// await module.exports.addNewTokensFound(false);
// }

// await playwright.waitAndClickByText(notificationPageElements.copyAddress);
// await playwright.waitAndClick(
// notificationPageElements.walletSelectors(chainName),
// );

// walletAddress = clipboardy.readSync();
// await playwright.switchToCypressWindow();
// return walletAddress;
await page.waitForLoadState('domcontentloaded');
console.log(3)
const newTokensFoundSelector = await page.waitForSelector(homePageElements.newTokensFoundSelector);
console.log('New tokens found', newTokensFoundSelector);
if (newTokensFoundSelector) {
await page.waitForSelector(homePageElements.newTokensFoundSelector);
}
await page.waitForSelector(homePageElements.copyAddress);
const walletAddress = await page.click(homePageElements.copyAddress);
console.log('Wallet address copied', walletAddress);
return walletAddress;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import { notificationPageElements } from '../selectors';

export const acceptAccess = async () => {
console.log('Accepting access in Keplr wallet', notificationPageElements);
// const notificationPage = await playwright.switchToKeplrNotification();
// await playwright.waitAndClick(
// notificationPageElements.approveButton,
// notificationPage,
// { waitForEvent: 'close' },
// );
// return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { notificationPageElements } from "../selectors";

export const confirmTransaction = async () => {
console.log('Confirming transaction in Keplr wallet', notificationPageElements)
// const notificationPage = await playwright.switchToKeplrNotification();
// await playwright.waitAndClick(
// notificationPageElements.approveButton,
// notificationPage,
// { waitForEvent: 'close' },
// );
return true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './acceptAccess';
export * from './confirmAccess';
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Page } from '@playwright/test'
import { notificationPageElements } from './selectors'
import { confirmTransaction, acceptAccess } from './actions'

export class NotificationPage {
static readonly selectors = notificationPageElements
readonly selectors = notificationPageElements

readonly page: Page

constructor(page: Page) {
this.page = page
}

async confirmTransaction() {
await confirmTransaction()
}

async acceptAccess() {
await acceptAccess()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const notificationPageElements = {
approveButton: 'button',
copyAddress: 'Copy Address',
walletSelectors: (chainName: string) => `img[alt="${chainName}"]`,
};
1 change: 1 addition & 0 deletions wallets/keplr/src/pages/HomePage/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const homePageElements = {
newTokensFound: 'new token(s) found',
addChainsButton: 'Add Chains',
newTokensFoundSelector: 'text=new token(s) found',
copyAddress: 'Copy Address',
}
8 changes: 0 additions & 8 deletions wallets/keplr/test/playwright/addAccount.spec.ts

This file was deleted.

7 changes: 7 additions & 0 deletions wallets/keplr/test/playwright/getAddress.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from '../synpress'
const { expect } = test

test.only('should get address', async ({ page, keplr }) => {
console.log('page', page, keplr)
expect(await keplr.getWalletAddress(page)).toBeTruthy()
})
2 changes: 2 additions & 0 deletions wallets/keplr/test/synpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ 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))
9 changes: 9 additions & 0 deletions wallets/keplr/test/wallet-setup/connected-wallet.setup.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export declare const SEED_PHRASE = 'test test test test test test test test test test test junk'
export declare const PASSWORD = 'Tester@1234'
declare const _default: {
hash: string
fn: import('@synthetixio/synpress-cache').WalletSetupFunction
walletPassword: string
}
export default _default
//# sourceMappingURL=basic.setup.d.ts.map

0 comments on commit fd48092

Please sign in to comment.