Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSero committed Jun 19, 2024
1 parent b897897 commit 5671ba2
Show file tree
Hide file tree
Showing 47 changed files with 172 additions and 177 deletions.
9 changes: 4 additions & 5 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os from 'node:os'
import path from 'node:path'
import { WALLET_SETUP_DIR_NAME } from '@synthetixio/synpress-utils'
import { prepareExtension } from '@synthetixio/synpress-utils'
import chalk from 'chalk'
import { Command } from 'commander'
import { rimraf } from 'rimraf'
import { WALLET_SETUP_DIR_NAME } from '@synthetixio/synpress-utils'
import { createCache } from '../createCache'
import { prepareExtension } from '@synthetixio/synpress-utils'
import { compileWalletSetupFunctions } from './compileWalletSetupFunctions'
import { footer } from './footer'

Expand Down Expand Up @@ -53,7 +53,6 @@ export const cliEntrypoint = async () => {
console.log({ cacheDir: walletSetupDir, ...flags, headless: Boolean(process.env.HEADLESS) ?? false }, '\n')
}


const extensionsToSetup = () => {
const extensions = []
if (flags.keplr) {
Expand Down Expand Up @@ -84,10 +83,10 @@ export const cliEntrypoint = async () => {
console.log('extensions', extensionNames, 'walletSetupDir', walletSetupDir, 'flags', flags)
const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug)
for (const extensionName of extensionNames) {
await createCache(compiledWalletSetupDirPath, () => prepareExtension(extensionName), flags.force); // Pass extensionName
await createCache(compiledWalletSetupDirPath, () => prepareExtension(extensionName), flags.force) // Pass extensionName
}
// TODO: We should be using `prepareExtension` function from the wallet itself!

if (!flags.debug) {
await rimraf(compiledWalletSetupDirPath)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/cli/compileWalletSetupFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { ensureCacheDirExists } from '@synthetixio/synpress-utils'
import { glob } from 'glob'
import { build } from 'tsup'
import { ensureCacheDirExists } from '@synthetixio/synpress-utils'
import { FIXES_BANNER } from './compilationFixes'

const OUT_DIR_NAME = 'wallet-setup-dist'
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/src/synpress-utils.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module '@synthetixio/synpress-utils'
declare module '@synthetixio/synpress-utils'
2 changes: 1 addition & 1 deletion packages/cache/test/defineWalletSetup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { defineWalletSetup } from '@synthetixio/synpress-utils'
import { describe, expect, it } from 'vitest'

const PASSWORD = 'Quack Quack! 🦆'
const EXPECTED_HASH = 'f9c5ea5bb2c3aac96ff4'
Expand Down
3 changes: 0 additions & 3 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ export * from './utils/onDownloadProgress'
export * from './utils/triggerCacheCreation'
export * from './utils/waitForExtensionOnLoadPage'
export * from './utils/removeTempContextDir'



40 changes: 21 additions & 19 deletions packages/utils/src/prepareExtension.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import { downloadFile, ensureCacheDirExists, unzipArchive } from '.'

interface ExtensionConfig {
name: string;
version: string;
downloadUrl: string;
name: string
version: string
downloadUrl: string
}

async function getExtensionConfig(name: string): Promise<ExtensionConfig> {
const config = {
"extensions": [
extensions: [
{
"name": "MetaMask",
"version": "11.9.1",
"downloadUrl": "https://github.com/MetaMask/metamask-extension/releases/download/v11.9.1/metamask-chrome-11.9.1.zip"
name: 'MetaMask',
version: '11.9.1',
downloadUrl:
'https://github.com/MetaMask/metamask-extension/releases/download/v11.9.1/metamask-chrome-11.9.1.zip'
},
{
"name": "Keplr",
"version": "0.12.102",
"downloadUrl": "https://github.com/chainapsis/keplr-wallet/releases/download/v0.12.102/keplr-extension-manifest-v2-v0.12.102.zip"
name: 'Keplr',
version: '0.12.102',
downloadUrl:
'https://github.com/chainapsis/keplr-wallet/releases/download/v0.12.102/keplr-extension-manifest-v2-v0.12.102.zip'
}
]
}

const extension = config.extensions.find((ext: { name: string }) => ext.name === name);
const extension = config.extensions.find((ext: { name: string }) => ext.name === name)
if (!extension) {
throw new Error(`Extension configuration not found for ${name}`);
throw new Error(`Extension configuration not found for ${name}`)
}
return extension;
return extension
}

export async function prepareExtension(extensionName: string) {
const cacheDirPath = ensureCacheDirExists();
const extensionConfig = await getExtensionConfig(extensionName); // Get config
const cacheDirPath = ensureCacheDirExists()
const extensionConfig = await getExtensionConfig(extensionName) // Get config

const downloadResult = await downloadFile({
url: extensionConfig.downloadUrl,
outputDir: cacheDirPath,
fileName: `${extensionConfig.name.toLowerCase()}-chrome-${extensionConfig.version}.zip`
});
})

const unzipResult = await unzipArchive({
archivePath: downloadResult.filePath
});
})

return unzipResult.outputPath;
}
return unzipResult.outputPath
}
2 changes: 1 addition & 1 deletion release/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EthereumWalletMock, ethereumWalletMockFixtures } from '@synthetixio/ethereum-wallet-mock'
import { defineWalletSetup } from '@synthetixio/synpress-utils'
import { testWithSynpress } from '@synthetixio/synpress-core'
import { MetaMask, getExtensionId, metaMaskFixtures } from '@synthetixio/synpress-metamask'
import { defineWalletSetup } from '@synthetixio/synpress-utils'

