Skip to content

Commit

Permalink
Fork from block (#50)
Browse files Browse the repository at this point in the history
* Fork from block number

* Save anvil cache

* Kill anvil to flush caches

* No need for privateKey on anvil, use pre-defined test wallet

* No need to update prices

* Snapshots and account id

* New block with all prices

* Snapshot restore after test

* data-cy="balance amount"

* evmRevert

* fix timeouts

* stub icons

* Less annoying logs

* Comment out snapshots where not needed

* Fix for undefined historicalClaims: Cannot read properties of undefined (reading 'reduce')

* Fix for undefined vaults

* Comment out second deposit test until bug with wrapped token balance refetching is fixed

* Switch to a vanity address with simple new account

* Update block number on Base

* Typecheck

* Account number

* Fix undefined poolInfo

* More timeouts

* Back to test wallet

* poolInfo may be undefined

* Allow making price update calls

* More fixes

* Use importPythFeeds

* Fix Base tests

* Always have cypress_exit_code
  • Loading branch information
noisekit authored Nov 4, 2024
1 parent 93e6ddd commit 877a0e2
Show file tree
Hide file tree
Showing 33 changed files with 427 additions and 233 deletions.
35 changes: 27 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ jobs:
type: string
provider-url:
type: string
fork-block-number:
type: integer
working_directory: /tmp/app
docker:
- image: cypress/included:<< pipeline.parameters.cypress-version >>
Expand All @@ -163,6 +165,13 @@ jobs:
- install-foundry
- yarn-install

- run: date +"%Y-%W" > /tmp/week.txt && cat /tmp/week.txt
- restore_cache:
keys:
- &anvil-fork-cache anvil-fork-cache-{{ .Environment.ANVIL_CACHE_VERSION }}-{{ checksum "/tmp/week.txt" }}-{{ .BuildNum }}
- anvil-fork-cache-{{ .Environment.ANVIL_CACHE_VERSION }}-{{ checksum "/tmp/week.txt" }}-
- anvil-fork-cache-{{ .Environment.ANVIL_CACHE_VERSION }}-

- run:
name: Run server localhost:3000
working_directory: /tmp/app/liquidity/ui
Expand All @@ -171,7 +180,7 @@ jobs:

- run:
name: Run anvil localhost:8545
command: anvil --auto-impersonate --chain-id "<< parameters.chainId >>" --fork-url "<< parameters.provider-url >>"
command: anvil --auto-impersonate --chain-id "<< parameters.chainId >>" --fork-url "<< parameters.provider-url >>" --no-rate-limit --steps-tracing --fork-block-number "<< parameters.fork-block-number >>"
background: true

- run:
Expand All @@ -183,13 +192,21 @@ jobs:
command: wget -q -O - --retry-connrefused --waitretry=20 --read-timeout=20 --timeout=15 -t 10 --post-data='{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}' --header='Content-Type:application/json' http://localhost:8545

- run:
name: Update all prices
working_directory: /tmp/app/liquidity/cypress
command: yarn ts-node bin/doAllPriceUpdates.ts 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
command: |
echo "0" > /tmp/cypress_exit_code
cypress run --e2e --browser chrome \
--config specPattern="./cypress/e2e/<< parameters.chainId >>-<< parameters.preset >>/*.e2e.js" \
|| echo $? > /tmp/cypress_exit_code
- run:
working_directory: /tmp/app/liquidity/cypress
command: cypress run --e2e --browser chrome --config specPattern="./cypress/e2e/<< parameters.chainId >>-<< parameters.preset >>/*.e2e.js"
- run: pkill anvil

- save_cache:
key: *anvil-fork-cache
paths:
- '~/.foundry/cache'

- run: exit $(cat /tmp/cypress_exit_code)

- store_test_results:
path: 'liquidity/cypress/cypress/reports'
Expand Down Expand Up @@ -285,12 +302,14 @@ workflows:
name: liquidity-e2e-base-mainnet
chainId: 8453
preset: andromeda
provider-url: https://base-mainnet.infura.io/v3/$INFURA_KEY
provider-url: wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY
fork-block-number: 21781780
- liquidity-e2e:
name: liquidity-e2e-arbitrum-mainnet
chainId: 42161
preset: main
provider-url: https://arbitrum-mainnet.infura.io/v3/$INFURA_KEY
provider-url: wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY
fork-block-number: 269244293
- combine-coverage:
requires:
- tests
Expand Down
8 changes: 4 additions & 4 deletions liquidity/cypress/bin/approveCollateral.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ts-node

import { approveCollateral } from '../cypress/tasks/approveCollateral';
const [privateKey, symbol] = process.argv.slice(2);
if (!privateKey || !symbol) {
throw new Error('Usage: ./approveCollateral.ts <privateKey> <symbol>');
const [address, symbol] = process.argv.slice(2);
if (!address || !symbol) {
throw new Error('Usage: ./approveCollateral.ts <address> <symbol>');
}
approveCollateral({ privateKey, symbol });
approveCollateral({ address, symbol });
8 changes: 4 additions & 4 deletions liquidity/cypress/bin/createAccount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env ts-node

import { createAccount } from '../cypress/tasks/createAccount';
const [privateKey] = process.argv.slice(2);
if (!privateKey) {
throw new Error('Usage: ./approveCollateral.ts <privateKey>');
const [address, accountId] = process.argv.slice(2);
if (!address || !accountId) {
throw new Error('Usage: ./approveCollateral.ts <address> <accountId>');
}
createAccount({ privateKey });
createAccount({ address, accountId });
4 changes: 2 additions & 2 deletions liquidity/cypress/bin/doAllPriceUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env yarn ts-node

import { doAllPriceUpdates } from '../cypress/tasks/doAllPriceUpdates';
const [privateKey] = process.argv.slice(2);
doAllPriceUpdates({ privateKey }).then((data) => console.log(JSON.stringify(data, null, 2)));
const [address] = process.argv.slice(2);
doAllPriceUpdates({ address }).then((data) => console.log(JSON.stringify(data, null, 2)));
7 changes: 4 additions & 3 deletions liquidity/cypress/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = defineConfig({
...require('./cypress/tasks/getUSDC'),
...require('./cypress/tasks/doAllPriceUpdates'),
...require('./cypress/tasks/doPriceUpdateForPyth'),
...require('./cypress/tasks/snapshot'),
});
return config;
},
Expand All @@ -55,8 +56,8 @@ module.exports = defineConfig({
runMode: 1,
openMode: 0,
},
defaultCommandTimeout: 90_000,
execTimeout: 120_000,
taskTimeout: 300_000, // sometimes Anvil needs quite a bit of time to complete impersonating tx
defaultCommandTimeout: 60_000,
execTimeout: 60_000,
taskTimeout: 60_000,
},
});
18 changes: 16 additions & 2 deletions liquidity/cypress/cypress/e2e/42161-main/Create Account.e2e.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
before(() => {
cy.task('evmSnapshot').then((snapshot) => {
cy.wrap(snapshot).as('snapshot');
});
});
after(() => {
cy.get('@snapshot').then(async (snapshot) => {
cy.task('evmRevert', snapshot);
});
});

