Skip to content

Commit

Permalink
Merge pull request #3723 from Emurgo/denis/e2e-tests/dapp-tests-fixes
Browse files Browse the repository at this point in the history
Dapp tests fixes
  • Loading branch information
vsubhuman authored Nov 3, 2024
2 parents 6ba699c + 7f1f0e6 commit bed2ead
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 138 deletions.
2 changes: 1 addition & 1 deletion packages/e2e-tests/helpers/mock-dApp-webpage/dAppHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const connectNonAuth = async (
testWalettObj,
checkBalance = true
) => {
await mockedDApp.requestNonAuthAccess();
await mockedDApp.requestAccess();
const dappConnectPage = new DAppConnectWallet(webdriver, logger);
// the window focus is switched to the pop-up here
const popUpAppeared = await dappConnectPage.popUpIsDisplayed(windowManager);
Expand Down
25 changes: 7 additions & 18 deletions packages/e2e-tests/helpers/mock-dApp-webpage/mockedDApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
getCSLPubKeyHash,
getCslValue,
getDRepIDHexAndBechFromHex,
mapCborUtxos, bytesToHex,
mapCborUtxos,
bytesToHex,
} from './dAppTxHelper.js';

class MockDAppWebpageError extends Error {}
Expand All @@ -22,13 +23,9 @@ export class MockDAppWebpage {
this.logger = logger;
}

