def increment_sequence_number(self) -> None: """ Increments sequence number in this object by one. """ stellarAccount.increment_sequence_number(self) self.wallet.sequence = self.sequence self.wallet.sequencedate = int(time.time())
def test_verify_challenge_tx_contain_subsequent_ops_that_secend_op_no_source_account( self, ): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE domain_name = "example.com" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(domain_name), data_value=nonce_encoded, source=client_kp.public_key, ).append_manage_data_op(data_name="Hello", data_value="world").add_time_bounds( now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Operation should have a source account.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, domain_name, network_passphrase, )
def test_verify_challenge_tx_contain_subsequent_manage_data_ops_with_server_account_as_source_account( self, ): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE domain_name = "example.com" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(domain_name), data_value=nonce_encoded, source=client_kp.public_key, ).append_manage_data_op( data_name="data key", data_value="data value", source=server_kp.public_key, ).add_time_bounds(now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, domain_name, network_passphrase, )
def establish_trust(self, private_key, token): """ Amount as full """ # Load user secret and get account user_key_pair = Keypair.from_secret(private_key) root_account = Account(account_id=user_key_pair.public_key, sequence=1) public_key = root_account.account_id asset_issuer = self.integrated_coins[token.lower()]["assetIssuer"] try: source_account = self.server.load_account(public_key) tx = TransactionBuilder( source_account=source_account, network_passphrase=self.network_phrase, base_fee=self.server.fetch_base_fee()).append_change_trust_op(asset_code=f'{token.upper()}', asset_issuer=asset_issuer).set_timeout( 30).build() tx.sign(private_key) self.server.submit_transaction(tx) return True except exceptions.NotFoundError: return False
def test_to_txrep_fullline_comment(self): keypair = Keypair.from_secret( "SAHGKA7QJB6SRFDZSPZDEEIOEHUHTQS4XVN4IMR5YCKBPEN5A6YNKKUO") account = Account(keypair.public_key, 46489056724385792) transaction_builder = TransactionBuilder( source_account=account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100, ) transaction_builder.add_text_memo("Enjoy this transaction") transaction_builder.add_time_bounds(1535756672, 1567292672) transaction_builder.append_payment_op( destination= "GBAF6NXN3DHSF357QBZLTBNWUTABKUODJXJYYE32ZDKA2QBM2H33IK6O", asset_code="USD", asset_issuer= "GAZFEVBSEGJJ63WPVVIWXLZLWN2JYZECECGT6GUNP4FJDVZVNXWQWMYI", amount="40.0004", source=keypair.public_key, ) te = transaction_builder.build() te.sign(keypair) txrep = to_txrep(te) file_txrep = get_txrep_file("test_to_txrep_fullline_comment.txt") assert txrep == to_txrep( from_txrep(file_txrep, Network.TESTNET_NETWORK_PASSPHRASE))
def test_to_txrep_return_memo(self): keypair = Keypair.from_secret( "SAHGKA7QJB6SRFDZSPZDEEIOEHUHTQS4XVN4IMR5YCKBPEN5A6YNKKUO") account = Account(keypair.public_key, 46489056724385792) transaction_builder = TransactionBuilder( source_account=account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100, ) transaction_builder.add_return_hash_memo( "ef14f82df770697f56789b4db4e59d1ece902484739ba167cf99fae319ebcc34") transaction_builder.add_time_bounds(1535756672, 1567292672) transaction_builder.append_payment_op( destination= "GBAF6NXN3DHSF357QBZLTBNWUTABKUODJXJYYE32ZDKA2QBM2H33IK6O", asset_code="USD", asset_issuer= "GAZFEVBSEGJJ63WPVVIWXLZLWN2JYZECECGT6GUNP4FJDVZVNXWQWMYI", amount="40.0004", source=keypair.public_key, ) te = transaction_builder.build() te.sign(keypair) txrep = to_txrep(te) assert txrep == get_txrep_file("test_to_txrep_return_memo.txt") assert (from_txrep( txrep, Network.TESTNET_NETWORK_PASSPHRASE).to_xdr() == te.to_xdr())
def test_verify_challenge_tx_contain_subsequent_manage_data_ops_without_the_server_account_as_the_source_account( self, ): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE home_domain = "example.com" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(home_domain), data_value=nonce_encoded, source=client_kp.public_key, ).append_manage_data_op( data_name="data key", data_value="data value", source=client_kp.public_key, ).add_time_bounds(now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="The transaction has operations that are unrecognized.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, home_domain, network_passphrase, )
def test_verify_challenge_tx_operation_value_is_none(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE home_domain = "example.com" now = int(time.time()) nonce_encoded = None server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(home_domain), data_value=nonce_encoded, source=client_kp.public_key, ).add_time_bounds(now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Operation value should not be null.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, home_domain, network_passphrase, )
def test_verify_challenge_tx_contain_zero_op(self, ): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE domain_name = "example.com" now = int(time.time()) nonce = os.urandom(48) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder(server_account, network_passphrase, 100).add_time_bounds( now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction should contain at least one operation.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, domain_name, network_passphrase, )
async def test_check_memo_required_with_fee_bump_transaction_async( self, httpserver): self.__inject_mock_server(httpserver) horizon_url = httpserver.url_for("/") keypair = Keypair.from_secret( "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY") account = Account(keypair.public_key, 1) async with Server(horizon_url, AiohttpClient()) as server: transaction = (TransactionBuilder( account, v1=True).append_payment_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10", "XLM" ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_account_merge_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D).add_text_memo( "hello, world").build()) transaction.sign(keypair) fee_bump_tx = TransactionBuilder.build_fee_bump_transaction( fee_source=Keypair.random().public_key, base_fee=200, inner_transaction_envelope=transaction, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, ) await server.submit_transaction(fee_bump_tx)
def test_verify_challenge_tx_sequence_not_zero(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, 10086) challenge_te = ( TransactionBuilder(server_account, network_passphrase, 100) .append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ) .add_time_bounds(now, now + 900) .build() ) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="The transaction sequence number should be zero.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, network_passphrase )
def test_verify_challenge_tx_not_within_range_of_the_specified_timebounds(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = ( TransactionBuilder(server_account, network_passphrase, 100) .append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ) .add_time_bounds(now - 100, now - 50) .build() ) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction is not within range of the specified timebounds.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, network_passphrase )
def test_verify_challenge_tx_transaction_is_not_signed_by_the_server(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" timeout = 900 now = int(time.time()) server_keypair = Keypair.from_secret(server_kp.secret) server_account = Account(account_id=server_keypair.public_key, sequence=-1) transaction_builder = TransactionBuilder( server_account, network_passphrase, 100 ) transaction_builder.add_time_bounds(min_time=now, max_time=now + timeout) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) transaction_builder.append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ) challenge = transaction_builder.build().to_xdr() transaction = TransactionEnvelope.from_xdr(challenge, network_passphrase) transaction.sign(client_kp) challenge_tx = transaction.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction not signed by server: {}".format(server_kp.public_key), ): verify_challenge_transaction( challenge_tx, server_kp.public_key, network_passphrase )
def test_verify_challenge_tx_dont_contains_timebound(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = ( TransactionBuilder(server_account, network_passphrase, 100) .append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ) .build() ) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction requires timebounds." ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, network_passphrase )
def test_check_memo_required_with_account_not_found_sync(self, httpserver): self.__inject_mock_server(httpserver) horizon_url = httpserver.url_for("/") server = Server(horizon_url) keypair = Keypair.from_secret( "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY") account = Account(keypair.public_key, 1) transaction = (TransactionBuilder(account).append_payment_op( self.DESTINATION_ACCOUNT_NO_FOUND, "10", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_NO_FOUND, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_NO_FOUND, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_account_merge_op( self.DESTINATION_ACCOUNT_NO_FOUND).build()) transaction.sign(keypair) server.submit_transaction(transaction)
def test_verify_challenge_tx_operation_value_is_not_a_64_bytes_base64_string( self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(32) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce, source=client_kp.public_key, ).add_time_bounds(now, now + 300).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match= "Operation value should be a 64 bytes base64 random string.", ): verify_challenge_transaction(challenge_tx_signed, server_kp.public_key, network_passphrase)
def test_tx_not_v1(self): inner_keypair = Keypair.from_secret( "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E") inner_source = Account(inner_keypair.public_key, 7) destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM" amount = "2000.0000000" inner_tx = (TransactionBuilder(inner_source, Network.TESTNET_NETWORK_PASSPHRASE, 200, v1=False).append_payment_op( destination=destination, amount=amount, asset_code="XLM").add_time_bounds( 0, 0).build()) inner_tx.sign(inner_keypair) fee_source = Keypair.from_secret( "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V") base_fee = 200 with pytest.raises( ValueError, match= "Invalid `inner_transaction`, it should be TransactionV1.", ): TransactionBuilder.build_fee_bump_transaction( fee_source.public_key, base_fee, inner_tx, Network.TESTNET_NETWORK_PASSPHRASE, )
def test_verify_challenge_tx_donot_contain_managedata_operation(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE domain_name = "example.com" now = int(time.time()) server_account = Account(server_kp.public_key, -1) challenge_te = ( TransactionBuilder(server_account, network_passphrase, 100) .append_set_options_op() .add_time_bounds(now, now + 900) .build() ) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Operation type should be ManageData." ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, domain_name, network_passphrase, )
def test_verify_challenge_tx_contains_infinite_timebounds(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE domain_name = "example.com" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = ( TransactionBuilder(server_account, network_passphrase, 100) .append_manage_data_op( data_name="{} auth".format(domain_name), data_value=nonce_encoded, source=client_kp.public_key, ) .add_time_bounds(now, 0) .build() ) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction requires non-infinite timebounds.", ): verify_challenge_transaction( challenge_tx_signed, server_kp.public_key, domain_name, network_passphrase, )
def test_read_challenge_transaction_fee_bump_transaction_raise(self): inner_keypair = Keypair.from_secret( "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E" ) inner_source = Account(inner_keypair.public_key, 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.from_secret( "SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V" ) base_fee = 200 fee_bump_tx = TransactionBuilder.build_fee_bump_transaction( fee_source.public_key, base_fee, inner_tx, Network.TESTNET_NETWORK_PASSPHRASE, ) fee_bump_tx.sign(fee_source) challenge = fee_bump_tx.to_xdr() with pytest.raises( ValueError, match="Invalid challenge, expected a TransactionEnvelope but received a FeeBumpTransactionEnvelope.", ): read_challenge_transaction( challenge, inner_keypair.public_key, Network.TESTNET_NETWORK_PASSPHRASE )
async def test_check_memo_required_with_memo_muxed_account_async( self, httpserver): self.__inject_mock_server(httpserver) horizon_url = httpserver.url_for("/") keypair = Keypair.from_secret( "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY") account = Account(keypair.public_key, 1) async with Server(horizon_url, AiohttpClient()) as server: transaction = (TransactionBuilder(account).append_payment_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_A, "10", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_B, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_C, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_account_merge_op( self.DESTINATION_ACCOUNT_MEMO_REQUIRED_D).add_text_memo( "hello, world").build()) transaction.sign(keypair) await server.submit_transaction(transaction)
async def test_check_memo_required_with_fetch_account_error_raise_async( self, httpserver): self.__inject_mock_server(httpserver) horizon_url = httpserver.url_for("/") keypair = Keypair.from_secret( "SDQXFKA32UVQHUTLYJ42N56ZUEM5PNVVI4XE7EA5QFMLA2DHDCQX3GPY") account = Account(keypair.public_key, 1) async with Server(horizon_url, AiohttpClient()) as server: transaction = (TransactionBuilder(account).append_payment_op( self.DESTINATION_ACCOUNT_FETCH_ERROR, "10", "XLM").append_path_payment_strict_receive_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_path_payment_strict_send_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED, "XLM", None, "10", "BTC", "GA7GYB3QGLTZNHNGXN3BMANS6TC7KJT3TCGTR763J4JOU4QHKL37RVV2", "1", [], ).append_account_merge_op( self.DESTINATION_ACCOUNT_NO_MEMO_REQUIRED).build()) transaction.sign(keypair) with pytest.raises(BadRequestError) as err: await server.submit_transaction(transaction) assert err.value.status == 400
def test_verify_transaction_signatures_raise_no_signature(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = ( TransactionBuilder(server_account, network_passphrase, 100) .append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ) .add_time_bounds(now, now + 900) .build() ) signers = [] with pytest.raises( InvalidSep10ChallengeError, match="Transaction has no signatures." ): _verify_transaction_signatures(challenge_te, signers)
def mock_load_not_exist_account(account_id): if account_id != settings.STELLAR_ISSUER_ACCOUNT_ADDRESS and account_id != settings.STELLAR_DISTRIBUTION_ACCOUNT_ADDRESS: raise NotFoundError(response=Response(status_code=404, headers={}, url="", text=json.dumps(dict( status=404)))) return Account(account_id, 1)
def test_to_xdr_sponsored_reserves(self): sequence = 1 source = Account( "GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM", sequence ) builder = TransactionBuilder( source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150, v1=False ) builder.add_text_memo("Stellar Python SDK") builder.add_time_bounds(1565590000, 1565600000) op_source = "GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM" op_account_id = "GCWWANEIF3Z4DMOE4LDRCS22HLLHOEQCOF3QKAC2XWTSYR2AEEQ3P5FW" te = ( builder.append_begin_sponsoring_future_reserves_op( sponsored_id="GCEYOF66NL73LL6RIPSIP34WOCESQ3GKJOAYXOEVNKRWRNQRYUILCQWC", source=op_source, ) .append_end_sponsoring_future_reserves_op(source=op_source) .append_revoke_account_sponsorship_op( account_id=op_account_id, source=op_source ) .append_revoke_trustline_sponsorship_op( account_id=op_account_id, asset=Asset.native(), source=op_source ) .append_revoke_offer_sponsorship_op( seller_id=op_account_id, offer_id=12315, source=op_source ) .append_revoke_data_sponsorship_op( account_id=op_account_id, data_name="stellar", source=op_source ) .append_revoke_claimable_balance_sponsorship_op( claimable_balance_id="00000000da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be", source=op_source, ) .append_revoke_ed25519_public_key_signer_sponsorship_op( account_id=op_account_id, signer_key="GBWYVWA2PZBTRRBNZI55OG4EFDJSDNL6ASP2VAQKHORNUSSXP2NCV4N2", source=op_source, ) .append_revoke_hashx_signer_sponsorship_op( account_id=op_account_id, signer_key="da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be", source=op_source, ) .append_revoke_pre_auth_tx_signer_sponsorship_op( account_id=op_account_id, signer_key="da0d57da7d4850e7fc10d2a9d0ebc731f7afb40574c03395b17d49149b91f5be", source=op_source, ) .build() ) xdr = "AAAAAMvXcdYjKhx0qxnsDsczxKuqa/65lZz6sjjHHczyh50JAAAF3AAAAAAAAAACAAAAAQAAAABdUQHwAAAAAF1RKQAAAAABAAAAElN0ZWxsYXIgUHl0aG9uIFNESwAAAAAACgAAAAEAAAAAy9dx1iMqHHSrGewOxzPEq6pr/rmVnPqyOMcdzPKHnQkAAAAQAAAAAImHF95q/7Wv0UPkh++WcIkobMpLgYu4lWqjaLYRxRCxAAAAAQAAAADL13HWIyocdKsZ7A7HM8Srqmv+uZWc+rI4xx3M8oedCQAAABEAAAABAAAAAMvXcdYjKhx0qxnsDsczxKuqa/65lZz6sjjHHczyh50JAAAAEgAAAAAAAAAAAAAAAK1gNIgu88GxxOLHEUtaOtZ3EgJxdwUAWr2nLEdAISG3AAAAAQAAAADL13HWIyocdKsZ7A7HM8Srqmv+uZWc+rI4xx3M8oedCQAAABIAAAAAAAAAAQAAAACtYDSILvPBscTixxFLWjrWdxICcXcFAFq9pyxHQCEhtwAAAAAAAAABAAAAAMvXcdYjKhx0qxnsDsczxKuqa/65lZz6sjjHHczyh50JAAAAEgAAAAAAAAACAAAAAK1gNIgu88GxxOLHEUtaOtZ3EgJxdwUAWr2nLEdAISG3AAAAAAAAMBsAAAABAAAAAMvXcdYjKhx0qxnsDsczxKuqa/65lZz6sjjHHczyh50JAAAAEgAAAAAAAAADAAAAAK1gNIgu88GxxOLHEUtaOtZ3EgJxdwUAWr2nLEdAISG3AAAAB3N0ZWxsYXIAAAAAAQAAAADL13HWIyocdKsZ7A7HM8Srqmv+uZWc+rI4xx3M8oedCQAAABIAAAAAAAAABAAAAADaDVfafUhQ5/wQ0qnQ68cx96+0BXTAM5WxfUkUm5H1vgAAAAEAAAAAy9dx1iMqHHSrGewOxzPEq6pr/rmVnPqyOMcdzPKHnQkAAAASAAAAAQAAAACtYDSILvPBscTixxFLWjrWdxICcXcFAFq9pyxHQCEhtwAAAABtitgafkM4xC3KO9cbhCjTIbV+BJ+qggo7otpKV36aKgAAAAEAAAAAy9dx1iMqHHSrGewOxzPEq6pr/rmVnPqyOMcdzPKHnQkAAAASAAAAAQAAAACtYDSILvPBscTixxFLWjrWdxICcXcFAFq9pyxHQCEhtwAAAALaDVfafUhQ5/wQ0qnQ68cx96+0BXTAM5WxfUkUm5H1vgAAAAEAAAAAy9dx1iMqHHSrGewOxzPEq6pr/rmVnPqyOMcdzPKHnQkAAAASAAAAAQAAAACtYDSILvPBscTixxFLWjrWdxICcXcFAFq9pyxHQCEhtwAAAAHaDVfafUhQ5/wQ0qnQ68cx96+0BXTAM5WxfUkUm5H1vgAAAAAAAAAA" assert te.to_xdr() == xdr restore_te = TransactionBuilder.from_xdr( xdr, Network.TESTNET_NETWORK_PASSPHRASE ).build() assert restore_te.to_xdr() == xdr
def check_stellar_private(private_key): try: user_key_pair = Keypair.from_secret(private_key) root_account = Account(account_id=user_key_pair.public_key, sequence=1) print(root_account) return True except Ed25519SecretSeedInvalidError as e: print(e) return False
def check_stellar_address(address): """ Filter for withdrawals """ try: Account(account_id=address, sequence=0) return True except Ed25519PublicKeyInvalidError: return False
def test_set_timeout(self): source = Account("GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM", 1) timeout = 1000 builder = TransactionBuilder( source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150 ).set_timeout(1000) now = int(time.time()) assert isinstance(builder.time_bounds, TimeBounds) assert builder.time_bounds.min_time == 0 assert now + timeout - 1 <= builder.time_bounds.max_time <= now + timeout + 1
def mock_load_account_no_account(account_id): if account_id not in [ Keypair.from_secret(v).public_key for v in [USD_DISTRIBUTION_SEED, ETH_DISTRIBUTION_SEED] ]: raise NotFoundError(response=Response(status_code=404, headers={}, url="", text=json.dumps(dict( status=404)))) return Account(account_id, 1)
def test_set_timeout_timebounds_raise(self): source = Account("GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM", 1) timeout = 1000 now = int(time.time()) with pytest.raises( ValueError, match="TimeBounds has been already set - setting timeout would overwrite it.", ): TransactionBuilder( source, Network.TESTNET_NETWORK_PASSPHRASE, base_fee=150 ).add_time_bounds(0, now + timeout).set_timeout(1000)