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

Microapps create liq pool tests #333

Merged
merged 1 commit into from
Oct 26, 2023
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
81 changes: 75 additions & 6 deletions test/microapps-ui-xcm/microapps-ui-main.liq.pools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import {
} from "../../utils/frontend/utils/Helper";
import { Keyring } from "@polkadot/api";
import { KeyringPair } from "@polkadot/keyring/types";
import {
FIVE_MIN,
KSM_ASSET_ID,
MGA_ASSET_ID,
TUR_ASSET_NAME,
} from "../../utils/Constants";
import { FIVE_MIN, KSM_ASSET_ID, MGA_ASSET_ID } from "../../utils/Constants";
import { AssetWallet, User } from "../../utils/User";
import { getEnvironmentRequiredVars } from "../../utils/utils";
import {
Expand Down Expand Up @@ -48,6 +43,8 @@ const acc_name = "acc_automation";
const userAddress = "5CfLmpjCJu41g3cpZVoiH7MSrSppgVVVC3xq23iy9dZrW2HR";
const KSM_ASSET_NAME = "KSM";
const MGX_ASSET_NAME = "MGX";
const TUR_ASSET_NAME = "TUR";
const ZLK_ASSET_NAME = "ZLK";

describe("Miocroapps UI liq pools tests", () => {
let kusama: ApiContext;
Expand All @@ -71,6 +68,11 @@ describe("Miocroapps UI liq pools tests", () => {
Tokens: {
Accounts: [
[[userAddress, { token: 4 }], { free: 10 * 1e12 }],
[[userAddress, { token: 7 }], { free: 10 * 1e10 }],
[
[userAddress, { token: 26 }],
{ free: AssetId.Mgx.unit.mul(BN_THOUSAND).toString() },
],
[
[userAddress, { token: 0 }],
{ free: AssetId.Mgx.unit.mul(BN_TEN_THOUSAND).toString() },
Expand Down Expand Up @@ -242,6 +244,7 @@ describe("Miocroapps UI liq pools tests", () => {
expect(firstTokenAmount).toBeGreaterThan(0);

// not enough one token
await poolDetails.clearFirstTokenAmount();
await poolDetails.clearSecondTokenAmount();
await poolDetails.setSecondTokenAmount("9");
await poolDetails.waitFirstTokenAmountSet(true);
Expand All @@ -251,6 +254,7 @@ describe("Miocroapps UI liq pools tests", () => {
expect(firstTokenAlert).toBeTruthy();

// not enough both tokens
await poolDetails.clearFirstTokenAmount();
await poolDetails.clearSecondTokenAmount();
await poolDetails.setSecondTokenAmount("20");
await poolDetails.waitFirstTokenAmountSet(true);
Expand Down Expand Up @@ -321,6 +325,71 @@ describe("Miocroapps UI liq pools tests", () => {
expect(my_new_pool_share).toBeGreaterThan(my_pool_share);
});

it("User can create new liquidity pool", async () => {
await setupPageWithState(driver, acc_name);
const sidebar = new Sidebar(driver);
await sidebar.clickNavLiqPools();

const poolsList = new LiqPools(driver);
const isPoolsListDisplayed = await poolsList.isDisplayed();
expect(isPoolsListDisplayed).toBeTruthy();
await poolsList.clickAllPoolsTab();
await poolsList.clickCreateLiquidity();
await poolsList.pickFirstToken(TUR_ASSET_NAME);
await poolsList.pickSecondToken(ZLK_ASSET_NAME);
await poolsList.setFirstTokenAmount("2");
await poolsList.setSecondTokenAmount("1");

await poolsList.waitForContinueState(true);
const isExpectedShareDisplayed = await poolsList.isExpectedShareDisplayed();
expect(isExpectedShareDisplayed).toBeTruthy();
const isFeeDisplayed = await poolsList.isFeeDisplayed();
expect(isFeeDisplayed).toBeTruthy();

await poolsList.createLiqPoolsubmit();
await waitForMicroappsActionNotification(
driver,
mangata,
kusama,
TransactionType.CreatePool,
2
);

const poolDetails = new LiqPoolDetils(driver);
const isPoolDetailsVisible = await poolDetails.isDisplayed(
TUR_ASSET_NAME + " / " + ZLK_ASSET_NAME
);
expect(isPoolDetailsVisible).toBeTruthy();
const my_pool_share = await poolDetails.getMyPositionAmount();
expect(my_pool_share).toBeGreaterThan(0);
});

it("User can add liquidity from create liquidity widget", async () => {
await setupPageWithState(driver, acc_name);
const sidebar = new Sidebar(driver);
await sidebar.clickNavLiqPools();

const poolsList = new LiqPools(driver);
const isPoolsListDisplayed = await poolsList.isDisplayed();
expect(isPoolsListDisplayed).toBeTruthy();
await poolsList.clickAllPoolsTab();
await poolsList.clickCreateLiquidity();
await poolsList.pickFirstToken(MGX_ASSET_NAME);
await poolsList.pickSecondToken(TUR_ASSET_NAME);
const isPoolExistsInfoDisplayed =
await poolsList.isPoolExistsInfoDisplayed();
expect(isPoolExistsInfoDisplayed).toBeTruthy();

await poolsList.setFirstTokenAmount("10");
await poolsList.waitForContinueState(true);
const isExpectedShareDisplayed = await poolsList.isExpectedShareDisplayed();
expect(isExpectedShareDisplayed).toBeTruthy();
const isFeeDisplayed = await poolsList.isFeeDisplayed();
expect(isFeeDisplayed).toBeTruthy();
const isEstRewardDisplayed = await poolsList.isEstRewardDisplayed();
expect(isEstRewardDisplayed).toBeTruthy();
});

afterEach(async () => {
const session = await driver.getSession();
await addExtraLogs(
Expand Down
144 changes: 144 additions & 0 deletions utils/frontend/microapps-pages/LiqPools.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import { WebDriver } from "selenium-webdriver";
import {
buildDataTestIdXpath,
buildXpathByElementText,
buildXpathByText,
clearText,
clickElement,
isDisplayed,
scrollIntoView,
waitForElement,
waitForElementStateInterval,
writeText,
} from "../utils/Helper";

const SEARCH_CONTAINER = "pool-list-search-container";
const SEARCH_INPUT = "pool-list-search-input";
const TAB_PROMOTED_POOLS = "Promoted-Pools-item";
const TAB_ALL_POOLS = "All-Pools-item";
const CREATE_LIQUIDITY_WIDGET = "create-liquidity-widget";
const BTN_SELECT_FIRST_TOKEN = "firstToken-selector-btn";
const BTN_SELECT_SECOND_TOKEN = "secondToken-selector-btn";
const DIV_FIRST_TOKEN_SELECTOR_CONTENT = "firstToken-selector-content";
const DIV_SECOND_TOKEN_SELECTOR_CONTENT = "secondToken-selector-content";
const DIV_TOKEN_SELECTOR_ITEM = "tokenList-item";
const DIV_FIRST_TOKEN_CONTAINER = "firstToken-container";
const DIV_FIRST_TOKEN_INPUT = "firstToken-input";
const DIV_SECOND_TOKEN_CONTAINER = "secondToken-container";
const DIV_SECOND_TOKEN_INPUT = "secondToken-input";
const POOL_SHARE = "poolShare";
const EST_REWARDS = "est-rewards";
const FEE = "fee";
const BTN_SUBMIT = "submit-button";

export class LiqPools {
driver: WebDriver;
Expand Down Expand Up @@ -47,6 +66,23 @@ export class LiqPools {
await clickElement(this.driver, itemXpath);
}

async clickCreateLiquidity() {
const itemXpath = buildXpathByElementText(
"a",
"Create a new liquidity pool"
);
await clickElement(this.driver, itemXpath);
}

async isPoolExistsInfoDisplayed() {
const itemXpath = buildXpathByElementText(
"span",
"selected pool already exists"
);
const displayed = await isDisplayed(this.driver, itemXpath);
return displayed;
}

async openSearch() {
const itemXpath = buildDataTestIdXpath(SEARCH_CONTAINER);
await clickElement(this.driver, itemXpath);
Expand All @@ -57,4 +93,112 @@ export class LiqPools {
await clickElement(this.driver, inputSearch);
await writeText(this.driver, inputSearch, text);
}

async isCreateLiqPoolWidgetVisible() {
const itemXpath = buildDataTestIdXpath(CREATE_LIQUIDITY_WIDGET);
const displayed = await isDisplayed(this.driver, itemXpath);
return displayed;
}

async pickFirstToken(tokenName: string) {
const selectFirstToken = buildDataTestIdXpath(BTN_SELECT_FIRST_TOKEN);
await clickElement(this.driver, selectFirstToken);
const firstTokenSelector = buildDataTestIdXpath(
DIV_FIRST_TOKEN_SELECTOR_CONTENT
);
await waitForElement(this.driver, firstTokenSelector);
const firstTokenSelectorButton =
buildDataTestIdXpath(DIV_TOKEN_SELECTOR_ITEM) +
buildXpathByText(tokenName);
await scrollIntoView(this.driver, firstTokenSelectorButton);
await clickElement(this.driver, firstTokenSelectorButton);
}

async pickSecondToken(tokenName: string) {
const selectSecondToken = buildDataTestIdXpath(BTN_SELECT_SECOND_TOKEN);
await clickElement(this.driver, selectSecondToken);
const secondTokenSelector = buildDataTestIdXpath(
DIV_SECOND_TOKEN_SELECTOR_CONTENT
);
await waitForElement(this.driver, secondTokenSelector);
const secondTokenSelectorButton =
buildDataTestIdXpath(DIV_TOKEN_SELECTOR_ITEM) +
buildXpathByText(tokenName);
await scrollIntoView(this.driver, secondTokenSelectorButton);
await clickElement(this.driver, secondTokenSelectorButton);
}

async setFirstTokenAmount(amount: string) {
const itemXpath =
buildDataTestIdXpath(DIV_FIRST_TOKEN_CONTAINER) +
buildDataTestIdXpath(DIV_FIRST_TOKEN_INPUT);
await clickElement(this.driver, itemXpath);
await writeText(this.driver, itemXpath, amount);
}

async clearFirstTokenAmount() {
const itemXpath =
buildDataTestIdXpath(DIV_FIRST_TOKEN_CONTAINER) +
buildDataTestIdXpath(DIV_FIRST_TOKEN_INPUT);
await clearText(this.driver, itemXpath);
}

async setSecondTokenAmount(amount: string) {
const itemXpath =
buildDataTestIdXpath(DIV_SECOND_TOKEN_CONTAINER) +
buildDataTestIdXpath(DIV_SECOND_TOKEN_INPUT);
await clickElement(this.driver, itemXpath);
await writeText(this.driver, itemXpath, amount);
}

async clearSecondTokenAmount() {
const itemXpath =
buildDataTestIdXpath(DIV_SECOND_TOKEN_CONTAINER) +
buildDataTestIdXpath(DIV_SECOND_TOKEN_INPUT);
await clearText(this.driver, itemXpath);
}

async isExpectedShareDisplayed() {
const itemXpath =
buildDataTestIdXpath(CREATE_LIQUIDITY_WIDGET) +
buildDataTestIdXpath(POOL_SHARE);
const displayed = await isDisplayed(this.driver, itemXpath);
return displayed;
}

async isFeeDisplayed() {
const itemXpath =
buildDataTestIdXpath(CREATE_LIQUIDITY_WIDGET) + buildDataTestIdXpath(FEE);
const displayed = await isDisplayed(this.driver, itemXpath);
return displayed;
}

async isEstRewardDisplayed() {
const itemXpath =
buildDataTestIdXpath(CREATE_LIQUIDITY_WIDGET) +
buildDataTestIdXpath(EST_REWARDS);
const displayed = await isDisplayed(this.driver, itemXpath);
return displayed;
}

async createLiqPoolsubmit() {
const continueBtn =
buildDataTestIdXpath(CREATE_LIQUIDITY_WIDGET) +
buildDataTestIdXpath(BTN_SUBMIT);
await scrollIntoView(this.driver, continueBtn);
await clickElement(this.driver, continueBtn);
}

async waitForContinueState(isEnabled: boolean, timeout = 5000) {
const continueBtn =
buildDataTestIdXpath(CREATE_LIQUIDITY_WIDGET) +
buildDataTestIdXpath(BTN_SUBMIT);
await scrollIntoView(this.driver, continueBtn);
await waitForElementStateInterval(
this.driver,
continueBtn,
isEnabled,
timeout
);
}
}
2 changes: 2 additions & 0 deletions utils/frontend/microapps-pages/NotificationModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum TransactionType {
Withdraw,
AddLiquidity,
RemoveLiquidity,
CreatePool,
Claim,
}

Expand All @@ -56,6 +57,7 @@ export class NotificationModal {
[TransactionType.Swap]: "-swap",
[TransactionType.RemoveLiquidity]: "-removeLiquidity",
[TransactionType.Claim]: "-claim",
[TransactionType.CreatePool]: "-createPool",
};

constructor(driver: WebDriver) {
Expand Down