fixes up code

This commit is contained in:
Oleg Silkin 2019-06-10 23:51:23 -04:00
parent 4d35bf3b9d
commit bdaa9b00d1
3 changed files with 8 additions and 5 deletions

View file

@ -94,9 +94,8 @@ def insert_comment(conn: sqlite3.Connection, claim_id: str = None, comment: str
channel_id: str = None, signature: str = None, signing_ts: str = None,
parent_id: str = None) -> str:
timestamp = int(time.time())
prehash = ':'.join((claim_id, comment, str(timestamp),))
prehash = bytes(prehash.encode('utf-8'))
comment_id = nacl.hash.sha256(prehash).decode('utf-8')
prehash = b':'.join((claim_id.encode(), comment.encode(), str(timestamp).encode(),))
comment_id = nacl.hash.sha256(prehash).decode()
with conn:
conn.execute(
"""

View file

@ -2,8 +2,10 @@ import logging
import sqlite3
from src.database import get_comment_or_none
from src.database import insert_comment, insert_channel
from src.misc import validate_channel, validate_signature
from src.database import insert_comment
from src.database import insert_channel
from src.misc import validate_channel
from src.misc import validate_signature
logger = logging.getLogger(__name__)

View file

@ -75,6 +75,7 @@ class TestCommentCreation(DatabaseTestCase):
signing_ts='asdasd'
)
self.assertIsNotNone(comment)
self.assertIn('signing_ts', comment)
previous_id = comment['comment_id']
reply = create_comment(
conn=self.conn,
@ -88,6 +89,7 @@ class TestCommentCreation(DatabaseTestCase):
)
self.assertIsNotNone(reply)
self.assertEqual(reply['parent_id'], comment['comment_id'])
self.assertIn('signing_ts', reply)
def test04UsernameVariations(self):
self.assertRaises(