review fixes

This commit is contained in:
Lex Berezhny 2019-06-02 23:09:56 -04:00
parent ec039825e8
commit 4fb6f2bb27
4 changed files with 58 additions and 168 deletions

View file

@ -534,7 +534,7 @@ class Config(CLIConfig):
('lbrynet4.lbry.com', 4444) # ASIA ('lbrynet4.lbry.com', 4444) # ASIA
]) ])
comment_server = String("Updated Comment Server version.", "https://comments.lbry.com/api") comment_server = String("Comment server API URL", "https://comments.lbry.com/api")
# blockchain # blockchain
blockchain_name = String("Blockchain name - lbrycrd_main, lbrycrd_regtest, or lbrycrd_testnet", 'lbrycrd_main') blockchain_name = String("Blockchain name - lbrycrd_main, lbrycrd_regtest, or lbrycrd_testnet", 'lbrycrd_main')

View file

@ -2278,7 +2278,7 @@ class Daemon(metaclass=JSONRPCServerType):
--duration=<duration> : (int) audio/video duration in seconds, automatically calculated --duration=<duration> : (int) audio/video duration in seconds, automatically calculated
--channel_id=<channel_id> : (str) claim id of the publisher channel --channel_id=<channel_id> : (str) claim id of the publisher channel
--channel_name=<channel_name> : (str) name of publisher channel --channel_name=<channel_name> : (str) name of publisher channel
--channel_account_id=<channel_id>: (str) one or more account ids for accounts to look in --channel_account_id=<channel_account_id>: (str) one or more account ids for accounts to look in
for channel certificates, defaults to all accounts. for channel certificates, defaults to all accounts.
--account_id=<account_id> : (str) account to use for funding the transaction --account_id=<account_id> : (str) account to use for funding the transaction
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified --claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
@ -2391,7 +2391,7 @@ class Daemon(metaclass=JSONRPCServerType):
--duration=<duration> : (int) audio/video duration in seconds, automatically calculated --duration=<duration> : (int) audio/video duration in seconds, automatically calculated
--channel_id=<channel_id> : (str) claim id of the publisher channel --channel_id=<channel_id> : (str) claim id of the publisher channel
--channel_name=<channel_name> : (str) name of the publisher channel --channel_name=<channel_name> : (str) name of the publisher channel
--channel_account_id=<channel_id>: (str) one or more account ids for accounts to look in --channel_account_id=<channel_account_id>: (str) one or more account ids for accounts to look in
for channel certificates, defaults to all accounts. for channel certificates, defaults to all accounts.
--account_id=<account_id> : (str) account to use for funding the transaction --account_id=<account_id> : (str) account to use for funding the transaction
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified --claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
@ -2541,7 +2541,7 @@ class Daemon(metaclass=JSONRPCServerType):
--channel_id=<channel_id> : (str) claim id of the publisher channel --channel_id=<channel_id> : (str) claim id of the publisher channel
--channel_name=<channel_name> : (str) name of the publisher channel --channel_name=<channel_name> : (str) name of the publisher channel
--clear_channel : (bool) remove channel signature --clear_channel : (bool) remove channel signature
--channel_account_id=<channel_id>: (str) one or more account ids for accounts to look in --channel_account_id=<channel_account_id>: (str) one or more account ids for accounts to look in
for channel certificates, defaults to all accounts. for channel certificates, defaults to all accounts.
--account_id=<account_id> : (str) account to use for funding the transaction --account_id=<account_id> : (str) account to use for funding the transaction
--claim_address=<claim_address>: (str) address where the claim is sent to, if not specified --claim_address=<claim_address>: (str) address where the claim is sent to, if not specified
@ -3382,17 +3382,18 @@ class Daemon(metaclass=JSONRPCServerType):
top_level=not include_replies top_level=not include_replies
) )
async def jsonrpc_comment_create(self, claim_id: str, comment: str, parent_id: str = None, async def jsonrpc_comment_create(
channel_name: str = None, channel_id: str = None) -> dict: self, claim_id: str, comment: str, parent_id: str = None,
channel_account_id=None, channel_name: str = None, channel_id: str = None) -> dict:
""" """
Create and associate a comment with a claim using your channel identity. Create and associate a comment with a claim using your channel identity.
Usage: Usage:
comment_create (<comment> | --comment=<comment>) comment_create (<comment> | --comment=<comment>)
(<claim_id> | --claim_id=<claim_id>) (<claim_id> | --claim_id=<claim_id>)
[--channel_id=<channel_id>]
[--channel_name=<channel_name>]
[--parent_id=<parent_id>] [--parent_id=<parent_id>]
[--channel_id=<channel_id>] [--channel_name=<channel_name>]
[--channel_account_id=<channel_account_id>...]
Options: Options:
--comment=<comment> : (str) Comment to be made, should be at most 2000 characters. --comment=<comment> : (str) Comment to be made, should be at most 2000 characters.
@ -3400,7 +3401,8 @@ class Daemon(metaclass=JSONRPCServerType):
--parent_id=<parent_id> : (str) The ID of a comment to make a response to --parent_id=<parent_id> : (str) The ID of a comment to make a response to
--channel_id=<channel_id> : (str) The ID of the channel you want to post under --channel_id=<channel_id> : (str) The ID of the channel you want to post under
--channel_name=<channel_name>: (str) The channel you want to post as, prepend with a '@' --channel_name=<channel_name>: (str) The channel you want to post as, prepend with a '@'
--channel_account_id=<channel_account_id>: (str) one or more account ids for accounts to look in
for channel certificates, defaults to all accounts.
Returns: Returns:
(dict) Comment object if successfully made, (None) otherwise (dict) Comment object if successfully made, (None) otherwise
@ -3415,34 +3417,23 @@ class Daemon(metaclass=JSONRPCServerType):
"timestamp": (int) The time at which comment was entered into the server at, in nanoseconds. "timestamp": (int) The time at which comment was entered into the server at, in nanoseconds.
} }
""" """
if bool(channel_name) ^ bool(channel_id): comment = {
try: 'comment': comment,
channel_list = await self.jsonrpc_channel_list() 'claim_id': claim_id,
if channel_name: 'parent_id': parent_id,
channel_name = channel_name.lower() }
channel: Output = [chan for chan in channel_list if chan.normalized_name == channel_name].pop() channel = await self.get_channel_or_none(channel_account_id, channel_id, channel_name, for_signing=True)
channel_id = channel.claim_id if channel:
else: comment.update({
channel: Output = [chan for chan in channel_list if chan.claim_id == channel_id].pop() 'channel_id': channel.claim_id,
channel_name = channel.normalized_name 'channel_name': channel.claim_name,
except IndexError: 'signature': sign_comment(
raise ValueError('You must enter a valid channel_%s' % ('id' if channel_id else 'name'))
signature = None
if channel_id and channel_name:
signature = sign_comment(
channel_name=channel_name, channel_name=channel_name,
channel_id=channel_id, channel_id=channel_id,
comment=comment, comment=comment,
salt=time.time_ns() salt=time.time_ns()
) )
comment = { })
'comment': comment,
'claim_id': claim_id,
'parent_id': parent_id,
'channel_id': channel_id,
'channel_name': channel_name,
'signature': signature
}
return await jsonrpc_post(self.conf.comment_server, 'create_comment', **comment) return await jsonrpc_post(self.conf.comment_server, 'create_comment', **comment)
def valid_address_or_error(self, address): def valid_address_or_error(self, address):

