def source_fee(self): claim = self.protobuf if not CLAIM_TYPE_NAMES[claim.claimType] == "stream": return None if claim.stream.metadata.HasField("fee"): return Fee.load_protobuf(claim.stream.metadata.fee) return None
def test_fee_zero(self): fee_dict = { 'currency': 'LBC', 'amount': 0.0, 'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9" } fee = Fee(fee_dict) self.assertEqual(0.0, fee['amount']) self.assertEqual('LBC', fee['currency'])
def test_fee_created_with_correct_inputs(self): fee_dict = { 'currency': 'USD', 'amount': 10.0, 'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9" } fee = Fee(fee_dict) self.assertEqual(10.0, fee['amount']) self.assertEqual('USD', fee['currency'])
def check_fee_and_convert(self, fee): max_key_fee_amount = self.convert_max_fee() converted_fee_amount = self.exchange_rate_manager.convert_currency(fee.currency, "LBC", fee.amount) if converted_fee_amount > self.wallet.get_balance(): raise InsufficientFundsError('Unable to pay the key fee of %s' % converted_fee_amount) if converted_fee_amount > max_key_fee_amount: raise KeyFeeAboveMaxAllowed('Key fee %s above max allowed %s' % (converted_fee_amount, max_key_fee_amount)) converted_fee = { 'currency': 'LBC', 'amount': converted_fee_amount, 'address': fee.address } return Fee(converted_fee)
def test_missing_feed(self): # test when a feed is missing for conversion fee = Fee({ 'currency':'USD', 'amount': 1.0, 'address': "bRcHraa8bYJZL7vkh5sNmGwPDERFUjGPP9" }) rates = { 'BTCLBC': {'spot': 1.0, 'ts': util.DEFAULT_ISO_TIME + 1}, } market_feeds = [BTCLBCFeed()] manager = DummyExchangeRateManager(market_feeds, rates) with self.assertRaises(Exception): manager.convert_currency(fee.currency, "LBC", fee.amount)
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 check_fee_and_convert(self, fee): max_key_fee_amount = self.convert_max_fee() converted_fee_amount = self.exchange_rate_manager.convert_currency( fee.currency, "LBC", fee.amount) if converted_fee_amount > (yield f2d( self.wallet.default_account.get_balance())): raise InsufficientFundsError('Unable to pay the key fee of %s' % converted_fee_amount) if converted_fee_amount > max_key_fee_amount and not self.disable_max_key_fee: raise KeyFeeAboveMaxAllowed( 'Key fee {} above max allowed {}'.format( converted_fee_amount, max_key_fee_amount)) converted_fee = { 'currency': 'LBC', 'amount': converted_fee_amount, 'address': fee.address } return Fee(converted_fee)