Skip to content

Commit

Permalink
chore: improve and fix error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-tb committed Sep 4, 2024
1 parent 2180fe2 commit 444d038
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
43 changes: 31 additions & 12 deletions src/ethereum_test_specs/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Ethereum blockchain test spec definition and filler.
"""

from pprint import pprint
from pprint import pformat
from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type

from pydantic import ConfigDict, Field, field_validator
Expand Down Expand Up @@ -472,13 +472,22 @@ def generate_block_data(

except Exception as e:
print_traces(t8n.get_traces())
pprint(transition_tool_output.result)
pprint(previous_alloc)
pprint(transition_tool_output.alloc)
print(f"\nTransition tool output result:\n{pformat(transition_tool_output.result)}")
print(f"\nPrevious transition tool alloc:\n{pformat(previous_alloc)}")
if transition_tool_output.alloc is not None:
print(
"\nTransition tool output alloc:\n" f"{pformat(transition_tool_output.alloc)}"
)
if transition_tool_output.vkt is not None:
pprint(transition_tool_output.vkt)
print(
"\nTransition tools output verkle tree:\n"
f"{pformat(transition_tool_output.vkt)}"
)
if transition_tool_output.witness is not None:
pprint(transition_tool_output.witness)
print(
"\nTransition tools output witness:\n"
f"{pformat(transition_tool_output.witness)}"
)
raise e

if len(rejected_txs) > 0 and block.exception is None:
Expand Down Expand Up @@ -621,7 +630,10 @@ def verify_witness(
None,
)
if stem_state_diff is None:
raise ValueError(f"Stem {stem} not found in witness state diff.")
raise ValueError(
"Witness check failed - stem not found in witness state diff.\n\n"
+ pformat({"stem": str(stem)}, indent=4),
)

# Check that the suffix exists in the stem state diff
suffix = int.from_bytes(key[31:], byteorder="big")
Expand All @@ -635,16 +647,23 @@ def verify_witness(
)
if suffix_state_diff is None:
raise ValueError(
f"Suffix {suffix} not found for stem {stem} in witness state diff."
"Witness check failed - suffix not found for stem in state diff.\n\n"
+ pformat({"stem": str(stem), "suffix": suffix}, indent=4)
)

# Compare the expected witness check value with the current value in the state diff
# TODO: fix basic account value.
if str(suffix_state_diff.current_value) != str(value):
raise ValueError(
f"Witness check failed: expected current value {value}, "
f"got {suffix_state_diff.current_value}, "
f"for stem {stem} and suffix {suffix}."
"Witness check failed - value mismatch.\n\n"
+ pformat(
{
"stem": str(stem),
"suffix": suffix,
"expected_value": str(value),
"actual_value": str(suffix_state_diff.current_value),
},
indent=4,
)
)

def make_fixture(
Expand Down
6 changes: 5 additions & 1 deletion src/ethereum_test_types/verkle/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ def add_account_basic_data(self, address: Address, account: Account | None) -> N

# Append the encoded basic data to account_entries
self.account_entries.append(
(address, WitnessCheck.AccountHeaderEntry.BASIC_DATA, Hash(basic_data_value))
(
address,
WitnessCheck.AccountHeaderEntry.BASIC_DATA,
Hash(bytes(basic_data_value)),
)
)

def add_account_codehash(self, address: Address, codehash: Optional[Hash]) -> None:
Expand Down

0 comments on commit 444d038

Please sign in to comment.