|
1 | 1 | # encoding: utf-8
|
| 2 | +import time |
2 | 3 |
|
3 |
| -import pytest |
4 | 4 | import mock
|
| 5 | +import pytest |
5 | 6 |
|
6 | 7 | from stellar_base import memo
|
7 | 8 | from stellar_base.builder import Builder
|
| 9 | +from stellar_base.exceptions import NoStellarSecretOrAddressError, FederationError |
8 | 10 | from stellar_base.horizon import horizon_testnet, horizon_livenet, Horizon
|
9 | 11 | from stellar_base.keypair import Keypair
|
10 |
| -from stellar_base.exceptions import NoStellarSecretOrAddressError, FederationError |
| 12 | +from stellar_base.operation import ManageData |
11 | 13 |
|
12 | 14 |
|
13 | 15 | @pytest.fixture(scope='module')
|
@@ -71,11 +73,11 @@ def test_builder_append_ops(self):
|
71 | 73 | pre_auth_tx=b"\x95\xe5\xbb\x95\x15\xd9\x9f\x82\x9d\xf9\x93\xc3'\x8e\xeb\xf1\nj!\xda\xa4\xa1\xe4\xf2<6cG}\x17\x97\xfe",
|
72 | 74 | signer_weight=1). \
|
73 | 75 | append_manage_sell_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
|
74 |
| - buying_issuer=bob_account, amount='1', price='10', offer_id=0). \ |
75 |
| - append_manage_buy_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', |
76 | 76 | buying_issuer=bob_account, amount='1', price='10', offer_id=0). \
|
| 77 | + append_manage_buy_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER', |
| 78 | + buying_issuer=bob_account, amount='1', price='10', offer_id=0). \ |
77 | 79 | append_create_passive_sell_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
|
78 |
| - buying_issuer=bob_account, amount='1', price={'n': 10, 'd': 1}). \ |
| 80 | + buying_issuer=bob_account, amount='1', price={'n': 10, 'd': 1}). \ |
79 | 81 | append_account_merge_op(destination=bob_account). \
|
80 | 82 | append_inflation_op(). \
|
81 | 83 | append_manage_data_op(data_name='hello', data_value='world'). \
|
@@ -199,3 +201,28 @@ def test_network_and_horizon(self, setup, test_data):
|
199 | 201 | horizon_uri=setup.horizon_endpoint_uri)
|
200 | 202 | assert builder.network == 'PUBLIC'
|
201 | 203 | assert builder.horizon.horizon_uri == Horizon(horizon_uri=setup.horizon_endpoint_uri).horizon_uri
|
| 204 | + |
| 205 | + def test_challenge_tx(self): |
| 206 | + server_kp = Keypair.random() |
| 207 | + client_account_id = "GBDIT5GUJ7R5BXO3GJHFXJ6AZ5UQK6MNOIDMPQUSMXLIHTUNR2Q5CFNF" |
| 208 | + timeout = 600 |
| 209 | + network = 'TESTNET' |
| 210 | + archor_name = "SDF" |
| 211 | + |
| 212 | + tx = Builder.challenge_tx(server_secret=server_kp.seed().decode(), |
| 213 | + client_account_id=client_account_id, |
| 214 | + archor_name=archor_name, |
| 215 | + network=network, |
| 216 | + timeout=timeout) |
| 217 | + assert len(tx.ops) == 1 |
| 218 | + op = tx.ops[0] |
| 219 | + assert isinstance(op, ManageData) |
| 220 | + assert op.data_name == "SDF auth" |
| 221 | + assert len(op.data_value) == 64 |
| 222 | + assert op.source == client_account_id |
| 223 | + |
| 224 | + now = int(time.time()) |
| 225 | + assert now - 3 < tx.time_bounds['minTime'] < now + 3 |
| 226 | + assert tx.time_bounds['maxTime'] - tx.time_bounds['minTime'] == timeout |
| 227 | + assert tx.keypair == server_kp |
| 228 | + assert tx.sequence == -1 |
0 commit comments