test(trading): 0003-WTXN submit vega transaction e2e tests (#3246)

This commit is contained in:
daro-maj 2023-03-23 09:46:28 +01:00 committed by GitHub
parent f649d78565
commit a060f94146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 133 additions and 32 deletions

View File

@ -143,6 +143,7 @@ describe('capsule - without MultiSign', { tags: '@slow' }, () => {
it('can not withdrawal because of no MultiSign', function () {
// 1002-WITH-022
// 1002-WITH-023
// 0003-WTXN-011
cy.getByTestId('Withdrawals').click();
cy.getByTestId('withdraw-dialog-button').click();

View File

@ -76,6 +76,8 @@ describe('must submit order', { tags: '@smoke' }, () => {
it('successfully places market buy order', () => {
// 7002-SORD-010
// 0003-WTXN-012
// 0003-WTXN-003
cy.mockVegaWalletTransaction();
const order: OrderSubmission = {
marketId: 'market-0',
@ -367,6 +369,7 @@ describe('deal ticket validation', { tags: '@smoke' }, () => {
});
it('must show place order button and connect wallet if wallet is not connected', () => {
// 0003-WTXN-001
cy.getByTestId('connect-vega-wallet'); // Not connected
cy.getByTestId('order-connect-wallet').should('exist');
cy.getByTestId(placeOrderBtn).should('exist');
@ -682,6 +685,7 @@ describe('account validation', { tags: '@regression' }, () => {
it('should display info and button for deposit', () => {
// 7002-SORD-003
// warning should show immediately
cy.getByTestId('dealticket-warning-margin').should(
'contain.text',
@ -698,4 +702,94 @@ describe('account validation', { tags: '@regression' }, () => {
.should('have.text', 'Deposit');
});
});
describe('must submit order', { tags: '@smoke' }, () => {
// 7002-SORD-039
beforeEach(() => {
cy.setVegaWallet();
cy.mockTradingPage();
cy.mockSubscription();
cy.visit('/#/markets/market-0');
cy.wait('@Markets');
});
it('must see a prompt to check connected vega wallet to approve transaction', () => {
// 0003-WTXN-002
cy.mockVegaWalletTransaction(1000);
const order: OrderSubmission = {
marketId: 'market-0',
type: Schema.OrderType.TYPE_MARKET,
side: Schema.Side.SIDE_BUY,
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK,
size: '100',
};
createOrder(order);
cy.getByTestId('toast-content').should(
'contain.text',
'Please go to your Vega wallet application and approve or reject the transaction.'
);
});
it('must show error returned by wallet ', () => {
// 0003-WTXN-009
// 0003-WTXN-011
//trigger error from the wallet
cy.intercept('POST', 'http://localhost:1789/api/v2/requests', (req) => {
req.on('response', (res) => {
res.send({
jsonrpc: '2.0',
id: '1',
});
});
});
const order: OrderSubmission = {
marketId: 'market-0',
type: Schema.OrderType.TYPE_MARKET,
side: Schema.Side.SIDE_BUY,
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK,
size: '100',
};
createOrder(order);
cy.getByTestId('toast-content').should(
'contain.text',
'The connection to your Vega Wallet has been lost.'
);
});
it('must see that the order was rejected by the connected wallet', () => {
// 0003-WTXN-007
//trigger rejection error from the wallet
cy.intercept('POST', 'http://localhost:1789/api/v2/requests', (req) => {
req.alias = 'client.send_transaction';
req.reply({
statusCode: 400,
body: {
jsonrpc: '2.0',
error: {
code: 3001,
data: 'the user rejected the wallet connection',
message: 'User error',
},
id: '0',
},
});
});
const order: OrderSubmission = {
marketId: 'market-0',
type: Schema.OrderType.TYPE_MARKET,
side: Schema.Side.SIDE_BUY,
timeInForce: Schema.OrderTimeInForce.TIME_IN_FORCE_FOK,
size: '100',
};
createOrder(order);
cy.getByTestId('toast-content').should(
'contain.text',
'Error occurredthe user rejected the wallet connection'
);
});
});
});

View File

@ -156,6 +156,7 @@ describe('connect vega wallet', { tags: '@smoke' }, () => {
// 0002-WCON-035
// 0002-WCON-014
// 0002-WCON-010
// 0003-WTXN-004
mockConnectWallet();
const key2 = Cypress.env('VEGA_PUBLIC_KEY2');

View File

@ -8,6 +8,7 @@ declare global {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Chainable<Subject> {
mockVegaWalletTransaction(
delayValue?: number,
override?: PartialDeep<TransactionResponse>
): void;
}
@ -17,7 +18,7 @@ declare global {
export function addMockTransactionResponse() {
Cypress.Commands.add(
'mockVegaWalletTransaction',
(override?: PartialDeep<TransactionResponse>) => {
(delayValue?: number, override?: PartialDeep<TransactionResponse>) => {
const defaultTransactionResponse = {
transactionHash: 'test-tx-hash',
sentAt: new Date().toISOString(),
@ -43,12 +44,16 @@ export function addMockTransactionResponse() {
},
};
cy.intercept('POST', 'http://localhost:1789/api/v2/requests', {
body: {
cy.intercept('POST', 'http://localhost:1789/api/v2/requests', (req) => {
req.on('response', (res) => {
res.setDelay(delayValue ?? 0);
res.statusCode = 400;
res.send({
jsonrpc: '2.0',
result: merge(defaultTransactionResponse, override),
id: '1',
},
});
});
}).as('VegaWalletTransaction');
}
);