test(e2e): reset hardhat between tests (#6487)

This commit is contained in:
Zach Pomerantz 2023-05-04 08:31:53 -07:00 committed by GitHub
parent c8a8149127
commit 2a50d6a17e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 76 deletions

@ -84,10 +84,9 @@ describe('Swap', () => {
const DEADLINE_MINUTES = 1
const TEN_MINUTES_MS = 1000 * 60 * DEADLINE_MINUTES * 10
cy.visit('/swap', { ethereum: 'hardhat' })
.hardhat()
.hardhat({ automine: false })
.then((hardhat) => {
cy.then(() => hardhat.setAutomine(false))
.then(() => hardhat.getBalance(hardhat.wallet.address, USDC_MAINNET))
cy.then(() => hardhat.getBalance(hardhat.wallet.address, USDC_MAINNET))
.then((balance) => Number(balance.toFixed(1)))
.then((initialBalance) => {
// Input swap info.
@ -209,7 +208,6 @@ describe('Swap', () => {
cy.get('#confirm-swap-or-send').click()
cy.get(getTestSelector('dismiss-tx-confirmation')).click()
cy.then(() => hardhat.provider.send('hardhat_mine', ['0x1', '0xc'])).then(() => {
// ui check
cy.get('#swap-currency-output [data-testid="balance-text"]').should(
'have.text',
@ -224,7 +222,6 @@ describe('Swap', () => {
})
})
})
})
it('should be able to wrap ETH', () => {
const BALANCE_INCREMENT = 1
@ -417,11 +414,9 @@ describe('Swap', () => {
it('should render an error for slippage failure', () => {
cy.visit('/swap', { ethereum: 'hardhat' })
.hardhat()
.hardhat({ automine: false })
.then((hardhat) => {
cy.then(() => hardhat.setAutomine(false))
.then(() => hardhat.provider.getBalance(hardhat.wallet.address))
.then((initialBalance) => {
cy.then(() => hardhat.provider.getBalance(hardhat.wallet.address)).then((initialBalance) => {
// Gas estimation fails for this transaction (that would normally fail), so we stub it.
const send = cy.stub(hardhat.provider, 'send')
send.withArgs('eth_estimateGas').resolves(BigNumber.from(2_000_000))
@ -478,7 +473,6 @@ describe('Swap', () => {
})
})
})
.then(() => hardhat.setAutomine(true))
})
})
})

@ -89,8 +89,9 @@ Cypress.Commands.overwrite(
)
beforeEach(() => {
cy
// Many API calls enforce that requests come from our app, so we must mock Origin and Referer.
cy.intercept('*', (req) => {
.intercept('*', (req) => {
req.headers['referer'] = 'https://app.uniswap.org'
req.headers['origin'] = 'https://app.uniswap.org'
})
@ -114,6 +115,10 @@ beforeEach(() => {
})
)
})
// Reset hardhat between tests to ensure isolation.
// This resets the fork, as well as options like automine.
.hardhat()
.then((hardhat) => hardhat.reset())
})
Cypress.on('uncaught:exception', () => {

@ -22,8 +22,8 @@ module.exports = {
count: 1,
},
mining: {
auto: true,
interval: 0,
auto: true, // automine to make tests easier to write.
interval: 0, // do not interval mine so that tests remain deterministic
},
},
},

@ -102,7 +102,7 @@
"@vanilla-extract/webpack-plugin": "^2.1.11",
"babel-plugin-istanbul": "^6.1.1",
"cypress": "10.3.1",
"cypress-hardhat": "^2.2.0",
"cypress-hardhat": "^2.3.0",
"env-cmd": "^10.1.0",
"eslint": "^7.11.0",
"eslint-plugin-import": "^2.27",

@ -9046,10 +9046,10 @@ cyclist@^1.0.1:
resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-1.0.1.tgz#596e9698fd0c80e12038c2b82d6eb1b35b6224d9"
integrity sha1-WW6WmP0MgOEgOMK4LW6xs1tiJNk=
cypress-hardhat@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/cypress-hardhat/-/cypress-hardhat-2.2.0.tgz#4e1c0f16f0c915dda54ddeccbf5dea19f80eed2f"
integrity sha512-Jtzd49vvyWSshR43w18WJ4b/40EhSItTTl82QYBNqiSPPrC/yj0derJHZyqMqq2LZvrsfmiY92fIBDgvxUCxZQ==
cypress-hardhat@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/cypress-hardhat/-/cypress-hardhat-2.3.0.tgz#646b35d57490d060e3fd4441e76e4d91b4ff4ec7"
integrity sha512-Sj437lFrUZ9UJGXS5a+DLQPBoyaWUxJafEiydNqKKpViKswBiylHD3ZJu2mrtQ/fhp7lgOPpMP72IQX4Ncwzdg==
dependencies:
"@uniswap/permit2-sdk" "^1.2.0"
"@uniswap/sdk-core" "^3.0.1"