cover more edge cases, add tests
This commit is contained in:
parent
54e53932bd
commit
5876d5c295
4 changed files with 49 additions and 4 deletions
|
@ -2609,8 +2609,16 @@ class Daemon(metaclass=JSONRPCServerType):
|
|||
elif old_txo.claim.is_signed and not clear_channel and not replace:
|
||||
channel = old_txo.channel
|
||||
|
||||
if 'fee_amount' in kwargs:
|
||||
kwargs['fee_address'] = self.get_fee_address(kwargs, old_txo.claim.stream.fee.address or claim_address)
|
||||
fee_address = self.get_fee_address(kwargs, old_txo.claim.stream.fee.address or claim_address)
|
||||
if fee_address:
|
||||
kwargs['fee_address'] = fee_address
|
||||
kwargs['fee_currency'] = kwargs.get('fee_currency', old_txo.claim.stream.fee.currency if not replace else None)
|
||||
kwargs['fee_amount'] = kwargs.get('fee_amount', old_txo.claim.stream.fee.amount if not replace else None)
|
||||
valid_currency = kwargs['fee_currency'] if kwargs['fee_currency'] != 'UNKNOWN_CURRENCY' else None
|
||||
if kwargs.get('fee_amount') and not valid_currency:
|
||||
raise Exception('In order to set a fee amount, please specify a fee currency')
|
||||
if valid_currency and not kwargs.get('fee_amount'):
|
||||
raise Exception('In order to set a fee currency, please specify a fee amount')
|
||||
|
||||
if replace:
|
||||
claim = Claim()
|
||||
|
|
|
@ -206,6 +206,8 @@ class Stream(BaseClaim):
|
|||
|
||||
def update(self, file_path=None, height=None, width=None, duration=None, **kwargs):
|
||||
if kwargs.pop('clear_fee', False):
|
||||
# clear_fee is set, ignore defaults
|
||||
kwargs.pop('fee_address', None), kwargs.pop('fee_currency', None), kwargs.pop('fee_amount', None)
|
||||
self.message.ClearField('fee')
|
||||
else:
|
||||
self.fee.update(
|
||||
|
|
|
@ -2,6 +2,7 @@ import os.path
|
|||
import tempfile
|
||||
import logging
|
||||
from binascii import unhexlify
|
||||
from copy import deepcopy
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
|
@ -705,6 +706,39 @@ class StreamCommands(ClaimTestCase):
|
|||
fixed_values['locations'] = [{'country': 'BR'}]
|
||||
self.assertEqual(txo['value'], fixed_values)
|
||||
|
||||
# fee tests, replacing all (--replace)
|
||||
fee_address = values['fee_address']
|
||||
with self.assertRaises(Exception, msg='In order to set a fee amount, please specify a fee currency'):
|
||||
await self.stream_update(claim_id, fee_amount='0.1', replace=True, preview=True, confirm=False)
|
||||
with self.assertRaises(Exception, msg='In order to set a fee currency, please specify a fee amount'):
|
||||
await self.stream_update(
|
||||
claim_id, fee_currency='usd', replace=True, preview=True, confirm=False, claim_address=fee_address
|
||||
)
|
||||
tx = await self.stream_update(
|
||||
claim_id, fee_amount='0.1', fee_currency='usd', replace=True, preview=True, confirm=False
|
||||
)
|
||||
self.assertEqual(
|
||||
tx['outputs'][0]['value']['fee'],
|
||||
{'address': fee_address, 'currency': 'USD', 'amount': '0.1'}
|
||||
)
|
||||
tx = await self.stream_update(claim_id, replace=True, preview=True, confirm=False)
|
||||
self.assertNotIn('fee', tx['outputs'][0]['value'])
|
||||
tx = await self.stream_update(claim_id, fee_address=fee_address, replace=True, preview=True, confirm=False)
|
||||
self.assertEqual(tx['outputs'][0]['value']['fee'], {'address': fee_address})
|
||||
# fee tests, but now replacing a single field (default)
|
||||
tx = await self.stream_update(claim_id, fee_address=txo['address'], preview=True, confirm=False)
|
||||
expected_value = deepcopy(fixed_values)
|
||||
expected_value['fee']['address'] = txo['address']
|
||||
self.assertEqual(tx['outputs'][0]['value'], expected_value)
|
||||
tx = await self.stream_update(claim_id, fee_amount='42', preview=True, confirm=False)
|
||||
expected_value['fee']['amount'] = '42'
|
||||
expected_value['fee']['address'] = fixed_values['fee']['address']
|
||||
self.assertEqual(tx['outputs'][0]['value'], expected_value)
|
||||
tx = await self.stream_update(claim_id, fee_currency='lbc', preview=True, confirm=False)
|
||||
expected_value['fee']['currency'] = 'LBC'
|
||||
expected_value['fee']['amount'] = fixed_values['fee']['amount']
|
||||
self.assertEqual(tx['outputs'][0]['value'], expected_value)
|
||||
|
||||
# clearing fee
|
||||
tx = await self.out(self.stream_update(claim_id, clear_fee=True))
|
||||
txo = tx['outputs'][0]
|
||||
|
|
|
@ -278,8 +278,9 @@ class FileCommands(CommandTestCase):
|
|||
self.assertEqual(response['content_fee']['outputs'][0]['address'], target_address)
|
||||
|
||||
async def __raw_value_update_no_fee_address(self, tx, claim_address, **kwargs):
|
||||
tx = await self.daemon.jsonrpc_stream_update(tx['outputs'][0]['claim_id'], fee_amount='0.1', preview=True, claim_address=claim_address)
|
||||
tx.outputs[0].claim.stream.update(**kwargs)
|
||||
tx = await self.daemon.jsonrpc_stream_update(
|
||||
tx['outputs'][0]['claim_id'], preview=True, claim_address=claim_address, **kwargs
|
||||
)
|
||||
tx.outputs[0].claim.stream.fee.address_bytes = b''
|
||||
tx.outputs[0].script.generate()
|
||||
await tx.sign([self.account])
|
||||
|
|
Loading…
Reference in a new issue