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

@ -42,7 +42,7 @@ describe('time in force default values', () => {
});
it('must have market order set up to IOC by default', function () {
//7002-SORD-031
// 7002-SORD-031
cy.getByTestId(toggleMarket).click();
cy.get(`[data-testid=${orderTIFDropDown}] option:selected`).should(
'have.text',
@ -51,7 +51,7 @@ describe('time in force default values', () => {
});
it('must have time in force set to GTC for limit order', function () {
//7002-SORD-031
// 7002-SORD-031
cy.getByTestId(toggleLimit).click();
cy.get(`[data-testid=${orderTIFDropDown}] option:selected`).should(
'have.text',
@ -75,7 +75,9 @@ describe('must submit order', { tags: '@smoke' }, () => {
});
it('successfully places market buy order', () => {
//7002-SORD-010
// 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');
@ -374,15 +377,15 @@ describe('deal ticket validation', { tags: '@smoke' }, () => {
});
it('must be able to select order direction - long/short', function () {
//7002-SORD-004
// 7002-SORD-004
cy.getByTestId(toggleShort).click().children('input').should('be.checked');
cy.getByTestId(toggleLong).click().children('input').should('be.checked');
});
it('must be able to select order type - limit/market', function () {
//7002-SORD-005
//7002-SORD-006
//7002-SORD-007
// 7002-SORD-005
// 7002-SORD-006
// 7002-SORD-007
cy.getByTestId(toggleLimit).click().children('input').should('be.checked');
cy.getByTestId(toggleMarket).click().children('input').should('be.checked');
});
@ -412,7 +415,7 @@ describe('deal ticket size validation', { tags: '@smoke' }, function () {
});
it('must warn if order size input has too many digits after the decimal place', function () {
//7002-SORD-016
// 7002-SORD-016
cy.getByTestId('order-type-TYPE_MARKET').click();
cy.getByTestId(orderSizeField).clear().type('1.234');
cy.getByTestId(placeOrderBtn).should('not.be.disabled');
@ -452,7 +455,7 @@ describe('limit order validations', { tags: '@smoke' }, () => {
});
it('must see the price unit', function () {
//7002-SORD-018
// 7002-SORD-018
cy.getByTestId(orderPriceField)
.siblings('label')
.should('have.text', 'Price (DAI)');
@ -478,7 +481,7 @@ describe('limit order validations', { tags: '@smoke' }, () => {
});
it('must see warning if price has too many digits after decimal place', function () {
//7002-SORD-059
// 7002-SORD-059
cy.getByTestId(toggleLimit).click();
cy.getByTestId(orderTIFDropDown).select('TIME_IN_FORCE_GTC');
cy.getByTestId(orderSizeField).clear().type('1');
@ -492,12 +495,12 @@ describe('limit order validations', { tags: '@smoke' }, () => {
describe('time in force validations', function () {
const validTIF = TIFlist;
validTIF.forEach((tif) => {
//7002-SORD-023
//7002-SORD-024
//7002-SORD-025
//7002-SORD-026
//7002-SORD-027
//7002-SORD-028
// 7002-SORD-023
// 7002-SORD-024
// 7002-SORD-025
// 7002-SORD-026
// 7002-SORD-027
// 7002-SORD-028
it(`must be able to select ${tif.code}`, function () {
cy.getByTestId(orderTIFDropDown).select(tif.value);
@ -544,7 +547,7 @@ describe('market order validations', { tags: '@smoke' }, () => {
});
it('must not see the price unit', function () {
//7002-SORD-019
// 7002-SORD-019
cy.getByTestId(orderPriceField).should('not.exist');
});
@ -555,8 +558,8 @@ describe('market order validations', { tags: '@smoke' }, () => {
);
validTIF.forEach((tif) => {
//7002-SORD-025
//7002-SORD-026
// 7002-SORD-025
// 7002-SORD-026
it(`must be able to select ${tif.code}`, function () {
cy.getByTestId(orderTIFDropDown).select(tif.value);
@ -568,10 +571,10 @@ describe('market order validations', { tags: '@smoke' }, () => {
});
invalidTIF.forEach((tif) => {
//7002-SORD-023
//7002-SORD-024
//7002-SORD-027
//7002-SORD-028
// 7002-SORD-023
// 7002-SORD-024
// 7002-SORD-027
// 7002-SORD-028
it(`must not be able to select ${tif.code}`, function () {
cy.getByTestId(orderTIFDropDown).should('not.contain', tif.text);
});
@ -652,7 +655,7 @@ describe('account validation', { tags: '@regression' }, () => {
it('should show an error if your balance is zero', () => {
cy.getByTestId('place-order').should('be.disabled');
//7002-SORD-003
// 7002-SORD-003
cy.getByTestId('dealticket-error-message-zero-balance').should(
'have.text',
'You need ' +
@ -681,7 +684,8 @@ describe('account validation', { tags: '@regression' }, () => {
});
it('should display info and button for deposit', () => {
//7002-SORD-003
// 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: {
jsonrpc: '2.0',
result: merge(defaultTransactionResponse, override),
id: '1',
},
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');
}
);