Skip to content

Commit

Permalink
Merge pull request #14 from cardanoapi/feat/test-wallet-setup
Browse files Browse the repository at this point in the history
Feat/test wallet setup
  • Loading branch information
mesudip authored Nov 12, 2024
2 parents 104f4f2 + c470147 commit 28fea29
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 4 deletions.
7 changes: 7 additions & 0 deletions integration_test/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
HOST_URL=http://localhost:3000

# Kuber
KUBER_API_URL=https://sanchonet.kuber.cardanoapi.io
KUBER_API_KEY=**********************

NETWORK_ID=0
44 changes: 44 additions & 0 deletions integration_test/lib/_mock/wallets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"payment": {
"private": "abe5d299bad4a8d647aa32c035db629ae280b53c86dc3b26b25b56b22ce0c8c5",
"public": "8e5272688b9767e5c05c837942cc7639c93170007485aa3327b0abae683bbfec",
"pkh": "bac5bd9f97c9376591dd2732726fecf0be1b36bb7092c64a7c51fef3"
},
"stake": {
"private": "bf69cd66f2804383fb87354ada9a7d6e11394f1282a283cc2539e6fa64085c33",
"public": "c43ab393110d7fc4012188ec9255da8bf43c2894c9f587a5048978bf08db2784",
"pkh": "b66f5cd9613c3d47b3530ba39ab6753066da4e789c8365e1bfabd6c6"
},
"dRepId": "drep1keh4ektp8s750v6npw3e4dn4xpnd5nncnjpktcdl40tvvmjt3xc",
"address": "addr_test1qzavt0vljlynwev3m5nnyun0anctuxekhdcf93j203glauakdawdjcfu84rmx5ct5wdtvafsvmdyu7yusdj7r0at6mrqxfl5gt"
},
{
"payment": {
"private": "4e0218009da82606795b7c5f4995e89a78698203bb135204ee1bc0fdedb97279",
"public": "89fe1dae4d0a3b06b9b321159ffa5bd7e1f808200ad2825e1ed9b893c42e72bb",
"pkh": "5156d476b9bde375c5c86eb0491c556c304315b7165fe70b67f337b4"
},
"stake": {
"private": "1ba124ca20b58dc2e08e1f2c5c7ac8303d4c3295916392425bf7c4d34852c039",
"public": "715e21815ce70d970728e5c362f85d0ce9e71b9e4d26118d84108a7c81ee6eb9",
"pkh": "e8751984dab6c3825e32664a321ba226721bbbf647589b9ef15977e0"
},
"dRepId": "drep1ap63npx6kmpcyh3jve9ryxazyeephwlkgavfh8h3t9m7qacatcx",
"address": "addr_test1qpg4d4rkhx77xaw9ephtqjgu24krqsc4kut9lectvlen0d8gw5vcfk4kcwp9uvnxfgephg3xwgdmhaj8tzdeau2ewlsq05hvt3"
},
{
"payment": {
"private": "40b50e5bf331b37d96e73b7ea765898920035c3ab67e0c872ffde26bfcae0df7",
"public": "730f888af3f11fb5d950d2e20926f0d549f01862948221db1445cfe4522be037",
"pkh": "826c6b4c7dedeadf495de7d630d29237c90753b42c4c844dbf8ded38"
},
"stake": {
"private": "0ec43db59aace8787647e448bb9a2f078c385a75d941c6b9ad0fbf261dc5dd7f",
"public": "5d086f9ea5b173befda3a75511dfc365c3ec657dd713f2bd73e0073465261778",
"pkh": "109f0738c2db939100551d53d8e018843d74256d269704f58eba541e"
},
"dRepId": "drep1zz0swwxzmwfezqz4r4fa3cqcss7hgftdy6tsfavwhf2pu7d95jj",
"address": "addr_test1qzpxc66v0hk74h6fthnavvxjjgmujp6nkskyepzdh7x76wqsnurn3skmjwgsq4ga20vwqxyy846z2mfxjuz0tr462s0qw8jepc"
}
]
6 changes: 6 additions & 0 deletions integration_test/lib/constants/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { config } from 'dotenv';
config();
const environments = {
baseUrl: process.env.HOST_URL || 'http://localhost:3000',
kuber: {
apiUrl:
process.env.KUBER_API_URL || 'https://sanchonet.kuber.cardanoapi.io',
apiKey: process.env.KUBER_API_KEY || '',
},
networkId: process.env.NETWORK_ID || 0,
ci: process.env.CI,
};

Expand Down
8 changes: 8 additions & 0 deletions integration_test/lib/constants/staticWallets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
const staticWallets: StaticWallet[] = require('../_mock/wallets.json');
import { StaticWallet } from '@types';

export const organizerWallet = staticWallets[0];

export const delegateWallet = staticWallets[1];
export const alternateWallet = staticWallets[2];
14 changes: 14 additions & 0 deletions integration_test/lib/fixtures/importWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CardanoTestWalletJson } from '@cardanoapi/cardano-test-wallet/types';
import { Page } from '@playwright/test';
import { StaticWallet } from '@types';

export async function importWallet(
page: Page,
wallet: StaticWallet | CardanoTestWalletJson
): Promise<void> {
await page.addInitScript((wallet) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
window.cardanoTestWallet.wallet = wallet;
}, wallet);
}
38 changes: 38 additions & 0 deletions integration_test/lib/fixtures/loadExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
CardanoTestWallet,
CardanoTestWalletConfig,
} from '@cardanoapi/cardano-test-wallet/types';
import environments from '@constants/environments';
import { Page } from '@playwright/test';


// eslint-disable-next-line @typescript-eslint/no-require-imports
import path = require('path');

