Skip to content

Commit

Permalink
[test] explicits messages (#301)
Browse files Browse the repository at this point in the history
* [test] abstract Message and instantiate RawMessage

* [test] build transaction

* [test] build failing-noop

* [test] build reveal

* [test] build origination

* [test] build delegation

* [test] build register-global-constant

* [test] build transfer-ticket

* [test] build smart-rollup-add-messages

* [test] build smart-rollup-execute-outbox-message

* [test] build proposals

* [test] build ballot

* [test] build set-deposit-limit

* [test] build increase-paid-storage

* [test] build update-consensus-key

* [test] build smart-rollup-originate

* [test] build operations group

* [test] build micheline expression
  • Loading branch information
spalmer25 authored Dec 12, 2024
1 parent 085c4e6 commit 4a8c7b1
Show file tree
Hide file tree
Showing 38 changed files with 1,417 additions and 544 deletions.
1 change: 1 addition & 0 deletions tests/integration/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[MESSAGES CONTROL]
disable=
broad-exception-caught,
dangerous-default-value,
global-statement,
line-too-long,
protected-access,
Expand Down
38 changes: 23 additions & 15 deletions tests/integration/nano/nanos/test_nanos_regression_batched_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,7 @@
from conftest import requires_device

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import Message

# Operation (0): Transaction
# Fee: 0.39 XTZ
# Storage limit: 6
# Amount: 0.02 XTZ
# Destination: tz1cfdVKpBb9VRBdny8BQ5RSK82UudAp2miM
# Entrypoint: jean_bob
# Parameter: {Pair {} (Right -76723569314251090535296646);Pair {Elt Unit (Pair {Left Unit} (Pair (Left 0x03F01167865DC63DFEE0E31251329CEAB660D94606) (Pair 0x0107B21FCA96C5763F67B286752C7AAEFC5931D15A Unit)))} (Right 3120123370638446806591421154959427514880865200209654970345);Pair {} (Left (Some Unit))}
# Operation (1): Transaction
# Fee: 0.65 XTZ
# Storage limit: 2
# Amount: 0.06 XTZ
# Destination: KT1CYT8oACUcCSNTu2qfgB4fj5bD7szYrpti
from utils.message import OperationGroup, Transaction

@requires_device("nanos")
def test_nanos_regression_batched_ops(app: TezosAppScreen):
Expand All @@ -42,7 +29,28 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen):

app.setup_expert_mode()

message = Message.from_bytes("0300000000000000000000000000000000000000000000000000000000000000006c001597c45b11b421bb806a0c56c5da5638bf4b1adbf0e617090006a09c010000bac799dfc7f6af2ff0b95f83d023e68c895020baffff086a65616e5f626f620000009a020000009507070200000000050800c6bab5ccc8d891cd8de4b6f7070707020000004b0704030b070702000000040505030b070705050a0000001503f01167865dc63dfee0e31251329ceab660d9460607070a000000150107b21fca96c5763f67b286752c7aaefc5931d15a030b050800a9df9fc1e7eaa7a9c1f7bd87a9ba9cadf5b5b2cd829deea2b7fef9070707020000000005050509030b6c01ee572f02e5be5d097ba17369789582882e8abb8790d627063202e0d403012b704944f5b5fd30eed2ab4385478488e09fe04a0000")
message = OperationGroup([
Transaction(
source = 'tz1McCh72NRhYmJBcWr3zDrLJAxnfR9swcFh',
fee = 390000,
counter = 9,
gas_limit = 0,
storage_limit = 6,
destination = 'tz1cfdVKpBb9VRBdny8BQ5RSK82UudAp2miM',
amount = 20000,
entrypoint = 'jean_bob',
parameter = [{'prim':'Pair','args':[[],{'prim':'Right','args':[{'int':-76723569314251090535296646}]}]},{'prim':'Pair','args':[[{'prim':'Elt','args':[{'prim':'Unit','args':[]},{'prim':'Pair','args':[[{'prim':'Left','args':[{'prim':'Unit','args':[]}]}],{'prim':'Pair','args':[{'prim':'Left','args':[{'bytes':"03F01167865DC63DFEE0E31251329CEAB660D94606"}]},{'prim':'Pair','args':[{'bytes':"0107B21FCA96C5763F67B286752C7AAEFC5931D15A"},{'prim':'Unit','args':[]}]}]}]}]}],{'prim':'Right','args':[{'int':3120123370638446806591421154959427514880865200209654970345}]},]},{'prim':'Pair','args':[[],{'prim':'Left','args':[{'prim':'Some','args':[{'prim':'Unit','args':[]}]}]}]}]
),
Transaction(
source = 'tz2W3Tvcm64GjcV2bipUynnEsctLFz5Z6yRa',
fee = 650000,
counter = 6,
gas_limit = 50,
storage_limit = 2,
destination = 'KT1CYT8oACUcCSNTu2qfgB4fj5bD7szYrpti',
amount = 60000
)
])

