Skip to content

Commit

Permalink
Feature/microapps prod checks (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariuszSzpyt authored Dec 6, 2023
1 parent c5112a3 commit bfb62a2
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 37 deletions.
71 changes: 34 additions & 37 deletions .github/workflows/ui-prod-smoke-test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: dex UI prod smoke tests
name: Microapps UI prod smoke tests

on:

workflow_dispatch:

# repository_dispatch:
# Goncer: Old app is decomissioned types: [run-ci]
schedule:
- cron: "5 10 * * *"
jobs:

setup-report:
name: setup testmo report
runs-on: ubuntu-latest
Expand Down Expand Up @@ -49,24 +46,24 @@ jobs:
strategy:
fail-fast: false
matrix:
command: ['prodUiSmoke']
command: ["first"]
runs-on: ubuntu-latest
env:
API_URL: 'wss://kusama-rpc.mangata.online'
API_URL: "wss://kusama-rpc.mangata.online"
UI_URL: https://app.mangata.finance/
TEST_SUDO_NAME: ${{ secrets.DEV_SUDO_NAME }}
MNEMONIC_POLK: ${{ secrets.MNEMONIC_PROD_POLK }}
TEST_SCRIPT: 'test-ui'
TEST_SCRIPT: "test-ui"
NODE_ENV: test
SELENIUM_REMOTE_URL: http://localhost:4444/wd/hub

steps:
steps:
- name: Start Selenoid Server
uses: Xotabu4/selenoid-github-action@v2
with:
selenoid-start-arguments: |
--args "-timeout 300s" --browsers 'chrome:110.0;chrome:112.0;chrome:114.0'
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
Expand All @@ -80,34 +77,34 @@ jobs:
- name: Tsc code quality check
run: yarn tsc-lint
- name: ESLint code quality check
run: yarn eslint
run: yarn eslint
- name: installed packages
run: yarn list

- name: is selenoid started?
run: curl http://localhost:4444/status

- name: Run tests
run: yarn test-ui --group=${{ matrix.command }}
run: yarn test-microapps-prod-${{ matrix.command }}

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
if: success() || failure() # run this step even if previous step failed
with:
name: JEST UI Tests ${{ matrix.command }} # Name of the check run which will be created
path: reports/*.xml # Path to test results
reporter: jest-junit # Format of test results
name: JEST UI Tests ${{ matrix.command }} # Name of the check run which will be created
path: reports/*.xml # Path to test results
reporter: jest-junit # Format of test results

- name: Install testmo
run: npm install --no-save @testmo/testmo-cli
run: yarn global add @testmo/testmo-cli

- name: Submit results to the testmo-run
if: always()
run: |
testmo automation:run:submit-thread \
--instance https://mangata-finance.testmo.net \
--run-id ${{needs.setup-report.outputs.testmo-run-id}} \
--results reports/*.xml
testmo automation:run:submit-thread \
--instance https://mangata-finance.testmo.net \
--run-id ${{needs.setup-report.outputs.testmo-run-id}} \
--results reports/*.xml
env:
TESTMO_URL: ${{ secrets.TESTMO_URL }}
TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }}
Expand Down Expand Up @@ -148,20 +145,20 @@ jobs:

steps:
- name: Install testmo
run: npm install --no-save @testmo/testmo-cli
run: yarn global add @testmo/testmo-cli

- name: Complete test run
run: |
npx testmo automation:run:complete \
--instance https://mangata-finance.testmo.net \
--run-id ${{needs.setup-report.outputs.testmo-run-id}} \
npx testmo automation:run:complete \
--instance https://mangata-finance.testmo.net \
--run-id ${{needs.setup-report.outputs.testmo-run-id}} \
env:
TESTMO_URL: ${{ secrets.TESTMO_URL }}
TESTMO_TOKEN: ${{ secrets.TESTMO_TOKEN }}
continue-on-error: true

slack-notify-ok:
needs: [e2e-test-matrix]
needs: [e2e-test-matrix, setup-report]
if: success()
runs-on: ubuntu-latest

Expand All @@ -171,11 +168,11 @@ jobs:
uses: bryannice/[email protected]
env:
SLACK_INCOMING_WEBHOOK: ${{ secrets.STG_SLACK_WEBHOOK }}
SLACK_TITLE: 'PROD dex smoke UI tests - results - OK'
SLACK_TITLE: "PROD Microapps smoke UI tests - results - OK"
SLACK_COLOR: "#00ff11"
SLACK_MESSAGE: 'Test succeed in [ ${{ env.TEST_SCRIPT }} ]
testmo report: https://mangata-finance.testmo.net/automation/runs/view/${{needs.setup-report.outputs.testmo-run-id}}'
GITHUB_REF: 'https://mangata-finance.github.io/mangata-e2e/${{ github.run_number }}'
SLACK_MESSAGE: "Test succeed in [ ${{ env.TEST_SCRIPT }} ]
testmo report: https://mangata-finance.testmo.net/automation/runs/view/${{needs.setup-report.outputs.testmo-run-id}}"
GITHUB_REF: "https://mangata-finance.github.io/mangata-e2e/${{ github.run_number }}"

slack-notify-nook:
needs: [e2e-test-matrix]
Expand All @@ -187,8 +184,8 @@ jobs:
uses: bryannice/[email protected]
env:
SLACK_INCOMING_WEBHOOK: ${{ secrets.STG_SLACK_WEBHOOK }}
SLACK_TITLE: 'PROD dex smoke UI tests - results - NOOK'
SLACK_TITLE: "PROD Microapps smoke UI tests - results - NOOK"
SLACK_COLOR: "#ff0011"
SLACK_MESSAGE: 'Test failures [ ${{ env.TEST_SCRIPT }} ]
testmo report: https://mangata-finance.testmo.net/automation/runs/view/${{needs.setup-report.outputs.testmo-run-id}}'
GITHUB_REF: 'https://mangata-finance.github.io/mangata-e2e/${{ github.run_number }}'
SLACK_MESSAGE: "Test failures [ ${{ env.TEST_SCRIPT }} ]
testmo report: https://mangata-finance.testmo.net/automation/runs/view/${{needs.setup-report.outputs.testmo-run-id}}"
GITHUB_REF: "https://mangata-finance.github.io/mangata-e2e/${{ github.run_number }}"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"test-microapps-chops-second": "export CHOPSTICK_UI=true ; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --ci --group=microappsTokens --group=microappsSwap --group=microappsPools",
"test-microapps-chops-third": "export CHOPSTICK_UI=true ; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --ci --group=microappsAccounts",
"test-microapps-chops-fourth": "export CHOPSTICK_UI=true ; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --ci --group=microappsPosition",
"test-microapps-prod-first": "export CHOPSTICK_UI=true ; rm nonce.db ; rm sudo.lock; node --experimental-specifier-resolution=node --loader ts-node/esm --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --runInBand --ci --group=microappsProdDeposit --group=microappsProdSwap --group=microappsProdWallet --group=microappsProdWithdraw",
"runtimeUpgrade": " jest --verbose --ci --group=upgradeRuntime --runInBand --forceExit"
},
"devDependencies": {
Expand Down
108 changes: 108 additions & 0 deletions test/microapps-prod/microapps-prod-main.deposit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
*
* @group microappsProdDeposit
*/
import { jest } from "@jest/globals";
import { Keyring } from "@polkadot/api";
import { WebDriver } from "selenium-webdriver";
import { getApi, initApi } from "../../utils/api";
import { DriverBuilder } from "../../utils/frontend/utils/Driver";
import {
addExtraLogs,
importPolkadotExtension,
} from "../../utils/frontend/utils/Helper";
import { AssetWallet, User } from "../../utils/User";
import { getEnvironmentRequiredVars } from "../../utils/utils";
import { KSM_ASSET_ID, MGA_ASSET_ID } from "../../utils/Constants";
import { Node } from "../../utils/Framework/Node/Node";
import "dotenv/config";
import {
connectWallet,
setupPage,
setupPageWithState,
} from "../../utils/frontend/microapps-utils/Handlers";
import { DepositModal } from "../../utils/frontend/microapps-pages/DepositModal";
import { WalletWrapper } from "../../utils/frontend/microapps-pages/WalletWrapper";

jest.spyOn(console, "log").mockImplementation(jest.fn());

jest.setTimeout(1500000);
let driver: WebDriver;
let testUser1: User;

const acc_name = "acc_automation";
const KSM_ASSET_NAME = "KSM";

describe("Microapps Prod UI deposit modal tests", () => {
beforeAll(async () => {
try {
getApi();
} catch (e) {
await initApi();
}

driver = await DriverBuilder.getInstance();
await importPolkadotExtension(driver);

const keyring = new Keyring({ type: "sr25519" });
const node = new Node(getEnvironmentRequiredVars().chainUri);
await node.connect();

testUser1 = new User(keyring);
testUser1.addFromMnemonic(
keyring,
getEnvironmentRequiredVars().mnemonicPolkadot,
);

testUser1.addAsset(KSM_ASSET_ID);
testUser1.addAsset(MGA_ASSET_ID);
await testUser1.refreshAmounts(AssetWallet.BEFORE);

await setupPage(driver);
await connectWallet(driver, "Polkadot", acc_name);
});

test("Deposit - not enough assets", async () => {
await setupPageWithState(driver, acc_name);

const walletWrapper = new WalletWrapper(driver);
await walletWrapper.openWalletConnectionInfo();
await walletWrapper.openDeposit();
const depositModal = new DepositModal(driver);
const isModalVisible = await depositModal.isModalVisible();
expect(isModalVisible).toBeTruthy();

await depositModal.openChainList();
await depositModal.selectChain("Kusama");
await depositModal.openTokensList();
await depositModal.waitForTokenListElementsVisible(KSM_ASSET_NAME);
await depositModal.selectToken(KSM_ASSET_NAME);
await depositModal.enterValue("1");

await depositModal.waitForContinueState(false, 60000);
const isOriginFeeDisplayed = await depositModal.isOriginFeeDisplayed();
expect(isOriginFeeDisplayed).toBeTruthy();
const isDestinationFeeDisplayed =
await depositModal.isDestinationFeeDisplayed();
expect(isDestinationFeeDisplayed).toBeTruthy();

const isContinueButtonEnabled =
await depositModal.isContinueButtonEnabled();
expect(isContinueButtonEnabled).toBeFalsy();
});

afterEach(async () => {
const session = await driver.getSession();
await addExtraLogs(
driver,
expect.getState().currentTestName + " - " + session.getId(),
);
});

afterAll(async () => {
const api = getApi();
await api.disconnect();
await driver.quit();
DriverBuilder.destroy();
});
});
122 changes: 122 additions & 0 deletions test/microapps-prod/microapps-prod-main.swap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
*
* @group microappsProdSwap
*/
import { jest } from "@jest/globals";
import { WebDriver } from "selenium-webdriver";
import { getApi, initApi } from "../../utils/api";
import { DriverBuilder } from "../../utils/frontend/utils/Driver";
import { Node } from "../../utils/Framework/Node/Node";
import {
addExtraLogs,
importPolkadotExtension,
} from "../../utils/frontend/utils/Helper";
import { Keyring } from "@polkadot/api";
import { FIVE_MIN, KSM_ASSET_ID, MGA_ASSET_ID } from "../../utils/Constants";
import { AssetWallet, User } from "../../utils/User";
import { getEnvironmentRequiredVars } from "../../utils/utils";
import {
connectWallet,
setupPage,
setupPageWithState,
} from "../../utils/frontend/microapps-utils/Handlers";
import { Swap } from "../../utils/frontend/microapps-pages/Swap";

jest.setTimeout(FIVE_MIN);
jest.spyOn(console, "log").mockImplementation(jest.fn());
let driver: WebDriver;
let testUser1: User;
const acc_name = "acc_automation";
const MGX_ASSET_NAME = "MGX";
const TUR_ASSET_NAME = "TUR";

describe("Miocroapps Prod UI swap tests", () => {
beforeAll(async () => {
try {
getApi();
} catch (e) {
await initApi();
}

driver = await DriverBuilder.getInstance();
await importPolkadotExtension(driver);

const keyring = new Keyring({ type: "sr25519" });
const node = new Node(getEnvironmentRequiredVars().chainUri);
await node.connect();

testUser1 = new User(keyring);
testUser1.addFromMnemonic(
keyring,
getEnvironmentRequiredVars().mnemonicPolkadot,
);

testUser1.addAsset(KSM_ASSET_ID);
testUser1.addAsset(MGA_ASSET_ID);
await testUser1.refreshAmounts(AssetWallet.BEFORE);

await setupPage(driver);
await connectWallet(driver, "Polkadot", acc_name);
});

it("Swap is enabled with enough tokens", async () => {
await setupPageWithState(driver, acc_name);
const swap = new Swap(driver);
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(MGX_ASSET_NAME);
await swap.pickGetToken(TUR_ASSET_NAME);
await swap.setPayTokenAmount("1");
const getTokenAmount = await swap.fetchGetAssetAmount();
expect(parseFloat(getTokenAmount)).toBeGreaterThan(0);

await swap.waitForSwapButtonEnabled();
const isSwapEnabled = await swap.isSwapButtonEnabled();
expect(isSwapEnabled).toBeTruthy();
});

it("Swap details are visible & dynamic", async () => {
await setupPageWithState(driver, acc_name);
const swap = new Swap(driver);
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(MGX_ASSET_NAME);
await swap.pickGetToken(TUR_ASSET_NAME);
await swap.setPayTokenAmount("10");
const getTokenAmount = await swap.fetchGetAssetAmount();
expect(parseFloat(getTokenAmount)).toBeGreaterThan(0);

const isTradeRateDisplayed = await swap.isTradeRateDisplayed();
expect(isTradeRateDisplayed).toBeTruthy();

const areTradeDetailsDisplayed = await swap.areTradeDetailsDisplayed();
expect(areTradeDetailsDisplayed).toBeTruthy();

await swap.toggleRouteDetails();
const areRouteDetailsDisplayed = await swap.areRouteDetailsDisplayed(
MGX_ASSET_NAME,
TUR_ASSET_NAME,
);
expect(areRouteDetailsDisplayed).toBeTruthy();

const minimumRecieved = await swap.fetchMinimumReceivedAmount();
await swap.setPayTokenAmount("50");
const minimumRecievedAfterChange = await swap.fetchMinimumReceivedAmount();
expect(minimumRecieved).toBeLessThan(minimumRecievedAfterChange);
});

afterEach(async () => {
const session = await driver.getSession();
await addExtraLogs(
driver,
expect.getState().currentTestName + " - " + session.getId(),
);
});

afterAll(async () => {
const api = getApi();
await api.disconnect();
await driver.quit();
DriverBuilder.destroy();
});
});
Loading

0 comments on commit bfb62a2

Please sign in to comment.