Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc tests improvements #7321

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ transport manual:
COMPOSE_PROJECT_NAME: $CI_JOB_ID
COMPOSE_FILE: ./docker/docker-compose.connect-popup-ci.yml
URL: ${DEV_SERVER_URL}/connect/${CI_BUILD_REF_NAME}/
TEST_FILE: $TEST_FILE
script:
- yarn install --immutable
- docker-compose pull
Expand All @@ -216,6 +217,11 @@ transport manual:
- ./packages/connect-popup/connect-popup-overview.html
- ./packages/connect-popup/test-results
interruptible: true
parallel:
matrix:
- TEST_FILE: ["methods"]
- TEST_FILE: ["popup-close"]
- TEST_FILE: ["unchained"]

connect-popup:
extends: .e2e connect-popup
Expand Down
3 changes: 2 additions & 1 deletion docker/docker-compose.connect-popup-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ services:
- CI_JOB_URL=$CI_JOB_URL
- CI_COMMIT_BRANCH=$CI_COMMIT_BRANCH
- CI_JOB_NAME=$CI_JOB_NAME
- TEST_FILE=$TEST_FILE
working_dir: /e2e
command: bash -c "npx playwright install && yarn workspace @trezor/connect-popup test:e2e"
command: bash -c "npx playwright install && yarn workspace @trezor/connect-popup test:e2e $TEST_FILE"
volumes:
- ../:/e2e
4 changes: 3 additions & 1 deletion packages/connect-popup/e2e/tests/popup-close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ test.beforeAll(async () => {
requests.push({ url: request.url() });
});

