Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Jan 26, 2024
1 parent eb3c8f3 commit 23665cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 3 additions & 1 deletion eth_defi/enzyme/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
from eth_defi.uniswap_v2.utils import ZERO_ADDRESS


@dataclass(slots=True)
# Cannot be slots because of cached property
# @dataclass(slots=True)
@dataclass()
class Vault:
"""Enzyme vault wrapper.
Expand Down
27 changes: 21 additions & 6 deletions tests/enzyme/test_guard_enzyme_uniswap_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
)
from web3 import Web3
from web3.contract import Contract
from web3.middleware import construct_sign_and_send_raw_middleware

from eth_defi.deploy import deploy_contract
from eth_defi.enzyme.deployment import EnzymeDeployment, RateAsset
from eth_defi.enzyme.generic_adapter_vault import deploy_vault_with_generic_adapter
from eth_defi.enzyme.uniswap_v3 import prepare_swap
from eth_defi.enzyme.vault import Vault
from eth_defi.hotwallet import HotWallet
from eth_defi.middleware import construct_sign_and_send_raw_middleware_anvil
from eth_defi.token import TokenDetails
from eth_defi.trace import (
Expand Down Expand Up @@ -163,12 +165,25 @@ def vault(
) -> Vault:
"""Deploy an Enzyme vault.
Set up a forge compatible deployer account.
- GuardV0
- GuardedGenericAdapter
- TermsOfService
- TermedVaultUSDCPaymentForwarder
"""
return deploy_vault_with_generic_adapter(enzyme, deployer, asset_manager, deployer, usdc, terms_of_service)

_deployer = web3.eth.accounts[0]
account: LocalAccount = Account.create()
stash = web3.eth.get_balance(_deployer)
tx_hash = web3.eth.send_transaction({"from": _deployer, "to": account.address, "value": stash // 2})
assert_transaction_success_with_explanation(web3, tx_hash)

hot_wallet = HotWallet(account)
hot_wallet.sync_nonce(web3)
web3.middleware_onion.add(construct_sign_and_send_raw_middleware(account))

return deploy_vault_with_generic_adapter(enzyme, hot_wallet, asset_manager, deployer, usdc, terms_of_service)


@pytest.fixture()
Expand All @@ -187,13 +202,13 @@ def uniswap_v3(
) -> UniswapV3Deployment:
"""Deploy Uniswap v3."""
assert web3.eth.get_balance(deployer) > 0
uniswap = deploy_uniswap_v3(web3, deployer, weth=weth, give_weth=500)
uniswap = deploy_uniswap_v3(web3, vault.deployer_hot_wallet.address, weth=weth, give_weth=500)

guard = vault.guard_contract
guard.functions.whitelistUniswapV3Router(uniswap.swap_router.address, "").transact({"from": deployer})
guard.functions.whitelistToken(usdc.address, "").transact({"from": deployer})
guard.functions.whitelistToken(weth.address, "").transact({"from": deployer})
guard.functions.whitelistToken(mln.address, "").transact({"from": deployer})
guard.functions.whitelistUniswapV3Router(uniswap.swap_router.address, "").transact({"from": vault.deployer_hot_wallet.address})
guard.functions.whitelistToken(usdc.address, "").transact({"from": vault.deployer_hot_wallet.address})
guard.functions.whitelistToken(weth.address, "").transact({"from": vault.deployer_hot_wallet.address})
guard.functions.whitelistToken(mln.address, "").transact({"from": vault.deployer_hot_wallet.address})

return uniswap

Expand Down

0 comments on commit 23665cc

Please sign in to comment.