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
                },
            ]
        }],
    )
示例#2
0
def test_load_account():
    mock_response = {
        "sequence":
        1,
        "account_id":
        Keypair.random().public_key,
        "signers": [{
            "key": Keypair.random().public_key,
            "weight": 1,
            "type": "ed25519_public_key",
        }],
        "thresholds": {
            "low_threshold": 0,
            "med_threshold": 1,
            "high_threshold": 2
        },
    }
    account = utils.load_account(mock_response)
    assert account.account_id == mock_response["account_id"]
    assert account.sequence == mock_response["sequence"]

    account.load_ed25519_public_key_signers()
    assert account.signers == mock_response["signers"]
    assert account.thresholds == Thresholds(
        mock_response["thresholds"]["low_threshold"],
        mock_response["thresholds"]["med_threshold"],
        mock_response["thresholds"]["high_threshold"],
    )
示例#3
0
 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 == account_id
         assert isinstance(account.sequence, int)
         assert account.thresholds == Thresholds(1, 2, 3)
示例#4
0
 async def test_load_acount_async(self):
     account_id = "GDV6FVHPY4JH7EEBSJYPQQYZA3OC6TKTM2TAXRHWT4EEL7BJ2BTDQT5D"
     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)
示例#5
0
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
示例#6
0
 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)
示例#7
0
 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)