Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci/update dev tests actions #460

Merged
merged 5 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/microapps-ui-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest

env:
API_URL: 'wss://collator-01-ws-rollup-dev.mangata.online'
API_URL: 'wss://collator-01-ws-rollup-frontend.gasp.xyz'
TEST_SUDO_NAME: ${{ secrets.TEST_SUDO_NAME }}
TEST_SCRIPT: 'test-gasp-ui'
TEST_ENV_TAG: 'develop'
Expand Down Expand Up @@ -68,12 +68,12 @@ jobs:
- name: Set Configuration - testnet
if: contains(github.event.client_payload.environment, 'testnet') || contains(github.event.inputs.environment, 'testnet')
run: |
echo 'API_URL=wss://collator-01-ws-rollup-testnet.mangata.online' >> $GITHUB_ENV
echo 'API_URL=wss://collator-01-ws-rollup-holesky.gasp.xyz' >> $GITHUB_ENV

- name: Set Configuration - Develop
if: contains(github.event.client_payload.environment, 'develop') || contains(github.event.inputs.environment, 'develop')
run: |
echo 'API_URL=wss://collator-01-ws-rollup-dev.mangata.online' >> $GITHUB_ENV
echo 'API_URL=wss://collator-01-ws-rollup-frontend.gasp.xyz' >> $GITHUB_ENV
echo 'TEST_SUDO_NAME=${{ secrets.DEV_SUDO_NAME }}' >> $GITHUB_ENV

- uses: actions/checkout@v3
Expand Down
15 changes: 8 additions & 7 deletions test/rollup-test/rollup-main.deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ let driver: WebDriver;

let acc_addr = "";
let acc_addr_short = "";
const GETH_ASSET_NAME = "GETH";
const ETH_ASSET_NAME = "ETH";
const CHAIN_NAME = "Holesky";

