forked from LBRYCommunity/lbry-sdk
unittest
This commit is contained in:
parent
f1cb7d27ac
commit
fb25ecb4a1
1 changed files with 8 additions and 47 deletions
|
@ -4,9 +4,8 @@ from time import time
|
||||||
from lbry.schema.claim import Claim
|
from lbry.schema.claim import Claim
|
||||||
from lbry.extras.daemon.exchange_rate_manager import (
|
from lbry.extras.daemon.exchange_rate_manager import (
|
||||||
ExchangeRate, ExchangeRateManager, CurrencyConversionError,
|
ExchangeRate, ExchangeRateManager, CurrencyConversionError,
|
||||||
LBRYFeed, LBRYBTCFeed,
|
CryptonatorUSDFeed, CryptonatorBTCFeed,
|
||||||
CryptonatorFeed, CryptonatorBTCFeed,
|
BittrexUSDFeed, BittrexBTCFeed
|
||||||
BittrexFeed,
|
|
||||||
)
|
)
|
||||||
from lbry.testcase import AsyncioTestCase, FakeExchangeRateManager, get_fake_exchange_rate_manager
|
from lbry.testcase import AsyncioTestCase, FakeExchangeRateManager, get_fake_exchange_rate_manager
|
||||||
from lbry.error import InvalidExchangeRateResponseError
|
from lbry.error import InvalidExchangeRateResponseError
|
||||||
|
@ -26,59 +25,21 @@ class ExchangeRateTests(AsyncioTestCase):
|
||||||
fee.address = "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
fee.address = "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
||||||
manager = get_fake_exchange_rate_manager()
|
manager = get_fake_exchange_rate_manager()
|
||||||
result = manager.convert_currency(fee.currency, "LBC", fee.amount)
|
result = manager.convert_currency(fee.currency, "LBC", fee.amount)
|
||||||
self.assertEqual(60.0, result)
|
self.assertEqual(20.0, result)
|
||||||
|
|
||||||
def test_missing_feed(self):
|
def test_missing_feed(self):
|
||||||
fee = Claim().stream.fee
|
fee = Claim().stream.fee
|
||||||
fee.usd = Decimal(1.0)
|
fee.usd = Decimal(1.0)
|
||||||
fee.address = "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
fee.address = "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9"
|
||||||
manager = FakeExchangeRateManager([LBRYFeed()], {'BTCLBC': 1.0})
|
manager = FakeExchangeRateManager([BittrexBTCFeed()], {'BTCLBC': 1.0})
|
||||||
with self.assertRaises(CurrencyConversionError):
|
with self.assertRaises(CurrencyConversionError):
|
||||||
manager.convert_currency(fee.currency, "LBC", fee.amount)
|
manager.convert_currency(fee.currency, "LBC", fee.amount)
|
||||||
|
|
||||||
def test_lbry_feed_response(self):
|
|
||||||
feed = LBRYFeed()
|
|
||||||
out = feed.get_rate_from_response({
|
|
||||||
'data': {
|
|
||||||
'fresh': 0, 'lbc_usd': 0.05863062523378918,
|
|
||||||
'lbc_btc': 5.065289549855739e-05, 'btc_usd': 1157.498
|
|
||||||
},
|
|
||||||
'success': True,
|
|
||||||
'error': None
|
|
||||||
})
|
|
||||||
self.assertEqual(1.0 / 5.065289549855739e-05, out)
|
|
||||||
with self.assertRaises(InvalidExchangeRateResponseError):
|
|
||||||
feed.get_rate_from_response({})
|
|
||||||
with self.assertRaises(InvalidExchangeRateResponseError):
|
|
||||||
feed.get_rate_from_response({
|
|
||||||
"success": True,
|
|
||||||
"result": []
|
|
||||||
})
|
|
||||||
|
|
||||||
def test_lbry_btc_feed_response(self):
|
|
||||||
feed = LBRYBTCFeed()
|
|
||||||
out = feed.get_rate_from_response({
|
|
||||||
'data': {
|
|
||||||
'fresh': 0, 'lbc_usd': 0.05863062523378918,
|
|
||||||
'lbc_btc': 5.065289549855739e-05, 'btc_usd': 1157.498
|
|
||||||
},
|
|
||||||
'success': True,
|
|
||||||
'error': None
|
|
||||||
})
|
|
||||||
self.assertEqual(1.0 / 1157.498, out)
|
|
||||||
with self.assertRaises(InvalidExchangeRateResponseError):
|
|
||||||
feed.get_rate_from_response({})
|
|
||||||
with self.assertRaises(InvalidExchangeRateResponseError):
|
|
||||||
feed.get_rate_from_response({
|
|
||||||
"success": True,
|
|
||||||
"result": {}
|
|
||||||
})
|
|
||||||
|
|
||||||
def test_cryptonator_lbc_feed_response(self):
|
def test_cryptonator_lbc_feed_response(self):
|
||||||
feed = CryptonatorFeed()
|
feed = CryptonatorUSDFeed()
|
||||||
out = feed.get_rate_from_response({
|
out = feed.get_rate_from_response({
|
||||||
'ticker': {
|
'ticker': {
|
||||||
'base': 'BTC', 'target': 'LBC', 'price': 23657.44026496,
|
'base': 'USD', 'target': 'LBC', 'price': 23657.44026496,
|
||||||
'volume': '', 'change': -5.59806916,
|
'volume': '', 'change': -5.59806916,
|
||||||
},
|
},
|
||||||
'timestamp': 1507470422,
|
'timestamp': 1507470422,
|
||||||
|
@ -115,7 +76,7 @@ class ExchangeRateTests(AsyncioTestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
def test_bittrex_feed_response(self):
|
def test_bittrex_feed_response(self):
|
||||||
feed = BittrexFeed()
|
feed = BittrexBTCFeed()
|
||||||
out = feed.get_rate_from_response({
|
out = feed.get_rate_from_response({
|
||||||
"symbol": "LBC-BTC",
|
"symbol": "LBC-BTC",
|
||||||
"lastTradeRate": "0.00000323",
|
"lastTradeRate": "0.00000323",
|
||||||
|
@ -132,7 +93,7 @@ class ExchangeRateTests(AsyncioTestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
class BadMarketFeed(LBRYFeed):
|
class BadMarketFeed(BittrexUSDFeed):
|
||||||
|
|
||||||
def get_response(self):
|
def get_response(self):
|
||||||
raise InvalidExchangeRateResponseError(self.name, 'bad stuff')
|
raise InvalidExchangeRateResponseError(self.name, 'bad stuff')
|
||||||
|
|
Loading…
Reference in a new issue