View file

@ -58,7 +58,6 @@ class ExchangeRateManagerComponent(Component):
class CommandTestCase(IntegrationTestCase): class CommandTestCase(IntegrationTestCase):
timeout = 180
LEDGER = lbrynet.wallet LEDGER = lbrynet.wallet
MANAGER = LbryWalletManager MANAGER = LbryWalletManager
VERBOSITY = logging.WARN VERBOSITY = logging.WARN

View file

@ -1,61 +1,16 @@
import logging
import time
import asyncio import asyncio
from aiohttp import web from aiohttp import web
from lbrynet.testcase import CommandTestCase from lbrynet.testcase import CommandTestCase
import lbrynet.schema
lbrynet.schema.BLOCKCHAIN_NAME = 'lbrycrd_regtest'
COMMENT_IDS = [
"b7de681c412e315bb1a9ada6f485a2e0399400db",
"0f7e1514f55c7fefba1e714386e05b3d705f6d29",
"8ae19f686c39f402c80dabf25df23cf72fe426af",
"a11ad59b54bb937ca1a88329f253b17196bd4dc3",
"7ee87b3249fa47b296c8347cd63bba679ef629eb",
"0100e3367f68284f4970736c9351ad90c37dade5",
"974a5bfcce6bc72605688ba6e2efd34aa934b1dc",
"97ea100a52aa46ae9f2a4356169307a2505e8d47",
"2b4d193371c8f0ed45c830cb1ba3188b90bf08f1",
"db335dc3183ca3552b6ef4a7bce36f26ed37b7eb"
]
CLAIM_IDS = [
"f6068bdc8cb66fe7eb6c3cf4cf98da93a697df47",
"44a8c10e36ed8b60da8d5fe590cba61544fb7179",
"a7d8a1fc90ab806c98743a7f9ca7480e2cebe2a0",
"81a8cc2fa41eea0ae9d65ab0f8a0440605a23f1b",
"49117e9a7bb2aab01356e1160871aad5edb09ed5",
"2b928261918b1f7c65973c8fee9e20d4a1f1b2a4",
"f9d6eb75d1592a967b1c405208593d30b46446c9",
"cc70bd497eb1305096fa4e28275645f47c5d809d",
"2e520f60bd8f79f309d68b291fe574531a7d6656",
"16b0248c103fb7b3497bd58543f6c5dd6d47d5f2"
]
CHANNEL_IDS = [
"7b65a9886869a367371ec621abe5bac4e5dd27b9",
"c3bbde23a8b31dc05490cede3a381080b024f878",
"c544579ca13ce5d97e9301789620547323da15eb",
"428e1c075b27bbce1380c16ecb5f0d228318315e",
"1558b39438f573a47a5e0fcd78ad24d0eb358be0",
"ac66521e1757d320568a52ab8b01029bd169b1a0",
"aa89729a08050694ffb62e725356bbaa26481193",
"23181733dc3b836e4d38e8cc21d79378b855cf36",
"60efc8ced56a6a02c2d5371310f0130c541a9ded",
"af1c95f2026d4a254512dd6e6a792a9d92b9fd21"
]
class FakedCommentServer: class FakedCommentServer:
ERRORS = { ERRORS = {
'INVALID_PARAMS': {'code': -32602, 'message': 'Invalid parameters'}, 'INVALID_PARAMS': {'code': -32602, 'message': 'Invalid parameters'},
'INTERNAL': {'code': -32603, 'message': 'An internal error'}, 'INTERNAL': {'code': -32603, 'message': 'An internal error'},
'UNKNOWN': {'code': -1, 'message': 'An unknown or very miscellaneous error'}, 'UNKNOWN': {'code': -1, 'message': 'An unknown or very miscellaneous error'},
'INVALID_METHOD': {'code': -32604, 'message': 'The Requested method does not exist'} 'INVALID_METHOD': {'code': -32604, 'message': 'The Requested method does not exist'}
} }
def __init__(self, port=2903): def __init__(self, port=2903):
@ -64,24 +19,17 @@ class FakedCommentServer:
self.app.add_routes([web.post('/api', self.api)]) self.app.add_routes([web.post('/api', self.api)])
self.runner = None self.runner = None
self.server = None self.server = None
self.comments = []
self.comment_id = 0
def get_comment(self, **kwargs) -> dict: def create_comment(self, **comment):
return { self.comment_id += 1
'comment_id': 'asbdsdasd', comment['comment_id'] = self.comment_id
'parent_id': 'asdsfsfsf', self.comments.append(comment)
'comment': 'asdsdadsdas', return comment
'timestamp': time.time_ns(),
'channel_id': 'asdsdsdasdad',
'channel_name': 'asdsasasfaf',
'channel_uri': 'asdsdasda',
'signature': 'aasdasdasda',
}
def create_comment(self, comment, claim_id, **kwargs):
return self.get_comment(**kwargs)
def get_claim_comments(self, page=1, page_size=50, **kwargs): def get_claim_comments(self, page=1, page_size=50, **kwargs):
return [self.get_comment(**kwargs) for i in range(page_size)] return self.comments[:page_size]
methods = { methods = {
'get_claim_comments': get_claim_comments, 'get_claim_comments': get_claim_comments,
@ -98,24 +46,16 @@ class FakedCommentServer:
response['error'] = self.ERRORS['INVALID_METHOD'] response['error'] = self.ERRORS['INVALID_METHOD']
return response return response
async def _start(self): async def start(self):
self.runner = web.AppRunner(self.app) self.runner = web.AppRunner(self.app)
await self.runner.setup() await self.runner.setup()
self.server = web.TCPSite(self.runner, 'localhost', self.port) self.server = web.TCPSite(self.runner, 'localhost', self.port)
await self.server.start() await self.server.start()
async def _stop(self): async def stop(self):
await self.runner.shutdown()
await self.runner.cleanup() await self.runner.cleanup()
async def run(self, max_timeout=3600):
try:
await self._start()
await asyncio.sleep(max_timeout)
except asyncio.CancelledError:
pass
finally:
await self._stop()
async def api(self, request): async def api(self, request):
body = await request.json() body = await request.json()
if type(body) is list or type(body) is dict: if type(body) is list or type(body) is dict:
@ -130,76 +70,36 @@ class FakedCommentServer:
class CommentCommands(CommandTestCase): class CommentCommands(CommandTestCase):
VERBOSITY = logging.WARN
async def asyncSetUp(self): async def asyncSetUp(self):
await super().asyncSetUp() await super().asyncSetUp()
self.daemon.conf.comment_server = 'http://localhost:2903/api' self.daemon.conf.comment_server = 'http://localhost:2903/api'
self.server = FakedCommentServer(2903) self.comment_server = FakedCommentServer(2903)
self.server_task = asyncio.create_task(self.server.run(self.timeout)) await self.comment_server.start()
self.addCleanup(self.comment_server.stop)
async def asyncTearDown(self):
await super().asyncTearDown()
self.server_task.cancel()
if not self.server_task.cancelled():
await self.server_task
async def test_comment_create(self): async def test_comment_create(self):
channel = (await self.channel_create('@JimmyBuffett'))['outputs'][0]
stream = (await self.stream_create())['outputs'][0]
self.assertEqual(0, len(await self.daemon.jsonrpc_comment_list(stream['claim_id'])))
comment = await self.daemon.jsonrpc_comment_create( comment = await self.daemon.jsonrpc_comment_create(
claim_id=CLAIM_IDS[0], claim_id=stream['claim_id'],
channel_name='@JimmyBuffett', channel_id=channel['claim_id'],
channel_id=CHANNEL_IDS[0],
comment="It's 5 O'Clock Somewhere" comment="It's 5 O'Clock Somewhere"
) )
self.assertIsNotNone(comment) comments = await self.daemon.jsonrpc_comment_list(stream['claim_id'])
self.assertNotIn('error', comment) self.assertEqual(1, len(comments))
self.assertIn('comment', comment, msg=f"Response {comment} doesn't contain message") self.assertEqual(comment['comment_id'], comments[0]['comment_id'])
self.assertIn('channel_name', comment) self.assertEqual(stream['claim_id'], comments[0]['claim_id'])
async def test_comment_create_reply(self): channel2 = (await self.channel_create('@BuffettJimmy'))['outputs'][0]
reply = await self.daemon.jsonrpc_comment_create( await self.daemon.jsonrpc_comment_create(
claim_id=CLAIM_IDS[0], claim_id=stream['claim_id'],
channel_name='@JimmyBuffett', channel_name=channel2['name'],
channel_id=CHANNEL_IDS[0],
comment='Let\'s all go to Margaritaville', comment='Let\'s all go to Margaritaville',
parent_id=COMMENT_IDS[0] parent_id=comments[0]['comment_id']
) )
self.assertIsNotNone(reply) comments = await self.daemon.jsonrpc_comment_list(stream['claim_id'])
self.assertNotIn('error', reply) self.assertEqual(2, len(comments))
self.assertIn('comment_id', reply) self.assertEqual(comments[1]['channel_id'], channel2['claim_id'])
self.assertIsNotNone(reply['parent_id']) self.assertEqual(comments[0]['comment_id'], comments[1]['parent_id'])
async def test_comment_list_root_level(self):
comments = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[0])
self.assertIsNotNone(comments)
self.assertIs(type(comments), list)
comments = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[1], page_size=50)
self.assertIsNotNone(comments)
self.assertLessEqual(len(comments), 50)
self.assertGreaterEqual(len(comments), 0)
async def test_comment_list_replies(self):
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[0], parent_id=23)
self.assertIsInstance(replies, list)
self.assertGreater(len(replies), 0)
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[2], parent_id=COMMENT_IDS[3], page_size=50)
self.assertEqual(len(replies), 50)
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[3], parent_id=COMMENT_IDS[5],
page_size=23, page=5)
self.assertEqual(len(replies), 23)
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[5], parent_id=COMMENT_IDS[1],
page_size=60, page=2)
self.assertEqual(len(replies), 60)
async def test_comment_list_flatness_flatness_LA(self):
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[2], parent_id=23, include_replies=True)
self.assertGreater(len(replies), 0)
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[6], parent_id=25,
page_size=50, include_replies=True)
self.assertGreaterEqual(len(replies), 0)
self.assertLessEqual(len(replies), 50)
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[7], parent_id=67, page_size=23, page=5)
self.assertGreaterEqual(len(replies), 0)
self.assertLessEqual(len(replies), 23)
replies = await self.daemon.jsonrpc_comment_list(CLAIM_IDS[9], parent_id=79, page=2, include_replies=True)
self.assertGreaterEqual(len(replies), 15)