Skip to content

Commit

Permalink
[test] build micheline expression
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Nov 29, 2024
1 parent 6d69427 commit 8d1c494
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
from conftest import requires_device

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import RawMessage

# Expression: {IF_NONE {{SWAP;IF {DIP {{DROP 1;PUSH unit Unit;PUSH bool True;PUSH string ";L\\S?p$-Fq)VDg\n]te\no4v0_8)\""}}} {{DROP 2;PUSH unit Unit;PUSH bool False;PUSH string "Li-%*edF6~?E[5Kmu?dyviwJ^2\"\\d$FyQ>>!>D$g(Qg";PUSH string "*Tx<E`SiG6Yf*A^kZ\\=7?H[mOlQ\n]Ehs"}}}} {IF_NONE {DUP} {{DROP 4;PUSH unit Unit;PUSH bool True;PUSH string "\"\\6_4\n$k%";PUSH string "c^1\"\\?Ey_1!EVb~9;EX;YU\n#Kj2ZT8h`U!X "}}};SIZE}
from utils.message import MichelineExpr

@requires_device("nanosp")
def test_nanosp_regression_press_right_works_across_apdu_recieves(app: TezosAppScreen):
Expand All @@ -31,7 +29,7 @@ def test_nanosp_regression_press_right_works_across_apdu_recieves(app: TezosAppS

app.assert_screen(Screen.HOME)

message = RawMessage("050200000135072f02000000c502000000c0034c072c0200000040051f02000000390200000034052000010743036c030b07430359030a07430368010000001b3b4c5c533f70242d4671295644670a5d74650a6f3476305f3829220200000072020000006d052000020743036c030b07430359030307430368010000002b4c692d252a656446367e3f455b354b6d753f64797669774a5e32225c64244679513e3e213e4424672851670743036801000000202a54783c45605369473659662a415e6b5a5c3d373f485b6d4f6c510a5d4568730200000062072f020000000203210200000054020000004f052000040743036c030b07430359030a074303680100000009225c365f340a246b25074303680100000024635e31225c3f45795f31214556627e393b45583b59550a234b6a325a54386860552158200345")
message = MichelineExpr([{'prim':'IF_NONE','args':[[[{'prim':'SWAP'},{'prim':'IF','args':[[{'prim':'DIP','args':[[[{'prim':'DROP','args':[{'int':1}]},{'prim':'PUSH','args':[{'prim':'unit'},{'prim':'Unit'}]},{'prim':'PUSH','args':[{'prim':'bool'},{'prim':'True'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':';L\\S?p$-Fq)VDg\n]te\no4v0_8)\"'}]}]]]}],[[{'prim':'DROP','args':[{'int':2}]},{'prim':'PUSH','args':[{'prim':'unit'},{'prim':'Unit'}]},{'prim':'PUSH','args':[{'prim':'bool'},{'prim':'False'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':'Li-%*edF6~?E[5Kmu?dyviwJ^2\"\\d$FyQ>>!>D$g(Qg'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':'*Tx<E`SiG6Yf*A^kZ\\=7?H[mOlQ\n]Ehs'}]}]]]}]],[{'prim':'IF_NONE','args':[[{'prim':'DUP'}],[[{'prim':'DROP','args':[{'int':4}]},{'prim':'PUSH','args':[{'prim':'unit'},{'prim':'Unit'}]},{'prim':'PUSH','args':[{'prim':'bool'},{'prim':'True'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':'\"\\6_4\n$k%'}]},{'prim':'PUSH','args':[{'prim':'string'},{'string':'c^1\"\\?Ey_1!EVb~9;EX;YU\n#Kj2ZT8h`U!X '}]}]]]}]]},{'prim':'SIZE'}])

data = app.sign(DEFAULT_ACCOUNT,
message,
Expand Down
7 changes: 2 additions & 5 deletions tests/integration/nano/test_blindsign_reject.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@

from utils.app import ScreenText, TezosAppScreen, send_and_navigate, DEFAULT_ACCOUNT
from utils.backend import StatusCode
from utils.message import RawMessage

# Expression: 12345678901234567890123456789012345678901234567890123456789012345678901234567890
# is too large
from utils.message import MichelineExpr

def test_blindsign_reject(app: TezosAppScreen):
"""Check blindsigning rejection"""
test_name = Path(__file__).stem

expression = RawMessage("050092abf8e3d9e5f8cfd9ae8a9fe5f28ea1d5b5abf1af82dae8a4b68df3d1889eb6f988f5e8d31a")
expression = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890})

app.parsing_error_signing(DEFAULT_ACCOUNT,
expression,
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/nano/test_blindsign_too_deep.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@
from pathlib import Path

from utils.app import Screen, ScreenText, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import RawMessage

# Expression: {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{42}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
from utils.message import MichelineExpr

def test_blindsign_too_deep(app: TezosAppScreen):
"""Check blindsigning on too deep expression"""
test_name = Path(__file__).stem

app.assert_screen(Screen.HOME)

expression = RawMessage("0502000000f702000000f202000000ed02000000e802000000e302000000de02000000d902000000d402000000cf02000000ca02000000c502000000c002000000bb02000000b602000000b102000000ac02000000a702000000a2020000009d02000000980200000093020000008e02000000890200000084020000007f020000007a02000000750200000070020000006b02000000660200000061020000005c02000000570200000052020000004d02000000480200000043020000003e02000000390200000034020000002f020000002a02000000250200000020020000001b02000000160200000011020000000c02000000070200000002002a")
expression = MichelineExpr([[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{'int':42}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]])

if app.backend.firmware.device == "nanos":
def send(result_queue: Queue) -> None:
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/nano/test_blindsign_too_large.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
from pathlib import Path

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import RawMessage

# Expression: 12345678901234567890123456789012345678901234567890123456789012345678901234567890
from utils.message import MichelineExpr

def test_blindsign_too_large(app: TezosAppScreen):
"""Check blindsigning on too large expression"""
test_name = Path(__file__).stem

app.assert_screen(Screen.HOME)

message = RawMessage("050092abf8e3d9e5f8cfd9ae8a9fe5f28ea1d5b5abf1af82dae8a4b68df3d1889eb6f988f5e8d31a")
message = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890})

data = app.blind_sign(DEFAULT_ACCOUNT,
message=message,
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/nano/test_sign_micheline_without_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
from pathlib import Path

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import RawMessage

# Expression: {"CACA";"POPO";"BOUDIN"}
from utils.message import MichelineExpr

def test_sign_micheline_without_hash(app: TezosAppScreen):
"""Check signing micheline wihout getting hash"""
test_name = Path(__file__).stem

app.assert_screen(Screen.HOME)

message = RawMessage("05020000001d0100000004434143410100000004504f504f0100000006424f5544494e")
message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}])

data = app.sign(DEFAULT_ACCOUNT,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

from utils.account import Account, SigType
from utils.app import Screen, TezosAppScreen
from utils.message import RawMessage

# Expression: {"CACA";"POPO";"BOUDIN"}
from utils.message import MichelineExpr

def test_tz1_bip25519_sign_micheline_basic(app: TezosAppScreen):
"""Check signing with bip25519"""
Expand All @@ -33,7 +31,7 @@ def test_tz1_bip25519_sign_micheline_basic(app: TezosAppScreen):
SigType.BIP32_ED25519,
"edpkumJgSsSxkpiB5hmTq6eZcrmc6BsJtLAhYceFTiziFqje4mongz")

message = RawMessage("05020000001d0100000004434143410100000004504f504f0100000006424f5544494e")
message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}])

data = app.sign(account,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

from utils.account import Account, SigType
from utils.app import Screen, TezosAppScreen
from utils.message import RawMessage

# Expression: {"CACA";"POPO";"BOUDIN"}
from utils.message import MichelineExpr

def test_tz1_ed25519_sign_micheline_basic(app: TezosAppScreen):
"""Check signing with ed25519"""
Expand All @@ -33,7 +31,7 @@ def test_tz1_ed25519_sign_micheline_basic(app: TezosAppScreen):
SigType.ED25519,
"edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY")

message = RawMessage("05020000001d0100000004434143410100000004504f504f0100000006424f5544494e")
message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}])

data = app.sign(account,
message,
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/nano/test_tz2_sign_micheline_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

from utils.account import Account, SigType
from utils.app import TezosAppScreen
from utils.message import RawMessage

# Expression: {"CACA";"POPO";"BOUDIN"}
from utils.message import MichelineExpr

def test_tz2_sign_micheline_basic(app: TezosAppScreen):
"""Check signing with secp256k1"""
Expand All @@ -31,7 +29,7 @@ def test_tz2_sign_micheline_basic(app: TezosAppScreen):
SigType.SECP256K1,
"sppk7bVy617DmGvXsMqcwsiLtnedTN2trUi5ugXcNig7en4rHJyunK1")

message = RawMessage("05020000001d0100000004434143410100000004504f504f0100000006424f5544494e")
message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}])

data = app.sign(account,
message,
Expand Down
6 changes: 2 additions & 4 deletions tests/integration/nano/test_tz3_sign_micheline_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

from utils.account import Account, SigType
from utils.app import TezosAppScreen
from utils.message import RawMessage

# Expression: {"CACA";"POPO";"BOUDIN"}
from utils.message import MichelineExpr

def test_tz3_sign_micheline_basic(app: TezosAppScreen):
"""Check signing with p256"""
Expand All @@ -31,7 +29,7 @@ def test_tz3_sign_micheline_basic(app: TezosAppScreen):
SigType.SECP256R1,
"p2pk67fq5pzuMMABZ9RDrooYbLrgmnQbLt8z7PTGM9mskf7LXS5tdBG")

message = RawMessage("05020000001d0100000004434143410100000004504f504f0100000006424f5544494e")
message = MichelineExpr([{'string': 'CACA'}, {'string': 'POPO'}, {'string': 'BOUDIN'}])

data = app.sign(account,
message,
Expand Down
18 changes: 17 additions & 1 deletion tests/integration/nano/utils/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,23 @@ class Micheline:

class Watermark(IntEnum):
"""Class hodling messages watermark."""
MANAGER_OPERATION = 0x03
MANAGER_OPERATION = 0x03
MICHELINE_EXPRESSION = 0x05


class MichelineExpr(Message):
"""Class representing a tezos micheline expression."""

expr: Micheline

def __init__(self, expr: Micheline):
self.expr = expr

def __bytes__(self) -> bytes:
raw = b''
raw += forge_int_fixed(Watermark.MICHELINE_EXPRESSION, 1)
raw += forge_micheline(self.expr)
return raw


class OperationBuilder(ContentMixin):
Expand Down

0 comments on commit 8d1c494

Please sign in to comment.