Skip to content

Commit

Permalink
check 'test address key-hash'
Browse files Browse the repository at this point in the history
  • Loading branch information
saratomaz committed Mar 21, 2023
1 parent 5898a5a commit cda0b41
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions cardano_node_tests/tests/test_cli.py
Expand Up @@ -290,6 +290,65 @@ def test_address_info_with_invalid_address(self, cluster: clusterlib.ClusterLib,
assert "Invalid address" in err_str, err_str


@pytest.mark.smoke
class TestAddressKeyHash:
"""Tests for cardano-cli address key-hash."""

@allure.link(helpers.get_vcs_link())
@pytest.mark.parametrize("option", ("vkey", "vkey_file"))
def test_valid_verification_key(self, cluster: clusterlib.ClusterLib, option: str):
"""Check `address key-hash` with valid verification key."""
temp_template = f"{common.get_test_id(cluster)}_{option}"

vkey_file = cluster.g_address.gen_payment_addr_and_keys(
name=temp_template,
).vkey_file

if option == "vkey":
with open(vkey_file, encoding="utf-8") as infile:
# Ignore the first 4 chars, just an informative keyword
vkey = helpers.encode_bech32(
prefix="vrf_vk", data=json.loads(infile.read().strip()).get("cborHex", "")[4:]
)

cluster.g_address.get_payment_vkey_hash(
payment_vkey=vkey if option == "vkey" else None,
payment_vkey_file=vkey_file if option == "vkey_file" else None,
)

@allure.link(helpers.get_vcs_link())
@pytest.mark.parametrize("option", ("vkey", "vkey_file"))
@hypothesis.given(vkey=st.text(alphabet=ADDR_ALPHABET, min_size=1))
@common.hypothesis_settings(max_examples=300)
def test_invalid_verification_key(self, cluster: clusterlib.ClusterLib, option: str, vkey: str):
"""Try to use `address key-hash` with invalid verification key (property-based test).
Expect failure.
"""
temp_template = f"{common.get_test_id(cluster)}_{option}_{common.unique_time_str()}"

if option == "vkey_file":
vkey_file = f"{temp_template}.redeemer"
vkey_file_content = {
"type": "PaymentVerificationKeyShelley_ed25519",
"description": "Payment Verification Key",
"cborHex": vkey,
}

with open(vkey_file, "w", encoding="utf-8") as outfile:
json.dump(vkey_file_content, outfile)

with pytest.raises(clusterlib.CLIError) as excinfo:
cluster.g_address.get_payment_vkey_hash(
payment_vkey=vkey if option == "vkey" else None,
payment_vkey_file=vkey_file if option == "vkey_file" else None,
)

err_str = str(excinfo.value)

assert "Invalid key" in err_str, err_str


@common.SKIPIF_WRONG_ERA
@pytest.mark.smoke
class TestKey:
Expand Down

0 comments on commit cda0b41

Please sign in to comment.