describe("Gasp UI deposit tests", () => {
beforeAll(async () => {
Expand All @@ -50,7 +51,7 @@ describe("Gasp UI deposit tests", () => {
await connectWallet(driver, "Metamask", acc_addr_short);
});

test("User can deposit GETH", async () => {
test("User can deposit ETH", async () => {
await setupPageWithState(driver, acc_addr_short);

const walletWrapper = new WalletWrapper(driver);
Expand All @@ -61,10 +62,10 @@ describe("Gasp UI deposit tests", () => {
expect(isModalVisible).toBeTruthy();

await depositModal.openChainList();
await depositModal.selectChain("Ethereum");
await depositModal.selectChain(CHAIN_NAME);
await depositModal.openTokensList();
await depositModal.waitForTokenListElementsVisible(GETH_ASSET_NAME);
await depositModal.selectToken(GETH_ASSET_NAME);
await depositModal.waitForTokenListElementsVisible(ETH_ASSET_NAME);
await depositModal.selectToken(ETH_ASSET_NAME);

const randomNum = Math.floor(Math.random() * 99) + 1;
await depositModal.enterValue("1." + randomNum.toString());
Expand All @@ -79,8 +80,8 @@ describe("Gasp UI deposit tests", () => {
await depositModal.clickDepositButtonByText(DepositActionType.Network);
await acceptNetworkSwitchInNewWindow(driver);

await depositModal.clickDepositButtonByText(DepositActionType.Approve);
await waitForActionNotification(driver, TransactionType.ApproveContract);
// await depositModal.clickDepositButtonByText(DepositActionType.Approve);
// await waitForActionNotification(driver, TransactionType.ApproveContract);

await depositModal.clickDepositButtonByText(DepositActionType.Deposit);
await waitForActionNotification(driver, TransactionType.Deposit);
Expand Down
31 changes: 16 additions & 15 deletions test/rollup-test/rollup-main.swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ let driver: WebDriver;

let acc_addr = "";
let acc_addr_short = "";
const GETH_ASSET_NAME = "GETH";
const GASP_ASSET_NAME = "GASP";
const ETH_ASSET_NAME = "ETH";
const GASP_ASSET_NAME = "GASPV2";
const ETH_ORIGIN = "Ethereum";

describe("Gasp UI swap tests", () => {
beforeAll(async () => {
Expand All @@ -55,9 +56,9 @@ describe("Gasp UI swap tests", () => {
const swap = new Swap(driver);
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GETH_ASSET_NAME);
await swap.pickPayToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.pickGetToken(GASP_ASSET_NAME);
await swap.setPayTokenAmount("10000");
await swap.setPayTokenAmount("10000000");
const getTokenAmount = await swap.fetchGetAssetAmount();
expect(parseFloat(getTokenAmount)).toBeGreaterThan(0);

Expand All @@ -70,13 +71,13 @@ describe("Gasp UI swap tests", () => {
const walletWrapper = new WalletWrapper(driver);
await walletWrapper.openWalletConnectionInfo();
const tokensAmountBefore =
await walletWrapper.getMyTokensRowAmount(GASP_ASSET_NAME);
parseFloat(await walletWrapper.getMyTokensRowAmount(GASP_ASSET_NAME)) - 1;
const swap = new Swap(driver);
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GASP_ASSET_NAME);
await swap.pickGetToken(GETH_ASSET_NAME);
await swap.setPayTokenAmount(tokensAmountBefore);
await swap.pickGetToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.setPayTokenAmount(tokensAmountBefore.toString());
const getTokenAmount = await swap.fetchGetAssetAmount();
expect(parseFloat(getTokenAmount)).toBeGreaterThan(0);

Expand All @@ -98,7 +99,7 @@ describe("Gasp UI swap tests", () => {
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GASP_ASSET_NAME);
await swap.pickGetToken(GETH_ASSET_NAME);
await swap.pickGetToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.setPayTokenAmount("1000");
const getTokenAmount = await swap.fetchGetAssetAmount();
expect(parseFloat(getTokenAmount)).toBeGreaterThan(0);
Expand All @@ -112,7 +113,7 @@ describe("Gasp UI swap tests", () => {
await swap.toggleRouteDetails();
const areRouteDetailsDisplayed = await swap.areRouteDetailsDisplayed(
GASP_ASSET_NAME,
GETH_ASSET_NAME,
ETH_ASSET_NAME,
);
expect(areRouteDetailsDisplayed).toBeTruthy();

Expand All @@ -128,14 +129,14 @@ describe("Gasp UI swap tests", () => {
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GASP_ASSET_NAME);
await swap.pickGetToken(GETH_ASSET_NAME);
await swap.pickGetToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.setPayTokenAmount("100");

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

const swapFee = await swap.fetchSwapFee();
expect(swapFee).toEqual(1);
expect(swapFee).toEqual(50);
});

it("Swap free - more than 1k GASP", async () => {
Expand All @@ -144,7 +145,7 @@ describe("Gasp UI swap tests", () => {
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GASP_ASSET_NAME);
await swap.pickGetToken(GETH_ASSET_NAME);
await swap.pickGetToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.setPayTokenAmount("10001");

const areTradeDetailsDisplayed = await swap.areTradeDetailsDisplayed();
Expand All @@ -160,7 +161,7 @@ describe("Gasp UI swap tests", () => {
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GASP_ASSET_NAME);
await swap.pickGetToken(GETH_ASSET_NAME);
await swap.pickGetToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.setPayTokenAmount("1000");
const getTokenAmount = await swap.fetchGetAssetAmount();
expect(parseFloat(getTokenAmount)).toBeGreaterThan(0);
Expand All @@ -169,7 +170,7 @@ describe("Gasp UI swap tests", () => {
await sleep(1000);

const payTokenNameAfterSwitch = await swap.fetchPayTokenName();
expect(payTokenNameAfterSwitch).toEqual(GETH_ASSET_NAME);
expect(payTokenNameAfterSwitch).toEqual(ETH_ASSET_NAME);
const getTokenNameAfterSwitch = await swap.fetchGetTokenName();
expect(getTokenNameAfterSwitch).toEqual(GASP_ASSET_NAME);
const payTokeAmountAfterSwitch = await swap.fetchPayAssetAmount();
Expand All @@ -184,7 +185,7 @@ describe("Gasp UI swap tests", () => {
const swap = new Swap(driver);
const isSwapFrameDisplayed = await swap.isDisplayed();
expect(isSwapFrameDisplayed).toBeTruthy();
await swap.pickPayToken(GETH_ASSET_NAME);
await swap.pickPayToken(ETH_ASSET_NAME, ETH_ORIGIN);
await swap.pickGetToken(GASP_ASSET_NAME);
await swap.setPayTokenAmount("1.213");
const getTokenAmount = await swap.fetchGetAssetAmount();
Expand Down
11 changes: 6 additions & 5 deletions test/rollup-test/rollup-main.withdraw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ let driver: WebDriver;

let acc_addr = "";
let acc_addr_short = "";
const GETH_ASSET_NAME = "GETH";
const ETH_ASSET_NAME = "ETH";
const CHAIN_NAME = "Holesky";

describe("Gasp UI withdraw tests", () => {
beforeAll(async () => {
Expand All @@ -50,7 +51,7 @@ describe("Gasp UI withdraw tests", () => {
await connectWallet(driver, "Metamask", acc_addr_short);
});

test("User can withdraw GETH", async () => {
test("User can withdraw ETH", async () => {
await setupPageWithState(driver, acc_addr_short);

const walletWrapper = new WalletWrapper(driver);
Expand All @@ -61,10 +62,10 @@ describe("Gasp UI withdraw tests", () => {
expect(isModalVisible).toBeTruthy();

await withdrawModal.openChainList();
await withdrawModal.selectChain("Ethereum");
await withdrawModal.selectChain(CHAIN_NAME);
await withdrawModal.openTokensList();
await withdrawModal.waitForTokenListElementsVisible(GETH_ASSET_NAME);
await withdrawModal.selectToken(GETH_ASSET_NAME);
await withdrawModal.waitForTokenListElementsVisible(ETH_ASSET_NAME);
await withdrawModal.selectToken(ETH_ASSET_NAME);
await withdrawModal.enterValue("1");

await withdrawModal.waitForContinueState(true, 60000);
Expand Down
14 changes: 10 additions & 4 deletions test/rollup-test/rollup-prod.deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let driver: WebDriver;
let acc_addr = "";
let acc_addr_short = "";
const ETH_ASSET_NAME = "ETH";
const ETH_ORIGIN = "Ethereum";

describe("Gasp Prod UI deposit tests", () => {
beforeAll(async () => {
Expand All @@ -56,8 +57,10 @@ describe("Gasp Prod UI deposit tests", () => {

const walletWrapper = new WalletWrapper(driver);
await walletWrapper.openWalletConnectionInfo();
const tokensAmountBefore =
await walletWrapper.getMyTokensRowAmount(ETH_ASSET_NAME);
const tokensAmountBefore = await walletWrapper.getMyTokensRowAmount(
ETH_ASSET_NAME,
ETH_ORIGIN,
);
await walletWrapper.openDeposit();
const depositModal = new DepositModal(driver);
const isModalVisible = await depositModal.isModalVisible();
Expand Down Expand Up @@ -92,9 +95,12 @@ describe("Gasp Prod UI deposit tests", () => {
await walletWrapper.waitTokenAmountChange(
ETH_ASSET_NAME,
tokensAmountBefore,
ETH_ORIGIN,
);
const tokensAmountAfter = await walletWrapper.getMyTokensRowAmount(
ETH_ASSET_NAME,
ETH_ORIGIN,
);
const tokensAmountAfter =
await walletWrapper.getMyTokensRowAmount(ETH_ASSET_NAME);
expect(await uiStringToNumber(tokensAmountAfter)).toBeGreaterThan(
await uiStringToNumber(tokensAmountBefore),
);
Expand Down
7 changes: 6 additions & 1 deletion test/rollup-test/rollup-prod.withdraw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ let driver: WebDriver;
let acc_addr = "";
let acc_addr_short = "";
const ASSET_NAME = "GASPV2";
const NATIVE_ORIGIN = "Native";
const CHAIN_NAME = "Holesky";

describe("Gasp Prod UI withdraw tests", () => {
Expand Down Expand Up @@ -100,7 +101,11 @@ describe("Gasp Prod UI withdraw tests", () => {
await waitForActionNotification(driver, TransactionType.Withdraw);
await withdrawModal.closeSuccessModal();

await walletWrapper.waitTokenAmountChange(ASSET_NAME, tokensAmountBefore);
await walletWrapper.waitTokenAmountChange(
ASSET_NAME,
tokensAmountBefore,
NATIVE_ORIGIN,
);
const tokensAmountAfter =
await walletWrapper.getMyTokensRowAmount(ASSET_NAME);
expect(await uiStringToNumber(tokensAmountAfter)).toBeLessThan(
Expand Down
2 changes: 1 addition & 1 deletion utils/frontend/rollup-pages/BalanceWarningModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class BalanceWarningModal {
}

async displayed() {
const xpath = buildXpathByText("Warning! Low GASP Balance");
const xpath = buildXpathByText("Warning! Low GASPV2 Balance");
return await isDisplayed(this.driver, xpath);
}
}
18 changes: 11 additions & 7 deletions utils/frontend/rollup-pages/Swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
areDisplayed,
buildDataTestIdXpath,
buildXpathByElementText,
buildXpathByText,
buildXpathByMultiText,
clickElement,
getAttribute,
getText,
Expand Down Expand Up @@ -80,7 +80,7 @@ export class Swap {
return await isDisplayed(this.driver, firstTokenSelector);
}

async pickPayToken(tokenName: string) {
async pickPayToken(tokenName: string, origin = "Native") {
const selectFirstToken = buildDataTestIdXpath(BTN_SELECT_FIRST_TOKEN);
await clickElement(this.driver, selectFirstToken);
const firstTokenSelector = buildDataTestIdXpath(
Expand All @@ -89,13 +89,15 @@ export class Swap {
await waitForElement(this.driver, firstTokenSelector);
const firstTokenSelectorButton =
buildDataTestIdXpath(DIV_TOKEN_SELECTOR_ITEM) +
buildXpathByText(tokenName);
buildXpathByMultiText([tokenName, origin]);
await scrollIntoView(this.driver, firstTokenSelectorButton);
await clickElement(this.driver, firstTokenSelectorButton);
}

async fetchPayTokenName() {
const tokenSelector = buildDataTestIdXpath(BTN_SELECT_FIRST_TOKEN);
const tokenSelector =
buildDataTestIdXpath(BTN_SELECT_FIRST_TOKEN) +
"//*[contains(@class, 'font-normal')]";
return await getText(this.driver, tokenSelector);
}

Expand All @@ -117,7 +119,9 @@ export class Swap {
}

async fetchGetTokenName() {
const tokenSelector = buildDataTestIdXpath(BTN_SELECT_SECOND_TOKEN);
const tokenSelector =
buildDataTestIdXpath(BTN_SELECT_SECOND_TOKEN) +
"//*[contains(@class, 'font-normal')]";
return await getText(this.driver, tokenSelector);
}

Expand Down Expand Up @@ -165,7 +169,7 @@ export class Swap {
await clickElement(this.driver, xpath);
}

async pickGetToken(tokenName: string) {
async pickGetToken(tokenName: string, origin = "Native") {
const selectSecondToken = buildDataTestIdXpath(BTN_SELECT_SECOND_TOKEN);
await clickElement(this.driver, selectSecondToken);
const secondTokenSelector = buildDataTestIdXpath(
Expand All @@ -174,7 +178,7 @@ export class Swap {
await waitForElement(this.driver, secondTokenSelector);
const secondTokenSelectorButton =
buildDataTestIdXpath(DIV_TOKEN_SELECTOR_ITEM) +
buildXpathByText(tokenName);
buildXpathByMultiText([tokenName, origin]);
await scrollIntoView(this.driver, secondTokenSelectorButton);
await clickElement(this.driver, secondTokenSelectorButton);
}
Expand Down
14 changes: 10 additions & 4 deletions utils/frontend/rollup-pages/WalletWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FIVE_MIN } from "../../Constants";
import {
buildDataTestIdXpath,
buildXpathByElementText,
buildXpathByMultiText,
buildXpathByText,
clickElement,
elementExists,
Expand Down Expand Up @@ -110,26 +111,31 @@ export class WalletWrapper {
return await isDisplayed(this.driver, tokenRow);
}

async getMyTokensRowAmount(tokenName: string) {
async getMyTokensRowAmount(tokenName: string, origin = "Native") {
const tokenRowAmount =
buildDataTestIdXpath(MY_TOKENS) +
buildXpathByText(tokenName) +
buildXpathByMultiText([tokenName, origin]) +
buildDataTestIdXpath(MY_TOKENS_ROW_AMOUNT);
await waitForElementVisible(this.driver, tokenRowAmount);
return await getText(this.driver, tokenRowAmount);
const amount = await getText(this.driver, tokenRowAmount);
return amount.split(",").join("");
}

async waitTokenAmountChange(
tokenName: string,
initValue: string,
tokenOrigin = "Native",
timeout = FIVE_MIN,
) {
const startTime = Date.now();
const endTime = startTime + timeout;

while (Date.now() < endTime) {
try {
const tokenAmount = await this.getMyTokensRowAmount(tokenName);
const tokenAmount = await this.getMyTokensRowAmount(
tokenName,
tokenOrigin,
);
if (tokenAmount !== initValue) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions utils/frontend/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,10 @@ export function buildXpathByText(text: string) {
return `//*[contains(., "${text}")]`;
}

export function buildXpathByMultiText(texts: string[]) {
return `//*[${texts.map((text) => `contains(., "${text}")`).join(" and ")}]`;
}

export function buildXpathByElementText(element: string, text: string) {
return `//${element}[contains(., "${text}")]`;
}
Expand Down
Loading