Add socket test missing warning
This commit is contained in:
parent
d7853acc7d
commit
9876efe377
6
TODO
Normal file
6
TODO
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Missing tests for:
|
||||||
|
|
||||||
|
- crypto_dev_signer/cli/http.py
|
||||||
|
- crypto_dev_signer/cli/socket.py
|
||||||
|
|
||||||
|
tests/test_keystore_reference.py is dependent on postgres, should use sqlite for tests so that it can run independently
|
@ -8,6 +8,7 @@ from jsonrpc.exceptions import (
|
|||||||
JSONRPCParseError,
|
JSONRPCParseError,
|
||||||
JSONRPCInvalidParams,
|
JSONRPCInvalidParams,
|
||||||
)
|
)
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
||||||
@ -96,12 +97,11 @@ class SignRequestHandler:
|
|||||||
'raw': '0x' + raw_signed_tx.hex(),
|
'raw': '0x' + raw_signed_tx.hex(),
|
||||||
'tx': t.serialize(),
|
'tx': t.serialize(),
|
||||||
}
|
}
|
||||||
logg.debug('signed {}'.format(o))
|
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def eth_signTransaction(self, tx):
|
def eth_signTransaction(self, tx):
|
||||||
o = personal_signTransaction([tx[0], ''])
|
o = self.personal_signTransaction([tx[0], ''])
|
||||||
return o['raw']
|
return o['raw']
|
||||||
|
|
||||||
|
|
||||||
@ -111,5 +111,5 @@ class SignRequestHandler:
|
|||||||
if message_type != 'str':
|
if message_type != 'str':
|
||||||
raise ValueError('invalid message format, must be {}, not {}'.format(message_type))
|
raise ValueError('invalid message format, must be {}, not {}'.format(message_type))
|
||||||
z = self.signer.sign_ethereum_message(p[0], p[1][2:])
|
z = self.signer.sign_ethereum_message(p[0], p[1][2:])
|
||||||
return str(z)
|
return add_0x(z.hex())
|
||||||
|
|
||||||
|
@ -11,24 +11,33 @@ from .handle import SignRequestHandler
|
|||||||
logg = logging.getLogger(__name__)
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def start_server_socket(s):
|
class SocketHandler:
|
||||||
s.listen(10)
|
|
||||||
logg.debug('server started')
|
def __init__(self):
|
||||||
handler = SignRequestHandler()
|
self.handler = SignRequestHandler()
|
||||||
while True:
|
|
||||||
(csock, caddr) = s.accept()
|
|
||||||
|
def process(self, csock):
|
||||||
d = csock.recv(4096)
|
d = csock.recv(4096)
|
||||||
|
|
||||||
r = None
|
r = None
|
||||||
try:
|
try:
|
||||||
r = handler.handle_jsonrpc(d)
|
r = self.handler.handle_jsonrpc(d)
|
||||||
except SignerError as e:
|
except SignerError as e:
|
||||||
r = e.to_jsonrpc()
|
r = e.to_jsonrpc()
|
||||||
|
|
||||||
csock.send(r)
|
csock.send(r)
|
||||||
|
|
||||||
|
|
||||||
|
def start_server_socket(s):
|
||||||
|
s.listen(10)
|
||||||
|
logg.debug('server started')
|
||||||
|
handler = SocketHandler()
|
||||||
|
while True:
|
||||||
|
(csock, caddr) = s.accept()
|
||||||
|
handler.process(csock)
|
||||||
csock.close()
|
csock.close()
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
os.unlink(socket_path)
|
os.unlink(socket_path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,10 +10,8 @@ from urllib.parse import urlparse
|
|||||||
# external imports
|
# external imports
|
||||||
import confini
|
import confini
|
||||||
from jsonrpc.exceptions import *
|
from jsonrpc.exceptions import *
|
||||||
from hexathon import add_0x
|
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from crypto_dev_signer.cli.cmd import *
|
|
||||||
from crypto_dev_signer.eth.signer import ReferenceSigner
|
from crypto_dev_signer.eth.signer import ReferenceSigner
|
||||||
from crypto_dev_signer.keystore.reference import ReferenceKeystore
|
from crypto_dev_signer.keystore.reference import ReferenceKeystore
|
||||||
from crypto_dev_signer.cli.handle import SignRequestHandler
|
from crypto_dev_signer.cli.handle import SignRequestHandler
|
||||||
|
2
setup.py
2
setup.py
@ -33,7 +33,7 @@ f.close()
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="crypto-dev-signer",
|
name="crypto-dev-signer",
|
||||||
version="0.4.15a2",
|
version="0.4.15a3",
|
||||||
description="A signer and keystore daemon and library for cryptocurrency software development",
|
description="A signer and keystore daemon and library for cryptocurrency software development",
|
||||||
author="Louis Holbrook",
|
author="Louis Holbrook",
|
||||||
author_email="dev@holbrook.no",
|
author_email="dev@holbrook.no",
|
||||||
|
88
tests/test_cli.py
Normal file
88
tests/test_cli.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# standard imports
|
||||||
|
import unittest
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
# external imports
|
||||||
|
from hexathon import strip_0x
|
||||||
|
|
||||||
|
# local imports
|
||||||
|
from crypto_dev_signer.eth.signer import ReferenceSigner
|
||||||
|
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||||
|
from crypto_dev_signer.cli.handle import SignRequestHandler
|
||||||
|
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
logg = logging.getLogger()
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
data_dir = os.path.join(script_dir, 'testdata')
|
||||||
|
|
||||||
|
class TestCli(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
#pk = bytes.fromhex('5087503f0a9cc35b38665955eb830c63f778453dd11b8fa5bd04bc41fd2cc6d6')
|
||||||
|
#pk_getter = pkGetter(pk)
|
||||||
|
self.keystore = DictKeystore()
|
||||||
|
SignRequestHandler.keystore = self.keystore
|
||||||
|
self.signer = ReferenceSigner(self.keystore)
|
||||||
|
SignRequestHandler.signer = self.signer
|
||||||
|
self.handler = SignRequestHandler()
|
||||||
|
|
||||||
|
|
||||||
|
def test_new_account(self):
|
||||||
|
q = {
|
||||||
|
'id': 0,
|
||||||
|
'method': 'personal_newAccount',
|
||||||
|
'params': [''],
|
||||||
|
}
|
||||||
|
(rpc_id, result) = self.handler.process_input(q)
|
||||||
|
self.assertTrue(self.keystore.get(result))
|
||||||
|
|
||||||
|
|
||||||
|
def test_sign_tx(self):
|
||||||
|
keystore_file = os.path.join(data_dir, 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72')
|
||||||
|
sender = self.keystore.import_keystore_file(keystore_file)
|
||||||
|
tx_hexs = {
|
||||||
|
'nonce': '0x',
|
||||||
|
'from': sender,
|
||||||
|
'gasPrice': "0x04a817c800",
|
||||||
|
'gas': "0x5208",
|
||||||
|
'to': '0x3535353535353535353535353535353535353535',
|
||||||
|
'value': "0x03e8",
|
||||||
|
'data': "0xdeadbeef",
|
||||||
|
'chainId': 8995,
|
||||||
|
}
|
||||||
|
tx = EIP155Transaction(tx_hexs, 42, 8995)
|
||||||
|
tx_s = tx.serialize()
|
||||||
|
|
||||||
|
# TODO: move to serialization wrapper for tests
|
||||||
|
tx_s['chainId'] = tx_s['v']
|
||||||
|
tx_s['from'] = sender
|
||||||
|
|
||||||
|
# eth_signTransaction wraps personal_signTransaction, so here we test both already
|
||||||
|
q = {
|
||||||
|
'id': 0,
|
||||||
|
'method': 'eth_signTransaction',
|
||||||
|
'params': [tx_s],
|
||||||
|
}
|
||||||
|
(rpc_id, result) = self.handler.process_input(q)
|
||||||
|
logg.debug('result {}'.format(result))
|
||||||
|
|
||||||
|
self.assertEqual(strip_0x(result), 'f86c2a8504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef82466aa0b7c1bbf52f736ada30fe253c7484176f44d6fd097a9720dc85ae5bbc7f060e54a07afee2563b0cf6d00333df51cc62b0d13c63108b2bce54ce2ad24e26ce7b4f25')
|
||||||
|
|
||||||
|
def test_sign_msg(self):
|
||||||
|
keystore_file = os.path.join(data_dir, 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72')
|
||||||
|
sender = self.keystore.import_keystore_file(keystore_file)
|
||||||
|
q = {
|
||||||
|
'id': 0,
|
||||||
|
'method': 'eth_sign',
|
||||||
|
'params': [sender, '0xdeadbeef'],
|
||||||
|
}
|
||||||
|
(rpc_id, result) = self.handler.process_input(q)
|
||||||
|
logg.debug('result msg {}'.format(result))
|
||||||
|
self.assertEqual(strip_0x(result), '50320dda75190a121b7b5979de66edadafd02bdfbe4f6d49552e79c01410d2464aae35e385c0e5b61663ff7b44ef65fa0ac7ad8a57472cf405db399b9dba3e1600')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
@ -29,7 +29,6 @@ class TestDict(unittest.TestCase):
|
|||||||
db = None
|
db = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
logg.debug('setup')
|
|
||||||
self.db = DictKeystore()
|
self.db = DictKeystore()
|
||||||
|
|
||||||
keystore_filepath = os.path.join(script_dir, 'testdata', 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72')
|
keystore_filepath = os.path.join(script_dir, 'testdata', 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72')
|
||||||
|
15
tests/test_socket.py
Normal file
15
tests/test_socket.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# standard imports
|
||||||
|
import unittest
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logg = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class SocketTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_placeholder_warning(self):
|
||||||
|
logg.warning('socket tests are missing! :/')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user