Example #1
0
def test_builder_xdr(setup, helpers, test_data):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    helpers.fund_account(setup, hot_account)

    cold = Builder(secret=test_data.cold_secret, horizon=setup.horizon_endpoint_uri, network=setup.network) \
        .append_trust_op(test_data.cold_account, 'BEER', '1000', hot_account) \
        .append_allow_trust_op(hot_account, 'BEER', True, test_data.cold_account) \
        .append_payment_op(hot_account, '100', 'BEER', test_data.cold_account, test_data.cold_account) \
        .append_payment_op(test_data.cold_account, '2.222', 'BEER', test_data.cold_account, hot_account)
    cold.sign()

    xdr = cold.gen_xdr()

    hot = Builder(secret=hot_secret,
                  horizon=setup.horizon_endpoint_uri,
                  network=setup.network)
    hot.import_from_xdr(xdr)
    hot.sign()

    assert len(hot.te.signatures) == 2
    assert len(hot.ops) == 4

    response = hot.submit()
    assert response.get('hash') == hot.hash_hex()
Example #2
0
def test_builder(setup, test_data):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    cold = Builder(secret=test_data.cold_secret, horizon=setup.horizon_endpoint_uri, network=setup.network) \
        .append_create_account_op(hot_account, '200') \
        .append_set_options_op(inflation_dest=test_data.cold_account, set_flags=1,
                               home_domain='256kw.com', master_weight=10,
                               low_threshold=5, ) \
        .append_trust_op(test_data.cold_account, 'BEER', '1000', hot_account) \
        .append_allow_trust_op(hot_account, 'BEER', True)
    # append twice for test
    cold.append_payment_op(hot_account, '50.123', 'BEER', test_data.cold_account) \
        .append_payment_op(hot_account, '50.123', 'BEER', test_data.cold_account)
    # TODO: append_bump_sequence_op test
    cold.sign()
    cold.sign(hot_secret)
    # try to sign twice
    with pytest.raises(SignatureExistError):
        cold.sign(hot_secret)

    assert len(cold.te.signatures) == 2
    assert len(cold.ops) == 5

    response = cold.submit()
    assert response.get('hash') == cold.hash_hex()
Example #3
0
    def test_builder_append_ops(self):
        alice_secret = 'SDIMY25XL2TDSUZNM42Y2WLA2E2R52EV3GR6MXCPVTBSWJLN6MLX6JZV'
        bob_account = 'GBZ5VJD6VMQMRDSMCCZAF23K5VIGBHXJQQYLLYQOEIZB4AUJNMFN5R3U'

        builder = Builder(secret=alice_secret,
                          sequence=938635037769728,
                          fee=100)
        builder. \
            append_create_account_op(destination=bob_account, starting_balance='10'). \
            append_change_trust_op(asset_code='BEER', asset_issuer=bob_account, limit='1000'). \
            append_payment_op(destination=bob_account, asset_code='XLM', amount='100'). \
            append_path_payment_op(destination=bob_account, send_code='BEER',
                                   send_issuer=bob_account,
                                   send_max='100', dest_code='XLM', dest_issuer=None, dest_amount='100',
                                   path=[('HELLO', bob_account)]). \
            append_allow_trust_op(trustor=bob_account, asset_code='MOE', authorize=True). \
            append_set_options_op(set_flags=7, home_domain='stellar.org'). \
            append_hashx_signer(
            hashx=b"\xe7\xd40j:>pH\xa0\x11\x90(q\x88\xa0IV\xf6\xa9\xc90\x15H&\xeb\xcd\x03\t\x93\x1f'8",
            signer_weight=1). \
            append_pre_auth_tx_signer(
            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",
            signer_weight=1). \
            append_manage_sell_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
                                   buying_issuer=bob_account, amount='1', price='10', offer_id=0). \
            append_manage_buy_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
                                        buying_issuer=bob_account, amount='1', price='10', offer_id=0). \
            append_create_passive_sell_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
                                           buying_issuer=bob_account, amount='1', price={'n': 10, 'd': 1}). \
            append_account_merge_op(destination=bob_account). \
            append_inflation_op(). \
            append_manage_data_op(data_name='hello', data_value='world'). \
            append_bump_sequence_op(bump_to=938635037769749). \
            add_text_memo("hello, stellar"). \
            add_time_bounds({'minTime': 1534392138, 'maxTime': 1534392238})
        assert builder.hash_hex(
        ) == 'f646a891ed9ecde6f98bf7fb1afcb52acbc73aabd08f9390c61fdfc8f426815f'
        builder.sign()
        assert builder.gen_xdr().decode(
        ) == 'AAAAAP4sA2cn9oggk4cfzPLqZVfpSEhmindW2FQofl5b0SjDAAAF3AADVa8AAAABAAAAAQAAAABbdPdKAAAAAFt0964AAAABAAAADmhlbGxvLCBzdGVsbGFyAAAAAAAPAAAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAABfXhAAAAAAAAAAAGAAAAAUJFRVIAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAACVAvkAAAAAAAAAAABAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAAAAAAIAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAA7msoAAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAQAAAAJIRUxMTwAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAAAABwAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAFNT0UAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAABAAAABwAAAAAAAAAAAAAAAAAAAAAAAAABAAAAC3N0ZWxsYXIub3JnAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAALn1DBqOj5wSKARkChxiKBJVvapyTAVSCbrzQMJkx8nOAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAGV5buVFdmfgp35k8MnjuvxCmoh2qSh5PI8NmNHfReX/gAAAAEAAAAAAAAAAwAAAAAAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAAAmJaAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAMAAAAAAAAAAFCRUVSAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAACYloAAAAAKAAAAAQAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAUJFRVIAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAJiWgAAAAAoAAAABAAAAAAAAAAgAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAAAACQAAAAAAAAAKAAAABWhlbGxvAAAAAAAAAQAAAAV3b3JsZAAAAAAAAAAAAAALAANVrwAAABUAAAAAAAAAAVvRKMMAAABAM1rhFzh2mbT283+lJsqeckCxnO9vC0m8ADTbyUbFXNJNAfSpI23W/kS69wgeq8qp/1knDpkn72b6e6Eac9coCw=='
