1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

refactor(tests): use common Stellar fixtures in tests

All test cases are generated and verified in Stellar Laboratory.
Source XDR is also tested to match the vectors, and it is easy to verify
in Laboratory directly.
This commit is contained in:
matejcik 2021-09-22 14:13:44 +02:00 committed by matejcik
parent b96adcac5c
commit f484c42d41
5 changed files with 158 additions and 535 deletions

View File

@ -1,7 +1,7 @@
{ {
"setup": { "setup": {
"mnemonic": "all all all all all all all all all all all all", "mnemonic": "all all all all all all all all all all all all",
"passphrase": "" "passphrase": ""
}, },
"tests": [ "tests": [
{ {

View File

@ -1,56 +0,0 @@
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
import pytest
from trezorlib import messages as proto, stellar
from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path
from ..common import MNEMONIC12
@pytest.mark.altcoin
@pytest.mark.stellar
class TestMsgStellarGetAddress:
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_stellar_get_address(self, client):
address = stellar.get_address(client, parse_path(stellar.DEFAULT_BIP32_PATH))
assert address == "GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW"
@pytest.mark.setup_client(
mnemonic="illness spike retreat truth genius clock brain pass fit cave bargain toe"
)
def test_stellar_get_address_sep(self, client):
# data from https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
address = stellar.get_address(client, parse_path(stellar.DEFAULT_BIP32_PATH))
assert address == "GDRXE2BQUC3AZNPVFSCEZ76NJ3WWL25FYFK6RGZGIEKWE4SOOHSUJUJ6"
address = stellar.get_address(
client, parse_path("m/44h/148h/1h"), show_display=True
)
assert address == "GBAW5XGWORWVFE2XTJYDTLDHXTY2Q2MO73HYCGB3XMFMQ562Q2W2GJQX"
def test_stellar_get_address_fail(self, client):
with pytest.raises(TrezorFailure) as exc:
stellar.get_address(client, parse_path("m/0/1"))
if client.features.model == "1":
assert exc.value.code == proto.FailureType.ProcessError
assert exc.value.message.endswith("Failed to derive private key")
else:
assert exc.value.code == proto.FailureType.DataError
assert exc.value.message == "Non-hardened paths unsupported on Ed25519"

View File

@ -1,458 +0,0 @@
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
# XDR decoding tool available at:
# https://www.stellar.org/laboratory/#xdr-viewer
#
# ## Test Info
#
# The default mnemonic generates the following Stellar keypair at path 44'/148'/0':
# GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW
# SDE2YU4V2IYSJIUH7MONDYZTSSLDXV5QDEGUUOLCU4TK7CZWTAXZ5CEG
#
# ### Testing a new Operation
#
# 1. Start at the Stellar transaction builder: https://www.stellar.org/laboratory/#txbuilder?network=test
# (Verify that the "test" network is active in the upper right)
#
# 2. Fill out the fields at the top as follows:
# Source account: GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW
# Transaction sequence number: 4294967296 (see _create_msg)
# Base fee: 100
# Memo: None
# Time Bounds: <leave blank>
#
# 3. Select the operation to test, such as Create Account
#
# 4. Fill out the fields for the operation
#
# 5. Scroll down to the bottom of the page and click "Sign in Transaction Signer"
#
# 6. In the first "Add Signer" text box enter the secret key: SDE2YU4V2IYSJIUH7MONDYZTSSLDXV5QDEGUUOLCU4TK7CZWTAXZ5CEG
#
# 7. Scroll down to the signed XDR blob and click "View in XDR Viewer"
#
# 8. Scroll down to the bottom and look at the "signatures" section. The Trezor should generate the same signature
#
from base64 import b64encode
import pytest
from trezorlib import messages, stellar
from trezorlib.tools import parse_path
from ..common import MNEMONIC12
pytestmark = [
pytest.mark.altcoin,
pytest.mark.stellar,
pytest.mark.setup_client(mnemonic=MNEMONIC12),
]
ADDRESS_N = parse_path(stellar.DEFAULT_BIP32_PATH)
NETWORK_PASSPHRASE = "Test SDF Network ; September 2015"
def _create_msg(memo=False) -> messages.StellarSignTx:
kwargs = {"memo_type": messages.StellarMemoType.NONE}
if memo:
kwargs = {"memo_type": messages.StellarMemoType.TEXT, "memo_text": "hi"}
return messages.StellarSignTx(
source_account="GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW",
fee=100,
sequence_number=0x100000000,
**kwargs,
)
def test_sign_tx_bump_sequence_op(client):
op = messages.StellarBumpSequenceOp()
op.bump_to = 0x7FFFFFFFFFFFFFFF
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"ZMIfHWhpyXdg40PzwOtkcXYnbZIO12Qy0WvkGqoYpb7jyWbG2HQCG7dgWhCoU5K81pvZTA2pMwiPjMwCXA//Bg=="
# 64c21f1d6869c97760e343f3c0eb647176276d920ed76432d16be41aaa18a5bee3c966c6d874021bb7605a10a85392bcd69bd94c0da933088f8ccc025c0fff06
)
def test_sign_tx_account_merge_op(client):
op = messages.StellarAccountMergeOp()
op.destination_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
response.public_key.hex()
== "15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469"
)
assert (
b64encode(response.signature)
== b"2R3Pj89U+dWrqy7otUrLLjtANjAg0lmBQL8E+89Po0Y94oqZkauP8j3WE7+/z7vF6XvAMLoOdqRYkUzr2oh7Dg=="
# d91dcf8fcf54f9d5abab2ee8b54acb2e3b40363020d2598140bf04fbcf4fa3463de28a9991ab8ff23dd613bfbfcfbbc5e97bc030ba0e76a458914cebda887b0e
)
def test_sign_tx_create_account_op(client):
"""Create new account with initial balance of 100.0333"""
op = messages.StellarCreateAccountOp()
op.new_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
op.starting_balance = 1000333000
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"vrRYqkM4b54NrDR05UrW7ZHU7CNcidV0fn+bk9dqOW1bCbmX3YfeRbk2Tf1aea8nr9SD0sfBhtrDpdyxUenjBw=="
# beb458aa43386f9e0dac3474e54ad6ed91d4ec235c89d5747e7f9b93d76a396d5b09b997dd87de45b9364dfd5a79af27afd483d2c7c186dac3a5dcb151e9e307
)
def test_sign_tx_payment_op_native(client):
"""Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
op = messages.StellarPaymentOp()
op.amount = 500111000
op.destination_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
op.asset = messages.StellarAsset(type=messages.StellarAssetType.NATIVE)
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg=="
# a4373a8212822cda186edde1e1e070fb9df7db7ee6d01074269fddfd3c49080f37985de8e45af8979bf0016051eb685d4d600ff4c85596e63471de62e785300e
)
def test_sign_tx_payment_op_custom_asset1(client):
"""Custom asset payment (code length 1) of 50.0111 X to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
op = messages.StellarPaymentOp()
op.amount = 500111000
op.destination_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
op.asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM4,
code="X",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"ArZydOtXU2whoRuSjJLFIWPSIsq3AbsncJZ+THF24CRSriVWw5Fy/dHrDlUOu4fzU28I6osDMeI39aWezg5tDw=="
# 02b67274eb57536c21a11b928c92c52163d222cab701bb2770967e4c7176e02452ae2556c39172fdd1eb0e550ebb87f3536f08ea8b0331e237f5a59ece0e6d0f
)
def test_sign_tx_payment_op_custom_asset12(client):
"""Custom asset payment (code length 12) of 50.0111 ABCDEFGHIJKL to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
op = messages.StellarPaymentOp()
op.amount = 500111000
op.destination_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
op.asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM12,
code="ABCDEFGHIJKL",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"QZIP4XKPfe4OpZtuJiyrMZBX9YBzvGpHGcngdgFfHn2kcdONreF384/pCF80xfEnGm8grKaoOnUEKxqcMKvxAA=="
# 41920fe1728f7dee0ea59b6e262cab319057f58073bc6a4719c9e076015f1e7da471d38dade177f38fe9085f34c5f1271a6f20aca6a83a75042b1a9c30abf100
)
# testcase added for UI code coverage, may not normally make sense
def test_sign_tx_allow_trust_op(client):
op = messages.StellarAllowTrustOp()
op.is_authorized = True
op.trusted_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
op.asset_type = messages.StellarAssetType.ALPHANUM4
op.asset_code = "X"
tx = _create_msg(memo=True)
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"JLLwaDvPAomcDnljhlM3LF6WQvlQzI+V/afI95X41HGRYgwbYrxXOplzzdBhbRxd09VxDkb3nQ271l6MEqn/CQ=="
)
# testcase added for UI code coverage, may not normally make sense
def test_sign_tx_change_trust_op(client):
op = messages.StellarChangeTrustOp()
op.limit = 5000000000
op.source_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
op.asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM12,
code="ABCDEFGHIJKL",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"B7UyKRCzVf6esTkzDJgac0vJ1YfI4Z7Ecq65/3TY0+D/VB3myZVg06LMjgIf10q8kF+GvJwN6XGKRd6q1wxHAw=="
)
# testcase added for UI code coverage, may not normally make sense
def test_sign_tx_passive_offer_op(client):
op = messages.StellarCreatePassiveOfferOp()
op.selling_asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM12,
code="ABCDEFGHIJKL",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
op.buying_asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM4,
code="X",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
op.amount = 4
op.price_n = 5
op.price_d = 6
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"78/YNz3U4PZmKubPgl+PIm/Jr8omISshJtwJuqXp4rSo9bAxxYRvMSa2IGFIy9PfIe2kDxnqSajTwiUFGOOtAw=="
)
# testcase added for UI code coverage, may not normally make sense
def test_sign_tx_manage_offer_op(client):
op = messages.StellarManageOfferOp()
op.selling_asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM12,
code="ABCDEFGHIJKL",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
op.buying_asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM4,
code="X",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
op.amount = 4
op.price_n = 5
op.price_d = 6
op.offer_id = 1337
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"tkCta8G5dmxOVYJ+/mGve1lzNyIKZB83DwWdZH2A6zGI7KF2VYGG8RNHmlMpMqeBFcit9o+/Ss+IAQ86CZBTAw=="
)
# testcase added for UI code coverage, may not normally make sense
def test_sign_tx_path_payment_op(client):
op = messages.StellarPathPaymentOp()
op.send_asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM4,
code="X",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
op.send_max = 50000
op.destination_account = "GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC"
op.destination_asset = messages.StellarAsset(
type=messages.StellarAssetType.ALPHANUM4,
code="X",
issuer="GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
)
op.destination_amount = 6667
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"KMUKub6SRXS4R86ux74bSSJXtMMQ1tEWhxc71jcAozKRX/db5dJC7oBVSeijSCT+hJOG/wTw6Jd1UBkJC0JgCw=="
)
def test_sign_tx_set_options(client):
"""Set inflation destination"""
op = messages.StellarSetOptionsOp()
op.inflation_destination_account = (
"GAFXTC5OV5XQD66T7WGOB2HUVUC3ZVJDJMBDPTVQYV3G3K7TUHC6CLBR"
)
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"dveWhKY8x7b0YqGHWH6Fo1SskxaHP11NXd2n6oHKGiv+T/LqB+CCzbmJA0tplZ+0HNPJbHD7L3Bsg/y462qLDA=="
# 76f79684a63cc7b6f462a187587e85a354ac9316873f5d4d5ddda7ea81ca1a2bfe4ff2ea07e082cdb989034b69959fb41cd3c96c70fb2f706c83fcb8eb6a8b0c
)
op = messages.StellarSetOptionsOp()
op.signer_type = messages.StellarSignerType.ACCOUNT
op.signer_key = bytes.fromhex(
"72187adb879c414346d77c71af8cce7b6eaa57b528e999fd91feae6b6418628e"
)
op.signer_weight = 2
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"EAeihuFBhUnjH6Sgd/+uAHlvajfv944VEpNSCLsOULNxYWdo/S0lJdUZw/2kN6I+ztKL7ZPQ5gYPJRNUePTOCg=="
# 1007a286e1418549e31fa4a077ffae00796f6a37eff78e1512935208bb0e50b371616768fd2d2525d519c3fda437a23eced28bed93d0e6060f25135478f4ce0a
)
op = messages.StellarSetOptionsOp()
op.medium_threshold = 0
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"E2pz06PFB5CvIT3peUcY0wxo7u9da2h6/+/qim1eRWLHC73ZtFqDtLMBaKnr63ZfjB/kDzZmCzHxiv5m+m6+AQ=="
# 136a73d3a3c50790af213de9794718d30c68eeef5d6b687affefea8a6d5e4562c70bbdd9b45a83b4b30168a9ebeb765f8c1fe40f36660b31f18afe66fa6ebe01
)
op = messages.StellarSetOptionsOp()
op.low_threshold = 0
op.high_threshold = 3
op.clear_flags = 0
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"ySQE4aS0TI+N1xjSwi/pABHpC+A6RrNPWDOuFYGJFQ5B4vIU2S+ql2gCGLE7bQiYZ5dK9021f+a30mZoYeFLDw=="
# c92404e1a4b44c8f8dd718d2c22fe90011e90be03a46b34f5833ae158189150e41e2f214d92faa97680218b13b6d089867974af74db57fe6b7d2666861e14b0f
)
op = messages.StellarSetOptionsOp()
op.set_flags = 3
op.master_weight = 4
op.home_domain = "hello"
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"22rfcOrxBiE5akpNsnWX8yPgAOpclbajVqXUaXMNeL000p1OhFhi050t1+GNRpoSNyfVsJGNvtlICGpH4ksDAQ=="
# db6adf70eaf10621396a4a4db27597f323e000ea5c95b6a356a5d469730d78bd34d29d4e845862d39d2dd7e18d469a123727d5b0918dbed948086a47e24b0301
)
op = messages.StellarSetOptionsOp()
op.signer_type = messages.StellarSignerType.PRE_AUTH
op.signer_key = bytes.fromhex(
"72187adb879c414346d77c71af8cce7b6eaa57b528e999fd91feae6b6418628e"
)
op.signer_weight = 0
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"fvZ8rzZPkJwa1lsr4/z/wXZLT6cBwFmwY861nmEnhy57Stw1dxCipo5PJeXk/EhyLxlAwL99+m7qWtdW38EZBg=="
)
op = messages.StellarSetOptionsOp()
op.clear_flags = 4
tx = _create_msg()
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"ZObGPxqyavv1fjXnlVQJM35FZu8zkJBAWkuOaI+KqyHTB8rOI4oXb27tohAnxiAzMn7e/tiNfqZwzQQS6RqmBg=="
)
def test_sign_tx_timebounds(client):
op = messages.StellarSetOptionsOp()
tx = _create_msg()
tx.timebounds_start = 1577836800
tx.timebounds_end = 1577839000
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"KkZSQxXxEwfeGuFEHD7e93hei34rwK7VB79udYzileg6P/QEzK+lKyB9blUy+dPV3e7PvlHMj1FKXOsrgj/uCA=="
# 2a46524315f11307de1ae1441c3edef7785e8b7e2bc0aed507bf6e758ce295e83a3ff404ccafa52b207d6e5532f9d3d5ddeecfbe51cc8f514a5ceb2b823fee08
)
tx.timebounds_start = 100
tx.timebounds_end = None
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"ukpdaMwe6wdNnbVnOl0ZDvU1dde7Mtnjzy2IhjeZAjk8Ze+52WCv4M8IFjLoNF5c0aB847XYozFj8AsZ/k5fDQ=="
# ba4a5d68cc1eeb074d9db5673a5d190ef53575d7bb32d9e3cf2d8886379902393c65efb9d960afe0cf081632e8345e5cd1a07ce3b5d8a33163f00b19fe4e5f0d
)
tx.timebounds_start = None
tx.timebounds_end = 111111111
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"9sFE/EC+zYlYC2t7R33HsI540nOmJi/aHruu2qG+RW4FEvhKLybLS5pRRhSb0IP3comcv1Q3e2Glvis6PgVICQ=="
# f6c144fc40becd89580b6b7b477dc7b08e78d273a6262fda1ebbaedaa1be456e0512f84a2f26cb4b9a5146149bd083f772899cbf54377b61a5be2b3a3e054809
)
def test_manage_data(client):
tx = _create_msg()
# testing a value whose length is not divisible by 4
op = messages.StellarManageDataOp(key="data", value=b"abc")
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"MTa8fmhM7BxYYo9kY1RKQFFrg/MVfzsgiPSuP7+SJZjhQ3P1ucN5JUnfmD5484ULRPjVTd+0YYjS6hScLupbCQ=="
# 3136bc7e684cec1c58628f6463544a40516b83f3157f3b2088f4ae3fbf922598e14373f5b9c3792549df983e78f3850b44f8d54ddfb46188d2ea149c2eea5b09
)

View File

@ -0,0 +1,118 @@
# This file is part of the Trezor project.
#
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
# XDR decoding tool available at:
# https://www.stellar.org/laboratory/#xdr-viewer
#
# ## Test Info
#
# The default mnemonic generates the following Stellar keypair at path 44'/148'/0':
# GAXSFOOGF4ELO5HT5PTN23T5XE6D5QWL3YBHSVQ2HWOFEJNYYMRJENBV
# SDK6NSLLKX5UE3DSXGK56MEMTZBOJ6XT3LLA33BEAZUYGO6TXMHNRUPB
#
# ### Testing a new Operation
#
# 1. Start at the Stellar transaction builder: https://www.stellar.org/laboratory/#txbuilder?network=test
# (Verify that the "test" network is active in the upper right)
#
# 2. Fill out the fields at the top as you like. We use mostly these values:
# Source account: GAXSFOOGF4ELO5HT5PTN23T5XE6D5QWL3YBHSVQ2HWOFEJNYYMRJENBV
# Transaction sequence number: 1000
# Base fee: 100
# Memo: None
# Time Bounds: 461535181, 1575234180
#
# 3. Select the operation to test, such as Create Account
#
# 4. Fill out the fields for the operation
#
# 5. Scroll down to the bottom of the page and click "Sign in Transaction Signer"
#
# 6. Copy the generated XDR and add it as an "xdr" field to your test case
#
# 7. In the first "Add Signer" text box enter the secret key: SDK6NSLLKX5UE3DSXGK56MEMTZBOJ6XT3LLA33BEAZUYGO6TXMHNRUPB
#
# 8. Scroll down to the signed XDR blob and click "View in XDR Viewer"
#
# 9. Scroll down to the bottom and look at the "signatures" section. The Trezor should generate the same signature
#
from base64 import b64encode
import pytest
from trezorlib import messages, protobuf, stellar
from trezorlib.tools import parse_path
from ..common import parametrize_using_common_fixtures
def parameters_to_proto(parameters):
tx_data = parameters["tx"]
ops_data = parameters["operations"]
tx_data["address_n"] = parse_path(parameters["address_n"])
tx_data["network_passphrase"] = parameters["network_passphrase"]
tx_data["num_operations"] = len(ops_data)
def make_op(operation_data):
type_name = operation_data["_message_type"]
assert type_name.startswith("Stellar") and type_name.endswith("Op")
cls = getattr(messages, type_name)
return protobuf.dict_to_proto(cls, operation_data)
tx = protobuf.dict_to_proto(messages.StellarSignTx, tx_data)
operations = [make_op(op) for op in ops_data]
return tx, operations
@pytest.mark.altcoin
@pytest.mark.stellar
@parametrize_using_common_fixtures("stellar/sign_tx.json")
def test_sign_tx(client, parameters, result):
tx, operations = parameters_to_proto(parameters)
response = stellar.sign_tx(
client, tx, operations, tx.address_n, tx.network_passphrase
)
assert response.public_key.hex() == result["public_key"]
assert b64encode(response.signature).decode() == result["signature"]
@pytest.mark.altcoin
@pytest.mark.stellar
@parametrize_using_common_fixtures("stellar/sign_tx.json")
@pytest.mark.skipif(not stellar.HAVE_STELLAR_SDK, reason="requires Stellar SDK")
def test_xdr(parameters, result):
from stellar_sdk import TransactionEnvelope
envelope = TransactionEnvelope.from_xdr(
parameters["xdr"], parameters["network_passphrase"]
)
tx, operations = stellar.from_envelope(envelope)
tx.address_n = parse_path(parameters["address_n"])
tx_expected, operations_expected = parameters_to_proto(parameters)
assert tx == tx_expected
for expected, actual in zip(operations_expected, operations):
assert expected == actual
@pytest.mark.altcoin
@pytest.mark.stellar
@parametrize_using_common_fixtures("stellar/get_address.json")
def test_get_address(client, parameters, result):
address_n = parse_path(parameters["path"])
address = stellar.get_address(client, address_n, show_display=True)
assert address == result["address"]

View File

@ -613,24 +613,6 @@
"test_msg_signtx_zcash.py-test_spend_old_versions": "c3f75b5c8ceb63ad2102d270689f55fbf3b204581bec7dcee930f875416e1a07", "test_msg_signtx_zcash.py-test_spend_old_versions": "c3f75b5c8ceb63ad2102d270689f55fbf3b204581bec7dcee930f875416e1a07",
"test_msg_signtx_zcash.py-test_v3_not_supported": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738", "test_msg_signtx_zcash.py-test_v3_not_supported": "1c100ce4b7c1e47e72428f390de0846c1ff933e9f07894872644a369a9422738",
"test_msg_signtx_zcash.py-test_version_group_id_missing": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "test_msg_signtx_zcash.py-test_version_group_id_missing": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"test_msg_stellar_get_address.py-test_stellar_get_address": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"test_msg_stellar_get_address.py-test_stellar_get_address_fail": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"test_msg_stellar_get_address.py-test_stellar_get_address_sep": "9b090a0a202024fabcd105824024ed4e37caaade034f0e6791e53c51e628fd50",
"test_msg_stellar_sign_transaction.py::test_manage_data": "d60815fa322382eb7fb34c7becf211dac77cd49eec7c175725dd9b8cca4990f4",
"test_msg_stellar_sign_transaction.py::test_sign_tx_account_merge_op": "3f64b525b7840ba4188aee2eddb9854a511e62fc86317b477919042e282a7e96",
"test_msg_stellar_sign_transaction.py::test_sign_tx_allow_trust_op": "881885b017b294bad51b64f45cc5e35a1a26a176a3f11bcf961dd93dfb4bb01e",
"test_msg_stellar_sign_transaction.py::test_sign_tx_bump_sequence_op": "8a8b1a7c99d37165a53a70ff6d12a71bed1ed5110b845216edca5e7828bf252f",
"test_msg_stellar_sign_transaction.py::test_sign_tx_change_trust_op": "6e9e3ae12b8a2c54a8eaab00f083d954fedaa04a0b985ea6906eba0f1df66a2e",
"test_msg_stellar_sign_transaction.py::test_sign_tx_create_account_op": "54bf2f8fa5c6d69dabef20b96c1d8f80dd1091a4c88a4e15be9732a145efecf6",
"test_msg_stellar_sign_transaction.py::test_sign_tx_manage_offer_op": "ee4c7c2c5587740bc067a14fcef443d3503b1a986025fadf9cb6ef3311dabdbd",
"test_msg_stellar_sign_transaction.py::test_sign_tx_passive_offer_op": "e12a89159be675f19c0b4e0edabc5cdb4a75d96fcafb33050970d72fa615448d",
"test_msg_stellar_sign_transaction.py::test_sign_tx_path_payment_op": "61b726d0554e264e0b776a0a1b2a1509a2fc1067014c2e67f4cf39b06c3bee6e",
"test_msg_stellar_sign_transaction.py::test_sign_tx_payment_op_custom_asset1": "ff8a7e1eb6f95414ad9b781a2b68de0d91a8792560a0b8456b752711e7c46ff6",
"test_msg_stellar_sign_transaction.py::test_sign_tx_payment_op_custom_asset12": "04d15badfdc039b80ba8070abb43296229bb699ace807d00d33c2829d493f8e4",
"test_msg_stellar_sign_transaction.py::test_sign_tx_payment_op_native": "d08ea23e86a72737dcb0f3a77fb727a8713ded08402515a1da53f1c052ca305f",
"test_msg_stellar_sign_transaction.py::test_sign_tx_payment_op_native_explicit_asset": "d08ea23e86a72737dcb0f3a77fb727a8713ded08402515a1da53f1c052ca305f",
"test_msg_stellar_sign_transaction.py::test_sign_tx_set_options": "077a6781b1bd4afea174de9b09c1e8601af52be80629acc8a31e1e2f665ada6c",
"test_msg_stellar_sign_transaction.py::test_sign_tx_timebounds": "24700cdbc99126d34bf099d218ac4992ac82a91705fc47a33c97f4b422a81db8",
"test_msg_tezos_getaddress.py-test_tezos_get_address": "77e28f49803c483f9aa61ff79861cd705bbac7f9ec021cc1ff15c0185a63c673", "test_msg_tezos_getaddress.py-test_tezos_get_address": "77e28f49803c483f9aa61ff79861cd705bbac7f9ec021cc1ff15c0185a63c673",
"test_msg_tezos_getpublickey.py-test_tezos_get_public_key": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1", "test_msg_tezos_getpublickey.py-test_tezos_get_public_key": "c09de07fbbf1e047442180e2facb5482d06a1a428891b875b7dd93c9e4704ae1",
"test_msg_tezos_sign_tx.py-test_tezos_kt_remove_delegation": "13053d1f52bd2a8f68ad23ccfbc58d3f0af98493d9be397db541856108945bb6", "test_msg_tezos_sign_tx.py-test_tezos_kt_remove_delegation": "13053d1f52bd2a8f68ad23ccfbc58d3f0af98493d9be397db541856108945bb6",
@ -762,5 +744,42 @@
"test_session_id_and_passphrase.py::test_passphrase_on_device": "46b26112ea2318eb8eddea7a91195234e4e8ad73d0924b27bd511eddb2c9bb23", "test_session_id_and_passphrase.py::test_passphrase_on_device": "46b26112ea2318eb8eddea7a91195234e4e8ad73d0924b27bd511eddb2c9bb23",
"test_session_id_and_passphrase.py::test_session_enable_passphrase": "df97cba828afe5e61a17492f54b2bc2bd16594cf1f76715bb6ee7d9775c78621", "test_session_id_and_passphrase.py::test_session_enable_passphrase": "df97cba828afe5e61a17492f54b2bc2bd16594cf1f76715bb6ee7d9775c78621",
"test_session_id_and_passphrase.py::test_session_with_passphrase": "46dcc72a89373c23c8e3e86c1c251ffa36b124aa081732bdebc5fd1fd33f10a7", "test_session_id_and_passphrase.py::test_session_with_passphrase": "46dcc72a89373c23c8e3e86c1c251ffa36b124aa081732bdebc5fd1fd33f10a7",
"test_stellar.py::test_get_address[parameters0-result0]": "60791a8a95b5f08b1ba55fafdd8dc954fb128e89e9a32b4f97b1b29f03faf993",
"test_stellar.py::test_get_address[parameters1-result1]": "2d4088c71f8198ab3a609c1f24c5bd349a0c444358a97089d9ae8e03d58e698c",
"test_stellar.py::test_get_address[parameters2-result2]": "53537e945bfebac7706646ff0b06e12934bcfcf4bf3fbd194d2e5123d19f7bec",
"test_stellar.py::test_get_address[parameters3-result3]": "76f91a1d52df5f0aa049fc2330c9ca4120e489996fd37958d347c5cc984ad876",
"test_stellar.py::test_get_address[parameters4-result4]": "d2ea6475ab1ff28ceb4fbadb344bdf9c3ad87a9073c771c0f674d2b2fc288898",
"test_stellar.py::test_get_address[parameters5-result5]": "39fa25d491afdc231d94079e695585f8cf4014c88457f554f03710a00467e4af",
"test_stellar.py::test_get_address[parameters6-result6]": "75897cca1437a54732d3970645b9d98013c89c0f6eaa68e446bfd57df138639f",
"test_stellar.py::test_get_address[parameters7-result7]": "d2e7e6add4b6862679b30033d36305bcbbda051cb1afa56f2e7ec8063266de0d",
"test_stellar.py::test_get_address[parameters8-result8]": "e8019f5d02f2145c643b7cdf626bd9409f9fb25780f4ea2cb0c2b5e562454e90",
"test_stellar.py::test_get_address[parameters9-result9]": "d040d9688c49c2bebe1bc74d5cc47a2d447b4de60acc8a63f6f032be22dbee04",
"test_stellar.py::test_sign_tx[StellarAccountMergeOp]": "91d1c7982ce491803e2e81bfd110893418467210187fb2c54e86e8da30b033ad",
"test_stellar.py::test_sign_tx[StellarAllowTrustOp-allow]": "58fa7d3979b95348d48142f87a120ff4dbdd1929b6e8835f7251a11079787cc3",
"test_stellar.py::test_sign_tx[StellarAllowTrustOp-revoke]": "73a5213df2fe880ff3e3b4f393f38b2a26d1b9a25b9ab9492342033fb1a3b71e",
"test_stellar.py::test_sign_tx[StellarBumpSequenceOp]": "583475eacf030cf9618c14b165eab2703582fa6373996e100697080432bc33f9",
"test_stellar.py::test_sign_tx[StellarChangeTrustOp-add]": "81c1208f684fdc542d46ce813d2884184c96509d9d024b438290af3fec85f1b6",
"test_stellar.py::test_sign_tx[StellarChangeTrustOp-delete]": "65514b813e3dcb247c27e1a26251aa63c0a3573e5f31bce73ae1a93489faa005",
"test_stellar.py::test_sign_tx[StellarCreateAccountOp]": "b2ee244c289471b94c7dda1d836a3065799c47abbe568d16d1f8633568a1d1bd",
"test_stellar.py::test_sign_tx[StellarCreatePassiveOfferOp]": "14d06af87462c7ea490339be030ecd647365568a173b5adda3c37473a3c42298",
"test_stellar.py::test_sign_tx[StellarManageDataOp]": "b462a3234199b29bf4f4cc636750b3a983e85b492f4caed480846869e389b900",
"test_stellar.py::test_sign_tx[StellarManageOfferOp]": "e5c002214d48acb9282845cbf6a0a3482a144c3ffb32ea91a4b0df5a7dfff0fc",
"test_stellar.py::test_sign_tx[StellarPathPaymentOp]": "a688b4865171437e49e0a421ea966c24c376e8e5514a276ab3ed8cd323105e6f",
"test_stellar.py::test_sign_tx[StellarPaymentOp-asset12]": "fb4db9a82787f42eb536d9d52d082c0e93e98658dd451c697665c64b2bbd7cb4",
"test_stellar.py::test_sign_tx[StellarPaymentOp-asset4]": "dd0996484008d30eb469d047b8036653bf9e26a86472281caa0af082f65f6241",
"test_stellar.py::test_sign_tx[StellarPaymentOp-native_asset]": "3d03a327623f1936097c613a63e1257f62a3ac7d49e1b91e27c9bff53668e6e3",
"test_stellar.py::test_sign_tx[StellarSetOptionsOp-all]": "bc7456b0182c102db93738408c8d837543908fa667e47e104619d376e6177c43",
"test_stellar.py::test_sign_tx[StellarSetOptionsOp-one]": "658c5c78672979691739992246c446ed9b6fa3c8dc500d474d1b7849bd3e5642",
"test_stellar.py::test_sign_tx[StellarSetOptionsOp-some]": "642f76c0cc11308dc68ee0e6899bb48b88fa4b65404dbfb696ada8155bf53989",
"test_stellar.py::test_sign_tx[memo_hash]": "c4e7db69acfacdfc42a2426829660799a64f15ab6f2238290110d614607871c8",
"test_stellar.py::test_sign_tx[memo_id]": "adf7a42534e0b2d6b321a195b3678f147bbe9244a3119040b9b24d2a43db5e4c",
"test_stellar.py::test_sign_tx[memo_return]": "b714d5cbecda1f420569d4891e9c42f3a782f69b9d7679648d5ef19c839ddb0a",
"test_stellar.py::test_sign_tx[memo_text]": "ee67b7b1c3a588c2d0a44af1e3c431e2d6c89f22441f933832de6384a4a8d110",
"test_stellar.py::test_sign_tx[multiple_operations]": "0a4af0d29399470ef5a6c411cf33ff4be2b2372bc583e1820a0e048cef942a59",
"test_stellar.py::test_sign_tx[source_account]": "eec21adf68ce037bf1f54026c1d6e102f2873e41462f784cb73b866ab1ffc07c",
"test_stellar.py::test_sign_tx[timebounds-0-0]": "99925099c044838aedbe1885aaac01ee4b118e148e89e7d1607c62bbc5c14eca",
"test_stellar.py::test_sign_tx[timebounds-0-1575234180]": "4e097ef73dda5f0be6550666a550d2acc2714364d51d76dc6834882a59ab883f",
"test_stellar.py::test_sign_tx[timebounds-461535181-0]": "64288f5ca66c618d267035b795d84e3aaa2fbd48fa4501e77851a7284e8eaa20",
"test_stellar.py::test_sign_tx[timebounds-461535181-1575234180]": "3d03a327623f1936097c613a63e1257f62a3ac7d49e1b91e27c9bff53668e6e3",
"test_u2f_counter.py::test_u2f_counter": "19f77e2d284431da5fadac938f5822c1a6b17c07ee6c801085efd84974f3163f" "test_u2f_counter.py::test_u2f_counter": "19f77e2d284431da5fadac938f5822c1a6b17c07ee6c801085efd84974f3163f"
} }