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
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) @patch("polaris.utils.get_account_obj", mock_get_account_obj)