def test_load_ed25519_public_key_signers(self): signers = [ { "weight": 10, "key": "XCRJANZNX6PX42O2PTZ5PTKAQYZNQOXHDRF7PI7ANSJSW4RKGT63XCDN", "type": "sha256_hash", }, { "weight": 1, "key": "GCV5YZ7R6IAKQCIGDP6TS6GHUXSNWVLP2CNRCUSIPQFRX67LGQRXTCL6", "type": "ed25519_public_key", }, { "weight": 2, "key": "GBUGPGCH6YTEOT2CQJDRYPIXK5KTVUZOWIQMLIAOLYKZMPWT23CVQMPH", "type": "ed25519_public_key", }, ] account_id = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH" sequence = 123123 account = Account(account_id=account_id, sequence=sequence) account.signers = signers assert account.load_ed25519_public_key_signers() == [ Ed25519PublicKeySigner( "GCV5YZ7R6IAKQCIGDP6TS6GHUXSNWVLP2CNRCUSIPQFRX67LGQRXTCL6", 1), Ed25519PublicKeySigner( "GBUGPGCH6YTEOT2CQJDRYPIXK5KTVUZOWIQMLIAOLYKZMPWT23CVQMPH", 2), ]
def mock_load_account_no_account(account_id): if isinstance(account_id, Keypair): account_id = account_id.public_key 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)))) account = Account(account_id, 1) account.signers = [] account.thresholds = Thresholds(0, 0, 0) return ( account, [{ "balances": [ { "asset_code": "USD", "asset_issuer": USD_ISSUER_ACCOUNT }, { "asset_code": "ETH", "asset_issuer": ETH_ISSUER_ACCOUNT }, ] }], )
def load_account(resp): sequence = int(resp["sequence"]) thresholds = Thresholds( resp["thresholds"]["low_threshold"], resp["thresholds"]["med_threshold"], resp["thresholds"]["high_threshold"], ) account = Account(account_id=resp["account_id"], sequence=sequence) account.signers = resp["signers"] account.thresholds = thresholds return account
def account_from_json(self, json): sequence = int(json["sequence"]) thresholds = Thresholds( json["thresholds"]["low_threshold"], json["thresholds"]["med_threshold"], json["thresholds"]["high_threshold"], ) account = Account(account_id=json["id"], sequence=sequence) account.signers = json["signers"] account.thresholds = thresholds return account
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_bad_account_id_raise(self): invalid_account_id = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOBAD" with pytest.raises( Ed25519PublicKeyInvalidError, match="Invalid Ed25519 Public Key: {}".format(invalid_account_id), ): Account(invalid_account_id, 0)
from stellar_sdk.account import Account from stellar_sdk.keypair import Keypair from stellar_sdk.network import Network from stellar_sdk.transaction_builder import TransactionBuilder inner_keypair = Keypair.from_secret( "SBKTIFHJSS3JJWEZO2W74DZSA45WZU56LOL3AY7GAW63BXPEJQFYV53E") inner_source = Account(inner_keypair.public_key, 7) destination = "GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM" amount = "2000" inner_tx = (TransactionBuilder(inner_source, Network.TESTNET_NETWORK_PASSPHRASE, 200, v1=True).append_payment_op( destination=destination, amount=amount, asset_code="XLM").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)
try: return mock_load_account_no_account(account_id=account_id) except NotFoundError as e: raise RuntimeError(str(e)) mock_server_no_account = Mock( accounts=Mock(return_value=Mock(account_id=Mock(return_value=Mock( call=Mock(return_value={"balances": []}))))), load_account=mock_load_account_no_account, submit_transaction=Mock(return_value=HORIZON_SUCCESS_RESPONSE), fetch_base_fee=Mock(return_value=100), ) channel_account_kp = Keypair.random() channel_account = Account(channel_account_kp.public_key, 1) channel_account.signers = [] channel_account.thresholds = Thresholds(0, 0, 0) mock_account = Account(STELLAR_ACCOUNT_1, 1) mock_account.signers = [{ "key": STELLAR_ACCOUNT_1, "weight": 1, "type": "ed25519_public_key" }] mock_account.thresholds = Thresholds(low_threshold=0, med_threshold=1, high_threshold=1) @pytest.mark.django_db