Skip to content

Commit

Permalink
fix tests, add notification tests for native + erc20
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtzData committed Apr 14, 2024
1 parent a80a2c1 commit 03180b6
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 89 deletions.
26 changes: 22 additions & 4 deletions tests/e2e/pages/Login.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable guard-for-in */
import { APIRequestContext, request } from "@playwright/test"
import { APIRequestContext, expect, request } from "@playwright/test"
import { WebActions } from "@lib/WebActions"
import { MailSlurp } from "mailslurp-client"
import type { Page } from 'playwright'
Expand Down Expand Up @@ -75,9 +75,9 @@ export class AuthorizedArea extends CommonPage {

WATCHLIST_TAB = `text=Watch list`

WATCHLIST_ADDRESS_INPUT = `#watchlist_address_address_hash`
WATCHLIST_ADDRESS_INPUT = `[role="dialog"] >> text=/Address.*0x/`

WATCHLIST_ADDRESS_NAME_INPUT = `#watchlist_address_name`
WATCHLIST_ADDRESS_NAME_INPUT = `[role="dialog"] >> text=/Private.*tag.*max.*characters/`

WATCHLIST_ETHER_IN_CHECKBOX = `text=Incoming >> nth=0`

Expand All @@ -95,7 +95,7 @@ export class AuthorizedArea extends CommonPage {

SAVE_BTN = `section >> button >> nth=1`

ADD_ADDRESS_BUTTON = `text=Add address`
ADD_ADDRESS_BUTTON = `text=/Add address/`

WARN_ADDRESS_REQUIRED = `text=Address required >> span`

Expand Down Expand Up @@ -179,6 +179,12 @@ export class AuthorizedArea extends CommonPage {
await this.actions.navigateToURL(`${process.env.BLOCKSCOUT_URL}auth/profile`, options)
}

async openWatchlist(options?: Object): Promise<void> {
await this.actions.navigateToURL(process.env.BLOCKSCOUT_URL, options)
await this.actions.clickElement(this.SIGNED_IN)
await this.actions.navigateToURL(`${process.env.BLOCKSCOUT_URL}account/watchlist`, options)
}

async openVerifiedAddresses(): Promise<void> {
await this.actions.navigateToURL(`${process.env.BLOCKSCOUT_URL}account/verified-addresses`)
}
Expand Down Expand Up @@ -253,6 +259,12 @@ export class AuthorizedArea extends CommonPage {
await this.actions.verifyElementIsDisplayed(`tbody >> tr >> nth=${row} >> td >> nth=${col} >> text=/${text}/`)
}

async checkNotificationItem(): Promise<void> {
await this.actions.verifyElementIsDisplayed(`table >> tr >> nth=1 >> text=/0x/`)
await this.actions.verifyElementIsDisplayed(`table >> tr >> nth=1 >> text=/ETH.*balance/`)
await this.actions.verifyElementIsDisplayed(`table >> tr >> nth=1 >> text=/Net.*worth/`)
}

async clickListRow(row: number, col: number): Promise<void> {
await this.actions.clickElement(`tbody >> tr >> nth=${row} >> td >> nth=${col} >> div >> a`)
}
Expand Down Expand Up @@ -347,6 +359,12 @@ export class AuthorizedArea extends CommonPage {
await this.actions.clickElement(this.SAVE_BTN)
}

async deleteAddressWatch(): Promise<void> {
await this.actions.clickElement(`table >> button[aria-label="delete"] >> nth=0`)
await this.actions.clickElement(`section[role="dialog"] >> nth=5 >> button >> nth=1`)
await expect(this.page.locator(`table`)).toBeVisible({ visible: false })
}

async checkValidationWarn(asserts: string[]): Promise<void> {
for (const a of asserts) {
await this.actions.verifyElementIsDisplayed(`text=${a}`, `validation warning not found`)
Expand Down
34 changes: 7 additions & 27 deletions tests/e2e/pages/TransactionsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,13 @@ export class TransactionsListPage extends CommonPage {
await this.actions.verifyElementIsDisplayed(`${this.TABLE_HEADER}7 >> text=Fee ETH`)
}

async check_table_data(nftSymbolV: string, nftSymbol: string, erc20SymbolV: string, erc20Symbol: string): Promise<void> {
await this.table_element_displayed(1, 1, `/0x.*ago/`)
await this.table_element_displayed(1, 2, `/Token transfer.*Success/`)
await this.table_element_displayed(1, 3, `/0x/`)
await this.table_element_displayed(1, 4, `/\\d+/`)
await this.table_element_displayed(1, 5, `0x`)
await this.table_element_displayed(1, 5, nftSymbolV)
await this.table_element_displayed(1, 6, `/\\d+/`)
await this.table_element_displayed(1, 7, `/\\d\\.\\d+/`)

await this.table_element_displayed(2, 1, `/0x.*ago/`)
await this.table_element_displayed(2, 2, `/Token creation.*Success/`)
await this.table_element_displayed(2, 3, ``)
await this.table_element_displayed(2, 4, `/\\d+/`)
await this.table_element_displayed(2, 5, `0x`)
await this.table_element_displayed(2, 5, nftSymbolV)
await this.table_element_displayed(2, 6, `/\\d+/`)
await this.table_element_displayed(2, 7, `/\\d\\.\\d+/`)

await this.table_element_displayed(3, 1, `/0x.*ago/`)
await this.table_element_displayed(3, 2, `/Contract call.*Failed/`)
await this.table_element_displayed(3, 3, `/alwaysReverts/`)
await this.table_element_displayed(3, 4, `/\\d+/`)
await this.table_element_displayed(3, 5, `0x`)
await this.table_element_displayed(3, 5, erc20SymbolV)
await this.table_element_displayed(3, 6, `/\\d+/`)
await this.table_element_displayed(3, 7, `/\\d\\.\\d+/`)
async check_table_data(): Promise<void> {
await this.actions.verifyElementIsDisplayed(`text=/0x/`)
await this.actions.verifyElementIsDisplayed(`text=/Token transfer/`)
await this.actions.verifyElementIsDisplayed(`text=/Success/`)
await this.actions.verifyElementIsDisplayed(`text=/Failed/`)
await this.actions.verifyElementIsDisplayed(`text=/alwaysReverts/`)
await this.actions.verifyElementIsDisplayed(`text=/0.01/`)
}

async findText(tags: string[]): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const config: PlaywrightTestConfig = {
timeout: 60000,

// number of retries if test case fails
retries: 1,
retries: 0,

// Reporters
reporter: [[`list`], [`html`, { outputFolder: `html-report`, open: `never` }], [`junit`, { outputFile: `results.xml` }]],
Expand Down
8 changes: 0 additions & 8 deletions tests/e2e/tests/functional/Blocks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import test from '@lib/BaseTest'

test.describe.configure({ mode: `parallel` })

test.skip(`@AccountImage @Blocks Block with a create tx`, async ({ blocksPage }) => {
const { TestTokenDeployTXHash } = process.env
await blocksPage.mock_ads()
await blocksPage.open(TestTokenDeployTXHash)
await blocksPage.check_block_description_new()
await blocksPage.check_details()
})

test(`@AccountImage @Blocks Check blocks list`, async ({ blocksListPage }) => {
await blocksListPage.open()
await blocksListPage.check_header()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/tests/functional/Marketplace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test(`@AccountImage @Marketplace Check favorites filter`, async ({ marketplace }
await marketplace.checkGroupsVisible(appName, 1)
})

test.skip(`@AccountImage @Marketplace Propose a new app`, async ({ context, marketplace }) => {
test.skip(`@AccountImage @Marketplace Propose new app`, async ({ context, marketplace }) => {
await marketplace.open()
await marketplace.submitNewApp(context, {
Name: `New app`,
Expand Down
64 changes: 35 additions & 29 deletions tests/e2e/tests/functional/Notifications.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import test from '@lib/BaseTest'
import { faker } from '@faker-js/faker'
import { WatchListSpec } from '@pages/Login'
import { MatchOptionFieldEnum, MatchOptionShouldEnum } from 'mailslurp-client'
import { expect } from "@playwright/test"
import { TestToken } from '../../../contracts/typechain/contracts/TestToken'
import { TestNFT } from '../../../contracts/typechain/contracts/TestNFT'

const emailTimeout = 30000

test(`@Notifications Check notification received on Ether transfer`, async ({ authorized }) => {
const { TestTokenAddress } = process.env
await authorized.openAccount()

const token = await authorized.contracts.loadContract(`TestToken`, TestTokenAddress) as TestToken
test(`@AccountImage @Notifications Check notification received on Ether transfer`, async ({ authorized }) => {
await authorized.openWatchlist()
const recipient = authorized.contracts.newWallet()
console.log(`created recipient address: ${recipient.address}`)

Expand All @@ -22,24 +20,27 @@ test(`@Notifications Check notification received on Ether transfer`, async ({ au
address: recipient.address.toLowerCase(),
name: watchName,
} as WatchListSpec)
await authorized.check_tag_list(0, 0, watchName)
await authorized.check_tag_list(0, 1, `0x`)
await authorized.check_tag_list(0, 1, `(N/A)`)
await authorized.check_tag_list(0, 1, `Edit`)
await authorized.delay(5000)
await authorized.checkNotificationItem()
console.log(`sending Ether to recipient`)
await authorized.contracts.sendEther(recipient.address, `0.01`)
console.log(`awaiting blockscout indexing`)
await authorized.delay(30000)

await authorized.ms.waitForMatchingEmails(
const emailResult = await authorized.ms.waitForMatchingEmails(
{ matches: [{ field: MatchOptionFieldEnum.SUBJECT, should: MatchOptionShouldEnum.CONTAIN, value: watchName }] },
1,
process.env.MAILSLURP_EMAIL_ID,
emailTimeout,
)
console.log(`Received email: ${JSON.stringify(emailResult)}`)
expect(emailResult[0].subject).toContain(`[Address Watch Alert] 0.01 ETH received at ${recipient.address.toLowerCase()} ${watchName}`)
expect(emailResult[0].from).toContain(`[email protected]`)
await authorized.deleteAddressWatch()
})

test.skip(`@Notifications Check notification received on ERC20 transfer`, async ({ authorized }) => {
test(`@AccountImage @Notifications Check notification received on ERC20 transfer`, async ({ authorized }) => {
const { TestTokenAddress } = process.env
await authorized.openAccount()
await authorized.openWatchlist()

const token = await authorized.contracts.loadContract(`TestToken`, TestTokenAddress) as TestToken
const recipient = authorized.contracts.newWallet()
Expand All @@ -51,25 +52,28 @@ test.skip(`@Notifications Check notification received on ERC20 transfer`, async
address: recipient.address.toLowerCase(),
name: watchName,
} as WatchListSpec)
await authorized.check_tag_list(0, 0, watchName)
await authorized.check_tag_list(0, 1, `0x`)
await authorized.check_tag_list(0, 1, `(N/A)`)
await authorized.check_tag_list(0, 1, `Edit`)
await authorized.delay(5000)
await authorized.checkNotificationItem()
console.log(`sending ERC20 tokens to recipient`)
const receipt = await (await token.transfer(recipient.address, 1)).wait()
console.log(`receipt: ${JSON.stringify(receipt)}`)
console.log(`awaiting blockscout indexing`)
await authorized.delay(30000)

await authorized.ms.waitForMatchingEmails(
const emailResult = await authorized.ms.waitForMatchingEmails(
{ matches: [{ field: MatchOptionFieldEnum.SUBJECT, should: MatchOptionShouldEnum.CONTAIN, value: watchName }] },
1,
process.env.MAILSLURP_EMAIL_ID,
emailTimeout,
)
console.log(`Received email: ${JSON.stringify(emailResult)}`)
expect(emailResult[0].subject).toContain(`[Address Watch Alert] 0.000000000000000001 EPIC received at ${recipient.address.toLowerCase()} ${watchName}`)
expect(emailResult[0].from).toContain(`[email protected]`)
await authorized.deleteAddressWatch()
})

test.skip(`@Notifications Check notification received on NFT transfer`, async ({ authorized }) => {
const { TestNFTAddress } = process.env
await authorized.openAccount()
test.skip(`@AccountImage @Notifications Check notification received on NFT transfer`, async ({ authorized }) => {
const { TestNFTAddress, TestTokenHolder } = process.env
await authorized.openWatchlist()

const nft = await authorized.contracts.loadContract(`TestNFT`, TestNFTAddress) as TestNFT
const recipient = authorized.contracts.newWallet()
Expand All @@ -81,18 +85,20 @@ test.skip(`@Notifications Check notification received on NFT transfer`, async ({
address: recipient.address.toLowerCase(),
name: watchName,
} as WatchListSpec)
await authorized.check_tag_list(0, 0, watchName)
await authorized.check_tag_list(0, 1, `0x`)
await authorized.check_tag_list(0, 1, `(N/A)`)
await authorized.check_tag_list(0, 1, `Edit`)
await authorized.checkNotificationItem()
await authorized.delay(5000)
const receipt = await (await nft.transferOwnership(recipient.address)).wait()
console.log(`receipt: ${JSON.stringify(receipt)}`)
// const receipt = await (await nft.transferOwnership(recipient.address)).wait()
// console.log(`transferred ownership: ${JSON.stringify(receipt)}`)
const receipt = await (await nft.mintNFT(recipient.address, watchName)).wait()
console.log(`minted new token for recipient: ${JSON.stringify(receipt)}`)

await authorized.ms.waitForMatchingEmails(
const emailResult = await authorized.ms.waitForMatchingEmails(
{ matches: [{ field: MatchOptionFieldEnum.SUBJECT, should: MatchOptionShouldEnum.CONTAIN, value: watchName }] },
1,
process.env.MAILSLURP_EMAIL_ID,
emailTimeout,
)
expect(emailResult[0].subject).toContain(`[Address Watch Alert] 0.000000000000000001 NFT received at ${recipient} ${watchName}`)
expect(emailResult[0].from).toContain(`[email protected]`)
console.log(`Received email: ${JSON.stringify(emailResult)}`)
})
6 changes: 1 addition & 5 deletions tests/e2e/tests/functional/Tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NativeCurrencyProps, TokenRowProps } from '@pages/Tokens'

test.describe.configure({ mode: `parallel` })

test(`@AccountImage @Token Search token by the name`, async ({ tokensPage }) => {
test(`@AccountImage @Token Search token by name`, async ({ tokensPage }) => {
const { TestTokenSymbol, TestNFTSymbol } = process.env
await tokensPage.mock_ads()
await tokensPage.open()
Expand All @@ -15,15 +15,13 @@ test(`@AccountImage @Token Search token by the name`, async ({ tokensPage }) =>
summary: [`1`, `EPIC (EPC)`, `0x`, `ERC-20`],
price: ``,
marketCap: ``,
holders: `1`,
} as TokenRowProps)
await tokensPage.setFilter(`ERC-721`)
await tokensPage.search(TestNFTSymbol)
await tokensPage.check_token_row(1, {
summary: [`1`, `NFT`, `0x`, `ERC-721`],
price: ``,
marketCap: ``,
holders: `1`,
} as TokenRowProps)
})

Expand All @@ -37,15 +35,13 @@ test(`@AccountImage @Token Search a token by symbol`, async ({ tokensPage }) =>
summary: [`1`, `EPIC (EPC)`, `0x`, `ERC-20`],
price: ``,
marketCap: ``,
holders: `1`,
} as TokenRowProps)
await tokensPage.setFilter(`ERC-721`)
await tokensPage.search(TestNFTName)
await tokensPage.check_token_row(1, {
summary: [`1`, `NFT`, `0x`, `ERC-721`],
price: ``,
marketCap: ``,
holders: `1`,
} as TokenRowProps)
})

Expand Down
8 changes: 1 addition & 7 deletions tests/e2e/tests/functional/Transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ import test from '@lib/BaseTest'
test.describe.configure({ mode: `parallel` })

test(`@AccountImage @Transactions Check transactions list`, async ({ transactionsListPage }) => {
const {
TestNFTSymbolV,
TestTokenSymbolV,
TestNFTSymbol,
TestTokenSymbol,
} = process.env
await transactionsListPage.open()
await transactionsListPage.check_header()
await transactionsListPage.check_table_data(TestNFTSymbolV, TestNFTSymbol, TestTokenSymbolV, TestTokenSymbol)
await transactionsListPage.check_table_data()
})

test(`@AccountImage @Transactions Check contract creation tx props`, async ({ transactionPage }) => {
Expand Down
15 changes: 8 additions & 7 deletions tests/load/browser_vitals.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/blocks" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/txs" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/ops" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/tokens" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/accounts" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/address/0x54FA517F05e11Ffa87f4b22AE87d91Cec0C2D7E1?tab=token_transfers" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/token/0x183209DA02C281709A5BcD40188AaFfA04A7fEfD?tab=holders" ITERATIONS=5 VUS=10 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/blocks" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/txs" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/ops" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/tokens" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/accounts" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/address/0x54FA517F05e11Ffa87f4b22AE87d91Cec0C2D7E1" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/address/0x54FA517F05e11Ffa87f4b22AE87d91Cec0C2D7E1?tab=token_transfers" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts
LOKI_URL="http://localhost:3100/loki/api/v1/push" BASE_URL="https://eth-sepolia.blockscout.com" PAGE="/token/0x183209DA02C281709A5BcD40188AaFfA04A7fEfD?tab=holders" ITERATIONS=5 VUS=1 K6_BROWSER_ENABLED=true K6_BROWSER_HEADLESS=true ./bin_k6/k6-tsdb-darwin run src/frontend.browser.test.suite.ts

0 comments on commit 03180b6

Please sign in to comment.