export {
// Framework fixtures
Expand Down
14 changes: 6 additions & 8 deletions wallets/keplr/src/KeplrWallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type BrowserContext, type Page } from '@playwright/test'
import { LockPage } from './pages/LockPage/page'
import { HomePage } from './pages/HomePage/page'
import { LockPage } from './pages/LockPage/page'
import { NotificationPage } from './pages/NotificationPage/page'

export class KeplrWallet {
Expand All @@ -12,28 +12,26 @@ export class KeplrWallet {
readonly page: Page,
readonly context?: BrowserContext,
readonly password?: string,
readonly extensionId?: string | undefined,
readonly extensionId?: string | undefined
) {
this.lockPage = new LockPage(page)
this.homePage = new HomePage(page)
this.notificationPage = new NotificationPage(page)
}
/**
* Does initial setup for the wallet.
*
*
* @param playwrightInstance. The playwright instance to use.
* @param secretWordsOrPrivateKey. The secret words or private key to import.
* @param password. The password to set.
*/
async setupWallet(
{ secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string },
) {
async setupWallet({ secretWordsOrPrivateKey, password }: { secretWordsOrPrivateKey: string; password: string }) {
const wallet = await this.lockPage.importWallet(secretWordsOrPrivateKey, password)
return wallet;
return wallet
}

async getWalletAddress(wallet: string) {
const walletAddress = await this.homePage.getWalletAddress(wallet)
return walletAddress;
return walletAddress
}
}
2 changes: 1 addition & 1 deletion wallets/keplr/src/cypress/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as installSynpress } from './installSynpress'
export { default as installSynpress } from './installSynpress'
2 changes: 1 addition & 1 deletion wallets/keplr/src/cypress/initKeplrWallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type BrowserContext, type Page, chromium } from '@playwright/test'

import { KeplrWallet } from '../KeplrWallet'
import { SEED_PHRASE, PASSWORD } from '../utils'
import { PASSWORD, SEED_PHRASE } from '../utils'
import { MISSING_INIT, NO_CONTEXT, NO_PAGE } from './errors'