let requestIndex = 0;
page.on('response', async response => {
// ignore other than bridge requests
if (!response.url().startsWith('http://127.0.0.1:21325')) {
Expand All @@ -69,7 +70,8 @@ test.beforeAll(async () => {
if (response.url().endsWith('release/2')) {
releasePromise!.resolve(undefined);
}
console.log(response.status(), response.url());
console.log(requestIndex, response.status(), response.url());
requestIndex++;
responses.push({
url: response.url(),
status: response.status(),
Expand Down
33 changes: 33 additions & 0 deletions packages/suite-web/e2e/tests/suite/passphrase-cancel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @group:passphrase
// @retry=2

const testedVersions = ['2-latest', '1-latest'];

describe('Passphrase cancel', () => {
beforeEach(() => {
cy.viewport(1080, 1440).resetDb();
});

testedVersions.forEach(version => {
it(version, () => {
cy.task('startEmu', { wipe: true, version });
cy.task('setupEmu', {
mnemonic: 'all all all all all all all all all all all all',
passphrase_protection: true,
});
cy.task('startBridge');
cy.prefixedVisit('/');
cy.passThroughInitialRun();

cy.getTestElement('@passphrase/input').type('abc');
cy.getTestElement('@passphrase/hidden/submit-button').click();
cy.getTestElement('@suite/modal/confirm-action-on-device');

cy.getTestElement('@modal/close-button').click();
cy.getTestElement('@toast/auth-failed');
// todo: interesting fact is that model One and model T have different text in the toast notification
});
});
});

export {};
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('safety_checks Warning For PromptTemporarily', () => {
});
cy.get(`[data-test="@radio-button-prompt"]`).click();
cy.getTestElement('@safety-checks-apply').click();
cy.getTestElement('@prompts/confirm-on-device');
cy.task('pressYes');
});

Expand All @@ -67,6 +68,7 @@ describe('safety_checks Warning For PromptTemporarily', () => {
});
cy.get('[data-test="@radio-button-strict"]').click();
cy.getTestElement('@safety-checks-apply').click();
cy.getTestElement('@prompts/confirm-on-device');
cy.task('pressYes');
// Assert the warning is gone.
cy.getTestElement('@banner/safety-checks/button').should('not.exist');
Expand All @@ -81,6 +83,7 @@ describe('safety_checks Warning For PromptTemporarily', () => {
});
cy.get('[data-test="@radio-button-strict"]').click();
cy.getTestElement('@safety-checks-apply').click();
cy.getTestElement('@prompts/confirm-on-device');
cy.task('pressYes');
// Assert the warning is gone.
cy.getTestElement('@banner/safety-checks/button').should('not.exist');
Expand All @@ -90,6 +93,7 @@ describe('safety_checks Warning For PromptTemporarily', () => {
});
cy.get(`[data-test="@radio-button-prompt"]`).click();
cy.getTestElement('@safety-checks-apply').click();
cy.getTestElement('@prompts/confirm-on-device');
cy.task('pressYes');
// Assert the warning appear again.
cy.getTestElement('@banner/safety-checks/button');
Expand Down
6 changes: 2 additions & 4 deletions packages/suite-web/e2e/tests/wallet/import-btc-csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ describe('Import a BTC csv file', () => {
// process data
cy.getTestElement('outputs[0].address')
.should('be.visible')
.invoke('val')
.should('equal', firstAddress);
.should('have.value', firstAddress);
cy.getTestElement('outputs[1].address')
.should('be.visible')
.invoke('val')
.should('equal', secondAddress);
.should('have.value', secondAddress);
cy.log(secondAddress);
});
});
Expand Down
3 changes: 3 additions & 0 deletions packages/transport/e2e/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import argv from './jest.config';
// Before actual tests start, establish connection with trezor-user-env
await TrezorUserEnvLink.connect();

// @ts-expect-error
argv.runInBand = true;

// @ts-expect-error
const { results } = await runCLI(argv, [__dirname]);

Expand Down
4 changes: 2 additions & 2 deletions packages/transport/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/tests/*.test.js'],
testMatch: ['**/tests/*.test.ts'],
modulePathIgnorePatterns: ['node_modules', '<rootDir>/lib', '<rootDir>/libDev'],
collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
testPathIgnorePatterns: ['e2e'],
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const { parseConfigure } = require('../src/lowlevel/protobuf/messages');
const { buildOne } = require('../src/lowlevel/send');
const { receiveOne } = require('../src/lowlevel/receive');
import * as protobuf from 'protobufjs/light';

const { buildBuffers } = require('../src/lowlevel/send');
const { receiveAndParse } = require('../src/lowlevel/receive');
import { buildOne, buildBuffers } from '../src/lowlevel/send';
import { receiveOne, receiveAndParse } from '../src/lowlevel/receive';

const messages = {
StellarPaymentOp: {
Expand Down Expand Up @@ -91,7 +89,7 @@ const fixtures = [
},
];

const parsedMessages = parseConfigure({
const parsedMessages = protobuf.Root.fromJSON({
nested: { hw: { nested: { trezor: { nested: { messages: { nested: messages } } } } } },
});

Expand All @@ -102,7 +100,7 @@ describe('encoding json -> protobuf -> json', () => {
// encoded message
const encodedMessage = buildOne(parsedMessages, f.name, f.in);
// then decode message and check, whether decoded message matches original json
const decodedMessage = receiveOne(parsedMessages, encodedMessage);
const decodedMessage = receiveOne(parsedMessages, encodedMessage.toString('hex'));
expect(decodedMessage.type).toEqual(f.name);
expect(decodedMessage.message).toEqual(f.in);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { encode } = require('../src/lowlevel/protobuf/encode');
const { decode } = require('../src/lowlevel/protobuf/decode');
import * as ProtoBuf from 'protobufjs/light';

const ProtoBuf = require('protobufjs/light');
import { encode } from '../src/lowlevel/protobuf/encode';
import { decode } from '../src/lowlevel/protobuf/decode';

const messages = {
nested: {
Expand Down Expand Up @@ -197,7 +197,7 @@ describe('basic concepts', () => {
describe('primitives encode/decode', () => {
basicFixtures.forEach(f => {
describe(f.name, () => {
const Message = Messages.lookup(`messages.${f.name}`);
const Message = Messages.lookupType(`messages.${f.name}`);

test(f.name, () => {
// serialize new way - this is to confirm new lib won't break old behavior
Expand All @@ -215,7 +215,7 @@ describe('basic concepts', () => {
describe('advanced', () => {
advancedFixtures.forEach(f => {
describe(f.name, () => {
const Message = Messages.lookup(`messages.${f.name}`);
const Message = Messages.lookupType(`messages.${f.name}`);

test(f.name, () => {
// serialize new way - this is to confirm new lib won't break old behavior
Expand Down Expand Up @@ -254,7 +254,7 @@ describe('basic concepts', () => {
};

const SenderMessages = ProtoBuf.Root.fromJSON(messages);
const senderEncoded = encode(SenderMessages.lookup('messages.ButtonRequest'), {
const senderEncoded = encode(SenderMessages.lookupType('messages.ButtonRequest'), {
type: 'foo',
pages: 123,
});
Expand All @@ -265,7 +265,7 @@ describe('basic concepts', () => {
const ReceiverMessages = ProtoBuf.Root.fromJSON(receiverMessages);

expect(() => {
decode(ReceiverMessages.lookup('messages.ButtonRequest'), senderEncoded);
decode(ReceiverMessages.lookupType('messages.ButtonRequest'), senderEncoded);
}).toThrow();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const ProtoBuf = require('protobufjs/light');
import * as ProtoBuf from 'protobufjs/light';

const { encode } = require('../src/lowlevel/protobuf/encode');
const { decode } = require('../src/lowlevel/protobuf/decode');
import { encode } from '../src/lowlevel/protobuf/encode';
import { decode } from '../src/lowlevel/protobuf/decode';

const HDNodeType = {
fields: {
Expand Down Expand Up @@ -521,9 +521,10 @@ describe('Real messages', () => {
fixtures.forEach(f => {
describe(f.name, () => {
const Messages = ProtoBuf.Root.fromJSON({
// @ts-expect-error
nested: { messages: { nested: { ...f.message } } },
});
const Message = Messages.lookup(`messages.${f.name}`);
const Message = Messages.lookupType(`messages.${f.name}`);

test('encode and decode', () => {
// serialize
Expand All @@ -538,6 +539,7 @@ describe('Real messages', () => {

test('without Messages object', () => {
expect(() => {
// @ts-expect-error
encode(null, {});
}).toThrowError();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { createMessageFromName } = require('../src/lowlevel/protobuf/messages');
const { parseConfigure } = require('../src/lowlevel/protobuf/messages');
import * as protobuf from 'protobufjs/light';

import { createMessageFromName } from '../src/lowlevel/protobuf/messages';

const json = {
nested: {
Expand Down Expand Up @@ -49,14 +50,7 @@ const json = {

describe('messages', () => {
test('createMessageFromName (wire_type case)', () => {
const messages = parseConfigure(json);
const name = 'TxAckPrevExtraData';

expect(() => createMessageFromName(messages, name)).not.toThrow();
});

test('[compatibility]: descriptors as string', () => {
const messages = parseConfigure(JSON.stringify(json));
const messages = protobuf.Root.fromJSON(json);
const name = 'TxAckPrevExtraData';

expect(() => createMessageFromName(messages, name)).not.toThrow();
Expand Down