export default async function loadEternlExtension(
page: Page,
enableStakeSigning?: boolean,
supportedExtensions?: Record<string, number>[]
): Promise<void> {
const eternlBundleScriptPath = path.resolve(
__dirname,
'../../node_modules/@cardanoapi/cardano-test-wallet/script.js'
);
const walletConfig: CardanoTestWalletConfig = {
enableStakeSigning,
kuberApiUrl: environments.kuber.apiUrl,
kuberApiKey: environments.kuber.apiKey,
};
await page.addInitScript(
({ walletConfig, supportedExtensions }) => {
window['cardanoTestWallet'] = {
walletName: 'eternl',
supportedExtensions,
config: walletConfig,
} as CardanoTestWallet;
},
{ walletConfig, supportedExtensions }
);

await page.addInitScript({ path: eternlBundleScriptPath });
}
31 changes: 31 additions & 0 deletions integration_test/lib/fixtures/walletExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test as base } from '@playwright/test';
import { StaticWallet } from '@types';
import { importWallet } from './importWallet';
import loadEternlExtension from './loadExtension';

type WalletExtensionTestOptions = {
wallet?: StaticWallet;
enableStakeSigning: boolean;
supportedExtensions: Record<string, number>[];
};

export const test = base.extend<WalletExtensionTestOptions>({
wallet: [null, { option: true }],

enableStakeSigning: [true, { option: true }],

supportedExtensions: [],

page: async (
{ page, wallet, enableStakeSigning, supportedExtensions },
use
) => {
await loadEternlExtension(page, enableStakeSigning, supportedExtensions);

if (wallet) {
await importWallet(page, wallet);
}

await use(page);
},
});
26 changes: 26 additions & 0 deletions integration_test/lib/helpers/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { importWallet } from '@fixtures/importWallet';
import LoginPage from '@pages/loginPage';
import { BrowserContext, Page } from '@playwright/test';
import { StaticWallet } from '@types';

interface CreateUserProps {
page: Page;
context: BrowserContext;
wallet: StaticWallet;
auth: string;
}

export async function createAuth({
page,
context,
wallet,
auth,
}: CreateUserProps): Promise<void> {
await importWallet(page, wallet);

const loginPage = new LoginPage(page);
await loginPage.login();
await loginPage.isLoggedIn();

await context.storageState({ path: auth });
}
29 changes: 29 additions & 0 deletions integration_test/lib/pages/loginPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Page, expect } from '@playwright/test';

export default class LoginPage {
readonly connectWalletBtn = this.page.getByTestId('connect-wallet-button');
readonly eternlWalletBtn = this.page.getByTestId('connect-wallet-Eternl');
readonly disconnectWalletBtn = this.page.getByTestId('disconnect-wallet');

constructor(private readonly page: Page) {}

async goto(): Promise<void> {
await this.page.goto('/');
}

async login(): Promise<void> {
await this.goto();

await this.connectWalletBtn.first().click();
await this.eternlWalletBtn.click({ force: true });
}

async logout(): Promise<void> {
await this.disconnectWalletBtn.click();
}

async isLoggedIn(): Promise<void> {
await this.connectWalletBtn.first().click();
await expect(this.disconnectWalletBtn).toBeVisible();
}
}
6 changes: 6 additions & 0 deletions integration_test/lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { CardanoTestWalletJson } from '@cardanoapi/cardano-test-wallet/types';

export type StaticWallet = CardanoTestWalletJson & {
dRepId: string;
address: string;
};
37 changes: 37 additions & 0 deletions integration_test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions integration_test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
"devDependencies": {
"@playwright/test": "^1.44.1",
"@types/node": "^20.12.12",
"dotenv": "^16.4.4",
"prettier": "3.2.5",
"allure-commandline": "^2.27.0",
"allure-playwright": "^2.15.0",
"allure-commandline": "^2.27.0"
"dotenv": "^16.4.4",
"prettier": "3.2.5"
},
"dependencies": {
"@cardanoapi/cardano-test-wallet": "^2.1.1",
"@noble/curves": "^1.6.0"
}
}
44 changes: 44 additions & 0 deletions integration_test/tests/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
alternateWallet,
delegateWallet,
organizerWallet,
} from '@constants/staticWallets';
import { test as setup } from '@fixtures/walletExtension';
import { setAllureEpic, setAllureStory } from '@helpers/allure';
import { createAuth } from '@helpers/auth';

const organizerAuthFile = '.auth/organizer.json';
const delegateAuthFile = '.auth/delegate.json';
const alternateAuthFile = '.auth/organizer.json';

setup.beforeEach(async () => {
await setAllureEpic('Setup');
await setAllureStory('Authentication');
});

setup('Create organizer auth', async ({ page, context }) => {
await createAuth({
page,
context,
wallet: organizerWallet,
auth: organizerAuthFile,
});
});

setup('Create delegate auth', async ({ page, context }) => {
await createAuth({
page,
context,
wallet: delegateWallet,
auth: delegateAuthFile,
});
});

setup('Create alternate auth', async ({ page, context }) => {
await createAuth({
page,
context,
wallet: alternateWallet,
auth: alternateAuthFile,
});
});
3 changes: 2 additions & 1 deletion integration_test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"@helpers/*": ["lib/helpers/*"],
"@pages/*": ["lib/pages/*"],
"@constants/*": ["lib/constants/*"],
"@datafactory/*": ["lib/datafactory/*"]
"@datafactory/*": ["lib/datafactory/*"],
"@types": ["lib/types.ts"],
}
}
}

0 comments on commit 28fea29

Please sign in to comment.