Skip to content

Commit

Permalink
Add pause/unpause tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Nov 17, 2023
1 parent 97cd991 commit 43c324f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
4 changes: 3 additions & 1 deletion api/logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,9 @@ def payout_amount(cls, order, user):
return True, context

context["swap_allowed"] = True
context["suggested_mining_fee_rate"] = order.payout_tx.suggested_mining_fee_rate
context["suggested_mining_fee_rate"] = float(
order.payout_tx.suggested_mining_fee_rate
)
context["swap_fee_rate"] = order.payout_tx.swap_fee_rate

return True, context
Expand Down
2 changes: 1 addition & 1 deletion api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ class OrderDetailSerializer(serializers.ModelSerializer):
swap_failure_reason = serializers.CharField(
required=False, help_text="Reason for why on-chain swap is not available"
)
suggested_mining_fee_rate = serializers.IntegerField(
suggested_mining_fee_rate = serializers.FloatField(
required=False, help_text="fee in sats/vbyte for the on-chain swap"
)
swap_fee_rate = serializers.FloatField(
Expand Down
3 changes: 2 additions & 1 deletion docs/assets/schemas/api-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,8 @@ components:
type: string
description: Reason for why on-chain swap is not available
suggested_mining_fee_rate:
type: integer
type: number
format: double
description: fee in sats/vbyte for the on-chain swap
swap_fee_rate:
type: number
Expand Down
4 changes: 3 additions & 1 deletion tests/node_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def pay_invoice(node_name, invoice):
f'http://localhost:{node["port"]}/v1/channels/transactions',
json=data,
headers=node["headers"],
timeout=0.3, # 0.15s is enough for LND to LND hodl ACCEPT.
# 0.15s is enough for LND to LND hodl ACCEPT
# 0.4s is enough for LND to CLN hodl ACCEPT
timeout=0.2 if LNVENDOR == "LND" else 0.8,
)
except ReadTimeout:
# Request to pay hodl invoice has timed out: that's good!
Expand Down
38 changes: 36 additions & 2 deletions tests/test_trade_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_initial_balance_log(self):
self.assertIsInstance(balance_log.time, datetime)
self.assertTrue(balance_log.total > 0)
self.assertTrue(balance_log.ln_local > 0)
self.assertEqual(balance_log.ln_local_unsettled, 0)
self.assertTrue(balance_log.ln_local_unsettled >= 0)
self.assertTrue(balance_log.ln_remote > 0)
self.assertEqual(balance_log.ln_remote_unsettled, 0)
self.assertTrue(balance_log.onchain_total > 0)
Expand Down Expand Up @@ -306,6 +306,15 @@ def cancel_order(self, order_id, robot_index=1):

return response

def pause_order(self, order_id, robot_index=1):
path = reverse("order")
params = f"?order_id={order_id}"
headers = self.get_robot_auth(robot_index)
body = {"action": "pause"}
response = self.client.post(path + params, body, **headers)

return response

def test_get_order_created(self):
"""
Tests the creation of an order and the first request to see details,
Expand Down Expand Up @@ -403,6 +412,31 @@ def test_publish_order(self):
# Cancel order to avoid leaving pending HTLCs after a successful test
self.cancel_order(data["id"])

def test_pause_unpause_order(self):
"""
Tests pausing and unpausing a public order
"""
maker_form = self.maker_form_buy_with_range
# Get order
response = self.make_and_publish_order(maker_form)

# PAUSE
response = self.pause_order(response.json()["id"])
data = response.json()

self.assertResponse(response)
self.assertEqual(data["status_message"], Order.Status(Order.Status.PAU).label)

# UNPAUSE
response = self.pause_order(response.json()["id"])
data = response.json()

self.assertResponse(response)
self.assertEqual(data["status_message"], Order.Status(Order.Status.PUB).label)

# Cancel order to avoid leaving pending HTLCs after a successful test
self.cancel_order(data["id"])

def take_order(self, order_id, amount, robot_index=2):
path = reverse("order")
params = f"?order_id={order_id}"
Expand Down Expand Up @@ -513,7 +547,7 @@ def test_make_and_lock_contract(self):

self.assertEqual(data["status_message"], Order.Status(Order.Status.WF2).label)
self.assertTrue(data["swap_allowed"])
self.assertIsInstance(data["suggested_mining_fee_rate"], int)
self.assertIsInstance(data["suggested_mining_fee_rate"], float)
self.assertIsInstance(data["swap_fee_rate"], float)
self.assertTrue(data["suggested_mining_fee_rate"] > 0)
self.assertTrue(data["swap_fee_rate"] > 0)
Expand Down

0 comments on commit 43c324f

Please sign in to comment.