data = app.sign(DEFAULT_ACCOUNT,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,7 @@
from conftest import requires_device

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import Message

# Operation (0): Transfer ticket
# Fee: 0.01 XTZ
# Storage limit: 4
# Contents: UNPAIR
# Type: pair "1" 2
# Ticketer: tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa
# Amount: 1
# Destination: KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT
# Entrypoint: S
#
# S
# S
# S
from utils.message import TransferTicket

@requires_device("nanosp")
def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen):
Expand All @@ -43,7 +29,19 @@ def test_nanosp_regression_potential_empty_screen(app: TezosAppScreen):

app.setup_expert_mode()

message = Message.from_bytes("0300000000000000000000000000000000000000000000000000000000000000009e00ffdd6102321bc251e4a5190ad5b12b251069d9b4904e02030400000002037a0000000a076501000000013100020000ffdd6102321bc251e4a5190ad5b12b251069d9b4010100000000000000000000000000000000000000000000000008530a0a530a530a53")
message = TransferTicket(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
fee = 10000,
counter = 2,
gas_limit = 3,
storage_limit = 4,
ticket_contents = {'prim': 'UNPAIR'},
ticket_ty = {'prim': 'pair', 'args': [{'string': '1'}, {'int': 2}]},
ticket_ticketer = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
ticket_amount = 1,
destination = 'KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT',
entrypoint = 'S\n\nS\nS\nS'
)

