forked from LBRYCommunity/lbry-sdk
fix LBRYExchangeRateManager test
This commit is contained in:
parent
52d954c64e
commit
5441379f38
2 changed files with 51 additions and 2 deletions
|
@ -148,3 +148,51 @@ class ExchangeRateManager(object):
|
||||||
'address': fee.address
|
'address': fee.address
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class DummyBTCLBCFeed(MarketFeed):
|
||||||
|
def __init__(self):
|
||||||
|
MarketFeed.__init__(
|
||||||
|
self,
|
||||||
|
"BTCLBC",
|
||||||
|
"market name",
|
||||||
|
"derp.com",
|
||||||
|
None,
|
||||||
|
0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DummyUSDBTCFeed(MarketFeed):
|
||||||
|
def __init__(self):
|
||||||
|
MarketFeed.__init__(
|
||||||
|
self,
|
||||||
|
"USDBTC",
|
||||||
|
"market name",
|
||||||
|
"derp.com",
|
||||||
|
None,
|
||||||
|
0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DummyExchangeRateManager(object):
|
||||||
|
def __init__(self, rates):
|
||||||
|
self.market_feeds = [DummyBTCLBCFeed(), DummyUSDBTCFeed()]
|
||||||
|
for feed in self.market_feeds:
|
||||||
|
feed.rate = rates[feed.market]
|
||||||
|
|
||||||
|
def convert_currency(self, from_currency, to_currency, amount):
|
||||||
|
log.info("Converting %f %s to %s" % (amount, from_currency, to_currency))
|
||||||
|
for market in self.market_feeds:
|
||||||
|
if market.rate.currency_pair == (from_currency, to_currency):
|
||||||
|
return amount * market.rate.spot
|
||||||
|
for market in self.market_feeds:
|
||||||
|
if market.rate.currency_pair[0] == from_currency:
|
||||||
|
return self.convert_currency(market.rate.currency_pair[1], to_currency, amount * market.rate.spot)
|
||||||
|
|
||||||
|
def to_lbc(self, fee):
|
||||||
|
return LBRYFeeValidator({fee.currency_symbol:
|
||||||
|
{
|
||||||
|
'amount': self.convert_currency(fee.currency_symbol, "LBC", fee.amount),
|
||||||
|
'address': fee.address
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,5 +1,6 @@
|
||||||
import mock
|
import mock
|
||||||
from lbrynet.core import LBRYMetadata
|
from lbrynet.core import LBRYMetadata
|
||||||
|
from lbrynet.lbrynet_daemon import LBRYExchangeRateManager
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
|
@ -33,8 +34,8 @@ class LBRYFeeTest(unittest.TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rates = {'BTCLBC': {'spot': 3.0, 'ts': 2}, 'USDBTC': {'spot': 2.0, 'ts': 3}}
|
rates = {'BTCLBC': {'spot': 3.0, 'ts': 2}, 'USDBTC': {'spot': 2.0, 'ts': 3}}
|
||||||
fee = LBRYMetadata.LBRYFee(fee_dict, rates, 0)
|
manager = LBRYExchangeRateManager.DummyExchangeRateManager(rates)
|
||||||
self.assertEqual(60.0, fee.to_lbc())
|
self.assertEqual(60.0, manager.to_lbc(fee_dict).amount)
|
||||||
|
|
||||||
|
|
||||||
class MetadataTest(unittest.TestCase):
|
class MetadataTest(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in a new issue