Skip to content

Commit

Permalink
[test] use a pytest param account set to DEFAULT_ACCOUNT
Browse files Browse the repository at this point in the history
Instead of using it directly
+ Move DEFAULT_ACCOUNT and DEFAULT_SEED into `account.py`
  • Loading branch information
spalmer25 committed Dec 12, 2024
1 parent c4b1268 commit b3631ba
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 175 deletions.
9 changes: 8 additions & 1 deletion tests/integration/nano/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import pytest
from ragger.firmware import Firmware

from utils.app import TezosAppScreen, SpeculosTezosBackend, DEFAULT_SEED
from utils.account import Account, DEFAULT_ACCOUNT, DEFAULT_SEED
from utils.app import TezosAppScreen, SpeculosTezosBackend

FIRMWARES: List[Firmware] = [
Firmware.NANOS,
Expand Down Expand Up @@ -150,6 +151,12 @@ def seed(request) -> str:
param = getattr(request, "param", None)
return param.get("seed", DEFAULT_SEED) if param else DEFAULT_SEED

@pytest.fixture(scope="function")
def account(request) -> Account:
"""Get `account` for pytest."""
param = getattr(request, "param", None)
return param.get("account", DEFAULT_ACCOUNT) if param else DEFAULT_ACCOUNT

@pytest.fixture(scope="function")
def backend(app_path: Path,
firmware: Firmware,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/nano/test_public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pytest

from utils.account import Account, PublicKey, SigType
from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.app import TezosAppScreen
from utils.backend import StatusCode

accounts = [
Expand Down Expand Up @@ -67,8 +67,8 @@ def test_provide_pk(app: TezosAppScreen, account: Account, snapshot_dir: Path):
f"Expected public key {expected_public_key} but got {public_key}"


def test_reject_pk(app: TezosAppScreen, snapshot_dir: Path):
def test_reject_pk(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check reject pk behaviour"""

with StatusCode.REJECT.expected():
app.reject_public_key(DEFAULT_ACCOUNT, snap_path=snapshot_dir)
app.reject_public_key(account, snap_path=snapshot_dir)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import Ballot

def test_sign_ballot(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_ballot(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing ballot"""

message = Ballot(
Expand All @@ -31,12 +32,12 @@ def test_sign_ballot(app: TezosAppScreen, snapshot_dir: Path):
period = 32
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

from conftest import requires_device

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import (
OperationGroup,
Origination,
Expand All @@ -29,7 +30,7 @@
)

@requires_device("nanos")
def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
def test_nanos_regression_batched_ops(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing batch operation"""

app.toggle_expert_mode()
Expand Down Expand Up @@ -57,18 +58,18 @@ def test_nanos_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
)
])

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)

@requires_device("nanox")
def test_nanox_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
def test_nanox_regression_batched_ops(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing batch operation"""

app.toggle_expert_mode()
Expand Down Expand Up @@ -96,17 +97,17 @@ def test_nanox_regression_batched_ops(app: TezosAppScreen, snapshot_dir: Path):
)
])

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)

def test_sign_complex_operation(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_complex_operation(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing complex operation"""

app.toggle_expert_mode()
Expand Down Expand Up @@ -136,12 +137,12 @@ def test_sign_complex_operation(app: TezosAppScreen, snapshot_dir: Path):
)
])

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import Delegation

def test_sign_delegation(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_delegation(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing delegation"""

message = Delegation(
Expand All @@ -33,12 +34,12 @@ def test_sign_delegation(app: TezosAppScreen, snapshot_dir: Path):
delegate = 'tz1TmFPVZsGQ8MnrBJtnECJgkFUwLa6EWYDm'
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import FailingNoop

def test_sign_failing_noop(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_failing_noop(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing failing noop"""

message = FailingNoop("9f09f2952d34528c733f94615cfc39bc555619fc550dd4a67ba2208ce8e867aa3d13a6ef99dfbe32c6974aa9a2150d21eca29c3349e59c13b9081f1c11b440ac4d3455dedbe4ee0de15a8af620d4c86247d9d132de1bb6da23d5ff9d8dffda22ba9a84")

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import IncreasePaidStorage

def test_sign_increase_paid_storage(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_increase_paid_storage(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing increase paid storage"""

message = IncreasePaidStorage(
Expand All @@ -34,12 +35,12 @@ def test_sign_increase_paid_storage(app: TezosAppScreen, snapshot_dir: Path):
destination = "KT18amZmM5W7qDWVt2pH6uj7sCEd3kbzLrHT"
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import Origination

def test_sign_origination(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_origination(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing origination"""

app.toggle_expert_mode()
Expand All @@ -37,12 +38,12 @@ def test_sign_origination(app: TezosAppScreen, snapshot_dir: Path):
balance = 500000
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import Proposals

def test_sign_proposals(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_proposals(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing proposals"""

message = Proposals(
Expand All @@ -33,12 +34,12 @@ def test_sign_proposals(app: TezosAppScreen, snapshot_dir: Path):
period = 32
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import RegisterGlobalConstant

def test_sign_register_global_constant(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_register_global_constant(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing register global constant"""

app.toggle_expert_mode()
Expand All @@ -35,12 +36,12 @@ def test_sign_register_global_constant(app: TezosAppScreen, snapshot_dir: Path):
value = {'prim': 'Pair', 'args': [{'string': '1'}, {'int': 2}]}
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import Reveal

def test_sign_reveal(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_reveal(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing reveal"""

message = Reveal(
Expand All @@ -33,12 +34,12 @@ def test_sign_reveal(app: TezosAppScreen, snapshot_dir: Path):
public_key = 'edpkuXX2VdkdXzkN11oLCb8Aurdo1BTAtQiK8ZY9UPj2YMt3AHEpcY'
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

from pathlib import Path

from utils.app import TezosAppScreen, DEFAULT_ACCOUNT
from utils.account import Account
from utils.app import TezosAppScreen
from utils.message import ScRollupAddMessage

def test_sign_sc_rollup_add_messages(app: TezosAppScreen, snapshot_dir: Path):
def test_sign_sc_rollup_add_messages(app: TezosAppScreen, account: Account, snapshot_dir: Path):
"""Check signing smart rollup add message"""

message = ScRollupAddMessage(
Expand All @@ -33,12 +34,12 @@ def test_sign_sc_rollup_add_messages(app: TezosAppScreen, snapshot_dir: Path):
message = [bytes.fromhex('012345'), bytes.fromhex('67'), bytes.fromhex('89abcdef')]
)

data = app.sign(DEFAULT_ACCOUNT,
data = app.sign(account,
message,
with_hash=True,
snap_path=snapshot_dir)

DEFAULT_ACCOUNT.check_signature(
account.check_signature(
message=message,
with_hash=True,
data=data)
Loading

0 comments on commit b3631ba

Please sign in to comment.