Skip to content

Commit

Permalink
updated tests workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-dubinin committed Dec 12, 2024
1 parent 2b9b78c commit 5611cf6
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 265 deletions.
56 changes: 52 additions & 4 deletions .github/workflows/frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
environment_url: ${{ steps.vercel.outputs.environment_url }}
run: echo "$environment_url"

preview-swap-tests:
preview-swap-osmo-tests:
timeout-minutes: 15
runs-on: macos-latest
needs: wait-for-deployment
Expand Down Expand Up @@ -65,13 +65,61 @@ jobs:
WALLET_ID: ${{ secrets.TEST_WALLET_ID }}
run: |
cd packages/e2e
npx playwright test -g "Test Swap feature"
npx playwright test swap.osmo.wallet
- name: upload Swap test results
if: failure()
id: swap-test-results
uses: actions/upload-artifact@v4
with:
name: preview-swap-test-results
name: osmo-swap-test-results
path: packages/e2e/playwright-report

preview-swap-usdc-tests:
timeout-minutes: 15
runs-on: macos-latest
needs: [wait-for-deployment, preview-swap-osmo-tests]
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
sparse-checkout: |
packages/e2e
- name: print environment_url and BRANCH_NAME
env:
BASE_URL: "https://${{ needs.wait-for-deployment.outputs.environment_url }}"
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
run: |
echo "$BASE_URL"
echo "$BRANCH_NAME"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Cache dependencies
uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.OS }}-20.x-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-20.x-
- name: Install Playwright
run: |
echo "$GITHUB_OUTPUT"
yarn --cwd packages/e2e install --frozen-lockfile && npx playwright install --with-deps chromium
- name: Run Swap Pair tests
env:
BASE_URL: "https://${{ needs.wait-for-deployment.outputs.environment_url }}"
PRIVATE_KEY: ${{ secrets.TEST_PRIVATE_KEY }}
WALLET_ID: ${{ secrets.TEST_WALLET_ID }}
run: |
cd packages/e2e
npx playwright test swap.usdc.wallet
- name: upload Swap test results
if: failure()
id: swap-test-results
uses: actions/upload-artifact@v4
with:
name: usdc-swap-test-results
path: packages/e2e/playwright-report

preview-portfolio-trx-tests:
Expand Down Expand Up @@ -155,7 +203,7 @@ jobs:
preview-trade-tests:
timeout-minutes: 15
runs-on: macos-latest
needs: [wait-for-deployment, preview-swap-tests]
needs: [wait-for-deployment, preview-swap-osmo-tests]
steps:
- name: Check out repository
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prod-frontend-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
WALLET_ID: ${{ secrets.TEST_WALLET_ID }}
run: |
cd packages/e2e
npx playwright test transactions portfolio swap.wallet
npx playwright test transactions portfolio swap.osmo.wallet
- name: upload test results
if: always()
id: e2e-test-results
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ All you need to add is a private keys for wallets that are being used:
To install Playwright, please execute `npx playwright install --with-deps chromium` from the /web folder.

To run a Select pair tests, please execute `npx playwright test -g "Test Select Swap Pair feature"` from the /web folder.
To run a Swap E2E tests, please execute `npx playwright test -g "Test Swap feature"` from the /web folder.
To run a Swap E2E tests, please execute `npx playwright test swap.osmo.wallet` from the /web folder.
To run a Monitoring E2E tests, please execute `npx playwright test monitoring --timeout 180000` from the /web folder.

Tests can be executed locally in a browser by changing `headless: true` to `headless: false`.
Expand Down
94 changes: 94 additions & 0 deletions packages/e2e/tests/swap.osmo.wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { type BrowserContext, chromium, expect, test } from "@playwright/test";

import { TestConfig } from "../test-config";
import { UnzipExtension } from "../unzip-extension";

import { WalletPage } from "../pages/keplr-page";
import { TradePage } from "../pages/trade-page";

