test(#2639): e2e view public key tests (#2688)

This commit is contained in:
Joe Tsang 2023-01-24 10:52:01 +00:00 committed by GitHub
parent 2f391cde5b
commit e883ef5c5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 126 additions and 5 deletions

View File

@ -61,7 +61,7 @@ context(
// 3002-PROP-007
cy.get(newProposalDescription).type('E2E test for proposals');
cy.get(proposalParameterSelect).find('option').should('have.length', 115);
cy.get(proposalParameterSelect).find('option').should('have.length', 116);
cy.get(proposalParameterSelect).select(
// 3007-PNEC-002
'governance_proposal_asset_minEnact'

View File

@ -93,6 +93,7 @@ context(
.contains(2.0, epochTimeout)
.should('be.visible');
cy.close_staking_dialog();
cy.navigate_to('validators');
// 2002-SINC-007
@ -145,6 +146,7 @@ context(
.contains(2.0, epochTimeout)
.should('be.visible');
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.validate_validator_list_total_stake_and_share(
@ -209,6 +211,7 @@ context(
.contains(6.0, epochTimeout)
.should('be.visible');
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.validate_validator_list_total_stake_and_share(
@ -243,6 +246,7 @@ context(
.parent()
.should('contain', 2.0, txTimeout);
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.click_on_validator_from_list(1);
@ -264,6 +268,7 @@ context(
.eq(1)
.should('contain', 1.0, txTimeout);
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.get(`[row-id="${0}"]`).within(() => {
@ -323,6 +328,7 @@ context(
txTimeout
);
cy.close_staking_dialog();
cy.navigate_to('validators');
// 2001-STKE-040
cy.click_on_validator_from_list(0);
@ -388,6 +394,7 @@ context(
txTimeout
);
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.click_on_validator_from_list('0');
@ -447,6 +454,7 @@ context(
txTimeout
);
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.click_on_validator_from_list(0);
@ -488,6 +496,7 @@ context(
txTimeout
);
cy.close_staking_dialog();
cy.navigate_to('validators');
cy.click_on_validator_from_list(0);

View File

@ -170,6 +170,27 @@ context(
});
});
it('Unable to withdraw asset on pub key view', function () {
const vegaWalletPubKey = Cypress.env('vegaWalletPublicKey');
const expectedErrorTxt = `You are connected in a view only state for public key: ${vegaWalletPubKey}. In order to send transactions you must connect to a real wallet.`;
// Disconnect vega wallet
cy.getByTestId('manage-vega-wallet').click();
cy.getByTestId('disconnect').click();
cy.connectPublicKey(vegaWalletPubKey);
cy.getByTestId(withdraw).should('be.visible').click();
cy.getByTestId(selectAsset).select(usdtName);
cy.getByTestId(balanceAvailable, txTimeout).should('exist');
cy.getByTestId(amountInput).click().type('100');
cy.getByTestId(submitWithdrawalButton).click();
cy.getByTestId('dialog-content').within(() => {
cy.get('h1').should('have.text', 'Transaction failed');
cy.getByTestId('Error').should('have.text', expectedErrorTxt);
});
});
function waitForAssetsDisplayed(expectedAsset) {
cy.contains(expectedAsset, txTimeout).should('be.visible');
}

View File

@ -0,0 +1,62 @@
/// <reference types="cypress" />
const vegaWalletPubKey = Cypress.env('vegaWalletPublicKey2');
const vegaPubkeyTruncated = Cypress.env('vegaWalletPublicKey2Short');
const banner = 'view-banner';
context('View functionality with public key', { tags: '@smoke' }, function () {
before('send asset to wallet', function () {
cy.vega_wallet_faucet_assets_without_check(
'fUSDC',
'1000000',
vegaWalletPubKey
);
});
beforeEach('visit home page', function () {
cy.visit('/');
cy.wait_for_spinner();
cy.connectPublicKey(vegaWalletPubKey);
});
it('Able to connect public key via wallet', function () {
verifyConnectedToPubKey();
cy.getByTestId('currency-title').should('contain.text', 'USDC (fake)');
});
it('Able to connect public key using url', function () {
cy.getByTestId('exit-view').click();
cy.visit(`/?address=${vegaWalletPubKey}`);
verifyConnectedToPubKey();
});
it('Unable to submit proposal with public key', function () {
const expectedErrorTxt = `You are connected in a view only state for public key: ${vegaWalletPubKey}. In order to send transactions you must connect to a real wallet.`;
cy.navigate_to('proposals');
cy.go_to_make_new_proposal('Freeform');
cy.enter_unique_freeform_proposal_body('50', 'pub key proposal test');
cy.getByTestId('proposal-submit').should('be.visible').click();
cy.getByTestId('dialog-content').within(() => {
cy.get('h1').should('have.text', 'Transaction failed');
cy.getByTestId('Error').should('have.text', expectedErrorTxt);
});
});
it('Able to disconnect via banner', function () {
cy.getByTestId('exit-view').click();
cy.getByTestId(banner).should('not.exist');
});
it('Able to disconnect via wallet', function () {
cy.getByTestId('manage-vega-wallet').click();
cy.getByTestId('disconnect').click();
cy.getByTestId(banner).should('not.exist');
});
function verifyConnectedToPubKey() {
cy.getByTestId(banner).should(
'contain.text',
`Viewing as Vega user: ${vegaPubkeyTruncated}`
);
}
});

View File

@ -40,7 +40,6 @@ Cypress.Commands.add('staking_validator_page_add_stake', (stake) => {
.and('contain', `Add ${stake} $VEGA tokens`)
.and('be.visible')
.click();
cy.get(dialogCloseButton).click();
});
Cypress.Commands.add('staking_validator_page_remove_stake', (stake) => {

View File

@ -16,6 +16,7 @@ import {
} from './lib/commands/vega-wallet-connect';
import { addMockTransactionResponse } from './lib/commands/mock-transaction-response';
import { addCreateMarket } from './lib/commands/create-market';
import { addConnectPublicKey } from './lib/commands/add-connect-public-key';
addGetTestIdcommand();
addSlackCommand();
@ -33,6 +34,7 @@ addVegaWalletConnect();
addSetVegaWallet();
addMockTransactionResponse();
addCreateMarket();
addConnectPublicKey();
export { mockConnectWallet } from './lib/commands/vega-wallet-connect';
export type { onMessage } from './lib/mock-ws';

View File

@ -0,0 +1,23 @@
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
connectPublicKey(publicKey: string): void;
}
}
}
export const addConnectPublicKey = () => {
Cypress.Commands.add('connectPublicKey', (publicKey) => {
cy.getByTestId('connect-vega-wallet').then((connectWallet) => {
if (connectWallet.length) {
cy.getByTestId('connect-vega-wallet').click();
cy.getByTestId('connector-view').should('be.visible').click();
cy.getByTestId('address').click();
cy.getByTestId('address').type(publicKey);
cy.getByTestId('connect').click();
}
});
});
};

View File

@ -21,11 +21,16 @@ export const ViewingAsBanner = ({
disconnect,
}: ViewingAsBannerProps) => {
return (
<div className="w-full p-2 bg-neutral-800 flex justify-between text-neutral-400">
<div
data-testid="view-banner"
className="w-full p-2 bg-neutral-800 flex justify-between text-neutral-400"
>
<div className="text-base flex items-center justify-center">
{t('Viewing as Vega user:')} {pubKey && truncateMiddle(pubKey)}
</div>
<Button onClick={disconnect}>{t('Exit view as')}</Button>
<Button data-testid="exit-view" onClick={disconnect}>
{t('Exit view as')}
</Button>
</div>
);
};

View File

@ -56,7 +56,7 @@ export function ViewConnectorForm({
<InputError intent="danger">{errors.address.message}</InputError>
)}
</FormGroup>
<Button variant="primary" type="submit" fill={true}>
<Button data-testid="connect" variant="primary" type="submit" fill={true}>
{t('Connect')}
</Button>
</form>