Rehabilitate tests, rename camelcase sign methods to snake case

This commit is contained in:
nolash
2021-03-26 13:08:36 +01:00
parent 80cc54e3ba
commit c669ed829f
9 changed files with 26 additions and 28 deletions

View File

@@ -4,12 +4,8 @@ import logging
# external imports
import sha3
import coincurve
#from eth_keys import KeyAPI
#from eth_keys.backends import NativeECCBackend
#keys = KeyAPI(NativeECCBackend)
#logg = logging.getLogger(__name__)
logg = logging.getLogger()
logg = logging.getLogger().getChild(__name__)
class Signer:
@@ -19,9 +15,8 @@ class Signer:
self.keyGetter = keyGetter
def signTransaction(self, tx, password=None):
raise NotImplementedError
def sign_transaction(self, tx, password=None):
return NotImplementedError
class ReferenceSigner(Signer):
@@ -31,7 +26,7 @@ class ReferenceSigner(Signer):
super(ReferenceSigner, self).__init__(keyGetter)
def signTransaction(self, tx, password=None):
def sign_transaction(self, tx, password=None):
s = tx.rlp_serialize()
h = sha3.keccak_256()
h.update(s)
@@ -58,7 +53,7 @@ class ReferenceSigner(Signer):
return z
def signEthereumMessage(self, address, message, password=None):
def sign_ethereum_message(self, address, message, password=None):
#k = keys.PrivateKey(self.keyGetter.get(address, password))
#z = keys.ecdsa_sign(message_hash=g, private_key=k)
@@ -82,6 +77,7 @@ class ReferenceSigner(Signer):
return z
# TODO: generic sign should be moved to non-eth context
def sign(self, address, message, password=None):
pk = coincurve.PrivateKey(secret=self.keyGetter.get(address, password))
z = pk.sign_recoverable(hasher=None, message=message)

View File

@@ -27,9 +27,11 @@ class EIP155Transaction:
to = None
data = None
if tx['to'] != None:
to = binascii.unhexlify(strip_0x(tx['to'], allow_empty=True))
#to = binascii.unhexlify(strip_0x(tx['to'], allow_empty=True))
to = bytes.fromhex(strip_0x(tx['to'], allow_empty=True))
if tx['data'] != None:
data = binascii.unhexlify(strip_0x(tx['data'], allow_empty=True))
#data = binascii.unhexlify(strip_0x(tx['data'], allow_empty=True))
data = bytes.fromhex(strip_0x(tx['data'], allow_empty=True))
gas_price = None
start_gas = None

View File

@@ -72,7 +72,7 @@ class TxExecutor:
logg.debug('from {} nonce {} tx {}'.format(self.sender, self.nonce, tx))
chain_tx = EIP155Transaction(tx, self.nonce, self.chain_id)
signature = self.signer.signTransaction(chain_tx)
signature = self.signer.sign_transaction(chain_tx)
chain_tx_serialized = chain_tx.rlp_serialize()
tx_hash = self.dispatcher('0x' + chain_tx_serialized.hex())
self.tx_hashes.append(tx_hash)

View File

@@ -106,7 +106,7 @@ def personal_sign_transaction(p):
logg.debug('got {} to sign'.format(p[0]))
#t = EIP155Transaction(p[0], p[0]['nonce'], 8995)
t = EIP155Transaction(p[0], p[0]['nonce'], int(p[0]['chainId']))
z = signer.signTransaction(t, p[1])
z = signer.sign_transaction(t, p[1])
raw_signed_tx = t.rlp_serialize()
o = {
'raw': '0x' + raw_signed_tx.hex(),
@@ -116,8 +116,8 @@ def personal_sign_transaction(p):
return o
# TODO: temporary workaround for platform, since personal_signTransaction is missing from web3.py
def eth_signTransaction(tx):
# TODO: temporary workaround for platform, since personal_sign_transaction is missing from web3.py
def eth_sign_transaction(tx):
return personal_sign_transaction([tx[0], ''])
@@ -126,14 +126,14 @@ def eth_sign(p):
message_type = type(p[1]).__name__
if message_type != 'str':
raise ValueError('invalid message format, must be {}, not {}'.format(message_type))
z = signer.signEthereumMessage(p[0], p[1][2:])
z = signer.sign_ethereum_message(p[0], p[1][2:])
return str(z)
methods = {
'personal_newAccount': personal_new_account,
'personal_signTransaction': personal_sign_transaction,
'eth_signTransaction': eth_signTransaction,
'personal_sign_transaction': personal_sign_transaction,
'eth_sign_transaction': eth_sign_transaction,
'eth_sign': eth_sign,
}