data = app.sign(DEFAULT_ACCOUNT,
message,
Expand Down
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 Message

# 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 = Message.from_bytes("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
38 changes: 23 additions & 15 deletions tests/integration/nano/nanox/test_nanox_regression_batched_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,7 @@
from conftest import requires_device

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import Message

# Operation (0): Transaction
# Fee: 0.39 XTZ
# Storage limit: 6
# Amount: 0.02 XTZ
# Destination: tz1cfdVKpBb9VRBdny8BQ5RSK82UudAp2miM
# Entrypoint: jean_bob
# Parameter: {Pair {} (Right -76723569314251090535296646);Pair {Elt Unit (Pair {Left Unit} (Pair (Left 0x03F01167865DC63DFEE0E31251329CEAB660D94606) (Pair 0x0107B21FCA96C5763F67B286752C7AAEFC5931D15A Unit)))} (Right 3120123370638446806591421154959427514880865200209654970345);Pair {} (Left (Some Unit))}
# Operation (1): Transaction
# Fee: 0.65 XTZ
# Storage limit: 2
# Amount: 0.06 XTZ
# Destination: KT1CYT8oACUcCSNTu2qfgB4fj5bD7szYrpti
from utils.message import OperationGroup, Transaction

@requires_device("nanox")
def test_nanox_regression_batched_ops(app: TezosAppScreen):
Expand All @@ -42,7 +29,28 @@ def test_nanox_regression_batched_ops(app: TezosAppScreen):

app.setup_expert_mode()

message = Message.from_bytes("0300000000000000000000000000000000000000000000000000000000000000006c001597c45b11b421bb806a0c56c5da5638bf4b1adbf0e617090006a09c010000bac799dfc7f6af2ff0b95f83d023e68c895020baffff086a65616e5f626f620000009a020000009507070200000000050800c6bab5ccc8d891cd8de4b6f7070707020000004b0704030b070702000000040505030b070705050a0000001503f01167865dc63dfee0e31251329ceab660d9460607070a000000150107b21fca96c5763f67b286752c7aaefc5931d15a030b050800a9df9fc1e7eaa7a9c1f7bd87a9ba9cadf5b5b2cd829deea2b7fef9070707020000000005050509030b6c01ee572f02e5be5d097ba17369789582882e8abb8790d627063202e0d403012b704944f5b5fd30eed2ab4385478488e09fe04a0000")
message = OperationGroup([
Transaction(
source = 'tz1McCh72NRhYmJBcWr3zDrLJAxnfR9swcFh',
fee = 390000,
counter = 9,
gas_limit = 0,
storage_limit = 6,
destination = 'tz1cfdVKpBb9VRBdny8BQ5RSK82UudAp2miM',
amount = 20000,
entrypoint = 'jean_bob',
parameter = [{'prim':'Pair','args':[[],{'prim':'Right','args':[{'int':-76723569314251090535296646}]}]},{'prim':'Pair','args':[[{'prim':'Elt','args':[{'prim':'Unit','args':[]},{'prim':'Pair','args':[[{'prim':'Left','args':[{'prim':'Unit','args':[]}]}],{'prim':'Pair','args':[{'prim':'Left','args':[{'bytes':"03F01167865DC63DFEE0E31251329CEAB660D94606"}]},{'prim':'Pair','args':[{'bytes':"0107B21FCA96C5763F67B286752C7AAEFC5931D15A"},{'prim':'Unit','args':[]}]}]}]}]}],{'prim':'Right','args':[{'int':3120123370638446806591421154959427514880865200209654970345}]},]},{'prim':'Pair','args':[[],{'prim':'Left','args':[{'prim':'Some','args':[{'prim':'Unit','args':[]}]}]}]}]
),
Transaction(
source = 'tz2W3Tvcm64GjcV2bipUynnEsctLFz5Z6yRa',
fee = 650000,
counter = 6,
gas_limit = 50,
storage_limit = 2,
destination = 'KT1CYT8oACUcCSNTu2qfgB4fj5bD7szYrpti',
amount = 60000
)
])

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 Message

# 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 = Message.from_bytes("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 Message

# 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 = Message.from_bytes("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 Message

# 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 = Message.from_bytes("050092abf8e3d9e5f8cfd9ae8a9fe5f28ea1d5b5abf1af82dae8a4b68df3d1889eb6f988f5e8d31a")
message = MichelineExpr({'int':12345678901234567890123456789012345678901234567890123456789012345678901234567890})

data = app.blind_sign(DEFAULT_ACCOUNT,
message=message,
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/nano/test_change_sign_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@

from utils.app import Screen, TezosAppScreen, DEFAULT_ACCOUNT
from utils.backend import Ins, StatusCode
from utils.message import Message
from utils.message import Transaction

def test_change_sign_instruction(app: TezosAppScreen):
"""Check signing instruction changes behaviour"""

app.assert_screen(Screen.HOME)

message = Message.from_bytes("0300000000000000000000000000000000000000000000000000000000000000006c016e8874874d31c3fbd636e924d5a036a43ec8faa7d0860308362d80d30e01000000000000000000000000000000000000000000ff02000000020316")
message = Transaction(
source = 'tz2JPgTWZZpxZZLqHMfS69UAy1UHm4Aw5iHu',
fee = 50000,
counter = 8,
gas_limit = 54,
storage_limit = 45,
destination = 'KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT',
amount = 240000,
entrypoint = 'do',
parameter = {'prim': 'CAR'}
)
payload=bytes(message)

app.backend._ask_sign(Ins.SIGN_WITH_HASH, DEFAULT_ACCOUNT)
Expand Down
22 changes: 12 additions & 10 deletions tests/integration/nano/test_ensure_always_clearsign.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@
from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.message import Message

# Operation (0): Transaction
# Fee: 0.01 XTZ
# Storage limit: 4
# Amount: 0 XTZ
# Destination: KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT
# Entrypoint: root
# Data: {pair "[" (pair "Z" (pair "Y" (pair "X" (pair "W" (pair "V" (pair "U" (pair "T" (pair "S" (pair "R" (pair "Q" (pair "P" (pair "O" (pair "N" (pair "M" (pair "L" (pair "K" (pair "J" (pair "I" (pair "H" (pair "G" (pair "F" (pair "E" (pair "D" (pair "C" (pair "B" {})))))))))))))))))))))))));pair 10 (pair 9 (pair 8 (pair 7 (pair 6 (pair 5 (pair 4 (pair 3 (pair 2 (pair 1 {})))))))))}
from utils.message import Transaction

def test_ensure_always_clearsign(app: TezosAppScreen):
"""Check clear signing never blindsign"""
test_name = Path(__file__).stem

app.setup_expert_mode()

message = Message.from_bytes("0300000000000000000000000000000000000000000000000000000000000000006c00ffdd6102321bc251e4a5190ad5b12b251069d9b4904e0203040001000000000000000000000000000000000000000000ff01000001070200000102076501000000015b076501000000015a0765010000000159076501000000015807650100000001570765010000000156076501000000015507650100000001540765010000000153076501000000015207650100000001510765010000000150076501000000014f076501000000014e076501000000014d076501000000014c076501000000014b076501000000014a0765010000000149076501000000014807650100000001470765010000000146076501000000014507650100000001440765010000000143076501000000014202000000000765000a0765000907650008076500070765000607650005076500040765000307650002076500010200000000")
message = Transaction(
source = 'tz1ixvCiPJYyMjsp2nKBVaq54f6AdbV8hCKa',
fee = 10000,
counter = 2,
gas_limit = 3,
storage_limit = 4,
destination = 'KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT',
amount = 0,
entrypoint = 'root',
parameter = [{'prim':'pair','args':[{'string':"["},{'prim':'pair','args':[{'string':"Z"},{'prim':'pair','args':[{'string':"Y"},{'prim':'pair','args':[{'string':"X"},{'prim':'pair','args':[{'string':"W"},{'prim':'pair','args':[{'string':"V"},{'prim':'pair','args':[{'string':"U"},{'prim':'pair','args':[{'string':"T"},{'prim':'pair','args':[{'string':"S"},{'prim':'pair','args':[{'string':"R"},{'prim':'pair','args':[{'string':"Q"},{'prim':'pair','args':[{'string':"P"},{'prim':'pair','args':[{'string':"O"},{'prim':'pair','args':[{'string':"N"},{'prim':'pair','args':[{'string':"M"},{'prim':'pair','args':[{'string':"L"},{'prim':'pair','args':[{'string':"K"},{'prim':'pair','args':[{'string':"J"},{'prim':'pair','args':[{'string':"I"},{'prim':'pair','args':[{'string':"H"},{'prim':'pair','args':[{'string':"G"},{'prim':'pair','args':[{'string':"F"},{'prim':'pair','args':[{'string':"E"},{'prim':'pair','args':[{'string':"D"},{'prim':'pair','args':[{'string':"C"},{'prim':'pair','args':[{'string':"B"},[]]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]}]},{'prim':'pair','args':[{'int':10},{'prim':'pair','args':[{'int':9},{'prim':'pair','args':[{'int':8},{'prim':'pair','args':[{'int':7},{'prim':'pair','args':[{'int':6},{'prim':'pair','args':[{'int':5},{'prim':'pair','args':[{'int':4},{'prim':'pair','args':[{'int':3},{'prim':'pair','args':[{'int':2},{'prim':'pair','args':[{'int':1},[]]}]}]}]}]}]}]}]}]}]}]
)

data = app.sign(DEFAULT_ACCOUNT,
message,
Expand Down
Loading

0 comments on commit 4a8c7b1

Please sign in to comment.