Libraries refactor and add some sinks #4
|
@ -731,22 +731,31 @@ fake_public_ads = {
|
||||||
|
|
||||||
|
|
||||||
expected_to_update = [
|
expected_to_update = [
|
||||||
["fb04a8e2-3c69-45f3-84a8-e23c6975f380", "coingeckoxmrusd*usdchf*1.3", "XMR", "CHF", False],
|
["2caa4afa-a1c7-4683-aa4a-faa1c7a683dc", "coingeckoxmrusd*usdrub*1.3", "XMR", "RUB", False],
|
||||||
["bf12756b-0138-49ca-9275-6b0138f9caf1", "coingeckoxmrusd*usdmxn*1.3", "XMR", "MXN", False],
|
["dd1148de-ba6e-4824-9148-deba6e8824e0", "coingeckoxmrusd*usdhkd*1.3", "XMR", "HKD", False],
|
||||||
["ef1455dc-4629-4827-9455-dc46291827f0", "coingeckoxmrusd*usddkk*1.3", "XMR", "DKK", False],
|
["929450a0-9a86-4133-9450-a09a86613363", "coingeckoxmrusd*usdtry*1.3", "XMR", "TRY", False],
|
||||||
["388442b4-0cb7-48f3-8442-b40cb7f8f39d", "coingeckoxmrusd*usdcad*1.3", "XMR", "CAD", False],
|
["262f54e5-faa1-4656-af54-e5faa106569e", "coingeckoxmrusd*usdgbp*1.1462", "XMR", "GBP", False],
|
||||||
["b5be2881-4491-4a60-be28-814491ca606a", "coingeckoxmrusd*usdpln*1.3", "XMR", "PLN", False],
|
["71911d6a-ef24-4b8a-911d-6aef24fb8a42", "coingeckoxmrusd*usdgbp*1.1462", "XMR", "GBP", False],
|
||||||
["3c5068ce-fcf9-40cc-9068-cefcf920cc02", "coingeckoxmrusd*usdtry*1.3", "XMR", "TRY", False],
|
["47c3d48b-385c-4d48-83d4-8b385c3d48d8", "coingeckoxmrusd*usdnok*1.3", "XMR", "NOK", False],
|
||||||
["b23aa3b3-4c91-42e4-baa3-b34c9162e4e0", "coingeckoxmrusd*usdhkd*1.3", "XMR", "HKD", False],
|
["1f48b508-cdd9-4e49-88b5-08cdd99e49c2", "coingeckoxmrusd*usdnzd*1.3", "XMR", "NZD", False],
|
||||||
["f886768f-b9c9-4cf7-8676-8fb9c9ccf7ee", "coingeckoxmrusd*usdhuf*1.3", "XMR", "HUF", False],
|
["2a769b75-6408-4823-b69b-75640828231b", "coingeckoxmrusd*usdhuf*1.3", "XMR", "HUF", False],
|
||||||
["0addd244-c5cb-40bf-9dd2-44c5cbd0bff4", "coingeckoxmrusd*usdnzd*1.3", "XMR", "NZD", False],
|
["2bcfb7a6-7ba6-4ea5-8fb7-a67ba69ea59f", "coingeckoxmrusd*usdchf*1.3", "XMR", "CHF", False],
|
||||||
["24a9cad1-0bce-46f3-a9ca-d10bce86f34f", "coingeckoxmrusd*usdrub*1.3", "XMR", "RUB", False],
|
["3bc93ad9-bc51-4939-893a-d9bc51e9395a", "coingeckoxmrusd*usdczk*1.3", "XMR", "CZK", False],
|
||||||
["80aa52ef-a5d3-462c-aa52-efa5d3862cbe", "coingeckoxmrusd*usdczk*1.3", "XMR", "CZK", False],
|
["f3663e72-12e1-4b87-a63e-7212e1ab87b0", "coingeckoxmrusd*usdpln*1.3", "XMR", "PLN", False],
|
||||||
["ac9eb9c8-88c7-4add-9eb9-c888c72addb2", "coingeckoxmrusd*usdsgd*1.3", "XMR", "SGD", False],
|
["8577c575-42d1-4ebc-b7c5-7542d17ebc82", "coingeckoxmrusd*usdjpy*1.3", "XMR", "JPY", False],
|
||||||
["68b50d95-91d2-4f21-b50d-9591d22f218d", "coingeckoxmrusd*usdaud*1.3", "XMR", "AUD", False],
|
["82423582-fe58-432d-8235-82fe58f32d0f", "coingeckoxmrusd*usdthb*1.3", "XMR", "THB", False],
|
||||||
["b048bad8-3aaa-4727-88ba-d83aaa1727b6", "coingeckoxmrusd*usdjpy*1.3", "XMR", "JPY", False],
|
["5223d44f-b620-42a5-a3d4-4fb620c2a530", "coingeckoxmrusd*usdsek*1.2208", "XMR", "SEK", False],
|
||||||
["9c3d9fb6-c74c-4a35-bd9f-b6c74c7a3504", "coingeckoxmrusd*usdnok*1.3", "XMR", "NOK", False],
|
["2f767f92-f1bd-4e3e-b67f-92f1bd2e3ed8", "coingeckoxmrusd*usdusd*1.1161", "XMR", "USD", False],
|
||||||
["9a7bd726-6229-4fda-bbd7-2662295fda98", "coingeckoxmrusd*usdthb*1.3", "XMR", "THB", False],
|
["6ca63cef-783b-40cd-a63c-ef783b90cdc7", "coingeckoxmrusd*usdusd*1.1161", "XMR", "USD", False],
|
||||||
|
["2db9190b-7f46-41cd-b919-0b7f4661cd9e", "coingeckoxmrusd*usdcad*1.3", "XMR", "CAD", False],
|
||||||
|
["f035c709-31f9-4c2b-b5c7-0931f9bc2b20", "coingeckoxmrusd*usdsgd*1.3", "XMR", "SGD", False],
|
||||||
|
["64cdcaca-0f61-4139-8dca-ca0f61e1390f", "coingeckoxmrusd*usdmxn*1.3", "XMR", "MXN", False],
|
||||||
|
["0f3fe35f-808f-4bae-bfe3-5f808ffbaee7", "coingeckoxmrusd*usdaud*1.2554", "XMR", "AUD", False],
|
||||||
|
["7034f552-271f-4f88-b4f5-52271f4f8839", "coingeckoxmrusd*usdeur*1.1795", "XMR", "EUR", False],
|
||||||
|
["3359fcab-4e02-4ea0-99fc-ab4e024ea0da", "coingeckoxmrusd*usdeur*1.1795", "XMR", "EUR", False],
|
||||||
|
["f70b6711-5b7e-4c5c-8b67-115b7e3c5c7a", "coingeckoxmrusd*usdeur*1.1795", "XMR", "EUR", False],
|
||||||
|
["473a3803-701d-45ee-ba38-03701dc5ee4d", "coingeckoxmrusd*usddkk*1.3", "XMR", "DKK", False],
|
||||||
|
["7b93d58b-7721-45be-93d5-8b772115bed3", "coingeckoxmrusd*usdzar*1.3", "XMR", "ZAR", False],
|
||||||
]
|
]
|
||||||
|
|
||||||
cg_prices = {
|
cg_prices = {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
from json import loads
|
from json import loads
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from tests.common import fake_public_ads, cg_prices, expected_to_update
|
from tests.common import fake_public_ads, cg_prices, expected_to_update
|
||||||
from agora import Agora
|
from agora import Agora
|
||||||
|
@ -89,7 +90,6 @@ class TestAgora(TestCase):
|
||||||
self.agora.markets.get_all_providers.return_value = self.all_providers
|
self.agora.markets.get_all_providers.return_value = self.all_providers
|
||||||
|
|
||||||
public_ads = self.agora.get_all_public_ads()
|
public_ads = self.agora.get_all_public_ads()
|
||||||
# print("PUBADS", public_ads)
|
|
||||||
self.assertDictEqual(public_ads, fake_public_ads)
|
self.assertDictEqual(public_ads, fake_public_ads)
|
||||||
|
|
||||||
for currency, ads in public_ads.items():
|
for currency, ads in public_ads.items():
|
||||||
|
@ -100,7 +100,6 @@ class TestAgora(TestCase):
|
||||||
|
|
||||||
@patch("twisted.internet.threads.deferToThread")
|
@patch("twisted.internet.threads.deferToThread")
|
||||||
def test_run_cheat_in_thread(self, defer):
|
def test_run_cheat_in_thread(self, defer):
|
||||||
return # TODO: FIX
|
|
||||||
asset1 = self.agora.run_cheat_in_thread()
|
asset1 = self.agora.run_cheat_in_thread()
|
||||||
|
|
||||||
asset2 = self.agora.run_cheat_in_thread()
|
asset2 = self.agora.run_cheat_in_thread()
|
||||||
|
@ -116,10 +115,14 @@ class TestAgora(TestCase):
|
||||||
self.assertNotEqual(asset3, asset4)
|
self.assertNotEqual(asset3, asset4)
|
||||||
|
|
||||||
def test_update_prices(self):
|
def test_update_prices(self):
|
||||||
return # TODO: FIX
|
# Override enum_public_ads
|
||||||
|
self.agora.agora._api_call = self.mock_enum_public_ads_api_call
|
||||||
|
self.agora.last_online_recent = MagicMock()
|
||||||
|
self.agora.last_online_recent.return_value = True
|
||||||
|
|
||||||
|
# Override get_price
|
||||||
self.agora.cg.get_price = MagicMock()
|
self.agora.cg.get_price = MagicMock()
|
||||||
self.agora.cg.get_price.return_value = cg_prices
|
self.agora.cg.get_price.return_value = cg_prices
|
||||||
self.agora.wrap_public_ads = self.mock_wrap_public_ads
|
|
||||||
|
|
||||||
self.agora.slow_ad_update = MagicMock()
|
self.agora.slow_ad_update = MagicMock()
|
||||||
self.agora.update_prices()
|
self.agora.update_prices()
|
||||||
|
@ -168,5 +171,25 @@ class TestAgora(TestCase):
|
||||||
self.assertEqual(len(ad_ids), len(ad_ids_dedup))
|
self.assertEqual(len(ad_ids), len(ad_ids_dedup))
|
||||||
|
|
||||||
def test_lookup_rates(self):
|
def test_lookup_rates(self):
|
||||||
# print("lookup rates ran")
|
# Override enum_public_ads
|
||||||
pass
|
self.agora.agora._api_call = self.mock_enum_public_ads_api_call
|
||||||
|
self.agora.last_online_recent = MagicMock()
|
||||||
|
self.agora.last_online_recent.return_value = True
|
||||||
|
|
||||||
|
# Override get_price
|
||||||
|
self.agora.cg.get_price = MagicMock()
|
||||||
|
self.agora.cg.get_price.return_value = cg_prices
|
||||||
|
|
||||||
|
enum_ads_return = self.agora.enum_public_ads("XMR", "USD", self.all_providers)
|
||||||
|
|
||||||
|
expected_return = []
|
||||||
|
# Let's manually calculate what it's supposed to look like
|
||||||
|
price_xmr = cg_prices["monero"]["usd"]
|
||||||
|
for ad in deepcopy(enum_ads_return):
|
||||||
|
price = float(ad[2])
|
||||||
|
margin = round(price / price_xmr, 4)
|
||||||
|
ad.append(margin)
|
||||||
|
expected_return.append(ad)
|
||||||
|
|
||||||
|
lookup_rates_return = self.agora.lookup_rates(enum_ads_return)
|
||||||
|
self.assertCountEqual(lookup_rates_return, expected_return)
|
||||||
|
|
|
@ -11,11 +11,11 @@ class TestMarkets(TestCase):
|
||||||
|
|
||||||
def test_autoprice(self):
|
def test_autoprice(self):
|
||||||
ads = [
|
ads = [
|
||||||
["2b6dba4d-c9db-48f2-adba-4dc9dba8f2a0", "Xpoterlolipop", "182.80", "REVOLUT", "XMR", 1.18],
|
["2b6dba4d-c9db-48f2-adba-4dc9dba8f2a0", "Xpoterlolipop", "182.80", "REVOLUT", "XMR", "USD", 1.18],
|
||||||
["57e3e8d6-45fe-40da-a3e8-d645fe20da46", "SecureMole", "183.26", "REVOLUT", "XMR", 1.19],
|
["57e3e8d6-45fe-40da-a3e8-d645fe20da46", "SecureMole", "183.26", "REVOLUT", "XMR", "USD", 1.19],
|
||||||
["87af6467-be02-476e-af64-67be02676e9a", "topmonero", "183.42", "REVOLUT", "XMR", 1.19],
|
["87af6467-be02-476e-af64-67be02676e9a", "topmonero", "183.42", "REVOLUT", "XMR", "USD", 1.19],
|
||||||
["65b452e3-a29f-4233-b452-e3a29fe23369", "topmonero", "183.42", "REVOLUT", "XMR", 1.19],
|
["65b452e3-a29f-4233-b452-e3a29fe23369", "topmonero", "183.42", "REVOLUT", "XMR", "USD", 1.19],
|
||||||
["d2c6645c-6d56-4094-8664-5c6d5640941b", "topmonero", "183.42", "REVOLUT", "XMR", 1.19],
|
["d2c6645c-6d56-4094-8664-5c6d5640941b", "topmonero", "183.42", "REVOLUT", "XMR", "USD", 1.19],
|
||||||
]
|
]
|
||||||
currency = "EUR"
|
currency = "EUR"
|
||||||
margin = self.markets.autoprice(ads, currency)
|
margin = self.markets.autoprice(ads, currency)
|
||||||
|
|
Loading…
Reference in New Issue