Skip to content

packages.valory.contracts.gnosis_safe.tests.test_encode

Unit tests for the EIP-712 encode helpers.

test_encode_forwards_to_codec_registry

def test_encode_forwards_to_codec_registry() -> None

encode resolves an encoder from the codec registry and calls it.

test_to_string_bytes_passthrough

def test_to_string_bytes_passthrough() -> None

to_string leaves a bytes input untouched.

test_to_string_str_encodes_utf8

def test_to_string_str_encodes_utf8() -> None

to_string encodes a str input as UTF-8.

test_to_string_int_encodes_as_decimal_digits

def test_to_string_int_encodes_as_decimal_digits() -> None

to_string renders an int as its decimal UTF-8 string.

test_to_string_rejects_unsupported_type

def test_to_string_rejects_unsupported_type() -> None

to_string raises on unsupported types (mirrors original).

test_sha3_256_delegates_to_ledger_keccak

def test_sha3_256_delegates_to_ledger_keccak() -> None

sha3_256 calls ledger_api.api.keccak.

test_sha3_coerces_to_bytes_before_keccak

def test_sha3_coerces_to_bytes_before_keccak() -> None

sha3 runs the seed through to_string before hashing.

test_scan_bin_handles_str_0x_prefix

def test_scan_bin_handles_str_0x_prefix() -> None

scan_bin strips a leading 0x before hex decoding.

test_scan_bin_handles_unprefixed_hex

def test_scan_bin_handles_unprefixed_hex() -> None

scan_bin accepts hex without a 0x prefix.

test_create_struct_definition_formats_fields

def test_create_struct_definition_formats_fields() -> None

create_struct_definition formats Name(type name,...).

test_find_dependencies_returns_reachable_types

def test_find_dependencies_returns_reachable_types() -> None

find_dependencies adds every reachable named type.

test_find_dependencies_stops_on_already_seen

def test_find_dependencies_stops_on_already_seen() -> None

A type already in the set is not re-traversed (early return).

test_find_dependencies_stops_on_unknown_name

def test_find_dependencies_stops_on_unknown_name() -> None

Non-registered types short-circuit without adding to the set.

test_create_schema_builds_sorted_definition

def test_create_schema_builds_sorted_definition() -> None

create_schema joins the primary + sorted dependency definitions.

test_create_schema_handles_array_type_names

def test_create_schema_handles_array_type_names() -> None

Array type names (Foo[]) are stripped before lookup.

test_create_schema_hash_composes_encode_and_sha3

def test_create_schema_hash_composes_encode_and_sha3() -> None

create_schema_hash returns encode("bytes32", keccak(schema)).

test_encode_value_string_branch

def test_encode_value_string_branch() -> None

A string field is hashed then encoded as bytes32.

test_encode_value_bytes_branch_goes_through_scan_bin

def test_encode_value_bytes_branch_goes_through_scan_bin() -> None

A bytes field is hex-decoded via scan_bin before hashing.

test_encode_value_struct_branch

def test_encode_value_struct_branch() -> None

A custom struct type recurses through encode_data.

test_encode_value_array_branch

def test_encode_value_array_branch() -> None

A T[] field encodes each element then hashes the concatenation.

test_encode_value_primitive_fallback

def test_encode_value_primitive_fallback() -> None

Primitive ABI types fall through to the default encode path.

test_encode_data_concats_schema_hash_and_field_values

def test_encode_data_concats_schema_hash_and_field_values() -> None

Test that encode_data prefixes field encodings with the schema hash.

test_create_struct_hash_runs_sha3_over_encode_data

def test_create_struct_hash_runs_sha3_over_encode_data() -> None

Test that create_struct_hash is sha3(encode_data(...)).

test_encode_typed_data_assembles_eip712_digest

def test_encode_typed_data_assembles_eip712_digest() -> None

encode_typed_data returns sha3(0x19 01 || domainHash || messageHash).