Commit f6c393b0 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

test(e2e): de-flake activity-history (#6583)

parent 15f8d343
import { getTestSelector } from '../../utils' import { getTestSelector } from '../../utils'
describe('mini-portfolio activity history', () => { describe('mini-portfolio activity history', () => {
afterEach(() => { beforeEach(() => {
cy.intercept( cy.hardhat()
{
method: 'POST',
url: 'https://beta.api.uniswap.org/v1/graphql',
},
// Pass an empty object to allow the original behavior
{}
).as('restoreOriginalBehavior')
})
it('should deduplicate activity history by nonce', () => {
cy.visit('/swap', { ethereum: 'hardhat' })
.hardhat({ automine: false })
.then((hardhat) => hardhat.wallet.getTransactionCount()) .then((hardhat) => hardhat.wallet.getTransactionCount())
.then((currentNonce) => { .then((nonce) => {
const nextNonce = currentNonce + 1 // Mock graphql response to include specific nonces.
// Mock graphql response to include a specific nonce.
cy.intercept( cy.intercept(
{ {
method: 'POST', method: 'POST',
...@@ -43,7 +30,7 @@ describe('mini-portfolio activity history', () => { ...@@ -43,7 +30,7 @@ describe('mini-portfolio activity history', () => {
status: 'CONFIRMED', status: 'CONFIRMED',
to: '0x034a40764485f7e08ca16366e503491a6af7850d', to: '0x034a40764485f7e08ca16366e503491a6af7850d',
from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
nonce: currentNonce, nonce,
__typename: 'Transaction', __typename: 'Transaction',
}, },
assetChanges: [], assetChanges: [],
...@@ -61,7 +48,7 @@ describe('mini-portfolio activity history', () => { ...@@ -61,7 +48,7 @@ describe('mini-portfolio activity history', () => {
status: 'CONFIRMED', status: 'CONFIRMED',
to: '0x1b5154aa4b8f027b9fd19341132fc9dae10f7359', to: '0x1b5154aa4b8f027b9fd19341132fc9dae10f7359',
from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', from: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
nonce: nextNonce, nonce: nonce + 1,
__typename: 'Transaction', __typename: 'Transaction',
}, },
assetChanges: [ assetChanges: [
...@@ -101,33 +88,37 @@ describe('mini-portfolio activity history', () => { ...@@ -101,33 +88,37 @@ describe('mini-portfolio activity history', () => {
}, },
}, },
} }
).as('graphqlMock') ).as('graphql')
})
})
it('should deduplicate activity history by nonce', () => {
cy.visit('/swap', { ethereum: 'hardhat' }).hardhat({ automine: false })
// Input swap info. // Input swap info.
cy.get('#swap-currency-input .token-amount-input').clear().type('1') cy.get('#swap-currency-input .token-amount-input').clear().type('1')
cy.get('#swap-currency-output .open-currency-select-button').click() cy.get('#swap-currency-output .open-currency-select-button').click()
cy.contains('USDC').click() cy.contains('USDC').click()
cy.get('#swap-currency-output .token-amount-input').should('not.equal', '') cy.get('#swap-currency-output .token-amount-input').should('not.equal', '')
// Set slippage to a high value. // Set slippage to a high value.
cy.get(getTestSelector('open-settings-dialog-button')).click() cy.get(getTestSelector('open-settings-dialog-button')).click()
cy.get(getTestSelector('max-slippage-settings')).click() cy.get(getTestSelector('max-slippage-settings')).click()
cy.get(getTestSelector('slippage-input')).clear().type('5') cy.get(getTestSelector('slippage-input')).clear().type('5')
cy.get('body').click('topRight') cy.get('body').click('topRight')
cy.get(getTestSelector('slippage-input')).should('not.exist') cy.get(getTestSelector('slippage-input')).should('not.exist')
// Click swap button. // Click swap button.
cy.contains('1 USDC = ').should('exist') cy.contains('1 USDC = ').should('exist')
cy.get('#swap-button').should('not.be', 'disabled').click() cy.get('#swap-button').should('not.be', 'disabled').click()
cy.get('#confirm-swap-or-send').click() cy.get('#confirm-swap-or-send').click()
cy.get(getTestSelector('dismiss-tx-confirmation')).click() cy.get(getTestSelector('dismiss-tx-confirmation')).click()
// Check activity history tab. // Check activity history tab.
cy.get(getTestSelector('web3-status-connected')).click() cy.get(getTestSelector('web3-status-connected')).click()
cy.get(getTestSelector('mini-portfolio-nav-activity')).click() cy.get(getTestSelector('mini-portfolio-nav-activity')).click()
// Assert that the local pending transaction is replaced by a remote transaction with the same nonce. // Assert that the local pending transaction is replaced by a remote transaction with the same nonce.
cy.contains('Swapping').should('not.exist') cy.contains('Swapping').should('not.exist')
})
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment