|
1 |
| -import uuid |
| 1 | +from eth_utils import to_checksum_address |
| 2 | +from hypothesis import given |
| 3 | +from hypothesis import strategies as st |
| 4 | +from hypothesis_jsonschema import from_schema |
2 | 5 |
|
3 | 6 | from silverback.cluster.types import ClusterConfiguration
|
4 | 7 |
|
| 8 | +CONFIG_SCHEMA = ClusterConfiguration.model_json_schema() |
5 | 9 |
|
6 |
| -def test_hmac_signature(): |
7 |
| - config = ClusterConfiguration() |
8 |
| - cluster_id = uuid.uuid4() |
9 |
| - owner = "0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97" |
| 10 | + |
| 11 | +@given( # type: ignore[call-overload] |
| 12 | + cluster_id=st.uuids(version=4), |
| 13 | + owner=st.binary(min_size=20, max_size=20).map(to_checksum_address), |
| 14 | + config_dict=from_schema(CONFIG_SCHEMA), |
| 15 | +) |
| 16 | +def test_hmac_signature(cluster_id, owner, config_dict): |
| 17 | + # NOTE: Ignore `version` fuzzed value |
| 18 | + config_dict["version"] = 1 |
| 19 | + config = ClusterConfiguration(**config_dict) |
10 | 20 | product_code = config.get_product_code(owner, cluster_id)
|
| 21 | + # NOTE: There is a gap of empty bytes between 8-16 |
| 22 | + encoded_config, sig = product_code[:8], product_code[16:] |
11 | 23 | # NOTE: Ensure we can properly decode the encoded product code into a configuration
|
12 |
| - assert config == ClusterConfiguration.decode(product_code[:16]) |
13 |
| - assert config.validate_product_code(owner, product_code[16:], cluster_id) |
| 24 | + assert config == ClusterConfiguration.decode(encoded_config) |
| 25 | + assert config.validate_product_code(owner, sig, cluster_id) |
0 commit comments