2022-07-15 10:09:54 +00:00
|
|
|
import logging
|
2022-02-09 09:01:18 +00:00
|
|
|
from unittest import TestCase
|
2022-04-19 20:02:39 +00:00
|
|
|
from unittest.mock import MagicMock
|
2022-07-15 10:09:54 +00:00
|
|
|
|
2022-05-05 17:16:56 +00:00
|
|
|
import lib.markets
|
2022-03-19 15:43:51 +00:00
|
|
|
import settings
|
2022-07-15 10:09:54 +00:00
|
|
|
from sources.agora import Agora
|
|
|
|
from tests.common import expected_to_update, fake_public_ads
|
2022-02-09 09:01:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestMarkets(TestCase):
|
|
|
|
def setUp(self):
|
2022-05-24 07:38:37 +00:00
|
|
|
logging.disable(logging.CRITICAL)
|
2022-05-05 17:16:56 +00:00
|
|
|
self.markets = lib.markets.Markets()
|
2022-02-09 09:01:18 +00:00
|
|
|
self.agora = Agora()
|
2022-04-19 20:02:39 +00:00
|
|
|
self.markets.sinks = MagicMock()
|
|
|
|
self.markets.sinks.currencies = [
|
|
|
|
"AUD",
|
|
|
|
"CAD",
|
|
|
|
"CHF",
|
|
|
|
"CZK",
|
|
|
|
"DKK",
|
|
|
|
"EUR",
|
|
|
|
"GBP",
|
|
|
|
"HKD",
|
|
|
|
"HUF",
|
|
|
|
"JPY",
|
|
|
|
"MXN",
|
|
|
|
"NOK",
|
|
|
|
"NZD",
|
|
|
|
"PLN",
|
|
|
|
"RUB",
|
|
|
|
"SEK",
|
|
|
|
"SGD",
|
|
|
|
"THB",
|
|
|
|
"TRY",
|
|
|
|
"USD",
|
|
|
|
"ZAR",
|
|
|
|
]
|
2022-02-09 09:01:18 +00:00
|
|
|
|
|
|
|
def test_autoprice(self):
|
|
|
|
ads = [
|
2022-04-12 21:06:28 +00:00
|
|
|
[
|
|
|
|
"2b6dba4d-c9db-48f2-adba-4dc9dba8f2a0",
|
|
|
|
"Xpoterlolipop",
|
|
|
|
"182.80",
|
2022-05-24 07:38:37 +00:00
|
|
|
"NATIONAL_BANK",
|
2022-04-12 21:06:28 +00:00
|
|
|
"XMR",
|
|
|
|
"USD",
|
|
|
|
1.18,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"57e3e8d6-45fe-40da-a3e8-d645fe20da46",
|
|
|
|
"SecureMole",
|
|
|
|
"183.26",
|
2022-05-24 07:38:37 +00:00
|
|
|
"NATIONAL_BANK",
|
2022-04-12 21:06:28 +00:00
|
|
|
"XMR",
|
|
|
|
"USD",
|
|
|
|
1.19,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"87af6467-be02-476e-af64-67be02676e9a",
|
|
|
|
"topmonero",
|
|
|
|
"183.42",
|
2022-05-24 07:38:37 +00:00
|
|
|
"NATIONAL_BANK",
|
2022-04-12 21:06:28 +00:00
|
|
|
"XMR",
|
|
|
|
"USD",
|
|
|
|
1.19,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"65b452e3-a29f-4233-b452-e3a29fe23369",
|
|
|
|
"topmonero",
|
|
|
|
"183.42",
|
2022-05-24 07:38:37 +00:00
|
|
|
"NATIONAL_BANK",
|
2022-04-12 21:06:28 +00:00
|
|
|
"XMR",
|
|
|
|
"USD",
|
|
|
|
1.19,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"d2c6645c-6d56-4094-8664-5c6d5640941b",
|
|
|
|
"topmonero",
|
|
|
|
"183.42",
|
2022-05-24 07:38:37 +00:00
|
|
|
"NATIONAL_BANK",
|
2022-04-12 21:06:28 +00:00
|
|
|
"XMR",
|
|
|
|
"USD",
|
|
|
|
1.19,
|
|
|
|
],
|
2022-02-09 09:01:18 +00:00
|
|
|
]
|
|
|
|
currency = "EUR"
|
2022-04-15 13:58:18 +00:00
|
|
|
margin = self.markets.autoprice("topmonero", 1.1, 1.3, ads, currency)
|
2022-02-09 09:01:18 +00:00
|
|
|
expected_margin = 1.18
|
|
|
|
self.assertEqual(margin, expected_margin)
|
|
|
|
|
|
|
|
def test_get_new_ad_equation(self):
|
2022-05-24 07:38:37 +00:00
|
|
|
self.maxDiff = None
|
|
|
|
settings.settings.Agora.MinMargin = 1.17
|
|
|
|
settings.settings.Agora.MaxMargin = 1.3
|
|
|
|
# 437 should be 1.3 but is 1.21
|
2022-04-15 13:53:39 +00:00
|
|
|
to_update = self.markets.get_new_ad_equations("agora", fake_public_ads)
|
2022-02-09 09:01:18 +00:00
|
|
|
self.assertCountEqual(to_update, expected_to_update)
|
2022-04-15 13:53:39 +00:00
|
|
|
res_xmr = self.markets.get_new_ad_equations("agora", fake_public_ads, ["XMR"])
|
2022-02-09 09:01:18 +00:00
|
|
|
expected_xmr_to_update = [x for x in expected_to_update if x[2] == "XMR"]
|
|
|
|
self.assertCountEqual(res_xmr, expected_xmr_to_update)
|
|
|
|
|
2022-04-15 13:53:39 +00:00
|
|
|
res_btc = self.markets.get_new_ad_equations("agora", fake_public_ads, ["BTC"])
|
2022-02-09 09:01:18 +00:00
|
|
|
expected_btc_to_update = [x for x in expected_to_update if x[2] == "BTC"]
|
|
|
|
self.assertCountEqual(res_btc, expected_btc_to_update)
|
|
|
|
|
2022-07-15 10:09:54 +00:00
|
|
|
res_both = self.markets.get_new_ad_equations(
|
|
|
|
"agora", fake_public_ads, ["XMR", "BTC"]
|
|
|
|
)
|
2022-02-09 09:01:18 +00:00
|
|
|
self.assertCountEqual(res_both, expected_to_update)
|
2022-03-19 15:43:51 +00:00
|
|
|
|
|
|
|
def test_format_ad(self):
|
|
|
|
settings.settings.Platform.Ad = """* Set **Country of recipient's bank** to **"United Kingdom"**
|
|
|
|
$PAYMENT$
|
|
|
|
* Set **Company name** to **"PATHOGEN LIMITED"**"""
|
2022-04-12 21:06:28 +00:00
|
|
|
payment_details = {
|
|
|
|
"sort_code": "02-03-04",
|
|
|
|
"account_number": "0023-0045",
|
|
|
|
}
|
2022-07-15 10:09:54 +00:00
|
|
|
payment_details_text = self.markets.format_payment_details(
|
|
|
|
"GBP", payment_details
|
|
|
|
)
|
2022-03-19 15:43:51 +00:00
|
|
|
ad_text = self.markets.format_ad("XMR", "GBP", payment_details_text)
|
|
|
|
expected = """* Set **Country of recipient's bank** to **"United Kingdom"**
|
2022-04-23 14:02:01 +00:00
|
|
|
Payment details will be released after verification has passed.
|
|
|
|
If you've already completed verification, they will be sent immediately.
|
2022-03-19 15:43:51 +00:00
|
|
|
* Set **Company name** to **"PATHOGEN LIMITED"**"""
|
2022-03-24 20:24:35 +00:00
|
|
|
|
2022-03-19 15:43:51 +00:00
|
|
|
self.assertEqual(ad_text, expected)
|
|
|
|
|
|
|
|
def test_format_payment_details(self):
|
2022-04-12 21:06:28 +00:00
|
|
|
payment_details = {
|
|
|
|
"sort_code": "02-03-04",
|
|
|
|
"account_number": "0023-0045",
|
|
|
|
}
|
2022-07-15 10:09:54 +00:00
|
|
|
payment_details_text = self.markets.format_payment_details(
|
|
|
|
"GBP", payment_details
|
|
|
|
)
|
2022-03-19 15:43:51 +00:00
|
|
|
|
2022-04-23 14:02:01 +00:00
|
|
|
expected = """Payment details will be released after verification has passed.
|
|
|
|
If you've already completed verification, they will be sent immediately."""
|
2022-03-19 15:43:51 +00:00
|
|
|
self.assertEqual(payment_details_text, expected)
|
2022-04-23 14:02:01 +00:00
|
|
|
|
|
|
|
expected_real = """* Sort code: **02-03-04**
|
|
|
|
* Account number: **0023-0045**
|
|
|
|
Please send in GBP."""
|
2022-07-15 10:09:54 +00:00
|
|
|
payment_details_text_real = self.markets.format_payment_details(
|
|
|
|
"GBP", payment_details, real=True
|
|
|
|
)
|
2022-04-23 14:02:01 +00:00
|
|
|
self.assertEqual(payment_details_text_real, expected_real)
|