async def test_send_payment(mock_mqtt): wallet = Wallet.factory("manta://localhost:8000/123") await wallet.send_payment(transaction_hash="myhash", crypto_currency="nano") expected = PaymentMessage(transaction_hash="myhash", crypto_currency="nano") mock_mqtt.subscribe.assert_called_with("acks/123") mock_mqtt.publish.assert_called_with("payments/123", JsonContains(expected), qos=1)
def test_confirm(mock_mqtt, payproc): test_payment_message(mock_mqtt, payproc) payproc.confirm("1423") ack = AckMessage( txid="0", status=Status.PAID, transaction_hash="myhash", transaction_currency="NANO", ) mock_mqtt.publish.assert_called_with("acks/1423", JsonContains(ack))
def test_receive_merchant_order_request(mock_mqtt, payproc): request = MerchantOrderRequestMessage( amount=Decimal("1000"), session_id="1423", fiat_currency="eur", ) expected = AckMessage(txid="0", url="manta://localhost/1423", status=Status.NEW) mock_mqtt.push("merchant_order_request/device1", request.to_json()) mock_mqtt.publish.assert_any_call("acks/1423", JsonContains(expected)) mock_mqtt.subscribe.assert_any_call("payments/1423") mock_mqtt.subscribe.assert_any_call("payment_requests/1423/+")
def test_invalidate(mock_mqtt, payproc): test_payment_message(mock_mqtt, payproc) payproc.invalidate("1423", "Timeout") ack = AckMessage( txid="0", status=Status.INVALID, transaction_hash="myhash", transaction_currency="NANO", memo="Timeout", ) mock_mqtt.publish.assert_called_with("acks/1423", JsonContains(ack))
def test_payment_message(mock_mqtt, payproc): test_get_payment_request_all(mock_mqtt, payproc) message = PaymentMessage(crypto_currency="NANO", transaction_hash="myhash") ack = AckMessage( txid="0", status=Status.PENDING, transaction_hash="myhash", transaction_currency="NANO", ) mock_mqtt.push("payments/1423", message.to_json()) mock_mqtt.publish.assert_called_with("acks/1423", JsonContains(ack))
def test_receive_merchant_cancel_order(mock_mqtt, payproc): test_receive_merchant_order_request(mock_mqtt, payproc) mock_mqtt.push("merchant_order_cancel/1423", "") expected = AckMessage( txid="0", url="manta://localhost/1423", status=Status.INVALID, memo="Canceled by Merchant", ) mock_mqtt.publish.assert_called_with("acks/1423", JsonContains(expected))
def test_receive_merchant_order_request_legacy(mock_mqtt, payproc): request = MerchantOrderRequestMessage( amount=Decimal("1000"), session_id="1423", fiat_currency="eur", crypto_currency="btc", ) expected = AckMessage(txid="0", url="bitcoin:btc_daddress?amount=5", status=Status.NEW) mock_mqtt.push("merchant_order_request/device1", request.to_json()) mock_mqtt.publish.assert_any_call("acks/1423", JsonContains(expected))
def test_receive_merchant_order_request_unkwnown_field(mock_mqtt, payproc): request = MerchantOrderRequestMessage( amount=Decimal("1000"), session_id="1423", fiat_currency="eur" ) expected = AckMessage(txid="0", url="manta://localhost/1423", status=Status.NEW) request_json = request.unstructure() request_json["extra_field"] = "extra" mock_mqtt.push("merchant_order_request/device1", json.dumps(request_json)) mock_mqtt.publish.assert_any_call("acks/1423", JsonContains(expected)) mock_mqtt.subscribe.assert_any_call("payments/1423") mock_mqtt.subscribe.assert_any_call("payment_requests/1423/+")