Revert "Add http server to signer daemon"
This reverts commit 441ace5ec4.
This commit is contained in:
91
tests/test_helper.py
Normal file
91
tests/test_helper.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# standard imports
|
||||
import unittest
|
||||
import logging
|
||||
import os
|
||||
|
||||
# local imports
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner
|
||||
from crypto_dev_signer.helper import TxExecutor
|
||||
#from crypto_dev_signer.eth.helper import EthTxExecutor
|
||||
from crypto_dev_signer.encoding import to_checksum_address
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
|
||||
|
||||
class MockEthTxBackend:
|
||||
|
||||
def dispatcher(self, tx):
|
||||
logg.debug('sender {}'.format(tx))
|
||||
return os.urandom(32)
|
||||
|
||||
def reporter(self, tx):
|
||||
logg.debug('reporter {}'.format(tx))
|
||||
|
||||
def verifier(self, rcpt):
|
||||
logg.debug('reporter {}'.format(rcpt))
|
||||
|
||||
def fee_price_helper(self):
|
||||
return 21
|
||||
|
||||
def fee_helper(self, tx):
|
||||
logg.debug('fee helper tx {}'.format(tx))
|
||||
return 2
|
||||
|
||||
def builder(self, tx):
|
||||
return tx
|
||||
|
||||
def builder_two(self, tx):
|
||||
tx['value'] = 10243
|
||||
tx['to'] = to_checksum_address('0x' + os.urandom(20).hex())
|
||||
tx['data'] = '0x'
|
||||
if tx.get('feePrice') != None:
|
||||
tx['gasPrice'] = tx['feePrice']
|
||||
del tx['feePrice']
|
||||
if tx.get('feeUnits') != None:
|
||||
tx['gas'] = tx['feeUnits']
|
||||
del tx['feeUnits']
|
||||
return tx
|
||||
|
||||
|
||||
class TestHelper(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
logg.debug('setup')
|
||||
self.db = DictKeystore()
|
||||
|
||||
keystore_filename = 'UTC--2021-01-08T18-37-01.187235289Z--00a329c0648769a73afac7f9381e08fb43dbea72'
|
||||
keystore_filepath = os.path.join(script_dir, 'testdata', keystore_filename)
|
||||
|
||||
self.address_hex = self.db.import_keystore_file(keystore_filepath, '')
|
||||
self.signer = ReferenceSigner(self.db)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_helper(self):
|
||||
backend = MockEthTxBackend()
|
||||
executor = TxExecutor(self.address_hex, self.signer, backend.builder, backend.dispatcher, backend.reporter, 666, 13, backend.fee_helper, backend.fee_price_helper, backend.verifier)
|
||||
|
||||
tx_ish = {'from': self.address_hex}
|
||||
executor.sign_and_send([backend.builder_two])
|
||||
|
||||
|
||||
# def test_eth_helper(self):
|
||||
# backend = MockEthTxBackend()
|
||||
# w3 = web3.Web3(web3.Web3.HTTPProvider('http://localhost:8545'))
|
||||
# executor = EthTxExecutor(w3, self.address_hex, self.signer, 1337)
|
||||
#
|
||||
# tx_ish = {'from': self.address_hex}
|
||||
# #executor.sign_and_send([backend.builder, backend.builder_two])
|
||||
# with self.assertRaises(ValueError):
|
||||
# executor.sign_and_send([backend.builder_two])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -1,12 +1,10 @@
|
||||
# standard imports
|
||||
#!/usr/bin/python
|
||||
|
||||
import unittest
|
||||
import logging
|
||||
import copy
|
||||
|
||||
# external imports
|
||||
from rlp import encode as rlp_encode
|
||||
|
||||
# local imports
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner
|
||||
from crypto_dev_signer.eth.transaction import EIP155Transaction
|
||||
|
||||
@@ -25,22 +23,15 @@ tx_ints = {
|
||||
}
|
||||
|
||||
tx_hexs = {
|
||||
'nonce': '0x',
|
||||
'nonce': '0x0',
|
||||
'from': "0xEB014f8c8B418Db6b45774c326A0E64C78914dC0",
|
||||
'gasPrice': "0x04a817c800",
|
||||
'gasPrice': "0x4a817c800",
|
||||
'gas': "0x5208",
|
||||
'to': '0x3535353535353535353535353535353535353535',
|
||||
'value': "0x03e8",
|
||||
'data': "0xdeadbeef",
|
||||
'value': "0x3e8",
|
||||
'data': "deadbeef",
|
||||
}
|
||||
|
||||
tx_hexs_r = copy.copy(tx_hexs)
|
||||
tx_hexs_r['r'] = '0x'
|
||||
tx_hexs_r['s'] = '0x'
|
||||
tx_hexs_r['v'] = '0x01'
|
||||
del tx_hexs_r['from']
|
||||
|
||||
|
||||
class pkGetter:
|
||||
|
||||
def __init__(self, pk):
|
||||
@@ -77,14 +68,14 @@ class TestSign(unittest.TestCase):
|
||||
t = EIP155Transaction(tx_ints, 0)
|
||||
self.assertRegex(t.__class__.__name__, "Transaction")
|
||||
s = t.serialize()
|
||||
self.assertDictEqual(s, tx_hexs_r)
|
||||
self.assertEqual('{}'.format(s), "{'nonce': '0x', 'gasPrice': '0x04a817c800', 'gas': '0x5208', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x03e8', 'data': '0xdeadbeef', 'v': '0x01', 'r': '0x', 's': '0x'}")
|
||||
r = t.rlp_serialize()
|
||||
self.assertEqual(r.hex(), 'ea808504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef018080')
|
||||
|
||||
t = EIP155Transaction(tx_hexs, 0)
|
||||
self.assertRegex(t.__class__.__name__, "Transaction")
|
||||
s = t.serialize()
|
||||
self.assertDictEqual(s, tx_hexs_r)
|
||||
self.assertEqual('{}'.format(s), "{'nonce': '0x', 'gasPrice': '0x04a817c800', 'gas': '0x5208', 'to': '0x3535353535353535353535353535353535353535', 'value': '0x03e8', 'data': '0xdeadbeef', 'v': '0x01', 'r': '0x', 's': '0x'}")
|
||||
r = t.rlp_serialize()
|
||||
self.assertEqual(r.hex(), 'ea808504a817c8008252089435353535353535353535353535353535353535358203e884deadbeef018080')
|
||||
|
||||
@@ -100,6 +91,7 @@ class TestSign(unittest.TestCase):
|
||||
s = ReferenceSigner(self.pk_getter)
|
||||
z = s.sign_ethereum_message(tx_ints['from'], '666f6f')
|
||||
z = s.sign_ethereum_message(tx_ints['from'], b'foo')
|
||||
logg.debug('zzz {}'.format(str(z)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user