Skip to content

Commit

Permalink
Add bad location tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Reckless-Satoshi committed Apr 29, 2024
1 parent eec1bcb commit 33a01d2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ ONION_LOCATION = ''

# Geoblocked countries (will reject F2F trades).
# List of A3 country codes (see fhttps://en.wikipedia.org/wiki/ISO_3166-1_alpha-3)
# Example 'NOR,USA,CZE'
GEOBLOCKED_COUNTRIES = 'NOR,USA,CZE'
# Leave empty '' to allow all countries.
# Example 'NOR,USA,CZE'.
GEOBLOCKED_COUNTRIES = 'ABW,AFG,AGO'

# Link to robosats alternative site (shown in frontend in statsfornerds so users can switch mainnet/testnet)
ALTERNATIVE_SITE = 'RoboSats6tkf3eva7x2voqso3a5wcorsnw34jveyxfqi2fu7oyheasid.onion'
Expand Down
1 change: 0 additions & 1 deletion api/logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ def validate_location(cls, order) -> bool:
return True, None

country = location_country(order.longitude, order.latitude)
print(country, "COUNTRYYY")
if country in GEOBLOCKED_COUNTRIES:
return False, {
"bad_request": f"The coordinator does not support orders in {country}"
Expand Down
32 changes: 32 additions & 0 deletions tests/test_trade_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,38 @@ def test_make_order(self):
self.assertIsNone(data["taker"], "New order's taker is not null")
self.assert_order_logs(data["id"])

def test_make_order_on_blocked_country(self):
"""
Test the creation of an F2F order on a geoblocked location
"""
trade = Trade(
self.client,
# latitude and longitud in Aruba. One of the countries blocked in the example conf.
maker_form={
"type": 0,
"currency": 1,
"has_range": True,
"min_amount": 21,
"max_amount": 101.7,
"payment_method": "Advcash Cash F2F",
"is_explicit": False,
"premium": 3.34,
"public_duration": 69360,
"escrow_duration": 8700,
"bond_size": 3.5,
"latitude": -11.8014, # Angola AGO
"longitude": 17.3575,
},
) # init of Trade calls make_order() with the default maker form.
data = trade.response.json()

self.assertEqual(trade.response.status_code, 400)
self.assertResponse(trade.response)

self.assertEqual(
data["bad_request"], "The coordinator does not support orders in AGO"
)

def test_get_order_created(self):
"""
Tests the creation of an order and the first request to see details,
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/trade.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def make_order(self, maker_form, robot_index=1):

response = self.client.post(path, maker_form, **headers)

self.response = response
if response.status_code == 201:
self.response = response
self.order_id = response.json()["id"]

def get_order(self, robot_index=1, first_encounter=False):
Expand Down

0 comments on commit 33a01d2

Please sign in to comment.