Skip to content

Commit

Permalink
Stata USDC e2e tests (#70)
Browse files Browse the repository at this point in the history
* stataUSDC e2e tests.

* Close static Aave USDC position.

* Update readme with new info on local dev

* No more magical loading on position page. Show exactly the page that is written in the URL

* Fix wonky tab logic

* Borrow is claim!

* Cleanup deprecated Borrow components and remove all index files

---------

Co-authored-by: Noisekit <[email protected]>
  • Loading branch information
peiman3 and noisekit authored Nov 27, 2024
1 parent 7aa6117 commit deaac78
Show file tree
Hide file tree
Showing 75 changed files with 581 additions and 1,085 deletions.
60 changes: 22 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,87 +33,71 @@ foundryup

Have `INFURA_KEY` env variable set

## Testing Base
## Testing with Cypress

1. Run Foundry Anvil fork

```sh
yarn anvil:base
```

2. Update all prices
1. Run Liquidity app locally

```sh
yarn update-prices:base
yarn start
```

3. Run Liquidity app locally
2. Open Cypress to debug

```sh
yarn start
yarn e2e
```

4. Open Cypress for Base
3. To run all the tests for all chains
```sh
yarn e2e:base
yarn e2e:run
```

## Local development with fork and Magic Wallet

Example for Arbitrum Mainnet

All RPC calls in this mode will be made to `127.0.0.1:8585`
and all transactions will be automatically signed, without any popups

1. Run Foundry Anvil fork

```sh
yarn anvil:arbitrum
# Mainnets
anvil --auto-impersonate --chain-id 1 --fork-url wss://mainnet.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing --fork-block-number 21233424
anvil --auto-impersonate --chain-id 8453 --fork-url wss://base-mainnet.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing --fork-block-number 22683522
anvil --auto-impersonate --chain-id 42161 --fork-url wss://arbitrum-mainnet.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing --fork-block-number 271813668
# Testnets
anvil --auto-impersonate --chain-id 11155111 --fork-url wss://sepolia.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing
anvil --auto-impersonate --chain-id 84532 --fork-url wss://base-sepolia.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing
anvil --auto-impersonate --chain-id 421614 --fork-url wss://arbitrum-sepolia.infura.io/ws/v3/$INFURA_KEY --no-rate-limit --steps-tracing
```

2. Update all prices (optionally, to speed up UI as it will not need to attach price updates to each call)

```sh
yarn update-prices:arbitrum
```

3. Run Liquidity app locally
2. Run Liquidity app locally

```sh
yarn start
```

4. Open app in browser
3. Open app in browser

```sh
open http://localhost:3000
```

5. Open devtools and set `localStorage` values
4. Open devtools and set `localStorage` values

```js
localStorage.DEBUG = 'true';
localStorage.DEBUG = 'snx:*';
localStorage.MAGIC_WALLET = '0xWalletAddress';
```

6. Reload page and proceed with connecting your wallet through UI choosing "Metamask" in popup
5. Reload page and proceed with connecting your wallet through UI choosing "Metamask" in popup
(the only option)

7. If wallet needs some ETH balance you can use foundry's `cast` to set balance
6. If wallet needs some ETH balance you can use foundry's `cast` to set balance
```sh
cast rpc anvil_setBalance 0xWalletAddress 10000000000000000000
# check your balance
cast balance 0xWalletAddress -e
```
8. Periodically (once an hour or less) sync fork time and update prices.
```sh
yarn update-prices:arbitrum
yarn sync-time
```
Because price updates are coming from offchain server we need to bring fork's internal time to realtime,
otherwise we will will have empty `priceUpdateTx` but then consistently get `OracleDataRequiredError` for ALL price feeds
190 changes: 0 additions & 190 deletions liquidity/components/BorrowModal/BorrowModal.tsx

This file was deleted.

3 changes: 0 additions & 3 deletions liquidity/components/BorrowModal/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions liquidity/components/BorrowModal/package.json

This file was deleted.

28 changes: 14 additions & 14 deletions liquidity/components/DepositModal/DepositModal.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { ArrowBackIcon } from '@chakra-ui/icons';
import { Button, Divider, Link, Text, useToast } from '@chakra-ui/react';
import { Amount } from '@snx-v3/Amount';
import { ONEWEI, ZEROWEI } from '@snx-v3/constants';
import { ContractError } from '@snx-v3/ContractError';
import { isBaseAndromeda, getWrappedStataUSDCOnBase } from '@snx-v3/isBaseAndromeda';
import { currency, parseUnits } from '@snx-v3/format';
import { getWrappedStataUSDCOnBase, isBaseAndromeda } from '@snx-v3/isBaseAndromeda';
import { ManagePositionContext } from '@snx-v3/ManagePositionContext';
import { Multistep } from '@snx-v3/Multistep';
import { useApprove } from '@snx-v3/useApprove';
import { useNetwork } from '@snx-v3/useBlockchain';
import { CollateralType, useCollateralTypes } from '@snx-v3/useCollateralTypes';
import { useContractErrorParser } from '@snx-v3/useContractErrorParser';
import { useConvertStataUSDC } from '@snx-v3/useConvertStataUSDC';
import { useCoreProxy } from '@snx-v3/useCoreProxy';
import { useDeposit } from '@snx-v3/useDeposit';
import { useDepositBaseAndromeda } from '@snx-v3/useDepositBaseAndromeda';
import { LiquidityPosition } from '@snx-v3/useLiquidityPosition';
import { useParams } from '@snx-v3/useParams';
import { usePool } from '@snx-v3/usePools';
import { useSpotMarketProxy } from '@snx-v3/useSpotMarketProxy';
import { useStaticAaveUSDC } from '@snx-v3/useStaticAaveUSDC';
import { useStaticAaveUSDCRate } from '@snx-v3/useStaticAaveUSDCRate';
import { useSynthTokens } from '@snx-v3/useSynthTokens';
import { useTokenBalance } from '@snx-v3/useTokenBalance';
import { useUSDC } from '@snx-v3/useUSDC';
import { useWrapEth } from '@snx-v3/useWrapEth';
import { Wei, wei } from '@synthetixio/wei';
import { useQueryClient } from '@tanstack/react-query';
Expand All @@ -22,21 +32,11 @@ import { BigNumber } from 'ethers';
import { FC, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { generatePath, useLocation, useNavigate } from 'react-router-dom';
import type { StateFrom } from 'xstate';
import { DepositMachine, Events, ServiceNames, State } from './DepositMachine';
import { LiquidityPositionUpdated } from '../../ui/src/components/Manage/LiquidityPositionUpdated';
import { ONEWEI, ZEROWEI } from '@snx-v3/constants';
import { ManagePositionContext } from '@snx-v3/ManagePositionContext';
import { LiquidityPosition } from '@snx-v3/useLiquidityPosition';
import { ChangeStat } from '../../ui/src/components/ChangeStat';
import { ChangeStat } from '../../ui/src/components/ChangeStat/ChangeStat';
import { CRatioChangeStat } from '../../ui/src/components/CRatioBar/CRatioChangeStat';
import { LiquidityPositionUpdated } from '../../ui/src/components/Manage/LiquidityPositionUpdated';
import { TransactionSummary } from '../../ui/src/components/TransactionSummary/TransactionSummary';
import { currency, parseUnits } from '@snx-v3/format';
import { useConvertStataUSDC } from '@snx-v3/useConvertStataUSDC';
import { useTokenBalance } from '@snx-v3/useTokenBalance';
import { useStaticAaveUSDCRate } from '@snx-v3/useStaticAaveUSDCRate';
import { useStaticAaveUSDC } from '@snx-v3/useStaticAaveUSDC';
import { useUSDC } from '@snx-v3/useUSDC';
import { useSynthTokens } from '@snx-v3/useSynthTokens';
import { DepositMachine, Events, ServiceNames, State } from './DepositMachine';

export const DepositModalUi: FC<{
collateralChange: Wei;
Expand Down
2 changes: 1 addition & 1 deletion liquidity/components/UndelegateModal/UndelegateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useQueryClient } from '@tanstack/react-query';
import { useMachine } from '@xstate/react';
import { FC, ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react';
import type { StateFrom } from 'xstate';
import { ChangeStat } from '../../ui/src/components/ChangeStat';
import { ChangeStat } from '../../ui/src/components/ChangeStat/ChangeStat';
import { CRatioChangeStat } from '../../ui/src/components/CRatioBar/CRatioChangeStat';
import { LiquidityPositionUpdated } from '../../ui/src/components/Manage/LiquidityPositionUpdated';
import { TransactionSummary } from '../../ui/src/components/TransactionSummary/TransactionSummary';
Expand Down
Loading

0 comments on commit deaac78

Please sign in to comment.