def test_challenge_transaction(self): server_kp = Keypair.random() client_account_id = "GBDIT5GUJ7R5BXO3GJHFXJ6AZ5UQK6MNOIDMPQUSMXLIHTUNR2Q5CFNF" timeout = 600 network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE anchor_name = "SDF" challenge = build_challenge_transaction( server_secret=server_kp.secret, client_account_id=client_account_id, anchor_name=anchor_name, network_passphrase=network_passphrase, timeout=timeout, ) transaction = TransactionEnvelope.from_xdr( challenge, network_passphrase).transaction assert len(transaction.operations) == 1 op = transaction.operations[0] assert isinstance(op, ManageData) assert op.data_name == "SDF auth" assert len(op.data_value) == 64 assert len(base64.b64decode(op.data_value)) == 48 assert op.source == MuxedAccount(client_account_id) now = int(time.time()) assert now - 3 < transaction.time_bounds.min_time < now + 3 assert (transaction.time_bounds.max_time - transaction.time_bounds.min_time == timeout) assert transaction.source == MuxedAccount.from_account( server_kp.public_key) assert transaction.sequence == 0
def test_to_xdr_v1(self): source = Keypair.from_public_key( "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ") destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" amount = "1000.0" sequence = 1 memo = IdMemo(100) fee = 200 asset = Asset.native() time_bounds = TimeBounds(12345, 56789) ops = [ Payment(destination, asset, amount), ManageData("hello", "world") ] tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds, True).to_xdr_object() assert ( tx_object.to_xdr() == "AAAAAImbKEDtVjbFbdxfFLI5dfefG6I4jSaU5MVuzd3JYOXvAAAAyAAAAAAAAAABAAAAAQAAAAAAADA5AAAAAAAA3dUAAAACAAAAAAAAAGQAAAACAAAAAAAAAAEAAAAA0pjFgVcRZZHpMgnpXHpb/xIbLh0/YYto0PzI7+Xl5HAAAAAAAAAAAlQL5AAAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAFd29ybGQAAAAAAAAA" ) restore_transaction = Transaction.from_xdr_object(tx_object, v1=True) assert isinstance(restore_transaction, Transaction) assert restore_transaction.source == MuxedAccount.from_account( source.public_key) assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds assert restore_transaction.sequence == sequence
def test_path_payment_strict_receive_muxed_account_not_support_raise(): tx = make_default_tx() destination = MuxedAccount( "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6", 1) send_max = "50.0111" dest_amount = "100" send_code = "XLM" send_issuer = None dest_code = "USD" dest_issuer = "GCSJ7MFIIGIRMAS4R3VT5FIFIAOXNMGDI5HPYTWS5X7HH74FSJ6STSGF" operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" path_asset1 = Asset( "JPY", "GD6PV7DXQJX7AGVXFQ2MTCLTCH6LR3E6IO2EO2YDZD7F7IOZZCCB5DSQ") path_asset2 = Asset( "BANANA", "GC7EKO37HNSKQ3V6RZ274EO7SFOWASQRHLX3OR5FIZK6UMV6LIEDXHGZ") envelope = tx.append_path_payment_strict_receive_op( destination=destination, send_code=send_code, send_issuer=send_issuer, send_max=send_max, dest_code=dest_code, dest_issuer=dest_issuer, dest_amount=dest_amount, path=[path_asset1, path_asset2], source=operation_source, ).build() with pytest.raises(ValueError, match="MuxedAccount is not supported"): stellar.from_envelope(envelope)
def test_to_xdr_with_muxed_account_fee_source(self): inner_keypair = Keypair.from_secret( "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E" ) inner_source = Account( MuxedAccount( "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234 ), 7, ) destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM" amount = "2000.0000000" inner_tx = ( TransactionBuilder( inner_source, Network.TESTNET_NETWORK_PASSPHRASE, 200, v1=True ) .append_payment_op(destination=destination, amount=amount, asset_code="XLM") .add_time_bounds(0, 0) .build() ) inner_tx.sign(inner_keypair) fee_source_keypair = Keypair.from_secret( "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V" ) fee_source = MuxedAccount(fee_source_keypair.public_key, 1234) base_fee = 200 fee_bump_tx = TransactionBuilder.build_fee_bump_transaction( fee_source, base_fee, inner_tx, Network.TESTNET_NETWORK_PASSPHRASE, ) fee_bump_tx.sign(fee_source_keypair) # xdr = "AAAABQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAGQAAAAAgAAAAAcVPE+R/n1VnbIrAK3tu5yVfTkhkqVz04ShWk2SrF3wAAAAMgAAAAAAAAACAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAADgSJG2GOUMy/H9lHyjYZOwyuyytH8y0wWaoc596L+bEgAAAAAAAAAEqBfIAAAAAAAAAAABSrF3wAAAAEAordQh63kT50muRLVYaWW7Pgtt8i1tc4t9Bv9MWFWFN3WfTHSU2Jxv7hedjZEyfBPvaS/XnwvYJFcHgPDd1JkNAAAAAAAAAAHov5sSAAAAQKu/RuArXn/P13IIJ8WlnVDStwOquXM0CsWzA4ooZY6gqJ3k1EfmMVIJ0cir0bMTJD9r+g2IUZCANU7wdC38PA0=" # assert fee_bump_tx.to_xdr() == xdr restore_te = FeeBumpTransactionEnvelope.from_xdr( fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE ) assert ( restore_te.to_xdr() == TransactionBuilder.from_xdr( fee_bump_tx.to_xdr(), Network.TESTNET_NETWORK_PASSPHRASE ).to_xdr() ) assert isinstance(restore_te, FeeBumpTransactionEnvelope) restore_tx = restore_te.transaction assert isinstance(restore_tx, FeeBumpTransaction) assert restore_tx.fee_source == fee_source assert restore_tx.base_fee == base_fee assert restore_tx.inner_transaction_envelope.to_xdr() == inner_tx.to_xdr()
def test_load_acount_sync(self): account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D" horizon_url = "https://horizon.stellar.org" with Server(horizon_url) as server: account = server.load_account(account_id) assert account.account_id == MuxedAccount.from_account(account_id) assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3)
async def test_load_acount_muxed_account_async(self): account_id = MuxedAccount( "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D", 1234 ) horizon_url = "https://horizon.stellar.org" client = AiohttpClient() async with Server(horizon_url, client) as server: account = await server.load_account(account_id) assert account.account_id == account_id assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3)
async def test_load_acount_muxed_account_str_async(self): account_id = ( "MAAAAAAAAAAAJUXL4LKO7RYSP6IIDETQ7BBRSBW4F5GVGZVGBPCPNHYIIX6CTUDGHDUWO" ) horizon_url = "https://horizon.stellar.org" client = AiohttpClient() async with Server(horizon_url, client) as server: account = await server.load_account(account_id) assert account.account_id == MuxedAccount.from_account(account_id) assert isinstance(account.sequence, int) assert account.thresholds == Thresholds(1, 2, 3)
def test_account_merge_muxed_account_not_support_raise(): tx = make_default_tx() destination = MuxedAccount( "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6", 1) operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = tx.append_account_merge_op(destination=destination, source=operation_source).build() with pytest.raises(ValueError, match="MuxedAccount is not supported"): stellar.from_envelope(envelope)
def test_account(self): account_id = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH" sequence = 123123 account = Account(account_id=account_id, sequence=sequence) assert account.sequence == sequence assert account.account_id == MuxedAccount(account_id) other_account = Account(account_id=account_id, sequence=sequence) assert account == other_account account.increment_sequence_number() assert account.sequence == sequence + 1 assert account != other_account assert account != "bad type"
def test_op_source_muxed_account_not_support_raise(): tx = make_default_tx() destination = "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6" amount = "50.0111" asset_code = "XLM" asset_issuer = None operation_source = MuxedAccount( "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V", 2) envelope = tx.append_payment_op( destination=destination, amount=amount, asset_code=asset_code, asset_issuer=asset_issuer, source=operation_source, ).build() with pytest.raises(ValueError, match="MuxedAccount is not supported"): stellar.from_envelope(envelope)
def test_to_xdr_str_muxed_account_str_source_v1(self): source = "MAAAAAAAAAAAJURAAB2X52XFQP6FBXLGT6LWOOWMEXWHEWBDVRZ7V5WH34Y22MPFBHUHY" destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" amount = "1000.0" sequence = 1 memo = IdMemo(100) fee = 200 asset = Asset.native() time_bounds = TimeBounds(12345, 56789) ops = [ Payment(destination, asset, amount), ManageData("hello", "world") ] tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds, True).to_xdr_object() restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), True) assert isinstance(restore_transaction, Transaction) assert restore_transaction.source == MuxedAccount.from_account(source) assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds assert restore_transaction.sequence == sequence
def test_to_xdr_v0(self): source = Keypair.from_public_key( "GC3GJU6L7V7ZLPLKG3NTMC6GYYKBMNNKCPP36FG3LWEVPOHUPY6QJIGL") destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" amount = "1000.0" sequence = 2 memo = NoneMemo() fee = 200 asset = Asset.native() time_bounds = TimeBounds(12345, 56789) ops = [Payment(destination, asset, amount)] tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds, False).to_xdr_object() restore_transaction = Transaction.from_xdr_object(tx_object, False) assert isinstance(restore_transaction, Transaction) assert restore_transaction.source == MuxedAccount.from_account( source.public_key) assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds assert restore_transaction.sequence == sequence
def test_tx_source_muxed_account_not_support_raise(): source_account = Account(account_id=MuxedAccount(TX_SOURCE, 123456), sequence=SEQUENCE) destination = "GDNSSYSCSSJ76FER5WEEXME5G4MTCUBKDRQSKOYP36KUKVDB2VCMERS6" amount = "50.0111" asset_code = "XLM" asset_issuer = None operation_source = "GAEB4MRKRCONK4J7MVQXAHTNDPAECUCCCNE7YC5CKM34U3OJ673A4D6V" envelope = (TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=BASE_FEE, ).add_time_bounds(TIMEBOUNDS_START, TIMEBOUNDS_END).append_payment_op( destination=destination, amount=amount, asset_code=asset_code, asset_issuer=asset_issuer, source=operation_source, ).build()) with pytest.raises(ValueError, match="MuxedAccount is not supported"): stellar.from_envelope(envelope)
def test_to_xdr_str_muxed_account_source_v1(self): source = MuxedAccount( "GAQAA5L65LSYH7CQ3VTJ7F3HHLGCL3DSLAR2Y47263D56MNNGHSQSTVY", 1234) destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2" amount = "1000.0" sequence = 1 memo = IdMemo(100) fee = 200 asset = Asset.native() time_bounds = TimeBounds(12345, 56789) ops = [ Payment(destination, asset, amount), ManageData("hello", "world") ] tx_object = Transaction(source, sequence, fee, ops, memo, time_bounds, True).to_xdr_object() restore_transaction = Transaction.from_xdr(tx_object.to_xdr(), True) assert isinstance(restore_transaction, Transaction) assert restore_transaction.source == source assert restore_transaction.fee == fee assert restore_transaction.memo == memo assert restore_transaction.time_bounds == time_bounds assert restore_transaction.sequence == sequence
import pprint from stellar_sdk import Keypair, Server, MuxedAccount, TransactionBuilder, Network horizon_url = "https://horizon-testnet.stellar.org/" network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE alice_secret = "SC5O7VZUXDJ6JBDSZ74DSERXL7W3Y5LTOAMRF7RQRL3TAGAPS7LUVG3L" bob_account = MuxedAccount( account_id="GBVKI23OQZCANDUZ2SI7XU7W6ICYKYT74JBXDD2CYRDAFZHZNRPASSQK", account_id_id=12387, ) print(f"account_id_muxed: {bob_account.account_id_muxed}") alice_keypair = Keypair.from_secret(alice_secret) server = Server(horizon_url=horizon_url) alice_account = server.load_account(alice_keypair.public_key) transaction = TransactionBuilder( source_account=alice_account, network_passphrase=network_passphrase, base_fee=100, v1=True, # If you want to build Protocol 13 transactions, you need to set `v1` to `True` ) \ .append_payment_op(destination=bob_account, amount="100", asset_code="XLM") \ .build() transaction.sign(alice_keypair) resp = server.submit_transaction(transaction) pprint.pprint(resp)