Example #4
0
    def test_builder_append_ops(self):
        alice_secret = 'SDIMY25XL2TDSUZNM42Y2WLA2E2R52EV3GR6MXCPVTBSWJLN6MLX6JZV'
        bob_account = 'GBZ5VJD6VMQMRDSMCCZAF23K5VIGBHXJQQYLLYQOEIZB4AUJNMFN5R3U'

        builder = Builder(secret=alice_secret,
                          sequence=938635037769728,
                          fee=100)
        builder. \
            append_create_account_op(destination=bob_account, starting_balance='10'). \
            append_change_trust_op(asset_code='BEER', asset_issuer=bob_account, limit='1000'). \
            append_payment_op(destination=bob_account, asset_code='XLM', amount='100'). \
            append_path_payment_op(destination=bob_account, send_code='BEER',
                                   send_issuer=bob_account,
                                   send_max='100', dest_code='XLM', dest_issuer=None, dest_amount='100',
                                   path=[('HELLO', bob_account)]). \
            append_allow_trust_op(trustor=bob_account, asset_code='MOE', authorize=True). \
            append_set_options_op(set_flags=7, home_domain='stellar.org'). \
            append_hashx_signer(
            hashx=b"\xe7\xd40j:>pH\xa0\x11\x90(q\x88\xa0IV\xf6\xa9\xc90\x15H&\xeb\xcd\x03\t\x93\x1f'8",
            signer_weight=1). \
            append_pre_auth_tx_signer(
            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",
            signer_weight=1). \
            append_manage_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
                                   buying_issuer=bob_account, amount='1', price='10', offer_id=0). \
            append_create_passive_offer_op(selling_code='XLM', selling_issuer=None, buying_code='BEER',
                                           buying_issuer=bob_account, amount='1', price={'n': 10, 'd': 1}). \
            append_account_merge_op(destination=bob_account). \
            append_inflation_op(). \
            append_manage_data_op(data_name='hello', data_value='world'). \
            append_bump_sequence_op(bump_to=938635037769749). \
            add_text_memo("hello, stellar"). \
            add_time_bounds({'minTime': 1534392138, 'maxTime': 1534392238})
        assert builder.hash_hex(
        ) == '82910e59edebeeafc86294372572812a251066ad1f0784e1e38ca63d3b6bdf24'
        builder.sign()
        assert builder.gen_xdr().decode(
        ) == 'AAAAAP4sA2cn9oggk4cfzPLqZVfpSEhmindW2FQofl5b0SjDAAAFeAADVa8AAAABAAAAAQAAAABbdPdKAAAAAFt0964AAAABAAAADmhlbGxvLCBzdGVsbGFyAAAAAAAOAAAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAABfXhAAAAAAAAAAAGAAAAAUJFRVIAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAACVAvkAAAAAAAAAAABAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAAAAAAIAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAA7msoAAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAA7msoAAAAAAQAAAAJIRUxMTwAAAAAAAAAAAAAAc9qkfqsgyI5MELIC62rtUGCe6YQwteIOIjIeAolrCt4AAAAAAAAABwAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAFNT0UAAAAAAQAAAAAAAAAFAAAAAAAAAAAAAAABAAAABwAAAAAAAAAAAAAAAAAAAAAAAAABAAAAC3N0ZWxsYXIub3JnAAAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAALn1DBqOj5wSKARkChxiKBJVvapyTAVSCbrzQMJkx8nOAAAAAEAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAGV5buVFdmfgp35k8MnjuvxCmoh2qSh5PI8NmNHfReX/gAAAAEAAAAAAAAAAwAAAAAAAAABQkVFUgAAAABz2qR+qyDIjkwQsgLrau1QYJ7phDC14g4iMh4CiWsK3gAAAAAAmJaAAAAACgAAAAEAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAFCRUVSAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAACYloAAAAAKAAAAAQAAAAAAAAAIAAAAAHPapH6rIMiOTBCyAutq7VBgnumEMLXiDiIyHgKJawreAAAAAAAAAAkAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAFd29ybGQAAAAAAAAAAAAACwADVa8AAAAVAAAAAAAAAAFb0SjDAAAAQOeOIQNAwscAcVIdCHVou6xILLKBJTqxqmXiOxxtD4pYVsl0G2tLoDrMfcoWkSb7eyj3c68SIWNZRZEvWyusNwM='
Example #5
0
 def test_builder_xdr(self, setup, test_data):
     builder = Builder(secret=test_data.cold_secret, horizon_uri=setup.horizon_endpoint_uri, network=setup.network) \
         .append_manage_data_op("hello", "world")
     builder.sign()
     response = builder.submit()
     assert response.get('hash') == builder.hash_hex()