Skip to content

Commit

Permalink
Tests: check delegation constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Feb 5, 2024
1 parent dbbcf31 commit d5833b1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
64 changes: 60 additions & 4 deletions test/python/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def test_sign_block_at_reset_level(client: TezosClient, tezos_navigator: TezosNa
client.sign_message(account, block)


PARAMETERS = [
PARAMETERS_SIGN_LEVEL_AUTHORIZED = [
(build_attestation, (0, 0), build_preattestation, (0, 1), True ),
(build_block, (0, 1), build_attestation_dal, (1, 0), True ),
(build_block, (0, 1), build_attestation_dal, (0, 0), False),
Expand Down Expand Up @@ -542,7 +542,7 @@ def test_sign_block_at_reset_level(client: TezosClient, tezos_navigator: TezosNa
"message_builder_1, level_round_1, " \
"message_builder_2, level_round_2, " \
"success",
PARAMETERS)
PARAMETERS_SIGN_LEVEL_AUTHORIZED)
def test_sign_level_authorized(
message_builder_1: Callable[[int, int, str], Message],
level_round_1: Tuple[int, int],
Expand Down Expand Up @@ -592,8 +592,7 @@ def test_sign_level_authorized(
def test_sign_delegation(
account: Account,
with_hash: bool,
tezos_navigator: TezosNavigator,
test_name: Path) -> None:
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on delegation."""
snap_path = Path(f"{account}")

Expand Down Expand Up @@ -630,6 +629,63 @@ def test_sign_delegation(
account.check_signature(signature, bytes(raw_delegation))


PARAMETERS_SIGN_DELEGATION_CONSTRAINTS = [
(
DEFAULT_ACCOUNT_2, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT,
StatusCode.SECURITY
),
(
DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_2, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT,
StatusCode.SECURITY
),
(
DEFAULT_ACCOUNT, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_2, DEFAULT_ACCOUNT,
# Warning: operation PARSE_ERROR are not available on DEBUG-mode
StatusCode.PARSE_ERROR
),
(
DEFAULT_ACCOUNT, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT, DEFAULT_ACCOUNT_2,
# Warning: operation PARSE_ERROR are not available on DEBUG-mode
StatusCode.PARSE_ERROR
)
]

@pytest.mark.parametrize(
"setup_account," \
"delegate_account," \
"source_account," \
"signer_account," \
"status_code",
PARAMETERS_SIGN_DELEGATION_CONSTRAINTS
)
def test_sign_delegation_constraints(
setup_account: Account,
delegate_account: Account,
source_account: Account,
signer_account: Account,
status_code: StatusCode,
tezos_navigator: TezosNavigator) -> None:
"""Test delegation signining constraints."""

tezos_navigator.setup_app_context(
setup_account,
DEFAULT_CHAIN_ID,
main_hwm=Hwm(0),
test_hwm=Hwm(0)
)

delegation = Delegation(
delegate=delegate_account.public_key_hash,
source=source_account.public_key_hash,
)

with status_code.expected():
tezos_navigator.sign_delegation(
signer_account,
delegation
)


def test_sign_not_authorized_key(
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
Expand Down
9 changes: 6 additions & 3 deletions test/python/utils/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,12 @@ def expected(self) -> Generator[None, None, None]:
yield
assert False, f"Expect fail with { self.name } but succeed"
except ExceptionRAPDU as e:
failing_code = StatusCode(e.status)
assert self == failing_code, \
f"Expect fail with { self.name } but fail with { failing_code.name }"
try:
name = f"{StatusCode(e.status).name}"
except ValueError:
name = f"0x{e.status:x}"
assert self == e.status, \
f"Expect fail with { self.name } but fail with {name}"


MAX_APDU_SIZE: int = 235
Expand Down

0 comments on commit d5833b1

Please sign in to comment.