2020-08-05 18:14:25 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import logging
|
|
|
|
import base64
|
|
|
|
|
|
|
|
import psycopg2
|
|
|
|
from psycopg2 import sql
|
|
|
|
from cryptography.fernet import Fernet
|
|
|
|
|
|
|
|
from keystore import ReferenceDatabase
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
logg = logging.getLogger()
|
|
|
|
|
|
|
|
|
|
|
|
class TestDatabase(unittest.TestCase):
|
|
|
|
|
|
|
|
conn = None
|
|
|
|
cur = None
|
|
|
|
symkey = None
|
2020-08-05 19:47:38 +02:00
|
|
|
address_hex = None
|
2020-08-05 18:14:25 +02:00
|
|
|
db = None
|
|
|
|
|
|
|
|
def setUp(self):
|
2020-08-05 19:47:38 +02:00
|
|
|
# arbitrary value
|
|
|
|
symkey_hex = 'E92431CAEE69313A7BE9E443C4ABEED9BF8157E9A13553B4D5D6E7D51B5021D9'
|
|
|
|
self.symkey = bytes.fromhex(symkey_hex)
|
|
|
|
self.address_hex = '9FA61f0E52A5C51b43f0d32404625BC436bb7041'
|
2020-08-05 18:14:25 +02:00
|
|
|
|
|
|
|
kw = {
|
|
|
|
'symmetric_key': self.symkey,
|
|
|
|
}
|
|
|
|
self.db = ReferenceDatabase('signer_test', **kw)
|
|
|
|
self.db.cur.execute("""CREATE TABLE ethereum (
|
|
|
|
id SERIAL NOT NULL PRIMARY KEY,
|
|
|
|
key_ciphertext VARCHAR(256) NOT NULL,
|
|
|
|
wallet_address_hex CHAR(40) NOT NULL
|
|
|
|
);
|
|
|
|
""")
|
|
|
|
self.db.cur.execute("CREATE UNIQUE INDEX ethereum_address_idx ON ethereum ( wallet_address_hex );")
|
|
|
|
self.db.conn.commit()
|
2020-08-05 19:47:38 +02:00
|
|
|
self.db.new(self.address_hex)
|
|
|
|
|
2020-08-05 18:14:25 +02:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.db.conn = psycopg2.connect('dbname=signer_test')
|
|
|
|
self.db.cur = self.db.conn.cursor()
|
|
|
|
self.db.cur.execute('DROP INDEX ethereum_address_idx;')
|
|
|
|
self.db.cur.execute('DROP TABLE ethereum;')
|
|
|
|
self.db.conn.commit()
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_key(self):
|
2020-08-05 19:47:38 +02:00
|
|
|
pk = self.db.get(self.address_hex)
|
|
|
|
logg.info('pk {}'.format(pk.hex()))
|
2020-08-05 18:14:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|