Пример #1
0
def test_check_trustlines_requires_multisig(
    mock_save_as_pending_signatures,
    mock_rdi,
    mock_requires_multisig,
    mock_submit,
    mock_server,
):
    usd = Asset.objects.create(code="USD", issuer=Keypair.random().public_key)
    transaction = Transaction.objects.create(
        asset=usd,
        stellar_account=Keypair.random().public_key,
        status=Transaction.STATUS.pending_trust,
        kind=Transaction.KIND.deposit,
    )
    mock_submit.return_value = True
    mock_requires_multisig.return_value = True
    account_json = {
        "id":
        1,
        "sequence":
        1,
        "balances": [
            {
                "asset_code": "USD",
                "asset_issuer": usd.issuer
            },
            {
                "asset_type": "native"
            },
        ],
        "thresholds": {
            "low_threshold": 1,
            "med_threshold": 1,
            "high_threshold": 1,
        },
        "signers": [{
            "key": transaction.stellar_account,
            "weight": 1
        }],
    }
    mock_server.accounts.return_value = Mock(account_id=Mock(return_value=Mock(
        call=Mock(return_value=account_json))))

    CheckTrustlinesCMD.check_trustlines()

    mock_server.accounts().account_id.assert_called_once_with(
        transaction.stellar_account)
    mock_server.accounts().account_id().call.assert_called_once()
    mock_requires_multisig.assert_called_once_with(transaction)
    mock_save_as_pending_signatures.assert_called_once_with(transaction)
    mock_submit.assert_not_called()
    mock_rdi.after_deposit.assert_not_called()
    transaction.refresh_from_db()
    assert transaction.pending_execution_attempt is False
Пример #2
0
def test_deposit_check_trustlines_success(
    mock_account,
    mock_submit,
    mock_base_fee,
    client,
    acc1_usd_deposit_transaction_factory,
):
    """
    Creates a transaction with status `pending_trust` and checks that
    `check_trustlines` changes its status to `completed`. All the necessary
    functionality and conditions are mocked for determinism.
    """
    del mock_account, mock_submit, mock_base_fee, client
    deposit = acc1_usd_deposit_transaction_factory()
    deposit.status = Transaction.STATUS.pending_trust
    deposit.save()
    assert (Transaction.objects.get(
        id=deposit.id).status == Transaction.STATUS.pending_trust)
    CheckTrustlinesCMD.check_trustlines()
    assert Transaction.objects.get(
        id=deposit.id).status == Transaction.STATUS.completed
Пример #3
0
def test_check_trustlines_horizon_connection_error(mock_rdi,
                                                   mock_requires_multisig,
                                                   mock_submit, mock_server):
    usd = Asset.objects.create(code="USD", issuer=Keypair.random().public_key)
    transaction = Transaction.objects.create(
        asset=usd,
        stellar_account=Keypair.random().public_key,
        status=Transaction.STATUS.pending_trust,
        kind=Transaction.KIND.deposit,
    )
    mock_server.accounts.return_value = Mock(account_id=Mock(return_value=Mock(
        call=Mock(side_effect=ConnectionError()))))

    CheckTrustlinesCMD.check_trustlines()

    mock_server.accounts().account_id.assert_called_once_with(
        transaction.stellar_account)
    mock_server.accounts().account_id().call.assert_called_once()
    mock_requires_multisig.assert_not_called()
    mock_submit.assert_not_called()
    mock_rdi.assert_not_called()
    transaction.refresh_from_db()
    assert transaction.pending_execution_attempt is False