Skip to content

Commit

Permalink
✨ Hack revm/non-revm testing imports based on config
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Oct 13, 2024
1 parent 96e6224 commit 805d0ee
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 37 deletions.
8 changes: 4 additions & 4 deletions wake/development/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,16 @@ def detect_default_chain() -> Chain:

if (
wake.deployment.default_chain.connected
and wake.testing.default_chain.connected
and wake.testing.chain.connected
):
raise ValueError(
"Both wake.testing.default_chain and wake.deployment.default_chain are connected. Please specify which chain to use."
)

if wake.deployment.default_chain.connected:
return wake.deployment.default_chain
elif wake.testing.default_chain.connected:
return wake.testing.default_chain
elif wake.testing.chain.connected:
return wake.testing.chain
else:
raise NotConnectedError("default_chain not connected")
elif "wake.deployment" in sys.modules:
Expand All @@ -748,7 +748,7 @@ def detect_default_chain() -> Chain:
elif "wake.testing" in sys.modules:
import wake.testing

return wake.testing.default_chain
return wake.testing.chain
else:
raise NotConnectedError("default_chain not connected")

Expand Down
95 changes: 64 additions & 31 deletions wake/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,68 @@
from rich import print

from wake.development.core import Abi, Account, Address, Eip712Domain, Wei, abi
from wake.development.globals import random
from wake.development.internal import UnknownEvent
from wake.development.primitive_types import *
from wake.development.transactions import (
Eip1559Transaction,
Eip2930Transaction,
Error,
LegacyTransaction,
Panic,
PanicCodeEnum,
TransactionAbc,
TransactionRevertedError,
UnknownTransactionRevertedError,
may_revert,
must_revert,
on_revert,
)
from wake.development.utils import (
burn_erc20,
get_create2_address_from_code,
get_create2_address_from_hash,
get_create_address,
get_logic_contract,
keccak256,
mint_erc20,
read_storage_variable,
write_storage_variable,
)
from wake.development.globals import random, get_config

from .core import Chain, default_chain
if get_config().testing.cmd == "revm":
from wake_rs import Abi, Account, Address, abi, keccak256, Chain, default_chain
from wake.development.core import Eip712Domain, Wei # TODO
from wake.development.internal import UnknownEvent
from wake.development.primitive_types import *
from wake.development.transactions import (
Eip1559Transaction,
Eip2930Transaction,
Error,
LegacyTransaction,
Panic,
PanicCodeEnum,
TransactionAbc,
TransactionRevertedError,
UnknownTransactionRevertedError,
may_revert,
must_revert,
on_revert,
)
from wake.development.utils import (
burn_erc20,
get_create2_address_from_code,
get_create2_address_from_hash,
get_create_address,
get_logic_contract,
mint_erc20,
read_storage_variable,
write_storage_variable,
)

chain = default_chain
chain = default_chain()
else:
from wake.development.core import Abi, Account, Address, Eip712Domain, Wei, abi
from wake.development.internal import UnknownEvent
from wake.development.primitive_types import *
from wake.development.transactions import (
Eip1559Transaction,
Eip2930Transaction,
Error,
LegacyTransaction,
Panic,
PanicCodeEnum,
TransactionAbc,
TransactionRevertedError,
UnknownTransactionRevertedError,
may_revert,
must_revert,
on_revert,
)
from wake.development.utils import (
burn_erc20,
get_create2_address_from_code,
get_create2_address_from_hash,
get_create_address,
get_logic_contract,
keccak256,
mint_erc20,
read_storage_variable,
write_storage_variable,
)

from .core import Chain, default_chain

chain = default_chain
9 changes: 7 additions & 2 deletions wake/testing/fuzzing/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

from typing_extensions import get_args, get_origin, get_type_hints

from wake.development.core import Account, Address, Chain, Wei, detect_default_chain
from wake.development.globals import random
from wake.development.core import Wei, detect_default_chain
from wake.development.globals import random, get_config
from wake.development.primitive_types import (
FixedSizeBytes, # pyright: ignore reportAttributeAccessIssue
)
from wake.development.primitive_types import (
Integer, # pyright: ignore reportAttributeAccessIssue
)

if get_config().testing.cmd == "revm":
from wake_rs import Account, Address, Chain
else:
from wake.development.core import Account, Address, Chain


def random_account(
*,
Expand Down

0 comments on commit 805d0ee

Please sign in to comment.