From 33a01d2bfff22c3f86b91b46f2ce94bb4c5e94a1 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 29 Apr 2024 23:35:52 +0100 Subject: [PATCH] Add bad location tests --- .env-sample | 5 +++-- api/logics.py | 1 - tests/test_trade_pipeline.py | 32 ++++++++++++++++++++++++++++++++ tests/utils/trade.py | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/.env-sample b/.env-sample index 40ea92b4..66841738 100644 --- a/.env-sample +++ b/.env-sample @@ -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' diff --git a/api/logics.py b/api/logics.py index 8ba9ba33..06d402ba 100644 --- a/api/logics.py +++ b/api/logics.py @@ -145,7 +145,6 @@ class Logics: 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}" diff --git a/tests/test_trade_pipeline.py b/tests/test_trade_pipeline.py index 4205b98c..32a39c9e 100644 --- a/tests/test_trade_pipeline.py +++ b/tests/test_trade_pipeline.py @@ -239,6 +239,38 @@ class TradeTest(BaseAPITestCase): 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, diff --git a/tests/utils/trade.py b/tests/utils/trade.py index b00d0ae7..16b9b89d 100644 --- a/tests/utils/trade.py +++ b/tests/utils/trade.py @@ -98,8 +98,8 @@ class Trade: 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):