Skip to content

Commit

Permalink
Merge pull request #128 from zkBob/staging
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
maxaleks authored Jan 16, 2023
2 parents 22b8757 + aa3dab2 commit c322e76
Show file tree
Hide file tree
Showing 75 changed files with 3,654 additions and 194 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/e2e_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: E2E tests

on:
pull_request:
branches:
staging
push:
branches:
e2e-tests

env:
ENV: local
jobs:
test:
name: E2E tests
runs-on: ubuntu-latest
env:
BASE_URL: ${{ secrets.BASE_URL }}
ZKACCOUNT_PASSWORD: ${{ secrets.ZKACCOUNT_PASSWORD }}
ZKACCOUNT_SEED_PHRASE: ${{ secrets.ZKACCOUNT_SEED_PHRASE }}
ZKBOB_RECEIVER_ADDRESS: ${{ secrets.ZKBOB_RECEIVER_ADDRESS }}
METAMASK_PASSWORD: ${{ secrets.METAMASK_PASSWORD }}
METAMASK_SEED_PHRASE: ${{ secrets.METAMASK_SEED_PHRASE }}
ADDRESS_METAMASK_ACCOUNT: ${{ secrets.ADDRESS_METAMASK_ACCOUNT }}
steps:
- name: Check out this repo
uses: actions/checkout@v3

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: v14.17.0

- name: Install Playwright
run: |
cd e2e-ci-cd/
npm install --global yarn
yarn
npx playwright install
- name: Create account
run: |
cd e2e-ci-cd/ && xvfb-run yarn test zkaccount.test.ts
- name: Deposit
if: always()
run: |
cd e2e-ci-cd/ && xvfb-run yarn test deposit.test.ts
- name: Transfer
if: always()
run: |
cd e2e-ci-cd/ && xvfb-run yarn test transfer.test.ts
- name: Withdraw
if: always()
run: |
cd e2e-ci-cd/ && xvfb-run yarn test withdraw.test.ts
- uses: actions/upload-artifact@v3
if: always()
with:
name: report
path: e2e-ci-cd/test-results/

45 changes: 45 additions & 0 deletions e2e-ci-cd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.swp

pids
logs
results
tmp

# Build
public/css/main.css

# Coverage reports
coverage

# API keys and secrets
.env
.env.local


# Dependency directory
node_modules
bower_components

# Editors
.idea
*.iml

# OS metadata
.DS_Store
Thumbs.db

# ignore yarn.lock
yarn.lock

