-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76c4c10
commit 3e77d9b
Showing
4 changed files
with
295 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,100 @@ | ||
import { MetaMask, metaMaskFixtures, testWithSynpress } from "@synthetixio/synpress"; | ||
import basicSetup from "./wallet-setup/basic.setup"; | ||
import { testWithSynpress } from "@synthetixio/synpress"; | ||
import { MetaMask, metaMaskFixtures } from "@synthetixio/synpress/playwright"; | ||
import basicSetup from "../test/wallet-setup/wallet-setup.setup"; | ||
|
||
const test = testWithSynpress(metaMaskFixtures(basicSetup)); | ||
|
||
const { expect } = test; | ||
|
||
test.beforeEach(async ({ context, page }) => { | ||
test.setTimeout(120000); | ||
|
||
await context.clearCookies(); | ||
await page.evaluate(() => window.localStorage.clear()); | ||
}); | ||
|
||
const TEST_WALLET_ADDRESS = "0xB5B3a244943E5A64511673528e003BE79B18901a"; | ||
const TEST_WALLET_ADDRESS = "0x8Bf421D4fe039000981ee77163eF777718af68e3"; | ||
|
||
test("should fetch credentials successfully", async ({ context, page, extensionId }) => { | ||
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId); | ||
|
||
test("should fetch credentials successfully", async ({ | ||
context, | ||
page, | ||
metamaskPage, | ||
extensionId, | ||
}) => { | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); | ||
await page.goto("/"); | ||
await page.getByRole("button", { name: "Connect a wallet" }).click(); | ||
await page.getByRole("button", { name: "Metamask" }).click(); | ||
await metamask.switchAccount("Account 1"); | ||
await metamask.connectToDapp(["Account 1"]); | ||
await page.getByRole("button", { name: "Metamask" }).first().click(); | ||
|
||
await metamask.connectToDapp(); | ||
await page.waitForTimeout(2000); | ||
await metamask.confirmSignature(); | ||
|
||
const list = page.locator("#credentials-list"); | ||
await expect(list.getByRole("listitem")).toHaveCount(2); | ||
await expect(list.getByRole("listitem")).toHaveCount(3); | ||
}); | ||
|
||
test("should fetch wallets successfully", async ({ context, page, metamaskPage, extensionId }) => { | ||
await page.goto("/wallets"); | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); | ||
test("should fetch wallets successfully", async ({ context, page, extensionId }) => { | ||
await page.goto("/"); | ||
const metamask = new MetaMask(context, page, basicSetup.walletPassword, extensionId); | ||
|
||
await page.getByRole("button", { name: "Connect a wallet" }).click(); | ||
await page.getByRole("button", { name: "Metamask" }).click(); | ||
await metamask.switchAccount("Account 1"); | ||
await metamask.connectToDapp(["Account 1"]); | ||
await page.waitForTimeout(3000); | ||
await page.getByRole("button", { name: "Metamask" }).first().click(); | ||
|
||
await metamask.connectToDapp(); | ||
await page.waitForTimeout(2000); | ||
await metamask.confirmSignature(); | ||
const list = page.locator("#wallets-list"); | ||
await expect(list.getByRole("listitem")).toHaveCount(1); | ||
const address = await metamask.getAccountAddress(); | ||
await expect(list.getByRole("listitem").first().locator("p").last()).toHaveText( | ||
address.toLocaleLowerCase(), // The address is stored in lowercase format in the idOS so we need to normalize the MetaMask address. | ||
); | ||
}); | ||
|
||
test("should add / delete a wallet successfully", async ({ | ||
context, | ||
page, | ||
metamaskPage, | ||
extensionId, | ||
}) => { | ||
await page.goto("/wallets"); | ||
const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword, extensionId); | ||
await page.getByRole("button", { name: "Connect a wallet" }).click(); | ||
await page.getByRole("button", { name: "Metamask" }).click(); | ||
await metamask.switchAccount("Account 1"); | ||
await metamask.connectToDapp(["Account 1"]); | ||
await page.getByTestId("wallets-link").click(); | ||
await page.waitForTimeout(3000); | ||
await metamask.confirmSignature(); | ||
// Testing wallet addition | ||
const addWalletButton = page.locator("#add-wallet-button"); | ||
await addWalletButton.click(); | ||
await page.locator("#address").fill(TEST_WALLET_ADDRESS); | ||
await page.locator("#add-wallet-form-submit").click(); | ||
await metamask.confirmSignature(); | ||
await page.waitForTimeout(5000); | ||
const list = page.locator("#wallets-list"); | ||
await expect(list.getByRole("listitem")).toHaveCount(2); | ||
|
||
// Testing wallet deletion | ||
const deleteButton = list.locator(`#delete-wallet-${TEST_WALLET_ADDRESS}`); | ||
await deleteButton.click(); | ||
await page.locator(`#confirm-delete-wallet-${TEST_WALLET_ADDRESS}`).click(); | ||
await metamask.confirmSignature(); | ||
await page.waitForTimeout(5000); | ||
await expect(list.getByRole("listitem")).toHaveCount(1); | ||
|
||
const walletListItems = await page.getByTestId("wallet-card"); | ||
const walletListItemsCount = await walletListItems.count(); | ||
|
||
const [connectedWallet] = await page.evaluate(() => | ||
// @ts-ignore for some reason using metamask.getAddress() is not working | ||
ethereum.request({ | ||
method: "eth_accounts", | ||
params: [], | ||
}), | ||
); | ||
await expect(walletListItemsCount).toBeGreaterThanOrEqual(1); | ||
// Check if the connected wallet exists in the list | ||
let walletFound = false; | ||
|
||
for (let i = 0; i < walletListItemsCount; i++) { | ||
const walletText = await walletListItems.nth(i).getByTestId("wallet-address").textContent(); | ||
|
||
if (walletText.toLowerCase() === connectedWallet.toLowerCase()) { | ||
walletFound = true; | ||
break; | ||
} | ||
} | ||
expect(walletFound).toBeTruthy(); | ||
}); | ||
|
||
// test("should add / delete a wallet successfully", async ({ | ||
// context, | ||
// page, | ||
// }) => { | ||
// await page.goto("/wallets"); | ||
// const metamask = new MetaMask(context, page, basicSetup.walletPassword); | ||
// await page.getByRole("button", { name: "Connect a wallet" }).click(); | ||
// await page.getByRole("button", { name: "Metamask" }).first().click(); | ||
// await metamask.switchAccount("Account 1"); | ||
// await metamask.connectToDapp(["Account 1"]); | ||
// await page.waitForTimeout(3000); | ||
// await metamask.confirmSignature(); | ||
// // Testing wallet addition | ||
// const addWalletButton = page.locator("#add-wallet-button"); | ||
// await addWalletButton.click(); | ||
// await page.locator("#address").fill(TEST_WALLET_ADDRESS); | ||
// await page.locator("#add-wallet-form-submit").click(); | ||
// await metamask.confirmSignature(); | ||
// await page.waitForTimeout(5000); | ||
// const list = page.locator("#wallets-list"); | ||
// await expect(list.getByRole("listitem")).toHaveCount(2); | ||
|
||
// // Testing wallet deletion | ||
// const deleteButton = list.locator(`#delete-wallet-${TEST_WALLET_ADDRESS}`); | ||
// await deleteButton.click(); | ||
// await page.locator(`#confirm-delete-wallet-${TEST_WALLET_ADDRESS}`).click(); | ||
// await metamask.confirmSignature(); | ||
// await page.waitForTimeout(5000); | ||
// await expect(list.getByRole("listitem")).toHaveCount(1); | ||
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.