def get_test_daemon(data_rate=None, generous=True, with_fee=False): if data_rate is None: data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1] rates = { 'BTCLBC': { 'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1 }, 'USDBTC': { 'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2 } } daemon = LBRYDaemon(None) daemon.session = mock.Mock(spec=Session.Session) daemon.session.wallet = mock.Mock(spec=Wallet.LBRYumWallet) market_feeds = [BTCLBCFeed(), USDBTCFeed()] daemon.exchange_rate_manager = DummyExchangeRateManager( market_feeds, rates) base_prm = PaymentRateManager.BasePaymentRateManager(rate=data_rate) prm = PaymentRateManager.NegotiatedPaymentRateManager( base_prm, DummyBlobAvailabilityTracker(), generous=generous) daemon.session.payment_rate_manager = prm metadata = { "author": "fake author", "language": "en", "content_type": "fake/format", "description": "fake description", "license": "fake license", "license_url": "fake license url", "nsfw": False, "sources": { "lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98' 'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280' }, "thumbnail": "fake thumbnail", "title": "fake title", "ver": "0.0.3" } if with_fee: metadata.update({ "fee": { "USD": { "address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75 } } }) daemon._resolve_name = lambda _: defer.succeed(metadata) migrated = smart_decode(json.dumps(metadata)) daemon.session.wallet.resolve = lambda *_: defer.succeed( {"test": { 'claim': { 'value': migrated.claim_dict } }}) return daemon
def test_fee_converts_to_lbc(self): fee = Fee({ 'currency': 'USD', 'amount': 10.0, 'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9" }) rates = { 'BTCLBC': {'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1}, 'USDBTC': {'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2} } market_feeds = [BTCLBCFeed(), USDBTCFeed()] manager = DummyExchangeRateManager(market_feeds, rates) result = manager.convert_currency(fee.currency, "LBC", fee.amount) self.assertEqual(60.0, result)
def get_test_daemon(data_rate=None, generous=True, with_fee=False): if data_rate is None: data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1] rates = { 'BTCLBC': { 'spot': 3.0, 'ts': util.DEFAULT_ISO_TIME + 1 }, 'USDBTC': { 'spot': 2.0, 'ts': util.DEFAULT_ISO_TIME + 2 } } component_manager = ComponentManager(skip_components=[ DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT, UPNP_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, HASH_ANNOUNCER_COMPONENT, STREAM_IDENTIFIER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT, BLOB_COMPONENT, HEADERS_COMPONENT, RATE_LIMITER_COMPONENT ], file_manager=FakeFileManager) daemon = LBRYDaemon(component_manager=component_manager) daemon.payment_rate_manager = OnlyFreePaymentsManager() daemon.wallet = mock.Mock(spec=Wallet.LBRYumWallet) daemon.wallet.wallet = mock.Mock(spec=NewWallet) daemon.wallet.wallet.use_encryption = False daemon.wallet.network = FakeNetwork() daemon.storage = mock.Mock(spec=SQLiteStorage) market_feeds = [BTCLBCFeed(), USDBTCFeed()] daemon.exchange_rate_manager = DummyExchangeRateManager( market_feeds, rates) daemon.file_manager = component_manager.get_component( FILE_MANAGER_COMPONENT) metadata = { "author": "fake author", "language": "en", "content_type": "fake/format", "description": "fake description", "license": "fake license", "license_url": "fake license url", "nsfw": False, "sources": { "lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98' 'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280' }, "thumbnail": "fake thumbnail", "title": "fake title", "ver": "0.0.3" } if with_fee: metadata.update({ "fee": { "USD": { "address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75 } } }) daemon._resolve_name = lambda _: defer.succeed(metadata) migrated = smart_decode(json.dumps(metadata)) daemon.wallet.resolve = lambda *_: defer.succeed( {"test": { 'claim': { 'value': migrated.claim_dict } }}) return daemon