def setup(testnet): class Struct: """Handy variable holder""" def __init__(self, **entries): self.__dict__.update(entries) sdk_keypair = Keypair.random() issuer_keypair = Keypair.random() test_asset = Asset('KIN', issuer_keypair.address().decode()) # global testnet if testnet: from stellar_base.horizon import HORIZON_TEST return Struct(type='testnet', network='TESTNET', sdk_keypair=sdk_keypair, issuer_keypair=issuer_keypair, test_asset=test_asset, horizon_endpoint_uri=HORIZON_TEST) # local testnet (zulucrypto docker) # https://github.com/zulucrypto/docker-stellar-integration-test-network from stellar_base.network import NETWORKS NETWORKS['CUSTOM'] = 'Integration Test Network ; zulucrypto' return Struct(type='local', network='CUSTOM', sdk_keypair=sdk_keypair, issuer_keypair=issuer_keypair, test_asset=test_asset, horizon_endpoint_uri='http://localhost:8000')
def test_sdk_create_fail(setup, helpers, test_sdk): with pytest.raises(ValueError, match='invalid secret key: bad'): kin.SDK(secret_key='bad', horizon_endpoint_uri=setup.horizon_endpoint_uri, network=setup.network, kin_asset=setup.test_asset) keypair = Keypair.random() secret_key = keypair.seed() address = keypair.address().decode() with pytest.raises(ValueError, match='invalid channel key: bad'): kin.SDK(secret_key=secret_key, channel_secret_keys=['bad'], horizon_endpoint_uri=setup.horizon_endpoint_uri, network=setup.network, kin_asset=setup.test_asset) # wallet account does not exist with pytest.raises(kin.AccountNotFoundError): kin.SDK(secret_key=secret_key, horizon_endpoint_uri=setup.horizon_endpoint_uri, network=setup.network, kin_asset=setup.test_asset) helpers.fund_account(setup, address) # wallet account exists but not yet activated with pytest.raises(kin.AccountNotActivatedError): kin.SDK(secret_key=secret_key, horizon_endpoint_uri=setup.horizon_endpoint_uri, network=setup.network, kin_asset=setup.test_asset) helpers.trust_asset(setup, secret_key) channel_keypair = Keypair.random() channel_secret_key = channel_keypair.seed() # channel account does not exist with pytest.raises(kin.AccountNotFoundError): kin.SDK(secret_key=secret_key, channel_secret_keys=[channel_secret_key], horizon_endpoint_uri=setup.horizon_endpoint_uri, network=setup.network, kin_asset=setup.test_asset) # bad Horizon endpoint with pytest.raises(kin.NetworkError): kin.SDK(secret_key=secret_key, horizon_endpoint_uri='bad', network=setup.network, kin_asset=setup.test_asset) # no Horizon on endpoint with pytest.raises(kin.NetworkError): kin.SDK(secret_key=secret_key, horizon_endpoint_uri='http://localhost:666', network=setup.network, kin_asset=setup.test_asset)
def test_verify_challenge_tx_source_is_different_to_server_account_id( self): server_kp = Keypair.random() client_kp = Keypair.random() network = 'TESTNET' challenge = Builder(server_kp.seed().decode(), network=network, sequence=-1, fee=100) challenge.sign() challenge_tx_server_signed = challenge.gen_xdr() transaction = Builder(client_kp.seed().decode(), network='TESTNET', sequence=0, fee=100) transaction.import_from_xdr(challenge_tx_server_signed) transaction.sign() challenge_tx = transaction.gen_xdr() with pytest.raises( InvalidSep10ChallengeError, match= "Transaction source account is not equal to server's account." ): Builder.verify_challenge_tx(challenge_tx, Keypair.random().address().decode(), 'TESTNET')
def test_verify_challenge_tx(self): server_kp = Keypair.random() client_kp = Keypair.random() timeout = 600 network = 'Public Global Stellar Network ; September 2015' archor_name = "SDF" challenge = Builder.challenge_tx( server_secret=server_kp.seed().decode(), client_account_id=client_kp.address().decode(), archor_name=archor_name, network=network, timeout=timeout) challenge.sign() challenge_tx_server_signed = challenge.gen_xdr() transaction = Builder( client_kp.seed().decode(), network='Public Global Stellar Network ; September 2015', sequence=0, fee=100) transaction.import_from_xdr(challenge_tx_server_signed) transaction.sign() challenge_tx = transaction.gen_xdr() Builder.verify_challenge_tx( challenge_tx, server_kp.address().decode(), 'Public Global Stellar Network ; September 2015')
def test_verify_challenge_tx_contains_infinite_timebounds(self): server_kp = Keypair.random() client_kp = Keypair.random() timeout = 600 network = 'TESTNET' archor_name = 'sdf' challenge = Builder(server_kp.seed().decode(), network=network, sequence=-1, fee=100) now = int(time.time()) challenge.add_time_bounds({'minTime': now, 'maxTime': 0}) nonce = os.urandom(64) challenge.append_manage_data_op( data_name='{} auth'.format(archor_name), data_value=nonce, source=client_kp.address().decode()) challenge.sign() challenge_tx_server_signed = challenge.gen_xdr() transaction = Builder(client_kp.seed().decode(), network='TESTNET', sequence=0, fee=100) transaction.import_from_xdr(challenge_tx_server_signed) transaction.sign() challenge_tx = transaction.gen_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction requires non-infinite timebounds."): Builder.verify_challenge_tx(challenge_tx, server_kp.address().decode(), 'TESTNET')
def test_verify_challenge_tx_donot_contain_managedata_operation(self): server_kp = Keypair.random() client_kp = Keypair.random() timeout = 600 network = 'TESTNET' challenge = Builder(server_kp.seed().decode(), network=network, sequence=-1, fee=100) now = int(time.time()) challenge.add_time_bounds({'minTime': now, 'maxTime': now + timeout}) challenge.append_bump_sequence_op(12, source=client_kp.address().decode()) challenge.sign() challenge_tx_server_signed = challenge.gen_xdr() transaction = Builder(client_kp.seed().decode(), network='TESTNET', sequence=0, fee=100) transaction.import_from_xdr(challenge_tx_server_signed) transaction.sign() challenge_tx = transaction.gen_xdr() with pytest.raises(InvalidSep10ChallengeError, match="Operation type should be ManageData."): Builder.verify_challenge_tx(challenge_tx, server_kp.address().decode(), 'TESTNET')
def test_set_account_signers(self): pool_kp = Keypair.random() signer1 = Keypair.random() signer2 = Keypair.random() # fixture for getting the account responses.add(responses.GET, 'https://horizon-testnet.stellar.org/accounts/%s' % (pool_kp.address().decode()), body=json.dumps({'sequence': '1234'}), content_type='application/json') # fixture for creating a transaction responses.add(responses.POST, 'https://horizon-testnet.stellar.org/transactions/', body=json.dumps({ '_links': { 'transaction': { 'href': 'http://transaction-url/' } } }), content_type='application/json') signers_file = self.mock_signers_file([ signer1, signer2, ]) signers = get_signers(signers_file.name) self.assertTrue( set_account_signers(horizon_testnet(), pool_kp, signers, SIGNING_THRESHOLD))
def test_create_pool_account(self): account_kp = Keypair.random() pool_kp = Keypair.random() # fixture for getting the account responses.add(responses.GET, 'https://horizon-testnet.stellar.org/accounts/%s' % (account_kp.address().decode()), body=json.dumps({'sequence': '1234'}), content_type='application/json') # fixture for creating a transaction responses.add(responses.POST, 'https://horizon-testnet.stellar.org/transactions/', body=json.dumps({ '_links': { 'transaction': { 'href': 'http://transaction-url/' } } }), content_type='application/json') self.assertTrue( create_pool_account(horizon_testnet(), 'TESTNET', account_kp.seed(), pool_kp))
def test_monitor_accounts_kin_payments_multiple(setup, test_sdk, helpers): keypair1 = Keypair.random() address1 = keypair1.address().decode() keypair2 = Keypair.random() address2 = keypair2.address().decode() assert test_sdk.create_account(address1, starting_balance=100) assert test_sdk.create_account(address2, starting_balance=100) assert helpers.trust_asset(setup, keypair1.seed()) assert helpers.trust_asset(setup, keypair2.seed()) ev1 = threading.Event() ev2 = threading.Event() tx_datas1 = [] tx_datas2 = [] def account_tx_callback(addr, tx_data): assert addr == address1 or addr == address2 op_data = tx_data.operations[0] if op_data.to_address == address1: tx_datas1.append(tx_data) ev1.set() elif op_data.to_address == address2: tx_datas2.append(tx_data) ev2.set() # start monitoring sleep(1) test_sdk.monitor_accounts_kin_payments([address1, address2], account_tx_callback) # send payments tx_hash12 = test_sdk.send_kin(address1, 10) assert tx_hash12 tx_hash22 = test_sdk.send_kin(address2, 10) assert tx_hash22 # wait until callback gets them all assert ev1.wait(3) assert ev2.wait(3) # check collected operations assert tx_datas1[0].hash == tx_hash12 op_data = tx_datas1[0].operations[0] assert op_data.type == 'payment' assert op_data.asset_code == setup.test_asset.code assert op_data.asset_issuer == setup.test_asset.issuer assert op_data.from_address == test_sdk.get_address() assert op_data.to_address == address1 assert op_data.amount == Decimal('10') assert tx_datas2[0].hash == tx_hash22 op_data = tx_datas2[0].operations[0] assert op_data.type == 'payment' assert op_data.asset_code == setup.test_asset.code assert op_data.asset_issuer == setup.test_asset.issuer assert op_data.from_address == test_sdk.get_address() assert op_data.to_address == address2 assert op_data.amount == Decimal('10')
def test_channels(setup): # prepare channel accounts channel_keypairs = [ Keypair.random(), Keypair.random(), Keypair.random(), Keypair.random() ] channel_seeds = [ channel_keypair.seed() for channel_keypair in channel_keypairs ] channel_addresses = [ channel_keypair.address().decode() for channel_keypair in channel_keypairs ] for channel_address in channel_addresses: fund(setup, channel_address) # init sdk with these channels sdk = kin.SDK(base_seed=setup.sdk_keypair.seed(), horizon_endpoint_uri=setup.horizon_endpoint_uri, network=setup.network, channel_seeds=channel_seeds) assert sdk assert sdk.channel_manager assert sdk.channel_manager.channel_builders.qsize() == len( channel_keypairs) def channel_worker(): # create an account using a channel address = Keypair.random().address().decode() tx_hash = sdk.create_account(address, starting_balance=100) assert tx_hash sleep(1) tx_data = sdk.get_transaction_data(tx_hash) assert tx_data # transaction envelope source is some channel account assert tx_data.source_account in channel_addresses # operation source is the base account assert tx_data.operations[0].source_account == sdk.get_address() # now issue parallel transactions threads = [] for channel_keypair in channel_keypairs: t = threading.Thread(target=channel_worker) threads.append(t) for t in threads: t.start() # wait for all to finish for t in threads: t.join()
def generate_pool_keypair(desired_tail=None): kp = None if desired_tail: logger.debug("Looking for address ending in '%s'..." % (desired_tail,)) while True: kp = Keypair.random() if kp.address().decode()[-len(desired_tail):] == desired_tail: break else: kp = Keypair.random() return kp
def generate_pool_keypair(): kp = None if len(sys.argv) > 1: desired_tail = sys.argv[1] print("Looking for address ending in '" + desired_tail + "'...") while True: kp = Keypair.random() if kp.address().decode()[-len(desired_tail):] == desired_tail: break else: kp = Keypair.random() return kp
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()
def create_vault_wallet(user, username, currency): if currency not in ('xmr','eth','xlm'): access = globals()['create_'+currency+'_connection']() addr = access.getnewaddress(username) elif currency == 'xmr': paymentid = (binascii.b2a_hex(os.urandom(8))).decode() moneropaymentid = MoneroPaymentid.objects.create( user=user, paymentid=paymentid) param = { "payment_id": paymentid } addr = create_xmr_connection("make_integrated_address", param)[ "result"]['integrated_address'] elif currency == 'xlm': kp = Keypair.random() addr = kp.address().decode() requests.get('https://friendbot.stellar.org/?addr=' + addr) vault, created = VaultWallet.objects.get_or_create( user=user, username=username, name=currency) vault.addresses.add(WalletAddress.objects.create(address=addr)) vault.private = kp.seed().decode() vault.save() return addr wallet, created = VaultWallet.objects.get_or_create( user=user, username=username, name=currency) wallet.addresses.add(WalletAddress.objects.create(address=addr)) return addr
def test_sign(test_builder): test_builder.append_create_account_op(Keypair.random().address().decode(), 100) assert len(test_builder.ops) == 1 test_builder.sign() assert test_builder.te assert test_builder.tx
def test_create_default(): keypair = Keypair.random() # with secret builder = Builder(secret=keypair.seed()) assert builder assert builder.key_pair.seed() == keypair.seed() assert builder.address == keypair.address().decode() assert builder.network == 'PUBLIC' assert builder.horizon assert builder.horizon.horizon_uri == HORIZON_LIVE # with address builder = Builder(address=keypair.address().decode()) assert builder assert builder.address == keypair.address().decode() assert builder.network == 'PUBLIC' assert builder.horizon assert builder.horizon.horizon_uri == HORIZON_LIVE # on testnet builder = Builder(secret=keypair.seed(), network='TESTNET') assert builder assert builder.network == 'TESTNET' assert builder.horizon assert builder.horizon.horizon_uri == HORIZON_TEST
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()
def channel_worker(thread_ex_holder): try: # create an account using a channel address = Keypair.random().address().decode() tx_hash1 = sdk.create_account(address, starting_balance=100) assert tx_hash1 # send lumens tx_hash2 = sdk.send_native(address, 1) assert tx_hash2 # send more lumens tx_hash3 = sdk.send_native(address, 1) assert tx_hash3 sleep(1) # check transactions tx_data = sdk.get_transaction_data(tx_hash1) assert tx_data # transaction envelope source is some channel account assert tx_data.source_account in channel_addresses # operation source is the base account assert tx_data.operations[0].source_account == sdk.get_address() tx_data = sdk.get_transaction_data(tx_hash2) assert tx_data assert tx_data.source_account in channel_addresses assert tx_data.operations[0].source_account == sdk.get_address() tx_data = sdk.get_transaction_data(tx_hash3) assert tx_data assert tx_data.source_account in channel_addresses assert tx_data.operations[0].source_account == sdk.get_address() except Exception as e: thread_ex_holder.append(e)
def initialize_keypair(add_funds=True): kp = Keypair.random() if add_funds: publickey = kp.address().decode() url = 'https://friendbot.stellar.org/?addr=' + publickey requests.get(url) return kp
def _init_session_from_new_account(): """ Initializes a session from a newly created account. A Stellar keypair is randomly generated. :return: Returns the initialized CLI session. :rtype: CliSession """ account_name = None if yes_or_no_input( "Do you want to give a name to the new account to be created?" ) == USER_INPUT_YES: account_name = safe_input("Please insert the account name") keypair = Keypair.random() address = keypair.address().decode() seed = keypair.seed().decode() cli_session = CliSession(account_name, address, seed) if _config_file_is_to_update(): if yes_or_no_input("Do you want to save the seed of the new account in the encrypted configuration file") == \ USER_INPUT_YES: cli_session.store_account_in_config_file() else: seed_file = safe_input( "Specify a file to which the seed of the new created account should be saved. " "Notice that the seed will be saved in plain text on the specified file. " "Please store it in a safe place. If anyone can reach the seed it can fully " "control your account") write_file(seed_file, seed) cli_session.store_account_in_config_file() return cli_session
def __init__(self): kp = Keypair.random() self.fee = 100 self.address = kp.address().decode('ascii') self.seed = kp.seed().decode('ascii') or None fund(self.address)
def create_and_fund_account(): keypair = Keypair.random() logging.info('Created account: secret=%s, address=%s', keypair.seed().decode(), keypair.address().decode()) fund_account(keypair) return keypair
def create_account(user): # type: (User) -> None # create keypair keypair = Keypair.random() public_key = keypair.address().decode() seed = keypair.seed().decode() # store account StellarAccount.objects.create(seed=seed, address=public_key, user=user, balance=0.0) horizon = horizon_testnet() if settings.DEMO_MODE else horizon_livenet() # fund account if settings.DEMO_MODE: for _ in range(5): # noinspection PyBroadException try: funding_keypair = Keypair.from_seed( settings.FUNDING_ACCOUNT_SEED) # create operation create_account_operation = CreateAccount({ 'destination': public_key, 'starting_balance': '1' }) # create transaction sequence = horizon.account( funding_keypair.address().decode()).get('sequence') tx = Transaction(source=funding_keypair.address().decode(), opts={ 'sequence': sequence, 'memo': TextMemo('Creating new Zendi account.'), 'operations': [create_account_operation] }) # create and sign envelope envelope = TransactionEnvelope(tx=tx, opts={"network_id": "TESTNET"}) envelope.sign(funding_keypair) # Submit the transaction to Horizon te_xdr = envelope.xdr() horizon.submit(te_xdr) break except Exception as ex: logger.error('Error while funding account', ex) time.sleep(1) logger.info('Created Stellar Lumen account {} for {}'.format( public_key, user))
def test_send_kin(setup, test_sdk, helpers): with pytest.raises(ValueError, match='invalid address: bad'): test_sdk.send_kin('bad', 10) keypair = Keypair.random() address = keypair.address().decode() with pytest.raises(ValueError, match='amount must be positive'): test_sdk.send_kin(address, 0) with pytest.raises(ValueError, match='invalid asset issuer: bad'): test_sdk._send_asset(Asset('TMP', 'bad'), address, 10) # account does not exist yet with pytest.raises(kin.AccountNotFoundError) as exc_info: test_sdk.send_kin(address, 10) assert exc_info.value.error_code == kin.PaymentResultCode.NO_DESTINATION assert test_sdk.create_account(address, starting_balance=100) # no trustline yet with pytest.raises(kin.AccountNotActivatedError) as exc_info: test_sdk.send_kin(address, 10) assert exc_info.value.error_code == kin.PaymentResultCode.NO_TRUST # add trustline from the newly created account to the kin issuer assert helpers.trust_asset(setup, keypair.seed()) # send and check the resulting balance tx_hash = test_sdk.send_kin(address, 10.123, memo_text='foobar') assert tx_hash assert test_sdk.get_account_kin_balance(address) == Decimal('10.123') # test get_transaction_data for this transaction sleep(1) tx_data = test_sdk.get_transaction_data(tx_hash) assert tx_data assert tx_data.hash == tx_hash assert tx_data.source_account == test_sdk.get_address() assert tx_data.created_at assert tx_data.source_account_sequence assert tx_data.fee_paid == 100 assert tx_data.memo_type == 'text' assert tx_data.memo == 'foobar' assert len(tx_data.signatures) == 1 assert len(tx_data.operations) == 1 op = tx_data.operations[0] assert op.id assert op.type == 'payment' assert op.asset_code == setup.test_asset.code assert op.asset_type == 'credit_alphanum4' assert op.asset_issuer == setup.test_asset.issuer assert op.trustor is None assert op.trustee is None assert op.limit is None assert op.from_address == test_sdk.get_address() assert op.to_address == address assert op.amount == Decimal('10.123')
def test_onboard(self): """test onboarding scenarios""" #TODO ensure there's enough money in the test account to begin with userid = str(uuid.uuid4()) resp = self.app.post('/user/register', data=json.dumps({ 'user_id': str(userid), 'os': 'android', 'device_model': 'samsung8', 'device_id': '234234', 'time_zone': '+05:00', 'token': 'fake_token', 'app_ver': '1.0' }), headers={}, content_type='application/json') self.assertEqual(resp.status_code, 200) # try to onboard user, should succeed kp = Keypair.random() resp = self.app.post('/user/onboard', data=json.dumps( {'public_address': kp.address().decode()}), headers={USER_ID_HEADER: str(userid)}, content_type='application/json') print(json.loads(resp.data)) self.assertEqual(resp.status_code, 200) # ensure that the account was created address = Address(address=kp.address().decode()) address.get() # get the updated information assert (address.balances[0]['asset_type'] == 'native' and int(float(address.balances[0]['balance'])) == 2 ) #TODO read 2 from config # try onboarding again with the same user - should fail resp = self.app.post('/user/onboard', data=json.dumps( {'public_address': kp.address().decode()}), headers={USER_ID_HEADER: str(userid)}, content_type='application/json') print(json.loads(resp.data)) self.assertEqual(resp.status_code, 400) # try sending kin to that public address resp = self.app.post('/send-kin', data=json.dumps({ 'public_address': kp.address().decode(), 'amount': 1 }), headers={USER_ID_HEADER: str(userid)}, content_type='application/json') print(json.loads(resp.data)) self.assertEqual(resp.status_code, 200)
def test_trust_asset(setup, test_sdk, helpers): # failures with pytest.raises(Exception, match='Issuer cannot be null'): test_sdk._trust_asset(Asset('')) with pytest.raises(XdrLengthError, match='Asset code must be 12 characters at max.'): test_sdk._trust_asset(Asset('abcdefghijklmnopqr')) with pytest.raises(Exception, match='Issuer cannot be null'): test_sdk._trust_asset(Asset('TMP')) with pytest.raises(ValueError, match='invalid asset issuer: tmp'): test_sdk._trust_asset(Asset('TMP', 'tmp')) address = Keypair.random().address().decode() with pytest.raises(kin.RequestError) as exc_info: test_sdk._trust_asset(Asset('TMP', address)) assert exc_info.value.error_code == kin.ChangeTrustResultCode.NO_ISSUER # success tx_hash = test_sdk._trust_asset(setup.test_asset, limit=1000, memo_text='foobar') assert tx_hash assert test_sdk._check_asset_trusted(test_sdk.get_address(), setup.test_asset) # TODO: check asset limit # test get_transaction_data for this transaction sleep(1) tx_data = test_sdk.get_transaction_data(tx_hash) assert tx_data assert tx_data.hash == tx_hash assert tx_data.source_account == test_sdk.get_address() assert tx_data.created_at assert tx_data.source_account_sequence assert tx_data.fee_paid == 100 assert tx_data.memo_type == 'text' assert tx_data.memo == 'foobar' assert len(tx_data.signatures) == 1 assert len(tx_data.operations) == 1 op = tx_data.operations[0] assert op.id # assert op.created_at # assert op.transaction_hash == tx_hash assert op.type == 'change_trust' assert op.asset_code == setup.test_asset.code assert op.asset_type == 'credit_alphanum4' assert op.asset_issuer == setup.test_asset.issuer assert op.trustor == test_sdk.get_address() assert op.trustee == setup.test_asset.issuer assert op.limit == Decimal('1000') assert op.from_address is None assert op.to_address is None assert op.amount is None # finally, fund the sdk account with asset assert helpers.fund_asset(setup, test_sdk.get_address(), 1000) assert test_sdk.get_account_kin_balance( test_sdk.get_address()) == Decimal('1000')
def newAccount(creator=False): kp = Keypair.random() r = requests.get(url + '/friendbot?addr=' + kp.address().decode('ascii')) # Get 1000 lumens assert 'hash' in json.loads(r.text) return { 'address': kp.address().decode('ascii'), 'seed': kp.seed().decode('ascii') }
def create_account(): key_pair = Keypair.random() friendbot_url = 'https://friendbot.stellar.org' r = requests.get(friendbot_url, params={'addr': key_pair.address().decode()}) public_key = key_pair.address().decode() private_key = key_pair.seed().decode() return {"public": public_key, "private": private_key}
def __init__(self): kp = Keypair.random() self.fee = 100 self.address = kp.address().decode('ascii') self.seed = kp.seed().decode('ascii') or None r = requests.get('https://horizon-testnet.stellar.org/friendbot?addr=' + self.address) assert 'hash' in json.loads(r.text), "\n" + urlParam + "\n" + r.text
def test_signing(self): previous_id = uuid.uuid1().hex receiver_kp = Keypair.random() amount = 10 source_kp = Keypair.random() tx = Transaction( previous_id=previous_id, receiver_address=receiver_kp.address().decode(), amount=amount, source_secret_seed=source_kp.seed().decode(), ) signed_message = tx.sign() self.assertTrue(type(signed_message) in (dict, )) self.assertTrue('signature' in signed_message) self.assertTrue('body' in signed_message)
def test_valiate(self): previous_id = uuid.uuid1().hex receiver_kp = Keypair.random() amount = 10 source_kp = Keypair.random() tx = Transaction( previous_id=previous_id, receiver_address=receiver_kp.address().decode(), amount=amount, source_secret_seed=source_kp.seed().decode(), ) signed_message = tx.message self.assertTrue(type(signed_message) in (str, )) self.assertNotEqual(Transaction.validate(signed_message), None)
def test_basic(self): previous_id = uuid.uuid1().hex receiver_kp = Keypair.random() amount = 10 source_kp = Keypair.random() tx = Transaction( previous_id=previous_id, receiver_address=receiver_kp.address().decode(), amount=amount, source_secret_seed=source_kp.seed().decode(), ) self.assertEqual(tx.previous_id, previous_id) self.assertNotEqual(tx.id, None) self.assertEqual(tx.receiver_address, receiver_kp.address().decode()) self.assertEqual(tx.source_kp.seed(), source_kp.seed()) self.assertEqual(tx.source_address, source_kp.address().decode())
def __init__(self): self.cold = Keypair.random() self.hot = Keypair.random()