Skip to content

Commit

Permalink
fix: wasnt getting unknown snap err
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 11, 2024
1 parent db20e1f commit c1efd86
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ape/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def __init__(self, snapshot_id: "SnapshotID"):
# Is block hash
snapshot_id = humanize_hash(cast(Hash32, snapshot_id))

super().__init__(f"Unknown snapshot ID '{str(snapshot_id)}'.")
super().__init__(f"Unknown snapshot ID '{snapshot_id}'.")


class QueryEngineError(ApeException):
Expand Down
2 changes: 1 addition & 1 deletion src/ape_test/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def restore(self, snapshot_id: SnapshotID):

try:
return self.evm_backend.revert_to_snapshot(snapshot_id)
except HeaderNotFound:
except (HeaderNotFound, ValidationError):
raise UnknownSnapshotError(snapshot_id)

def set_timestamp(self, new_timestamp: int):
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ProviderError,
TransactionError,
TransactionNotFoundError,
UnknownSnapshotError,
)
from ape.types import LogFilter
from ape.utils.testing import DEFAULT_TEST_ACCOUNT_BALANCE, DEFAULT_TEST_CHAIN_ID
Expand Down Expand Up @@ -543,3 +544,22 @@ def test_ipc_per_network(project, key):
# TODO: 0.9 investigate not using random if ipc set.

assert node.ipc_path == Path(ipc)


def test_snapshot(eth_tester_provider):
snapshot = eth_tester_provider.snapshot()
assert snapshot


def test_restore(eth_tester_provider, accounts):
account = accounts.test_accounts[0]
start_nonce = account.nonce
snapshot = eth_tester_provider.snapshot()
account.transfer(account, 0)
eth_tester_provider.restore(snapshot)
assert account.nonce == start_nonce


def test_restore_zero(eth_tester_provider, accounts):
with pytest.raises(UnknownSnapshotError, match="Unknown snapshot ID '0'."):
eth_tester_provider.restore(0)

0 comments on commit c1efd86

Please sign in to comment.