Skip to content

Commit

Permalink
Add test for attestation+DAL message
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinkyaraj-23 committed Jan 25, 2024
1 parent d1dd8cd commit 9e8f403
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 12 deletions.
47 changes: 47 additions & 0 deletions test/python/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from utils.message import (
Preattestation,
Attestation,
AttestationDal,
Fitness,
BlockHeader,
Block
Expand Down Expand Up @@ -397,6 +398,52 @@ def test_sign_attestation(
account.check_signature(signature, bytes(attestation))


@pytest.mark.parametrize("account", [DEFAULT_ACCOUNT])
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_attestation_dal(
account: Account,
with_hash: bool,
client: TezosClient,
firmware: Firmware,
navigator: Navigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on attestation."""

main_chain_id: int = 0
main_hwm = Hwm(0)
test_hwm = Hwm(0)

instructions = get_setup_app_context_instructions(firmware)

send_and_navigate(
send=lambda: client.setup_app_context(
account,
main_chain_id,
main_hwm,
test_hwm),
navigate=lambda: navigator.navigate(instructions))

attestation = AttestationDal(
chain_id=main_chain_id,
branch="0000000000000000000000000000000000000000000000000000000000000000",
slot=0,
op_level=0,
op_round=0,
block_payload_hash="0000000000000000000000000000000000000000000000000000000000000000",
dal_message="0000000000000000000000000000000000000000000000000000000000000000"
)

if with_hash:
signature = client.sign_message(account, attestation)
account.check_signature(signature, bytes(attestation))
else:
attestation_hash, signature = client.sign_message_with_hash(account, attestation)
assert attestation_hash == attestation.hash, \
f"Expected hash {attestation.hash.hex()} but got {attestation_hash.hex()}"
account.check_signature(signature, bytes(attestation))




@pytest.mark.parametrize("account", [DEFAULT_ACCOUNT])
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_block(
Expand Down
65 changes: 53 additions & 12 deletions test/python/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,19 @@ class ConsensusProtocol(IntEnum):
class OperationTag(IntEnum):
"""Class representing the operation tag."""

PROPOSAL = 5
BALLOT = 6
BABYLON_REVEAL = 107
BABYLON_TRANSACTION = 108
BABYLON_ORIGINATION = 109
BABYLON_DELEGATION = 110
ATHENS_REVEAL = 7
ATHENS_TRANSACTION = 8
ATHENS_ORIGINATION = 9
ATHENS_DELEGATION = 10
PREATTESTATION = 20
ATTESTATION = 21
PROPOSAL = 5
BALLOT = 6
BABYLON_REVEAL = 107
BABYLON_TRANSACTION = 108
BABYLON_ORIGINATION = 109
BABYLON_DELEGATION = 110
ATHENS_REVEAL = 7
ATHENS_TRANSACTION = 8
ATHENS_ORIGINATION = 9
ATHENS_DELEGATION = 10
PREATTESTATION = 20
ATTESTATION = 21
ATTESTATION_WITH_DAL = 23

class Preattestation(Message):
"""Class representing a preattestation."""
Expand Down Expand Up @@ -168,6 +169,46 @@ def raw(self) -> bytes:
raw += self.block_payload_hash
return raw

class AttestationDal(Message):
"""Class representing an attestation + DAL."""
chain_id: int
branch: bytes
slot: int
op_level: int
op_round: int
block_payload_hash: bytes
dal_message: bytes

def __init__(self,
chain_id: int,
branch: Union[str,bytes],
slot: int,
op_level: int,
op_round: int,
block_payload_hash: Union[str,bytes],
dal_message: Union[str,bytes]):
self.chain_id = chain_id
self.branch = scrub(branch)
assert_data_size("branch", self.branch, 32)
self.slot = slot
self.op_level = op_level
self.op_round = op_round
self.block_payload_hash = scrub(block_payload_hash)
assert_data_size("block_payload_hash", self.block_payload_hash, 32)
self.dal_message = scrub(dal_message)

def raw(self) -> bytes:
raw = b''
raw += MagicByte.TENDERBAKE_ENDORSEMENT.to_bytes(1, byteorder='big')
raw += self.chain_id.to_bytes(4, byteorder='big')
raw += self.branch
raw += OperationTag.ATTESTATION_WITH_DAL.to_bytes(1, byteorder='big')
raw += self.slot.to_bytes(2, byteorder='big')
raw += self.op_level.to_bytes(4, byteorder='big')
raw += self.op_round.to_bytes(4, byteorder='big')
raw += self.block_payload_hash
return raw

class Fitness:
"""Class representing a fitness."""
level: int
Expand Down

0 comments on commit 9e8f403

Please sign in to comment.