it('Create Account', () => {
cy.connectWallet().then((wallet) => {
cy.task('setEthBalance', { address: wallet.address, balance: 2 });
cy.connectWallet().then(({ address, accountId }) => {
cy.wrap(address).as('wallet');
cy.wrap(accountId).as('accountId');

cy.task('setEthBalance', { address, balance: 2 });
});

cy.viewport(1200, 900);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
before(() => {
cy.task('evmSnapshot').then((snapshot) => {
cy.wrap(snapshot).as('snapshot');
});
});
after(() => {
cy.get('@snapshot').then(async (snapshot) => {
cy.task('evmRevert', snapshot);
});
});

it('Dashboard - Connected', () => {
cy.connectWallet().then(({ address, privateKey }) => {
cy.connectWallet().then(({ address, accountId }) => {
cy.wrap(address).as('wallet');
cy.wrap(accountId).as('accountId');

cy.task('setEthBalance', { address, balance: 100 });
cy.task('createAccount', { privateKey }).then((accountId) => {
cy.wrap(accountId).as('accountId');
});
cy.task('createAccount', { address, accountId });
});

cy.viewport(1200, 900);
cy.visit('/#/dashboard');

cy.get('@wallet').then(({ address }) => {
cy.get('@wallet').then((address) => {
cy.get('[data-cy="short wallet address"]').contains(
`${address.substring(0, 6)}...${address.substring(address.length - 4)}`
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
// NO MUTATIONS!
//before(() => {
// cy.task('evmSnapshot').then((snapshot) => {
// cy.wrap(snapshot).as('snapshot');
// });
//});
//after(() => {
// cy.get('@snapshot').then(async (snapshot) => {
// cy.task('evmRevert', snapshot);
// });
//});

it('Dashboard - Not Connected', () => {
cy.viewport(1200, 900);
cy.visit('/#/dashboard');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
import { generatePath } from 'react-router-dom';

before(() => {
cy.task('evmSnapshot').then((snapshot) => {
cy.wrap(snapshot).as('snapshot');
});
});
after(() => {
cy.get('@snapshot').then(async (snapshot) => {
cy.task('evmRevert', snapshot);
});
});

it('should borrow against WETH position', () => {
cy.connectWallet().then(({ address, privateKey }) => {
cy.task('setEthBalance', { address, balance: 105 });
cy.connectWallet().then(({ address, accountId }) => {
cy.wrap(address).as('wallet');
cy.wrap(accountId).as('accountId');

cy.task('approveCollateral', { privateKey: privateKey, symbol: 'WETH' });
cy.task('wrapEth', { privateKey: privateKey, amount: 20 });

cy.task('createAccount', { privateKey }).then((accountId) => {
cy.wrap(accountId).as('accountId');
cy.task('depositCollateral', {
privateKey,
symbol: 'WETH',
accountId,
amount: 10,
});
cy.task('delegateCollateral', {
privateKey,
symbol: 'WETH',
accountId,
amount: 10,
poolId: 1,
});
cy.task('setEthBalance', { address, balance: 105 });
cy.task('createAccount', { address, accountId });
cy.task('approveCollateral', { address, symbol: 'WETH' });
cy.task('wrapEth', { address, amount: 20 });
cy.task('depositCollateral', {
address,
symbol: 'WETH',
accountId,
amount: 10,
});
cy.task('delegateCollateral', {
address,
symbol: 'WETH',
accountId,
amount: 10,
poolId: 1,
});
});

cy.viewport(1000, 800);
cy.viewport(1000, 1200);

cy.get('@accountId').then((accountId) => {
const path = generatePath('/positions/:collateralSymbol/:poolId', {
Expand All @@ -37,26 +47,24 @@ it('should borrow against WETH position', () => {

cy.contains('[data-status="info"]', 'You can take an interest-free loan up to').should('exist');

cy.get('[data-cy="claim amount input"]').should('exist').type('10');
cy.get('[data-cy="claim amount input"]').type('100');

cy.contains(
'[data-status="warning"]',
'Assets will be available to withdraw 24 hours after your last interaction with this position.'
).should('exist');

cy.contains('[data-status="info"]', 'You are about to take a $10 interest-free loan').should(
'exist'
);

cy.get('[data-cy="claim submit"]').should('be.enabled').click();
cy.get('[data-cy="claim submit"]').should('be.enabled').and('include.text', 'Borrow');
cy.get('[data-cy="claim submit"]').click();

cy.get('[data-cy="claim multistep"]')
.should('exist')
.and('include.text', 'Manage Debt')
.and('include.text', 'Borrow')
.and('include.text', 'Borrow 10 USDx');
.and('include.text', 'Borrow 100 USDx');

cy.get('[data-cy="claim confirm button"]').should('include.text', 'Execute Transaction').click();
cy.get('[data-cy="claim confirm button"]').should('include.text', 'Execute Transaction');
cy.get('[data-cy="claim confirm button"]').click();

cy.contains('[data-status="info"]', 'Debt successfully Updated').should('exist');
});
Loading

0 comments on commit 877a0e2

Please sign in to comment.