Esempio n. 1
0
def test_submit(setup, helpers):
    kp = Keypair.random()
    address = kp.address().decode()
    seed = kp.seed()

    helpers.fund_account(setup, address)

    horizon = Horizon(setup.horizon_endpoint_uri)

    envelope_xdr = make_envelope(
        setup.network, horizon, address, seed,
        Payment(destination=address, asset=Asset.native(), amount="0.0001618"))
    response = horizon.submit(envelope_xdr)
    assert 'hash' in response
Esempio n. 2
0
async def test_horizon_retry(setup):

    async with Horizon(setup.horizon_endpoint_uri) as horizon:
        horizon._session.get = MagicMock(side_effect=ClientConnectionError)
        horizon.num_retries = 3
        expected_time = 1.5  # 0 + 0.5 + 1
        start = time.time()
        with pytest.raises(HorizonRequestError):
            await horizon.account('GA3FLH3EVYHZUHTPQZU63JPX7ECJQL2XZFCMALPCLFYMSYC4JKVLAJWM')

        elapsed = time.time() - start
        assert horizon._session.get.call_count == horizon.num_retries
        assert elapsed >= expected_time
Esempio n. 3
0
async def test_data(setup, helpers, aio_session):
    class Struct:
        def __init__(self, **entries):
            self.__dict__.update(entries)

    cold = Keypair.random()
    cold_secret = cold.seed()
    cold_account = cold.address().decode()
    horizon = Horizon(setup.horizon_endpoint_uri)

    await helpers.fund_account(setup, cold.address().decode(), aio_session)

    yield Struct(cold_secret=cold_secret, cold_account=cold_account, horizon=horizon)
    await horizon.close()
Esempio n. 4
0
 async def trust_asset(setup, secret_key, memo_text=None):
     """A helper to establish a trustline"""
     async with Horizon(setup.horizon_endpoint_uri) as horizon:
         builder = Builder(secret=secret_key,
                           horizon=horizon,
                           network_name=setup.network,
                           fee=100)
         builder.append_trust_op(setup.test_asset.issuer,
                                 setup.test_asset.code)
         if memo_text:
             builder.add_text_memo(memo_text[:28])  # max memo length is 28
         builder.sign()
         reply = await builder.submit()
     return reply.get('hash')
Esempio n. 5
0
async def test_submit(setup, helpers, aio_session):
    kp = Keypair.random()
    address = kp.address().decode()
    seed = kp.seed()

    await helpers.fund_account(setup, address, aio_session)

    async with Horizon(setup.horizon_endpoint_uri) as horizon:
        envelope_xdr = await make_envelope(setup.network, horizon, address, seed,
                                     Payment(
                                         destination=address,
                                         asset=Asset.native(),
                                         amount="0.1618"))
        response = await horizon.submit(envelope_xdr.decode())
        assert 'hash' in response
Esempio n. 6
0
 async def send_asset(cls,
                      setup,
                      secret_key,
                      address,
                      amount,
                      memo_text=None):
     """A helper to send asset"""
     async with Horizon(setup.horizon_endpoint_uri) as horizon:
         builder = Builder(secret=secret_key,
                           horizon=horizon,
                           network_name=setup.network,
                           fee=100)
         builder.append_payment_op(address, amount, setup.test_asset.code,
                                   setup.test_asset.issuer)
         if memo_text:
             builder.add_text_memo(memo_text[:28])  # max memo length is 28
         builder.sign()
         reply = await builder.submit()
     return reply.get('hash')
Esempio n. 7
0
async def test_horizon_retry_successes(setup):

    class MockedGet:
        def __init__(self, return_value):
            self.return_value = return_value

        async def __aenter__(self):
            return self.return_value

        async def __aexit__(self, exc_type, exc_val, exc_tb):
            pass

    async with Horizon(setup.horizon_endpoint_uri) as horizon:
        real_resp = await horizon._session.get(setup.horizon_endpoint_uri + "/accounts/GA3FLH3EVYHZUHTPQZU63JPX7ECJQL2XZFCMALPCLFYMSYC4JKVLAJWM")
        horizon._session.get = MagicMock(side_effect=[ClientConnectionError, MockedGet(real_resp)])
        horizon.num_retries = 3
        res = await horizon.account('GA3FLH3EVYHZUHTPQZU63JPX7ECJQL2XZFCMALPCLFYMSYC4JKVLAJWM')

        assert horizon._session.get.call_count == 2
        assert res
        async def create_payout_xdr(payout_info, start_date, end_date, src_wallet, write_directory, digital_service_id_kin_2, kin_2_amount, sequence_increment = 0):
                operations = []
                for ix, row in payout_info.iterrows():
                        if row['digital_service_id'] == digital_service_id_kin_2:
                                amt = str(round(row['total_payout'], 2) - kin_2_amount)
                        else:
                                amt = str(round(row['total_payout'], 2))
                        payment_op = Payment(
                            destination=row['wallet'],
                            amount=amt,
                            asset=Asset.native()
                        )
                        operations.append(payment_op)

                async with Horizon(horizon_uri='https://horizon.kinfederation.com') as horizon:
                        total_fee = len(payout_info.index) * 100
                        network_id = "PUBLIC"
                        account_result = await horizon.account(src_wallet)

                sequence = int(account_result['sequence']) + 1

                tx = Transaction(
                        source = src_wallet,
                        sequence = int(sequence) + sequence_increment,
                        time_bounds = {'minTime': 0, 'maxTime': 0},
                        fee = total_fee,
                        operations = operations,
                        memo = None
                )

                envelope = Te(tx=tx, network_id="PUBLIC")
                xdr = envelope.xdr() 
                f = open(write_directory + "/xdr" + str(sequence_increment) + ".xdr", "w")
                f.write(xdr.decode("utf-8"))
                f.close()
                print(xdr.decode("utf-8"))
Esempio n. 9
0
 async def sse_handler(events):
     async with Horizon(setup.horizon_endpoint_uri) as horizon:
         async for event in await horizon.account_transactions(
                 'GA3FLH3EVYHZUHTPQZU63JPX7ECJQL2XZFCMALPCLFYMSYC4JKVLAJWM',
                 sse=True, sse_timeout=15):
             events.append(event)