Add readme, changelog...
This commit is contained in:
@@ -8,7 +8,7 @@ import psycopg2
|
||||
from psycopg2 import sql
|
||||
from cryptography.fernet import Fernet, InvalidToken
|
||||
|
||||
from keystore import ReferenceDatabase
|
||||
from keystore import ReferenceKeystore
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -31,16 +31,11 @@ class TestDatabase(unittest.TestCase):
|
||||
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 = ReferenceKeystore('signer_test', **kw)
|
||||
for ss in ReferenceKeystore.schema:
|
||||
self.db.cur.execute(ss)
|
||||
self.db.conn.commit()
|
||||
self.db.new(self.address_hex, 'foo')
|
||||
self.address_hex = self.db.new('foo')
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
@@ -52,6 +47,7 @@ class TestDatabase(unittest.TestCase):
|
||||
|
||||
|
||||
def test_get_key(self):
|
||||
logg.debug('getting {}'.format(self.address_hex))
|
||||
self.db.get(self.address_hex, 'foo')
|
||||
with self.assertRaises(InvalidToken):
|
||||
self.db.get(self.address_hex, 'bar')
|
||||
@@ -6,7 +6,7 @@ import logging
|
||||
from rlp import encode as rlp_encode
|
||||
|
||||
from signer import ReferenceSigner
|
||||
from transaction import Transaction
|
||||
from transaction import EIP155Transaction
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
@@ -21,14 +21,20 @@ tx = {
|
||||
'data': "deadbeef",
|
||||
}
|
||||
|
||||
class pkGetter:
|
||||
|
||||
def __init__(self, pk):
|
||||
self.pk = pk
|
||||
|
||||
def get(self, address, password=None):
|
||||
return self.pk
|
||||
|
||||
|
||||
class TestSign(unittest.TestCase):
|
||||
|
||||
pk = None
|
||||
nonce = -1
|
||||
|
||||
|
||||
def getPk(self, address):
|
||||
return self.pk
|
||||
pk_getter = None
|
||||
|
||||
|
||||
def getNonce(self):
|
||||
@@ -37,8 +43,8 @@ class TestSign(unittest.TestCase):
|
||||
|
||||
|
||||
def setUp(self):
|
||||
#self.pk = b'abcdefghijklmnopqrstuvwxyz012345' #random.sample(range(256), k=32)
|
||||
self.pk = bytes.fromhex('5087503f0a9cc35b38665955eb830c63f778453dd11b8fa5bd04bc41fd2cc6d6')
|
||||
self.pk_getter = pkGetter(self.pk)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
@@ -46,15 +52,20 @@ class TestSign(unittest.TestCase):
|
||||
|
||||
|
||||
|
||||
# TODO: verify rlp tx output
|
||||
def test_serialize_transaction(self):
|
||||
t = Transaction(tx, 0)
|
||||
t = EIP155Transaction(tx, 0)
|
||||
self.assertRegex(t.__class__.__name__, "Transaction")
|
||||
logg.debug('{}'.format(rlp_encode(t.serialize())))
|
||||
s = t.serialize()
|
||||
self.assertEqual('{}'.format(s), "{'nonce': '0x0x0', 'gasPrice': '0x0x4a817c800', 'gas': '0x0x55f0', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x0x3e8', 'data': '0xdeadbeef', 'v': '0x0x1', 'r': '0x', 's': '0x'}")
|
||||
r = t.rlp_serialize()
|
||||
self.assertEqual(r.hex(), 'ea808504a817c8008255f09435353535353535353535353535353535353535358203e884deadbeef018080')
|
||||
|
||||
|
||||
|
||||
def test_sign_transaction(self):
|
||||
t = Transaction(tx, 461, 8995)
|
||||
s = ReferenceSigner(self.getPk)
|
||||
t = EIP155Transaction(tx, 461, 8995)
|
||||
s = ReferenceSigner(self.pk_getter)
|
||||
z = s.signTransaction(t)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user