Skip to content

Commit

Permalink
Adjust the code after the merge
Browse files Browse the repository at this point in the history
We're removing some code that became unnecessary after the merge from `main`.
We're also switching from onboarding using seed phrase to onboarding using JSON
file with encrypted private key.
  • Loading branch information
michalinacienciala committed Jul 21, 2023
1 parent bdf5b87 commit 8d1b96a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ jobs:
# tests on every PR update. We'll tag those tests with the `@expensive`
# tag.
- name: Run free Playwright tests
env:
TEST_WALLET_3RD_ADDRESS_JSON_BODY: ${{ secrets.TEST_WALLET_3RD_ADDRESS_JSON_BODY }}
TEST_WALLET_3RD_ADDRESS_JSON_PASSWORD: ${{ secrets.TEST_WALLET_3RD_ADDRESS_JSON_PASSWORD }}
run: xvfb-run npx playwright test --grep-invert @expensive
#env:
# DEBUG: pw:api*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { FeatureFlags } from "@tallyho/tally-background/features"
import { skipIfFeatureFlagged, test, expect } from "./utils"
import { account1Name, account2Name } from "./utils/onboarding"

skipIfFeatureFlagged(FeatureFlags.SUPPORT_UNVERIFIED_ASSET)
import fs from "fs"
import { test, expect } from "../utils"
import { account1Name } from "../utils/onboarding"

// This test verifies functionalites of verified/unverified tokens using a
// publicly known Mainnet wallet 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266.
Expand All @@ -20,13 +18,34 @@ test.describe("Token Trust", () => {
}) => {
await test.step("Import account and add addresses", async () => {
/**
* Onboard using walletPageHelper, with testertesting.eth account.
* Create a JSON file with an encoded private key based on the file
* content passed from an environment variable. The further steps of
* the test assume that the file encodes the pk of the `testertesting.eth`
* account. The JSON file can be generated using a script
* `scripts/key-generation/export-key-as-json.js`.
*/
const recoveryPhrase = process.env.RECOVERY_PHRASE
if (recoveryPhrase) {
await walletPageHelper.onboardWithSeedPhrase(recoveryPhrase)
const jsonBody = process.env.TEST_WALLET_3RD_ADDRESS_JSON_BODY
if (jsonBody) {
fs.writeFileSync("./e2e-tests/utils/JSON.json", jsonBody)
} else {
throw new Error("RECOVERY_PHRASE environment variable is not defined.")
throw new Error(
"TEST_WALLET_3RD_ADDRESS_JSON_BODY environment variable is not defined."
)
}

/**
* Onboard using JSON file.
*/
const jsonPassword = process.env.TEST_WALLET_3RD_ADDRESS_JSON_PASSWORD
if (jsonPassword) {
await walletPageHelper.onboardWithJSON(
"./e2e-tests/utils/JSON.json",
jsonPassword
)
} else {
throw new Error(
"TEST_WALLET_3RD_ADDRESS_JSON_PASSWORD environment variable is not defined."
)
}

await walletPageHelper.goToStartPage()
Expand All @@ -38,21 +57,10 @@ test.describe("Token Trust", () => {
await walletPageHelper.verifyCommonElements(
/^Ethereum$/,
false,
account2Name
account1Name
)
await walletPageHelper.verifyAnalyticsBanner()

/**
* Add addresses to the wallet.
*/
await walletPageHelper.addAddressToAccount("Import 1")
await walletPageHelper.addAddressToAccount("Import 1")

/**
* Switch to the 3rd address of the `Import 1` wallet.
*/
await walletPageHelper.switchToAddress("Import 1", 3, account1Name)

/**
* Switch to the Polygon network.
*/
Expand Down
84 changes: 60 additions & 24 deletions e2e-tests/utils/onboarding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BrowserContext, test as base, expect, Page } from "@playwright/test"
import * as path from "path"

export const getOnboardingPage = async (
context: BrowserContext
Expand Down Expand Up @@ -37,30 +38,6 @@ export default class OnboardingHelper {
public readonly context: BrowserContext
) {}

async getOnboardingPage(): Promise<Page> {
await expect(async () => {
const pages = this.context.pages()
const onboarding = pages.find((page) => /onboarding/.test(page.url()))

if (!onboarding) {
throw new Error("Unable to find onboarding tab")
}

expect(onboarding).toHaveURL(/onboarding/)
}).toPass()

const onboarding = this.context
.pages()
.find((page) => /onboarding/.test(page.url()))

if (!onboarding) {
// Should never happen
throw new Error("Onboarding page closed too early")
}

return onboarding
}

async addReadOnlyAccount(
addressOrName: string,
onboardingPage?: Page
Expand Down Expand Up @@ -114,6 +91,65 @@ export default class OnboardingHelper {
})
}

async addAccountFromJSON({
file,
filePassword,
onboardingPage,
}: {
file: string
filePassword: string
onboardingPage?: Page
}): Promise<void> {
const page = onboardingPage || (await getOnboardingPage(this.context))

await base.step("Onboard using JSON with private key", async () => {
await page.getByRole("button", { name: "Use existing wallet" }).click()
await page.getByRole("button", { name: "Import private key" }).click()

const passwordInput = page.locator('input[name="password"]')

if (await passwordInput.isVisible()) {
await page.locator('input[name="password"]').fill(DEFAULT_PASSWORD)
await page
.locator('input[name="confirm_password"]')
.fill(DEFAULT_PASSWORD)
}

await page.getByRole("button", { name: "Begin the hunt" }).click()

await page.getByTestId("panel_switcher").getByText("JSON").click()
// await page.getByText("Browse files").click()

// Start waiting for file chooser before clicking. Note no await.
const fileChooserPromise = page.waitForEvent("filechooser")
await page.getByText("Browse files").click({ force: true })
const fileChooser = await fileChooserPromise
await fileChooser.setFiles(file)

await expect(
page.getByTestId("file_status").getByText(path.basename(file))
).toBeVisible()
await expect(
page.getByText("Wrong file, only JSON accepted")
).toHaveCount(0)

await page.getByPlaceholder(" ").fill(filePassword)
await page.getByRole("button", { name: "Decrypt file" }).click()

await expect(page.getByTestId("loading_doggo")).toBeVisible()
await expect(page.getByText("Decrypting file...")).toBeVisible()
await expect(page.getByText("this may take up to 1 minute")).toBeVisible()

await expect(page.getByText("Completed!")).toBeVisible({ timeout: 60000 })

await page.getByRole("button", { name: "Finalize" }).click()

await expect(
page.getByRole("heading", { name: "Welcome to Taho" })
).toBeVisible()
})
}

async addNewWallet(onboardingPage?: Page): Promise<void> {
const page = onboardingPage || (await getOnboardingPage(this.context))

Expand Down
14 changes: 14 additions & 0 deletions e2e-tests/utils/walletPageHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ export default class WalletPageHelper {
await this.goToStartPage()
}

/**
* Onboard using JSON with password-encrypted private key
*/
async onboardWithJSON(file: string, filePassword: string): Promise<void> {
const onboardingPage = await getOnboardingPage(this.context)
await this.onboarding.addAccountFromJSON({
file,
filePassword,
onboardingPage,
})
await this.setViewportSize()
await this.goToStartPage()
}

async verifyTopWrap(network: RegExp, accountLabel: RegExp): Promise<void> {
// TODO: maybe we could also verify graphical elements (network icon, profile picture, etc)?

Expand Down

0 comments on commit 8d1b96a

Please sign in to comment.