Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
canlopes committed Nov 26, 2024
1 parent 45bc399 commit dcd12ab
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 227 deletions.
142 changes: 139 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- develop
- main
pull_request:
env:
PNPM_VERSION: 9
NODE_VERSION: 20.x

jobs:
build:
Expand Down Expand Up @@ -32,6 +35,12 @@ jobs:
name: Install pnpm
with:
run_install: false
version: ${{ env.PNPM_VERSION }}

- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"

- name: Get pnpm store directory
shell: bash
Expand All @@ -48,8 +57,58 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Build demo-dapp-starknet
run: pnpm run build

- name: Use Cache
uses: actions/cache@v4
with:
path: ./*
key: ${{ github.sha }}


test-webwallet:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.48.2-jammy
needs: [build]
env:
ARGENT_X_ENVIRONMENT: "hydrogen"

WW_EMAIL: ${{ secrets.WW_EMAIL }}
WW_LOGIN_PASSWORD: ${{ secrets.WW_LOGIN_PASSWORD }}
EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
version: ${{ env.PNPM_VERSION }}
run_install: false

- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"

- name: Restore pnpm cache
uses: actions/cache/restore@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Restore cached build
uses: actions/cache/restore@v4
with:
path: ./*
key: ${{ github.sha }}

- name: Run e2e tests
run: |
pnpm run start & # Start the server in background
Expand All @@ -67,6 +126,84 @@ jobs:
sleep 1
done
xvfb-run --auto-servernum pnpm test:webwallet
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: test-artifacts
path: |
e2e/artifacts/playwright/
!e2e/artifacts/playwright/*.webm
retention-days: 5

- name: Upload blob report to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: all-blob-reports
path: e2e/blob-report/
retention-days: 5

test-argentX:
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.48.2-jammy
needs: [build]
env:
ARGENT_X_ENVIRONMENT: "hydrogen"
E2E_REPO: ${{ secrets.E2E_REPO }}
E2E_REPO_TOKEN: ${{ secrets.E2E_REPO_TOKEN }}
E2E_REPO_OWNER: ${{ secrets.E2E_REPO_OWNER }}
E2E_REPO_RELEASE_NAME: ${{ secrets.E2E_REPO_RELEASE_NAME }}

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
name: Install pnpm
id: pnpm-install
with:
version: ${{ env.PNPM_VERSION }}
run_install: false

- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"

- name: Restore pnpm cache
uses: actions/cache/restore@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Restore cached build
uses: actions/cache/restore@v4
with:
path: ./*
key: ${{ github.sha }}

- name: Run e2e tests
run: |
pnpm run start & # Start the server in background
echo "Waiting for server to be ready..."
for i in {1..30}; do
if curl -s http://localhost:3000 > /dev/null; then
echo "Server is ready!"
break
fi
echo "Attempt $i: Server not ready yet..."
if [ $i -eq 30 ]; then
echo "Server failed to start"
exit 1
fi
sleep 1
done
xvfb-run --auto-servernum pnpm test:argentx
- name: Upload artifacts
uses: actions/upload-artifact@v4
if: always()
Expand All @@ -76,12 +213,11 @@ jobs:
e2e/artifacts/playwright/
!e2e/artifacts/playwright/*.webm
retention-days: 5

- name: Upload blob report to GitHub Actions Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: all-blob-reports
path: e2e/blob-report/
retention-days: 5

retention-days: 5
2 changes: 1 addition & 1 deletion e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const playwrightConfig: PlaywrightTestConfig = {
forbidOnly: config.isCI,
outputDir: config.artifactsDir,
preserveOutput: "failures-only",
// globalTeardown: "./src/utils/global.teardown.ts",
globalTeardown: "./src/shared/cfg/global.teardown.ts",
}

export default playwrightConfig
File renamed without changes.
File renamed without changes.
File renamed without changes.
85 changes: 85 additions & 0 deletions e2e/src/shared/src/SapoEmailClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import * as ImapClient from 'imap-simple';
import { simpleParser } from 'mailparser';

export default class SapoEmailClient {
private config: any;

constructor(email: string, password: string) {
this.config = {
imap: {
user: email,
password: password,
host: 'imap.sapo.pt',
port: 993,
tls: true,
tlsOptions: { rejectUnauthorized: false },
authTimeout: 3000
}
};
}

private async getConnection() {
return await ImapClient.connect(this.config);
}

private async moveToTrash(connection: any, messageId: number) {
await connection.moveMessage(messageId, 'Lixo');
}

async waitForEmail(timeout: number = 30000): Promise<string> {
const startTime = Date.now();
console.log('Waiting for verification email...');

while (Date.now() - startTime < timeout) {
try {
const connection = await this.getConnection();
await connection.openBox('INBOX');

const messages = await connection.search(['UNSEEN'], {
bodies: ['HEADER', ''], // Include headers for date checking
markSeen: true
});

if (messages.length > 0) {
// Filter messages by received date
for (let i = messages.length - 1; i >= 0; i--) {
const message = messages[i];
const body = message.parts.find(part => part.which === '');

if (body) {
const parsed = await simpleParser(body.body);
const messageDate = parsed.date || new Date();

// Check if message is less than 10 seconds old
if (messageDate > new Date(Date.now() - 10000)) {
const pin = parsed.subject?.match(/\d{6}/)?.[0];
if (pin) {
await this.moveToTrash(connection, message.attributes.uid);
await connection.end();
return pin;
}
}
}
}
}

await connection.end();
await new Promise(resolve => setTimeout(resolve, 2000));

} catch (error) {
console.error('Error checking email:', error);
await new Promise(resolve => setTimeout(resolve, 2000));
}
}

throw new Error(`No verification code found within ${timeout}ms`);
}

async getPin(): Promise<string> {
const pin = await this.waitForEmail();
if (!pin) {
throw new Error('No verification code found in email');
}
return pin;
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TransactionFinalityStatus,
num,
} from "starknet"
import commonConfig from "../config"
import commonConfig from "../../../config"
import { expect } from "@playwright/test"
import { logInfo, sleep } from "./common"

Expand All @@ -23,16 +23,27 @@ const isEqualAddress = (a?: string, b?: string) => {
return false
}

export type TokenSymbol = "ETH" | "WBTC" | "STRK" | "SWAY" | "USDC" | "DAI"
export type TokenSymbol =
| "ETH"
| "WBTC"
| "STRK"
| "SWAY"
| "USDC"
| "DAI"
| "ádfas"
export type TokenName =
| "Ethereum"
| "Wrapped BTC"
| "Starknet"
| "Standard Weighted Adalian Yield"
| "USD Coin"
| "DAI"
| "USD Coin (Fake)"
export type FeeTokens = "ETH" | "STRK"
export interface AccountsToSetup {
assets: {
token: TokenSymbol
balance: number
}[]
deploy?: boolean
feeToken?: FeeTokens
}
Expand Down Expand Up @@ -74,7 +85,11 @@ tokenAddresses.set("SWAY", {
address: "0x0030058F19Ed447208015F6430F0102e8aB82D6c291566D7E73fE8e613c3D2ed",
decimals: 18,
})

tokenAddresses.set("USDC", {
name: "USD Coin (Fake)",
address: "0x07ab0b8855a61f480b4423c46c32fa7c553f0aac3531bbddaa282d86244f7a23",
decimals: 6,
})
export const getTokenInfo = (tkn: string) => {
const tokenInfo = tokenAddresses.get(tkn)
if (!tokenInfo) {
Expand Down Expand Up @@ -113,8 +128,7 @@ const getAccount = async (amount: string, token: TokenSymbol) => {
parseFloat(initialBalance) * Math.pow(10, 18)
if (initialBalanceFormatted < parseInt(amount)) {
log.push(
`${
commonConfig.senderAddrs![randomAccountPosition]
`${commonConfig.senderAddrs![randomAccountPosition]
} Not enough balance ${initialBalanceFormatted} ${token} < ${amount}`,
)
} else {
Expand All @@ -140,9 +154,9 @@ const isTXProcessed = async (txHash: string) => {
txStatusResponse = await provider.getTransactionStatus(txHash)
if (
txStatusResponse.finality_status ===
TransactionFinalityStatus.ACCEPTED_ON_L2 ||
TransactionFinalityStatus.ACCEPTED_ON_L2 ||
txStatusResponse.finality_status ===
TransactionFinalityStatus.ACCEPTED_ON_L1
TransactionFinalityStatus.ACCEPTED_ON_L1
) {
txProcessed = true
} else {
Expand Down Expand Up @@ -177,6 +191,7 @@ const getTXData = async (txHash: string) => {
}
return { nodeUpdated, txData }
}

export async function transferTokens(
amount: number,
to: string,
Expand Down Expand Up @@ -216,7 +231,7 @@ export async function transferTokens(
}

console.error(
`[Failed to place TX] ${tx.transaction_hash} ${txStatusResponse}`,
`[Failed to place TX] ${tx.transaction_hash} ${JSON.stringify(txStatusResponse)}`,
)
} catch (e) {
if (e instanceof Error) {
Expand All @@ -234,7 +249,10 @@ export async function transferTokens(
return null
}

async function getBalance(accountAddress: string, token: TokenSymbol = "ETH") {
export async function getBalance(
accountAddress: string,
token: TokenSymbol = "ETH",
) {
const tokenInfo = getTokenInfo(token)
logInfo({ op: "getBalance", accountAddress, token, tokenInfo })
const balanceOfCall = {
Expand Down
Loading

0 comments on commit dcd12ab

Please sign in to comment.