Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed Oct 14, 2024
1 parent 17fff35 commit ef20673
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 5 deletions.
5 changes: 5 additions & 0 deletions tests/hypothesis/e2e/stateful_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from hypothesis.stateful import RuleBasedStateMachine


class E2EStatefulBase(RuleBasedStateMachine):
pass
63 changes: 63 additions & 0 deletions tests/hypothesis/e2e/strategies.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import boa
from hypothesis.strategies import composite, integers

from tests.hypothesis.utils import (
original_vault_deployer,
vault_factory_deployer,
erc20_deployer,
rewards_handler_deployer,
hash_to_address,
)
from boa.test.strategies import strategy as boa_st

original_vault = original_vault_deployer(override_address=hash_to_address("original_vault"))

ZERO = boa.eval("empty(address)")

addresses = boa_st("address").filter(lambda addr: addr != ZERO)

# we don't use the `address` strategy here to
# avoid address collisions that are not realistic
yearn_gov = boa.env.generate_address()
role_manager = boa.env.generate_address()

vault_factory = vault_factory_deployer(
"mock factory", original_vault, yearn_gov, override_address=hash_to_address("vault_factory")
)

crvusd = erc20_deployer(override_address=hash_to_address("crvusd"))


@composite
def vault(draw):
_address = vault_factory.deploy_new_vault(crvusd, "Staked crvUSD", "st-crvUSD", role_manager, 0)

# we just "cast the interface" on the address
return original_vault_deployer.at(_address)


bps = integers(min_value=1, max_value=10_000)

minimum_weights = bps

scaling_factors = integers()


@composite
def rewards_handler(draw):
_rewards_handler = rewards_handler_deployer(
crvusd,
_vault := draw(vault()),
draw(minimum_weights),
draw(scaling_factors),
draw(addresses), # TODO mock this
draw(addresses),
)

_vault.set_role(_rewards_handler, 1, sender=role_manager)

return _rewards_handler


if __name__ == "__main__":
rewards_handler().example()
File renamed without changes.
Empty file removed tests/hypothesis/twa/__init__.py
Empty file.
10 changes: 5 additions & 5 deletions tests/hypothesis/twa/test_twa.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from tests.hypothesis.twa.stateful_base import TWAStatefulBase


def test_state_machine():
# Explicitly run the state machine
TestTWAStateful = TWAStateful.TestCase()
TestTWAStateful.run()
# def test_state_machine():
# # Explicitly run the state machine
# TestTWAStateful = TWAStateful.TestCase()
# TestTWAStateful.run()


@settings(
Expand Down Expand Up @@ -130,4 +130,4 @@ def compute_twa_rule(self, timestamp_delta):
), f"Mismatch in TWA: contract={contract_twa}, python={python_twa}"


# TestTWAStateful = TWAStateful.TestCase
TestTWAStateful = TWAStateful.TestCase
19 changes: 19 additions & 0 deletions tests/hypothesis/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import boa
from eth_account import Account
import hashlib

rewards_handler_deployer = boa.load_partial("contracts/RewardsHandler.vy")
original_vault_deployer = boa.load_partial("contracts/yearn/VaultV3.vy")
vault_factory_deployer = boa.load_partial("contracts/yearn/VaultFactory.vy")
erc20_deployer = boa.load_partial("tests/mocks/MockERC20.vy")
rewards_handler_deployer = boa.load_partial("contracts/RewardsHandler.vy")


def hash_to_address(input_string: str) -> str:
# Hash the input string using SHA-256 to create a 32-byte private key
private_key = hashlib.sha256(input_string.encode("utf-8")).hexdigest()
# Create an account object from the private key
account = Account.from_key(private_key)
# Retrieve the Ethereum address in checksum format
address = account.address
return address

0 comments on commit ef20673

Please sign in to comment.