test-results/
tmp/
dist/metamask/**
playwright-report/
24 changes: 24 additions & 0 deletions e2e-ci-cd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### E2E UI TESTS

Install dependencies:
```
npm install --global yarn
yarn
```

Create `.env.local` file :
```
BASE_URL=""
ZKACCOUNT_PASSWORD=""
ZKACCOUNT_SEED_PHRASE=""
ZKBOB_RECEIVER_ADDRESS = ""
METAMASK_PASSWORD = ""
METAMASK_SEED_PHRASE = ""
ADDRESS_METAMASK_ACCOUNT = ""
```
Run:
```
yarn test
```
18 changes: 18 additions & 0 deletions e2e-ci-cd/__tests__/deposit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test } from '../fixtures/testContextFixture';

test.beforeEach(async ({metamask, zkAccount}) => {
await metamask.importWallet()
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.ConnectMetaMaskWallet()
await zkAccount.GenerateKey()
await zkAccount.CreatePassword()
await zkAccount.CheckAccount()
});



test('Deposit', async({OperationsWithToken}) => {
await OperationsWithToken.Deposit()
})
7 changes: 7 additions & 0 deletions e2e-ci-cd/__tests__/metamask_connect.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { test } from '../fixtures/testContextFixture';

test('Import wallet', async ({app, metamask}) => {
await metamask.importWallet()
await app.open('/')
await app.connectMetamask()
});
28 changes: 28 additions & 0 deletions e2e-ci-cd/__tests__/operationswithtoken.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test } from '../fixtures/testContextFixture';

test.beforeEach(async ({metamask, zkAccount}) => {
await metamask.importWallet()
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.ConnectMetaMaskWallet()
await zkAccount.GenerateKey()
await zkAccount.CreatePassword()
await zkAccount.CheckAccount()
});



test('Deposit', async({OperationsWithToken}) => {
await OperationsWithToken.Deposit()
})

test('Transfer', async({OperationsWithToken}) => {
await OperationsWithToken.Transfer()
await OperationsWithToken.CheckTransfer()
})

test('Withdraw', async ({OperationsWithToken}) => {
await OperationsWithToken.Withdraw()
})

17 changes: 17 additions & 0 deletions e2e-ci-cd/__tests__/transfer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { test } from '../fixtures/testContextFixture';

test.beforeEach(async ({metamask, zkAccount}) => {
await metamask.importWallet()
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.ConnectMetaMaskWallet()
await zkAccount.GenerateKey()
await zkAccount.CreatePassword()
await zkAccount.CheckAccount()
});

test('Transfer', async({OperationsWithToken}) => {
await OperationsWithToken.Transfer()
await OperationsWithToken.CheckTransfer()
})
14 changes: 14 additions & 0 deletions e2e-ci-cd/__tests__/withdraw.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from '../fixtures/testContextFixture';

test.beforeEach(async ({metamask, zkAccount}) => {
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.RestoreAccount()
await zkAccount.CreatePassword()
await zkAccount.CheckAccount()
});

test('Withdraw', async ({OperationsWithToken}) => {
await OperationsWithToken.Withdraw()
})
33 changes: 33 additions & 0 deletions e2e-ci-cd/__tests__/zkaccount.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test } from '../fixtures/testContextFixture';

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


test('Create zkAccount with MetaMask', async ({zkAccount, metamask}) => {
await metamask.importWallet()
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.ConnectMetaMaskWallet()
await zkAccount.GenerateKey()
await zkAccount.CreatePassword()
await zkAccount.CheckAccount()
});

test('Create zkAccount from seed phrase', async ({zkAccount}) => {
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.CreateWithSecretRecoveryPhrase()
await zkAccount.CheckAccount()
});

test('Restore zkAccount', async ({zkAccount}) => {
await zkAccount.open('/')
await zkAccount.button_zkAccount()
await zkAccount.button_Agree()
await zkAccount.RestoreAccount()
await zkAccount.CreatePassword()
await zkAccount.CheckAccount()

});
11 changes: 11 additions & 0 deletions e2e-ci-cd/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const TIMEOUTS = {
tiny: 100,
fast: 1000,
small: 3 * 1000,
medium: 5 * 1000,
big: 30 * 1000,
huge: 45 * 1000,
oneMinute: 60 * 1000,
fiveMinutes: 5 * 60 * 1000,
tenMinutes: 10 * 60 * 1000,
};
Binary file added e2e-ci-cd/dist/metamask-chrome-10.19.0.zip
Binary file not shown.
75 changes: 75 additions & 0 deletions e2e-ci-cd/fixtures/testContextFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import path from 'path';
import { BrowserContext, chromium, test as base } from '@playwright/test';

import App from '../pages/app';
import zkAccountPage from '../pages/PageObjects/zkAccount/zkAccountElements';

import Metamask from '../pages/metamask';
import OperationsWithTokenPages from '../pages/PageObjects/OperationsWithToken/OperationsWithTokenElements';

interface TestContextFixture {
metamask: Metamask;
metamaskContext: BrowserContext;
app: App;
zkAccount: zkAccountPage;
OperationsWithToken: OperationsWithTokenPages;
}

export const test = base.extend<TestContextFixture>({
metamaskContext: [
async ({}, use) => {
const pathToExtension = path.join(__dirname, '../dist/metamask/');
const userDataDir = path.join(
__dirname,
`../tmp/${+new Date()}${Math.random()}`,
);

const context = await chromium.launchPersistentContext(userDataDir, {
headless: false,
viewport: { width: 1080, height: 800 },
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
'--disable-dev-shm-usage',
'--no-sandbox',
'--disable-gpu',
'--disable-dev-shm-usage',
],
locale: 'en-US',
});
await use(context);
await context.close()
},
{ scope: 'test', auto: true },
],
metamask: [
({ metamaskContext: context }, use) => {
context.on('page', async (page) => {
await page.waitForLoadState();
if ((await page.title()) === 'MetaMask') {
await page.reload();
await page.waitForLoadState();
await use(new Metamask(page));
}
});
},
{ scope: 'test' },
],

app: async ({ metamaskContext: context }, use) => {
await use(new App(context.pages()[0]));
await context.close();
},

zkAccount: async ({ metamaskContext: context }, use) => {
await use(new zkAccountPage(context.pages()[0]));
await context.close();
},

OperationsWithToken: async ({ metamaskContext: context }, use) => {
await use(new OperationsWithTokenPages(context.pages()[0]));
await context.close();
},


});
15 changes: 15 additions & 0 deletions e2e-ci-cd/globalSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import extract from 'extract-zip';
import path from 'path';

async function unpackMetamaskExtension(): Promise<void> {
const source = path.join(__dirname, './dist/metamask-chrome-10.19.0.zip');
const target = path.join(__dirname, './dist/metamask');

return extract(source, { dir: target });
}

async function globalSetup() {
await unpackMetamaskExtension();
}

export default globalSetup;
Loading

0 comments on commit c322e76

Please sign in to comment.