async 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=test_data.horizon, network_name=setup.network, fee=100) \ .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_change_trust_op('BEER', test_data.cold_account, '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 await cold.update_sequence() 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 = await cold.submit() assert response.get('hash') == cold.hash_hex()
async def test_builder_xdr(setup, helpers, test_data, aio_session): hot = Keypair.random() hot_account = hot.address().decode() hot_secret = hot.seed() await helpers.fund_account(setup, hot_account, aio_session) cold = Builder(secret=test_data.cold_secret, horizon=test_data.horizon, network_name=setup.network, fee=100) \ .append_change_trust_op('BEER', test_data.cold_account, '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) await cold.update_sequence() cold.sign() xdr = cold.gen_xdr() hot = Builder( secret=hot_secret, horizon=test_data.horizon, network_name=setup.network, fee=100) hot.import_from_xdr(xdr) hot.sign() assert len(hot.te.signatures) == 2 assert len(hot.ops) == 4 response = await hot.submit() assert response.get('hash') == hot.hash_hex()
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_uri=setup.horizon_endpoint_uri, network=setup.network) \ .append_change_trust_op('BEER', test_data.cold_account, '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_uri=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()
def test_data(setup, helpers): class Struct: def __init__(self, **entries): self.__dict__.update(entries) cold = Keypair.random() cold_secret = cold.seed() cold_account = cold.address().decode() helpers.fund_account(setup, cold.address().decode()) return Struct(cold_secret=cold_secret, cold_account=cold_account)
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()
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
async def test_sse(setup, helpers, aio_session): kp = Keypair.random() address = kp.address().decode() events = [] 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): events.append(event) break handler = asyncio.ensure_future(sse_handler(events)) await helpers.fund_account(setup, address, aio_session) await asyncio.sleep(5) assert len(events) == 1
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
def setup(): class Struct: """Handy variable holder""" def __init__(self, **entries): self.__dict__.update(entries) issuer_keypair = Keypair.random() test_asset = Asset('TEST', issuer_keypair.address().decode()) # local testnet (kinecosystem docker) from kin_base.network import NETWORKS # we will leave this passphrase instead of changing every envelop in the test suite NETWORKS['CUSTOM'] = 'Integration Test Network ; zulucrypto' return Struct(type='local', network='CUSTOM', issuer_keypair=issuer_keypair, test_asset=test_asset, horizon_endpoint_uri='http://localhost:8008', friendbot_url='http://localhost:8001')
async def test_sse_event_timeout(setup, helpers, aio_session): kp = Keypair.random() address = kp.address().decode() events = [] 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) handler = asyncio.ensure_future(sse_handler(events)) await helpers.fund_account(setup, address, aio_session) await asyncio.sleep(5) assert len(events) == 1 await asyncio.sleep(20) # Make sure that the sse generator raised timeout error with pytest.raises(asyncio.TimeoutError): raise handler.exception()
def generate_random_keypair(): print("Generate random keypair") keypair = Keypair.random() print("Public key / Account address:\n", keypair.address().decode()) print("Seed / Your secret to keep it on local:\n", keypair.seed().decode())