test.describe("Test Swap to/from OSMO feature", () => {
let context: BrowserContext;
const walletId =
process.env.WALLET_ID ?? "osmo1qyc8u7cn0zjxcu9dvrjz5zwfnn0ck92v62ak9l";
const privateKey = process.env.PRIVATE_KEY ?? "private_key";
let tradePage: TradePage;
const USDC =
"ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4";
const ATOM =
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2";
const TIA =
"ibc/D79E7D83AB399BFFF93433E54FAA480C191248FC556924A2A8351AE2638B3877";
const INJ =
"ibc/64BA6E31FE887D66C6F8F31C7B1A80C7CA179239677B4088BB55F5EA07DBE273";
const AKT =
"ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4";

test.beforeAll(async () => {
const pathToExtension = new UnzipExtension().getPathToExtension();
console.log("\nSetup Wallet Extension before tests.");
// Launch Chrome with a Keplr wallet extension
context = await chromium.launchPersistentContext(
"",
new TestConfig().getBrowserExtensionConfig(false, pathToExtension)
);
// Get all new pages (including Extension) in the context and wait
const emptyPage = context.pages()[0];
await emptyPage.waitForTimeout(2000);
const page = context.pages()[1];
const walletPage = new WalletPage(page);
// Import existing Wallet (could be aggregated in one function).
await walletPage.importWalletWithPrivateKey(privateKey);
await walletPage.setWalletNameAndPassword("Test Swaps");
await walletPage.selectChainsAndSave();
await walletPage.finish();
// Switch to Application
tradePage = new TradePage(context.pages()[0]);
await tradePage.goto();
await tradePage.connectWallet();
expect(await tradePage.isError(), "Swap is not available!").toBeFalsy();
});

test.afterAll(async () => {
await context.close();
});

test("User should be able to swap OSMO to WBTC", async () => {
await tradePage.goto();
await tradePage.selectPair("OSMO", "WBTC");
await tradePage.enterAmount("0.9");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain("denom: uosmo");
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap OSMO to ATOM", async () => {
await tradePage.goto();
await tradePage.selectPair("OSMO", "ATOM");
await tradePage.enterAmount("0.2");
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`token_out_denom: ${ATOM}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain("denom: uosmo");
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap ATOM to OSMO", async () => {
await tradePage.goto();
await tradePage.selectPair("ATOM", "OSMO");
await tradePage.enterAmount("0.01");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${ATOM}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain("token_out_denom: uosmo");
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});
});
194 changes: 194 additions & 0 deletions packages/e2e/tests/swap.usdc.wallet.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
import { type BrowserContext, chromium, expect, test } from "@playwright/test";

import { TestConfig } from "../test-config";
import { UnzipExtension } from "../unzip-extension";

import { WalletPage } from "../pages/keplr-page";
import { TradePage } from "../pages/trade-page";

test.describe("Test Swap to/from USDC feature", () => {
let context: BrowserContext;
const walletId =
process.env.WALLET_ID ?? "osmo1qyc8u7cn0zjxcu9dvrjz5zwfnn0ck92v62ak9l";
const privateKey = process.env.PRIVATE_KEY ?? "private_key";
let tradePage: TradePage;
const USDC =
"ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4";
const ATOM =
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2";
const TIA =
"ibc/D79E7D83AB399BFFF93433E54FAA480C191248FC556924A2A8351AE2638B3877";
const INJ =
"ibc/64BA6E31FE887D66C6F8F31C7B1A80C7CA179239677B4088BB55F5EA07DBE273";
const AKT =
"ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4";

test.beforeAll(async () => {
const pathToExtension = new UnzipExtension().getPathToExtension();
console.log("\nSetup Wallet Extension before tests.");
// Launch Chrome with a Keplr wallet extension
context = await chromium.launchPersistentContext(
"",
new TestConfig().getBrowserExtensionConfig(false, pathToExtension)
);
// Get all new pages (including Extension) in the context and wait
const emptyPage = context.pages()[0];
await emptyPage.waitForTimeout(2000);
const page = context.pages()[1];
const walletPage = new WalletPage(page);
// Import existing Wallet (could be aggregated in one function).
await walletPage.importWalletWithPrivateKey(privateKey);
await walletPage.setWalletNameAndPassword("Test Swaps");
await walletPage.selectChainsAndSave();
await walletPage.finish();
// Switch to Application
tradePage = new TradePage(context.pages()[0]);
await tradePage.goto();
await tradePage.connectWallet();
expect(await tradePage.isError(), "Swap is not available!").toBeFalsy();
});

test.afterAll(async () => {
await context.close();
});

test("User should be able to swap OSMO to USDC", async () => {
await tradePage.goto();
await tradePage.selectPair("OSMO", "USDC");
await tradePage.enterAmount("0.2");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`token_out_denom: ${USDC}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain("denom: uosmo");
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap USDC to OSMO", async () => {
await tradePage.goto();
await tradePage.selectPair("USDC", "OSMO");
await tradePage.enterAmount("0.1");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain("token_out_denom: uosmo");
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`denom: ${USDC}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap ATOM to USDC", async () => {
await tradePage.goto();
await tradePage.selectPair("ATOM", "USDC");
await tradePage.enterAmount("0.015");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${ATOM}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${USDC}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap USDC to ATOM", async () => {
await tradePage.goto();
await tradePage.selectPair("USDC", "ATOM");
await tradePage.enterAmount("0.1");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${USDC}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${ATOM}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap USDC to TIA", async () => {
await tradePage.goto();
await tradePage.selectPair("USDC", "TIA");
await tradePage.enterAmount("0.1");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${USDC}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${TIA}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap TIA to USDC", async () => {
await tradePage.goto();
await tradePage.selectPair("TIA", "USDC");
await tradePage.enterAmount("0.02");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${TIA}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${USDC}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap USDC to INJ", async () => {
await tradePage.goto();
await tradePage.selectPair("USDC", "INJ");
await tradePage.enterAmount("0.2");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${USDC}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${INJ}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap INJ to USDC", async () => {
await tradePage.goto();
await tradePage.selectPair("INJ", "USDC");
await tradePage.enterAmount("0.01");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${INJ}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${USDC}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap USDC to AKT", async () => {
await tradePage.goto();
await tradePage.selectPair("USDC", "AKT");
await tradePage.enterAmount("0.1");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${USDC}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${AKT}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});

test("User should be able to swap AKT to USDC", async () => {
await tradePage.goto();
await tradePage.selectPair("AKT", "USDC");
await tradePage.enterAmount("0.025");
await tradePage.showSwapInfo();
const { msgContentAmount } = await tradePage.swapAndGetWalletMsg(context);
expect(msgContentAmount).toBeTruthy();
expect(msgContentAmount).toContain(`denom: ${AKT}`);
expect(msgContentAmount).toContain(`sender: ${walletId}`);
expect(msgContentAmount).toContain(`token_out_denom: ${USDC}`);
await tradePage.isTransactionSuccesful();
await tradePage.getTransactionUrl();
});
});
Loading

0 comments on commit 5611cf6

Please sign in to comment.