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
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 @patch("polaris.utils.settings.HORIZON_SERVER", mock_server_no_account)