Пример #1
0
def send_fake_tx(amount=100, send_to_self=False) -> Tuple[int, Transaction]:
    user = OneUser.run(db_session,
                       account_amount=100_000_000_000,
                       account_currency=DiemCurrency.XUS)
    account_id = user.account_id
    amount = amount
    payment_type = types.TransactionType.EXTERNAL
    currency = diem_utils.types.currencies.DiemCurrency.XUS
    destination_address = "receiver_address"
    destination_subaddress = "receiver_subaddress"

    if send_to_self:
        destination_address = account_address_hex(
            context.get().config.vasp_address)
        destination_subaddress = generate_new_subaddress(account_id)

    send_tx = send_transaction(
        sender_id=account_id,
        amount=amount,
        currency=currency,
        payment_type=payment_type,
        destination_address=destination_address,
        destination_subaddress=destination_subaddress,
    )

    return account_id, get_transaction(send_tx.id) if send_tx else None
Пример #2
0
        def post(self):
            try:
                tx_params = request.json

                user = self.user
                account_id = user.account_id

                currency = DiemCurrency[tx_params["currency"]]
                amount = int(tx_params["amount"])
                recv_address: str = tx_params["receiver_address"]
                dest_address, dest_subaddress = identifier.decode_account(
                    recv_address,
                    context.get().config.diem_address_hrp())

                tx = transaction_service.send_transaction(
                    sender_id=account_id,
                    amount=amount,
                    currency=currency,
                    destination_address=utils.account_address_bytes(
                        dest_address).hex(),
                    destination_subaddress=dest_subaddress.hex()
                    if dest_subaddress else None,
                )
                transaction = AccountRoutes.get_transaction_response_object(
                    user.account_id, tx)
                return transaction, HTTPStatus.OK
            except transaction_service.RiskCheckError as risk_check_failed_error:
                return self.respond_with_error(HTTPStatus.FAILED_DEPENDENCY,
                                               str(risk_check_failed_error))
            except transaction_service.SelfAsDestinationError as send_to_self_error:
                return self.respond_with_error(HTTPStatus.FORBIDDEN,
                                               str(send_to_self_error))
Пример #3
0
    def testSuccessfulTransaction(self, user, transaction):
        # prepare
        transaction = Transaction({'amount': 100, 'receiver': 'SomeUser'})

        # test
        sent_transaction = send_transaction(transaction)
        # assert
        assert transaction.to_primitive() == sent_transaction
Пример #4
0
def create_transaction(model):
    """
    Creates transaction for current user.

    :param model: Request model
    :return: Created transaction
    """
    logger.info(f'Creating transaction for user {request.user.id}')
    return send_transaction(model)
Пример #5
0
    def testNotEnoughFunds(self, receiver_user):
        # prepare
        transaction = Transaction({'amount': 100, 'receiver': 'SomeUser'})

        # test
        with self.assertRaises(NotEnoughFundsError):
            sent_transaction = send_transaction(transaction)
            # assert
            assert transaction == sent_transaction
Пример #6
0
    def testNonExistingReceiver(self, user):
        # prepare

        transaction = Transaction({'amount': 100, 'receiver': 'SomeUser'})

        # test
        with self.assertRaises(ReceiverDoesNotExist):
            sent_transaction = send_transaction(transaction)
            # assert
            assert transaction == sent_transaction
Пример #7
0
def _transfer_funds_to_lp(order: Order) -> int:
    lp_details = LpClient().lp_details()
    inventory_account = get_account(account_name=INVENTORY_ACCOUNT_NAME).id

    tx = send_transaction(
        sender_id=inventory_account,
        amount=order.amount,
        currency=DiemCurrency[order.base_currency],
        destination_address=lp_details.vasp,
        destination_subaddress=lp_details.sub_address,
    )
    return _wait_for_lp_deposit_transaction_to_complete(tx.id)
Пример #8
0
def test_send_payment_between_vasps(lrw1, lrw2, vasp1, vasp2, user1, user2):
    sender_address = lrw1.context.config.vasp_diem_address()
    receiver_address = lrw2.context.config.vasp_diem_address()
    receiver_subaddress = generate_new_subaddress(account_id=user2.account_id)

    # setup global environment as lrw1 app
    context.set(lrw1.context)
    client.set(vasp1)

    txn = send_transaction(
        sender_id=user1.account_id,
        amount=2_000_000_000,
        currency=DiemCurrency.Coin1,
        destination_address=receiver_address.get_onchain_address_hex(),
        destination_subaddress=receiver_subaddress,
    )

    assert txn
    assert txn.off_chain
    assert len(txn.off_chain) == 1
    assert txn.off_chain[0].reference_id

    reference_id = txn.off_chain[0].reference_id

    num_tries = 20
    while num_tries > 1:
        txn = get_single_transaction(txn.id)
        if txn.status == TransactionStatus.COMPLETED:
            break
        num_tries -= 1
        time.sleep(1)

    payment = vasp1.get_payment_by_ref(reference_id)
    assert payment.sender.status.as_status() == Status.ready_for_settlement
    assert payment.receiver.status.as_status() == Status.ready_for_settlement

    payment = vasp2.get_payment_by_ref(reference_id)
    assert payment.sender.status.as_status() == Status.ready_for_settlement
    assert payment.receiver.status.as_status() == Status.ready_for_settlement