let context: BrowserContext | undefined
Expand Down
4 changes: 2 additions & 2 deletions wallets/keplr/src/cypress/setupTasks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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', {
Expand Down
2 changes: 1 addition & 1 deletion wallets/keplr/src/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
declare global {
namespace Cypress {
interface Chainable {
setupWallet({secretWordsOnPrivateKeys, password}: { secretWordsOnPrivateKeys: string, password: string }): any
setupWallet({ secretWordsOnPrivateKeys, password }: { secretWordsOnPrivateKeys: string; password: string }): Chainable<void>
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion wallets/keplr/src/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ import './commands'

Cypress.on('uncaught:exception', () => {
return false
})
})
2 changes: 1 addition & 1 deletion wallets/keplr/src/fixtureActions/getExtensionId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function getExtensionId(context: BrowserContext, extensionName: str
const allExtensions = Extensions.parse(unparsedExtensions)

const targetExtension = allExtensions.find(
(extension: any) => extension.name.toLowerCase() === extensionName.toLowerCase()
(extension: { name: string }) => extension.name.toLowerCase() === extensionName.toLowerCase()
)

if (!targetExtension) {
Expand Down
2 changes: 1 addition & 1 deletion wallets/keplr/src/fixtureActions/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './getExtensionId'
export * from './getExtensionId'
6 changes: 3 additions & 3 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 type { Page } from '@playwright/test'
import { LockPage } from '../pages/LockPage/page'

export default async function unlockForFixtures(page: Page, password: string) {
const lockpage = new LockPage(page)
const wallet = await lockpage.unlock(password)
return wallet;
}
return wallet
}
22 changes: 10 additions & 12 deletions wallets/keplr/src/fixtures/keplrFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import path from 'node:path'
import { type Page, chromium } from '@playwright/test'

import { test as base } from '@playwright/test'
import { KeplrWallet } from '../KeplrWallet'
import { PASSWORD } from '../utils'
import {
CACHE_DIR_NAME,
createTempContextDir,
defineWalletSetup,
removeTempContextDir
} from '@synthetixio/synpress-utils'
import { prepareExtension } from '@synthetixio/synpress-utils'
import fs from 'fs-extra'
import { persistLocalStorage } from '../fixtureActions/persistLocalStorage'
import { KeplrWallet } from '../KeplrWallet'
import { getExtensionId } from '../fixtureActions'
import { prepareExtension } from '@synthetixio/synpress-utils'
import { persistLocalStorage } from '../fixtureActions/persistLocalStorage'
import unlockForFixtures from '../fixtureActions/unlockForFixtures'
import { PASSWORD } from '../utils'

type KeplrFixtures = {
_contextPath: string
Expand All @@ -26,12 +26,11 @@ type KeplrFixtures = {
let _keplrPage: Page

export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>, slowMo = 0) => {

console.log(walletSetup, 'ee')
return base.extend<KeplrFixtures>({
_contextPath: async ({ browserName }, use, testInfo) => {
const contextDir = await createTempContextDir(browserName, testInfo.testId)

await use(contextDir)

const error = await removeTempContextDir(contextDir)
Expand Down Expand Up @@ -78,16 +77,15 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,
const extensionId = await getExtensionId(context, 'Keplr')

_keplrPage = context.pages()[0] as Page

await _keplrPage.goto(`chrome-extension://${extensionId}/popup.html`)

await unlockForFixtures(_keplrPage, PASSWORD)

await use(context)

},
keplrPage: async ({ context: _ }, use) => {
await use(_keplrPage);
await use(_keplrPage)
},
extensionId: async ({ context }, use) => {
const extensionId = await getExtensionId(context, 'Keplr')
Expand All @@ -103,6 +101,6 @@ export const keplrFixtures = (walletSetup: ReturnType<typeof defineWalletSetup>,
page: async ({ page }, use) => {
await page.goto('https://wallet.keplr.app/')
await use(page)
},
}
})
}
}
6 changes: 3 additions & 3 deletions wallets/keplr/src/pages/HomePage/actions/addNewTokensFound.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Page } from "@playwright/test";
import type { Page } from '@playwright/test'

export const addNewTokensFound = async (page: Page, switchScreens = true) => {
console.log('addNewTokensFound', switchScreens, page);
console.log('addNewTokensFound', switchScreens, page)
// if (switchScreens) {
// module.exports.switchToKeplrIfNotActive();
// await module.exports.goToHome();
// }

// await page.waitAndClickByText(homePageElements.newTokensFound);
// await playwright.waitAndClickWithDelay(
// homePageElements.selectAllTokensCheck,
Expand Down
6 changes: 3 additions & 3 deletions wallets/keplr/src/pages/HomePage/actions/getTokenAmount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Page } from "@playwright/test";
import type { Page } from '@playwright/test'

export const getTokenAmount = async (page: Page, tokenName: string) => {
console.log('getTokenAmount', tokenName, page);
console.log('getTokenAmount', tokenName, page)
// await module.exports.switchToKeplrIfNotActive();
// await module.exports.goToHome();

Expand All @@ -18,4 +18,4 @@ export const getTokenAmount = async (page: Page, tokenName: string) => {
// const parsedTokenValue = Number(tokenValue.replace(/,/g, ''));
// await playwright.switchToCypressWindow();
// return parsedTokenValue;
}
}
14 changes: 7 additions & 7 deletions wallets/keplr/src/pages/HomePage/actions/getWalletAddress.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Page } from '@playwright/test';
import { homePageElements } from '../selectors';
import type { Page } from '@playwright/test'
import { homePageElements } from '../selectors'

export const getWalletAddress = async (page: Page, wallet: string) => {
await page.waitForLoadState('domcontentloaded');
await page.getByText(homePageElements.copyAddress).click();
const chain = await page.waitForSelector(homePageElements.walletSelectors(wallet));
await chain.click();
await page.waitForLoadState('domcontentloaded')
await page.getByText(homePageElements.copyAddress).click()
const chain = await page.waitForSelector(homePageElements.walletSelectors(wallet))
await chain.click()

return 'no access to clipboard!'
}
}
6 changes: 3 additions & 3 deletions wallets/keplr/src/pages/HomePage/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './addNewTokensFound';
export * from './getWalletAddress';
export * from './getTokenAmount';
export * from './addNewTokensFound'
export * from './getWalletAddress'
export * from './getTokenAmount'
4 changes: 2 additions & 2 deletions wallets/keplr/src/pages/HomePage/page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Page } from '@playwright/test'
import { addNewTokensFound, getTokenAmount, getWalletAddress } from './actions'
import { homePageElements } from './selectors'
import { getTokenAmount, getWalletAddress, addNewTokensFound } from './actions'

export class HomePage {
static readonly selectors = homePageElements
Expand All @@ -15,7 +15,7 @@ export class HomePage {
async getTokenAmount() {
return await getTokenAmount(this.page, 'token name')
}

async getWalletAddress(wallet: string) {
return await getWalletAddress(this.page, wallet)
}
Expand Down
Loading

0 comments on commit 5671ba2

Please sign in to comment.