2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2018-04-04 01:50:38 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2018-04-04 01:50:38 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# 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>.
|
|
|
|
|
2018-04-04 01:50:38 +00:00
|
|
|
# XDR decoding tool available at:
|
|
|
|
# https://www.stellar.org/laboratory/#xdr-viewer
|
|
|
|
#
|
2018-06-01 03:30:40 +00:00
|
|
|
# ## 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 bottom and look at the "signatures" section. The Trezor should generate the same signature
|
|
|
|
#
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2018-05-16 14:00:08 +00:00
|
|
|
from base64 import b64encode
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2018-04-28 19:06:13 +00:00
|
|
|
import pytest
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib import messages as proto, stellar
|
|
|
|
from trezorlib.tools import parse_path
|
|
|
|
|
2019-09-11 12:43:32 +00:00
|
|
|
from ..common import MNEMONIC12
|
2018-08-13 16:21:24 +00:00
|
|
|
|
2018-04-28 18:59:08 +00:00
|
|
|
|
2019-08-22 16:47:01 +00:00
|
|
|
@pytest.mark.altcoin
|
device_tests: allow custom runxfail
We can now selectively runxfail certain tests. This is useful for
accepting PRs into trezor-core:
1. trezor-core is going to get a pytest.ini that sets xfail_strict.
That means that if an `xfail`ed test actually passes, that will
break the test suite. So it will be visible when we implement
a feature for which tests exist.
2. To allow PRs to pass the test suite without touching python-trezor
directly, we add a new pytest.ini option: run_xfail.
This adds a list of markers which will ignore `xfail`.
So:
2.1 First, the python-trezor PR marks the tests with the name
of the feature. This commit already does that: Lisk tests
are marked `@pytest.mark.lisk`, NEMs are `@pytest.mark.nem`,
etc.
The tests will be also marked with `xfail`, because the
feature is not in core yet.
2.2 Then, the trezor-core PR implements the feature, which makes
the `xfail`ed tests pass. That breaks the test suite.
2.3 To fix the test suite, the core PR also adds a `run_xfail`
to `pytest.ini`: `run_xfail = lisk`.
(it can take a list: `run_xfail = lisk nem stellar`)
That will make the test suite behave as if the tests are not
`xfail`ed. If the feature is implemented correctly, the tests
will pass.
2.4 When the PR is accepted to core, the next step should be
a PR to python-trezor that removes the `xfail`s. After that,
we should also remove the `run_xfail` option, just to be tidy.
2018-05-21 15:44:02 +00:00
|
|
|
@pytest.mark.stellar
|
2019-09-11 12:29:39 +00:00
|
|
|
class TestMsgStellarSignTransaction:
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2018-05-28 13:44:43 +00:00
|
|
|
ADDRESS_N = parse_path(stellar.DEFAULT_BIP32_PATH)
|
2018-08-13 16:21:24 +00:00
|
|
|
NETWORK_PASSPHRASE = "Test SDF Network ; September 2015"
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_bump_sequence_op(self, client):
|
2018-05-16 14:00:08 +00:00
|
|
|
op = proto.StellarBumpSequenceOp()
|
2018-10-01 12:01:33 +00:00
|
|
|
op.bump_to = 0x7FFFFFFFFFFFFFFF
|
2018-05-16 14:00:08 +00:00
|
|
|
tx = self._create_msg()
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"ZMIfHWhpyXdg40PzwOtkcXYnbZIO12Qy0WvkGqoYpb7jyWbG2HQCG7dgWhCoU5K81pvZTA2pMwiPjMwCXA//Bg=="
|
|
|
|
)
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_account_merge_op(self, client):
|
2018-05-16 14:00:08 +00:00
|
|
|
op = proto.StellarAccountMergeOp()
|
2018-08-13 16:21:24 +00:00
|
|
|
op.destination_account = (
|
|
|
|
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
)
|
2018-04-04 01:50:38 +00:00
|
|
|
|
2018-05-16 14:00:08 +00:00
|
|
|
tx = self._create_msg()
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-05-25 10:01:02 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
2018-09-12 18:34:26 +00:00
|
|
|
response.public_key.hex()
|
|
|
|
== "15d648bfe4d36f196cfb5735ffd8ca54cd4b8233f743f22449de7cf301cdb469"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"2R3Pj89U+dWrqy7otUrLLjtANjAg0lmBQL8E+89Po0Y94oqZkauP8j3WE7+/z7vF6XvAMLoOdqRYkUzr2oh7Dg=="
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_create_account_op(self, client):
|
2018-06-01 03:30:40 +00:00
|
|
|
"""Create new account with initial balance of 100.0333"""
|
|
|
|
|
|
|
|
op = proto.StellarCreateAccountOp()
|
2018-08-13 16:21:24 +00:00
|
|
|
op.new_account = "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
2018-06-01 03:30:40 +00:00
|
|
|
op.starting_balance = 1000333000
|
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"vrRYqkM4b54NrDR05UrW7ZHU7CNcidV0fn+bk9dqOW1bCbmX3YfeRbk2Tf1aea8nr9SD0sfBhtrDpdyxUenjBw=="
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_payment_op_native(self, client):
|
2018-06-01 03:30:40 +00:00
|
|
|
"""Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
|
|
|
|
|
|
|
|
op = proto.StellarPaymentOp()
|
|
|
|
op.amount = 500111000
|
2018-08-13 16:21:24 +00:00
|
|
|
op.destination_account = (
|
|
|
|
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg=="
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_payment_op_native_explicit_asset(self, client):
|
2018-09-18 01:13:24 +00:00
|
|
|
"""Native payment of 50.0111 XLM to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
|
|
|
|
|
|
|
|
op = proto.StellarPaymentOp()
|
|
|
|
op.amount = 500111000
|
|
|
|
op.destination_account = (
|
|
|
|
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
)
|
2018-09-18 08:36:31 +00:00
|
|
|
op.asset = proto.StellarAssetType(0)
|
2018-09-18 01:13:24 +00:00
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
|
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-09-18 01:13:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"pDc6ghKCLNoYbt3h4eBw+533237m0BB0Jp/d/TxJCA83mF3o5Fr4l5vwAWBR62hdTWAP9MhVluY0cd5i54UwDg=="
|
|
|
|
)
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_payment_op_custom_asset1(self, client):
|
2018-06-01 03:30:40 +00:00
|
|
|
"""Custom asset payment (code length 1) of 50.0111 X to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
|
|
|
|
|
|
|
|
op = proto.StellarPaymentOp()
|
|
|
|
op.amount = 500111000
|
2018-08-13 16:21:24 +00:00
|
|
|
op.destination_account = (
|
|
|
|
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
op.asset = proto.StellarAssetType(
|
|
|
|
1, "X", "GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC"
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
tx = self._create_msg()
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"ArZydOtXU2whoRuSjJLFIWPSIsq3AbsncJZ+THF24CRSriVWw5Fy/dHrDlUOu4fzU28I6osDMeI39aWezg5tDw=="
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_payment_op_custom_asset12(self, client):
|
2018-06-01 03:30:40 +00:00
|
|
|
"""Custom asset payment (code length 12) of 50.0111 ABCDEFGHIJKL to GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"""
|
|
|
|
|
|
|
|
op = proto.StellarPaymentOp()
|
|
|
|
op.amount = 500111000
|
2018-08-13 16:21:24 +00:00
|
|
|
op.destination_account = (
|
|
|
|
"GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V"
|
|
|
|
)
|
|
|
|
|
|
|
|
op.asset = proto.StellarAssetType(
|
|
|
|
2,
|
|
|
|
"ABCDEFGHIJKL",
|
|
|
|
"GAUYJFQCYIHFQNS7CI6BFWD2DSSFKDIQZUQ3BLQODDKE4PSW7VVBKENC",
|
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
tx = self._create_msg()
|
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-06-01 03:30:40 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"QZIP4XKPfe4OpZtuJiyrMZBX9YBzvGpHGcngdgFfHn2kcdONreF384/pCF80xfEnGm8grKaoOnUEKxqcMKvxAA=="
|
|
|
|
)
|
2018-05-16 14:00:08 +00:00
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
@pytest.mark.setup_client(mnemonic=MNEMONIC12)
|
|
|
|
def test_sign_tx_set_options(self, client):
|
2018-06-24 03:11:48 +00:00
|
|
|
"""Set inflation destination"""
|
2018-06-24 02:55:26 +00:00
|
|
|
|
|
|
|
op = proto.StellarSetOptionsOp()
|
2018-08-13 16:21:24 +00:00
|
|
|
op.inflation_destination_account = (
|
|
|
|
"GAFXTC5OV5XQD66T7WGOB2HUVUC3ZVJDJMBDPTVQYV3G3K7TUHC6CLBR"
|
|
|
|
)
|
2018-06-24 02:55:26 +00:00
|
|
|
|
|
|
|
tx = self._create_msg()
|
2018-08-13 16:21:24 +00:00
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2018-06-24 02:55:26 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"dveWhKY8x7b0YqGHWH6Fo1SskxaHP11NXd2n6oHKGiv+T/LqB+CCzbmJA0tplZ+0HNPJbHD7L3Bsg/y462qLDA=="
|
|
|
|
)
|
2018-06-24 02:55:26 +00:00
|
|
|
|
2019-01-17 12:53:51 +00:00
|
|
|
op = proto.StellarSetOptionsOp()
|
|
|
|
op.signer_type = 0
|
2019-01-17 13:31:07 +00:00
|
|
|
op.signer_key = bytes.fromhex(
|
2019-01-17 13:26:12 +00:00
|
|
|
"72187adb879c414346d77c71af8cce7b6eaa57b528e999fd91feae6b6418628e"
|
|
|
|
)
|
2019-01-17 12:53:51 +00:00
|
|
|
op.signer_weight = 2
|
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2019-01-17 12:53:51 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"EAeihuFBhUnjH6Sgd/+uAHlvajfv944VEpNSCLsOULNxYWdo/S0lJdUZw/2kN6I+ztKL7ZPQ5gYPJRNUePTOCg=="
|
|
|
|
)
|
|
|
|
|
|
|
|
op = proto.StellarSetOptionsOp()
|
|
|
|
op.medium_threshold = 0
|
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2019-01-17 12:53:51 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"E2pz06PFB5CvIT3peUcY0wxo7u9da2h6/+/qim1eRWLHC73ZtFqDtLMBaKnr63ZfjB/kDzZmCzHxiv5m+m6+AQ=="
|
|
|
|
)
|
|
|
|
|
|
|
|
op = proto.StellarSetOptionsOp()
|
|
|
|
op.low_threshold = 0
|
|
|
|
op.high_threshold = 3
|
|
|
|
op.clear_flags = 0
|
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2019-01-17 12:53:51 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"ySQE4aS0TI+N1xjSwi/pABHpC+A6RrNPWDOuFYGJFQ5B4vIU2S+ql2gCGLE7bQiYZ5dK9021f+a30mZoYeFLDw=="
|
|
|
|
)
|
|
|
|
|
|
|
|
op = proto.StellarSetOptionsOp()
|
|
|
|
op.set_flags = 3
|
|
|
|
op.master_weight = 4
|
|
|
|
op.home_domain = "hello"
|
|
|
|
|
|
|
|
tx = self._create_msg()
|
|
|
|
response = stellar.sign_tx(
|
2019-08-27 14:58:59 +00:00
|
|
|
client, tx, [op], self.ADDRESS_N, self.NETWORK_PASSPHRASE
|
2019-01-17 12:53:51 +00:00
|
|
|
)
|
|
|
|
assert (
|
|
|
|
b64encode(response.signature)
|
|
|
|
== b"22rfcOrxBiE5akpNsnWX8yPgAOpclbajVqXUaXMNeL000p1OhFhi050t1+GNRpoSNyfVsJGNvtlICGpH4ksDAQ=="
|
|
|
|
)
|
|
|
|
|
2018-05-16 14:00:08 +00:00
|
|
|
def _create_msg(self) -> proto.StellarSignTx:
|
|
|
|
tx = proto.StellarSignTx()
|
2018-08-13 16:21:24 +00:00
|
|
|
tx.source_account = "GAK5MSF74TJW6GLM7NLTL76YZJKM2S4CGP3UH4REJHPHZ4YBZW2GSBPW"
|
2018-05-16 14:00:08 +00:00
|
|
|
tx.fee = 100
|
|
|
|
tx.sequence_number = 0x100000000
|
|
|
|
tx.memo_type = 0
|
|
|
|
return tx
|