-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
132 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
"""Base mainnet fork based tests for Lagoon""" | ||
import os | ||
|
||
import pytest | ||
from eth_typing import HexAddress | ||
from web3 import Web3 | ||
|
||
from eth_defi.hotwallet import HotWallet | ||
from eth_defi.lagoon.vault import LagoonVault | ||
from eth_defi.provider.anvil import AnvilLaunch, fork_network_anvil | ||
from eth_defi.provider.multi_provider import create_multi_provider_web3 | ||
from eth_defi.token import TokenDetails, fetch_erc20_details | ||
from eth_defi.trace import assert_transaction_success_with_explanation | ||
from eth_defi.vault.base import VaultSpec | ||
|
||
JSON_RPC_BASE = os.environ.get("JSON_RPC_BASE") | ||
|
||
CI = os.environ.get("CI", None) is not None | ||
|
||
pytestmark = pytest.mark.skipif(not JSON_RPC_BASE, reason="No JSON_RPC_BASE environment variable") | ||
|
||
|
||
@pytest.fixture() | ||
def vault_owner() -> HexAddress: | ||
# Vaut owner | ||
return "0x0c9db006f1c7bfaa0716d70f012ec470587a8d4f" | ||
|
||
|
||
@pytest.fixture() | ||
def usdc_holder() -> HexAddress: | ||
# https://basescan.org/token/0x833589fcd6edb6e08f4c7c32d4f71b54bda02913#balances | ||
return "0x3304E22DDaa22bCdC5fCa2269b418046aE7b566A" | ||
|
||
|
||
|
||
@pytest.fixture() | ||
def anvil_base_fork(request, vault_owner, usdc_holder, deposit_user) -> AnvilLaunch: | ||
"""Create a testable fork of live BNB chain. | ||
:return: JSON-RPC URL for Web3 | ||
""" | ||
launch = fork_network_anvil( | ||
JSON_RPC_BASE, | ||
unlocked_addresses=[vault_owner, usdc_holder, deposit_user], | ||
) | ||
try: | ||
yield launch | ||
finally: | ||
# Wind down Anvil process after the test is complete | ||
launch.close() | ||
|
||
|
||
@pytest.fixture() | ||
def web3(anvil_base_fork) -> Web3: | ||
web3 = create_multi_provider_web3(anvil_base_fork.json_rpc_url) | ||
assert web3.eth.chain_id == 8453 | ||
return web3 | ||
|
||
|
||
@pytest.fixture() | ||
def usdc(web3) -> TokenDetails: | ||
return fetch_erc20_details( | ||
web3, | ||
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def hot_wallet_user(web3, usdc, usdc_holder) -> HotWallet: | ||
"""A test account with USDC balance.""" | ||
|
||
hw = HotWallet.create_for_testing( | ||
web3, | ||
test_account_n=1, | ||
eth_amount=10 | ||
) | ||
hw.sync_nonce(web3) | ||
|
||
# give hot wallet some native token | ||
web3.eth.send_transaction( | ||
{ | ||
"from": web3.eth.accounts[9], | ||
"to": hw.address, | ||
"value": 1 * 10**18, | ||
} | ||
) | ||
|
||
# Top up with 999 USDC | ||
tx_hash = usdc.contract.functions.transfer(hw.address, 999 * 10**6).transact({"from": usdc_holder, "gas": 100_000}) | ||
assert_transaction_success_with_explanation(web3, tx_hash) | ||
return hw | ||
|
||
|
||
@pytest.fixture() | ||
def base_test_vault_spec() -> VaultSpec: | ||
"""Vault https://dapp.velvet.capital/ManagerVaultDetails/0x205e80371f6d1b33dff7603ca8d3e92bebd7dc25""" | ||
return VaultSpec(1, "0x205e80371f6d1b33dff7603ca8d3e92bebd7dc25") | ||
|
||
|
||
@pytest.fixture() | ||
def lagoon_vault(web3, base_test_vault_spec: VaultSpec) -> LagoonVault: | ||
return LagoonVault(web3, base_test_vault_spec) | ||
|
||
|
||
@pytest.fixture() | ||
def deposit_user() -> HexAddress: | ||
"""A user that has preapproved 5 USDC deposit for the vault above, no approve(0 needed.""" | ||
return "0x7612A94AafF7a552C373e3124654C1539a4486A8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from eth_defi.lagoon.vault import LagoonVault | ||
|
||
|
||
def test_lagoon_info(lagoon_vault: LagoonVault): | ||
vault = lagoon_vault | ||
info = vault.fetch_info() | ||
assert info["safe_address"] == "0x205e80371f6d1b33dff7603ca8d3e92bebd7dc25" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters