Make signer test pass

This commit is contained in:
nolash
2021-10-10 09:55:15 +02:00
parent 91b94f5ddf
commit e606384ed2
4 changed files with 13 additions and 108 deletions

View File

@@ -1,91 +0,0 @@
# 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()

View File

@@ -12,8 +12,8 @@ from psycopg2 import sql
from cryptography.fernet import Fernet, InvalidToken
# local imports
from crypto_dev_signer.keystore.reference import ReferenceKeystore
from crypto_dev_signer.error import UnknownAccountError
from funga.eth.keystore.sql import SQLKeystore
from funga.error import UnknownAccountError
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
@@ -37,7 +37,7 @@ class TestDatabase(unittest.TestCase):
kw = {
'symmetric_key': self.symkey,
}
self.db = ReferenceKeystore('postgres+psycopg2://postgres@localhost:5432/signer_test', **kw)
self.db = SQLKeystore('postgres+psycopg2://postgres@localhost:5432/signer_test', **kw)
self.address_hex = self.db.new('foo')
#self.address_hex = add_0x(address_hex)