async _requestAccess(auth = false) {
this.logger.info(
`MockDApp::_requestAccess Requesting the access ${auth ? 'with' : 'without'} authentication`
);
const scriptString = `window.accessRequestPromise = cardano.yoroi.enable(${
auth ? '{requestIdentification: true}' : ''
})`;
async requestAccess() {
this.logger.info(`MockDApp::requestAccess Requesting the access without authentication`);
const scriptString = `window.accessRequestPromise = cardano.yoroi.enable()`;
await this.driver.executeScript(scriptString);
}

Expand Down Expand Up @@ -165,14 +162,6 @@ export class MockDAppWebpage {
return addressesResult;
}

async requestNonAuthAccess() {
await this._requestAccess();
}

async requestAuthAccess() {
await this._requestAccess(true);
}

async checkAccessRequest() {
this.logger.info(`MockDApp::checkAccessRequest Checking the access request`);
const accessResponse = await this.driver.executeAsyncScript((...args) => {
Expand Down Expand Up @@ -639,7 +628,7 @@ export class MockDAppWebpage {
}

async getSigningDataCIP95Result() {
this.logger.info(`MockDApp::getSigningDataResult Getting signing data result`);
this.logger.info(`MockDApp::getSigningDataCIP95Result Getting signing data result`);
const signingResult = await this.driver.executeAsyncScript((...args) => {
const callback = args[args.length - 1];
window.signDataCIP95Promise
Expand All @@ -656,7 +645,7 @@ export class MockDAppWebpage {
});
});
this.logger.info(
`MockDApp::getSigningDataResult Signing data result: ${JSON.stringify(signingResult, null, 2)}`
`MockDApp::getSigningDataCIP95Result Signing data result: ${JSON.stringify(signingResult, null, 2)}`
);
return signingResult;
}
Expand Down
13 changes: 9 additions & 4 deletions packages/e2e-tests/helpers/restoreWalletHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import CreateWalletStepOne from '../pages/newWalletPages/createWalletSteps/creat
import CreateWalletStepTwo from '../pages/newWalletPages/createWalletSteps/createWalletStepTwo.page.js';
import CreateWalletStepThree from '../pages/newWalletPages/createWalletSteps/createWalletStepThree.page.js';
import { isChrome, walletNameShortener } from '../utils/utils.js';
import { extensionTabName, serviceWorkersTabName, WindowManager } from './windowManager.js';
import {
extensionTabName,
serviceWorkersLink,
serviceWorkersTabName,
WindowManager,
} from './windowManager.js';

export const restoreWallet = async (webdriver, logger, testWallet, shouldBeModalWindow = true) => {
const addNewWalletPage = new AddNewWallet(webdriver, logger);
Expand Down Expand Up @@ -106,7 +111,7 @@ export const preloadDBAndStorage = async (webdriver, logger, templateName) => {
expect(state, 'The Add new wallet page is not displayed').to.be.true;
await addWalletPage.prepareDBAndStorage(templateName);
// It is necessary to re-run the service worker after loading info into the indexedDB
if (isChrome()){
if (isChrome()) {
await restartServiceWorker(webdriver, logger);
} else {
await addWalletPage.refreshPage();
Expand All @@ -125,7 +130,7 @@ export const restartServiceWorker = async (webdriver, logger) => {
logger.info(`--------------------- restartServiceWorker START ---------------------`);
const windowManager = new WindowManager(webdriver, logger);
windowManager.init();
await windowManager.openNewTab(serviceWorkersTabName, serviceWorkersTabName);
await windowManager.openNewTab(serviceWorkersTabName, serviceWorkersLink);

const basepage = new BasePage(webdriver, logger);

Expand Down Expand Up @@ -163,4 +168,4 @@ export const collectInfo = async (mochaContext, webdriver, logger) => {
basepage.getBrowserLogs(mochaContext.test.parent.title, 'preparationSteps');
basepage.getDriverLogs(mochaContext.test.parent.title, 'preparationSteps');
logger.info(`--------------------- collectInfo END ---------------------`);
}
};
2 changes: 1 addition & 1 deletion packages/e2e-tests/helpers/windowManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class WindowManagerError extends Error {}

export const mockDAppName = 'MockDApp';
export const popupConnectorName = 'popupConnectorWindow';
export const popupConnectorWindowTitle = 'Yoroi dApp Connector';
export const popupConnectorWindowTitle = 'Yoroi Dapp Connector';
export const extensionTabName = 'Yoroi';
export const faqTabName = 'Yoroi - EMURGO';
export const trezorConnectTabName = 'Trezor';
Expand Down
16 changes: 10 additions & 6 deletions packages/e2e-tests/pages/basepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,31 @@ class BasePage {
);
const testRundDataDir = createTestRunDataDir(testSuiteName);
const cleanName = logFileName.replace(/ /gi, '_');
const logsPaths = path.resolve(testRundDataDir, `console_${cleanName}-log.json`);
const logsPaths = path.resolve(testRundDataDir, `console_browser_${cleanName}.log`);
if (isChrome()) {
const logEntries = await this.driver
.manage()
.logs()
.get(logging.Type.BROWSER, logging.Level.ALL);
const jsonLogs = logEntries.map(l => JSON.stringify(l.toJSON(), null, 2));
await writeFile(logsPaths, `[\n${jsonLogs.join(',\n')}\n]`);
const jsonLogsStrings = logEntries.map(l => {
const splitMsg = l.message.split(' ');
const message = splitMsg.slice(2).join(' ');
return `[${l.level}] [${l.timestamp}] ${message}`
});
await writeFile(logsPaths, jsonLogsStrings.join(',\n'));
}
}
async getDriverLogs(testSuiteName, logFileName) {
this.logger.info(`BasePage::getDriverLogs is called.`);
const testRundDataDir = createTestRunDataDir(testSuiteName);
const cleanName = logFileName.replace(/ /gi, '_');
const driverLogsPaths = path.resolve(testRundDataDir, `driver_${cleanName}-log.json`);
const driverLogsPaths = path.resolve(testRundDataDir, `driver_${cleanName}.log`);
const driverLogEntries = await this.driver
.manage()
.logs()
.get(logging.Type.DRIVER, logging.Level.INFO);
const jsonDriverLogs = driverLogEntries.map(l => JSON.stringify(l.toJSON(), null, 2));
await writeFile(driverLogsPaths, `[\n${jsonDriverLogs.join(',\n')}\n]`);
const driverLogsStrings = driverLogEntries.map(l =>`[${l.level}] [${l.timestamp}] ${l.message}`);
await writeFile(driverLogsPaths, driverLogsStrings.join(','));
}
async waitForElementLocated(locator) {
this.logger.info(
Expand Down
27 changes: 15 additions & 12 deletions packages/e2e-tests/test/dapp/dAppConnection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { testWallet1 } from '../../utils/testWallets.js';
import { expect } from 'chai';
import { getTestLogger } from '../../utils/utils.js';
import { oneMinute } from '../../helpers/timeConstants.js';
import { restoreWallet } from '../../helpers/restoreWalletHelper.js';
import { WindowManager, extensionTabName, mockDAppName } from '../../helpers/windowManager.js';
import { getMockServer, mockDAppUrl } from '../../helpers/mock-dApp-webpage/mockServer.js';
import { MockDAppWebpage } from '../../helpers/mock-dApp-webpage/mockedDApp.js';
import { connectNonAuth } from '../../helpers/mock-dApp-webpage/dAppHelper.js';
import ConnectorTab from '../../pages/wallet/connectorTab/connectorTab.page.js';
import driversPoolsManager from '../../utils/driversPool.js';
import { collectInfo, preloadDBAndStorage, waitTxPage } from '../../helpers/restoreWalletHelper.js';

describe('dApp, connection in extension', function () {
this.timeout(2 * oneMinute);
Expand All @@ -21,25 +21,28 @@ describe('dApp, connection in extension', function () {
let mockedDApp = null;

before(async function () {
webdriver = await driversPoolsManager.getDriverFromPool();
mockServer = getMockServer({});
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
logger = getTestLogger(this.test.parent.title);
});

it('Restore a 15-word wallet', async function () {
await restoreWallet(webdriver, logger, testWallet1);
try {
webdriver = await driversPoolsManager.getDriverFromPool();
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
await preloadDBAndStorage(webdriver, logger, 'testWallet1');
await waitTxPage(webdriver, logger);
} catch (error) {
await collectInfo(this, webdriver, logger);
throw new Error(error);
}
});

it('Open a dapp page', async function () {
await windowManager.openNewTab(mockDAppName, mockDAppUrl);
});

it('Connect the wallet without auth to the dapp', async function () {
it('Connect the wallet to the dapp', async function () {
await connectNonAuth(webdriver, logger, windowManager, mockedDApp, testWallet1);
});

Expand Down
29 changes: 16 additions & 13 deletions packages/e2e-tests/test/dapp/dAppConnectionCancel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { testWallet1 } from '../../utils/testWallets.js';
import { expect } from 'chai';
import { getTestLogger } from '../../utils/utils.js';
import { oneMinute } from '../../helpers/timeConstants.js';
import { restoreWallet } from '../../helpers/restoreWalletHelper.js';
import { WindowManager, mockDAppName, popupConnectorName } from '../../helpers/windowManager.js';
import { getMockServer, mockDAppUrl } from '../../helpers/mock-dApp-webpage/mockServer.js';
import { MockDAppWebpage } from '../../helpers/mock-dApp-webpage/mockedDApp.js';
import DAppConnectWallet from '../../pages/dapp/dAppConnectWallet.page.js';
import { ApiErrorCode } from '../../helpers/mock-dApp-webpage/cip30Errors.js';
import driversPoolsManager from '../../utils/driversPool.js';
import { collectInfo, preloadDBAndStorage, waitTxPage } from '../../helpers/restoreWalletHelper.js';

describe('dApp, cancel connection', function () {
this.timeout(2 * oneMinute);
Expand All @@ -21,26 +21,29 @@ describe('dApp, cancel connection', function () {
let mockedDApp = null;

before(async function () {
webdriver = await driversPoolsManager.getDriverFromPool();
mockServer = getMockServer({});
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
logger = getTestLogger(this.test.parent.title);
});

it('Restore a 15-word wallet', async function () {
await restoreWallet(webdriver, logger, testWallet1);
try {
webdriver = await driversPoolsManager.getDriverFromPool();
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
await preloadDBAndStorage(webdriver, logger, 'testWallet1');
await waitTxPage(webdriver, logger);
} catch (error) {
await collectInfo(this, webdriver, logger);
throw new Error(error);
}
});

it('Open a dapp page', async function () {
await windowManager.openNewTab(mockDAppName, mockDAppUrl);
});

it('Request connection the wallet without auth to the dapp', async function () {
await mockedDApp.requestNonAuthAccess();
it('Request connection the wallet to the dapp', async function () {
await mockedDApp.requestAccess();
const dappConnectPage = new DAppConnectWallet(webdriver, logger);
// the window focus is switched to the pop-up here
const popUpAppeared = await dappConnectPage.popUpIsDisplayed(windowManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('dApp, connection, no wallets', function () {
});

it('Request connection', async function () {
await mockedDApp.requestNonAuthAccess();
await mockedDApp.requestAccess();
const dappConnectPage = new DAppConnectWallet(webdriver, logger);
const popUpAppeared = await dappConnectPage.popUpIsDisplayed(windowManager);
expect(popUpAppeared, 'The connector pop-up is not displayed').to.be.true;
Expand Down
25 changes: 14 additions & 11 deletions packages/e2e-tests/test/dapp/dAppGeneral.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { testWallet1 } from '../../utils/testWallets.js';
import { expect } from 'chai';
import { getTestLogger } from '../../utils/utils.js';
import { oneMinute } from '../../helpers/timeConstants.js';
import { restoreWallet } from '../../helpers/restoreWalletHelper.js';
import { WindowManager, mockDAppName } from '../../helpers/windowManager.js';
import { getMockServer, mockDAppUrl } from '../../helpers/mock-dApp-webpage/mockServer.js';
import { MockDAppWebpage } from '../../helpers/mock-dApp-webpage/mockedDApp.js';
import { connectNonAuth } from '../../helpers/mock-dApp-webpage/dAppHelper.js';
import { adaInLovelaces } from '../../helpers/constants.js';
import driversPoolsManager from '../../utils/driversPool.js';
import { collectInfo, preloadDBAndStorage, waitTxPage } from '../../helpers/restoreWalletHelper.js';

describe('dApp, general functions, without pop-up', function () {
this.timeout(2 * oneMinute);
Expand All @@ -21,18 +21,21 @@ describe('dApp, general functions, without pop-up', function () {
let mockedDApp = null;

before(async function () {
webdriver = await driversPoolsManager.getDriverFromPool();
mockServer = getMockServer({});
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
logger = getTestLogger(this.test.parent.title);
});

it('Restore a 15-word wallet', async function () {
await restoreWallet(webdriver, logger, testWallet1);
try {
webdriver = await driversPoolsManager.getDriverFromPool();
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
await preloadDBAndStorage(webdriver, logger, 'testWallet1');
await waitTxPage(webdriver, logger);
} catch (error) {
await collectInfo(this, webdriver, logger);
throw new Error(error);
}
});

it('Open a dapp page', async function () {
Expand Down
27 changes: 15 additions & 12 deletions packages/e2e-tests/test/dapp/dAppGetCollateralErrorMaxLimit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { testWallet1 } from '../../utils/testWallets.js';
import { expect } from 'chai';
import { getTestLogger } from '../../utils/utils.js';
import { oneMinute } from '../../helpers/timeConstants.js';
import { restoreWallet } from '../../helpers/restoreWalletHelper.js';
import { WindowManager, mockDAppName } from '../../helpers/windowManager.js';
import { getMockServer, mockDAppUrl } from '../../helpers/mock-dApp-webpage/mockServer.js';
import { MockDAppWebpage } from '../../helpers/mock-dApp-webpage/mockedDApp.js';
import { connectNonAuth } from '../../helpers/mock-dApp-webpage/dAppHelper.js';
import { adaInLovelaces } from '../../helpers/constants.js';
import { ApiErrorCode } from '../../helpers/mock-dApp-webpage/cip30Errors.js';
import driversPoolsManager from '../../utils/driversPool.js';
import { collectInfo, preloadDBAndStorage, waitTxPage } from '../../helpers/restoreWalletHelper.js';

describe('dApp, getCollateral, error, max limit, not auth,', function () {
describe('dApp, getCollateral, error, max limit', function () {
this.timeout(2 * oneMinute);
let webdriver = null;
let logger = null;
Expand All @@ -22,18 +22,21 @@ describe('dApp, getCollateral, error, max limit, not auth,', function () {
let mockedDApp = null;

before(async function () {
webdriver = await driversPoolsManager.getDriverFromPool();
mockServer = getMockServer({});
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
logger = getTestLogger(this.test.parent.title);
});

it('Restore a 15-word wallet', async function () {
await restoreWallet(webdriver, logger, testWallet1);
try {
webdriver = await driversPoolsManager.getDriverFromPool();
const wmLogger = getTestLogger('windowManager', this.test.parent.title);
windowManager = new WindowManager(webdriver, wmLogger);
windowManager.init();
const dappLogger = getTestLogger('dApp', this.test.parent.title);
mockedDApp = new MockDAppWebpage(webdriver, dappLogger);
await preloadDBAndStorage(webdriver, logger, 'testWallet1');
await waitTxPage(webdriver, logger);
} catch (error) {
await collectInfo(this, webdriver, logger);
throw new Error(error);
}
});

it('Open a dapp page', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { adaInLovelaces, getTestWalletName } from '../../helpers/constants.js';
import { ApiErrorCode } from '../../helpers/mock-dApp-webpage/cip30Errors.js';
import driversPoolsManager from '../../utils/driversPool.js';

describe('dApp, getCollateral, error, empty wallet, not auth', function () {
describe('dApp, getCollateral, error, empty wallet', function () {
const testWalletName = getTestWalletName();
let newTestWallet = {
name: '',
Expand Down
Loading

0 comments on commit bed2ead

Please sign in to comment.