Skip to content

Commit 4073127

Browse files
author
Ross Nicoll
committed
Added more unit tests on hash signing.
1 parent 22d0256 commit 4073127

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

bitcoin/core/key.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ def get_ecdh_key(self, other_pubkey, kdf=lambda k: hashlib.sha256(k).digest()):
9999
return kdf(r)
100100

101101
def sign(self, hash):
102-
# FIXME: need unit tests for below cases
103102
if not isinstance(hash, bytes):
104103
raise TypeError('Hash must be bytes instance; got %r' % hash.__class__)
105104
if len(hash) != 32:

bitcoin/tests/test_wallet.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,19 @@ def test_sign(self):
218218
hash = b'\x00' * 32
219219
sig = key.sign(hash)
220220

221-
# FIXME: need better tests than this
221+
# Check a valid signature
222222
self.assertTrue(key.pub.verify(hash, sig))
223+
224+
# Check invalid hash returns false
223225
self.assertFalse(key.pub.verify(b'\xFF'*32, sig))
226+
# Check invalid signature returns false
224227
self.assertFalse(key.pub.verify(hash, sig[0:-1] + b'\x00'))
228+
229+
def test_sign_invalid_hash(self):
230+
key = CBitcoinSecret('5KJvsngHeMpm884wtkJNzQGaCErckhHJBGFsvd3VyK5qMZXj3hS')
231+
with self.assertRaises(TypeError):
232+
sig = key.sign('0' * 32)
233+
234+
hash = b'\x00' * 32
235+
with self.assertRaises(ValueError):
236+
sig = key.sign(hash[0:-2])

0 commit comments

Comments
 (0)