electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 05dba32315d7d9ec7a50c7ea3c8d5dcc69462f0d
parent 54973062bd903bda787bb94a66bc4eff7b35b77b
Author: ThomasV <thomasv@gitorious>
Date:   Wed, 25 Jun 2014 16:46:05 +0200

Merge branch 'master' of git://github.com/spesmilo/electrum

Diffstat:
Mlib/tests/test_bitcoin.py | 39++++++++++++++++++++++++++++++++++++++-
Alib/tests/test_util.py | 19+++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/lib/tests/test_bitcoin.py b/lib/tests/test_bitcoin.py @@ -6,7 +6,7 @@ from lib.bitcoin import ( generator_secp256k1, point_to_ser, public_key_to_bc_address, EC_KEY, bip32_root, bip32_public_derivation, bip32_private_derivation, pw_encode, pw_decode, Hash, public_key_from_private_key, address_from_private_key, - is_valid, is_private_key) + is_valid, is_private_key, mnemonic_to_seed) try: import ecdsa @@ -81,6 +81,26 @@ class Test_bitcoin(unittest.TestCase): dec = pw_decode(enc, password) self.assertEqual(dec, payload) + def test_aes_encode_without_password(self): + """When not passed a password, pw_encode is noop on the payload.""" + payload = u'\u66f4\u7a33\u5b9a\u7684\u4ea4\u6613\u5e73\u53f0' + enc = pw_encode(payload, None) + self.assertEqual(payload, enc) + + def test_aes_deencode_without_password(self): + """When not passed a password, pw_decode is noop on the payload.""" + payload = u'\u66f4\u7a33\u5b9a\u7684\u4ea4\u6613\u5e73\u53f0' + enc = pw_decode(payload, None) + self.assertEqual(payload, enc) + + def test_aes_decode_with_invalid_password(self): + """pw_decode raises an Exception when supplied an invalid password.""" + payload = u"blah" + password = u"uber secret" + wrong_password = u"not the password" + enc = pw_encode(payload, password) + self.assertRaises(Exception, pw_decode, enc, wrong_password) + def test_hash(self): """Make sure the Hash function does sha256 twice""" payload = u"test" @@ -113,3 +133,20 @@ class Test_keyImport(unittest.TestCase): def test_is_private_key(self): self.assertTrue(is_private_key(self.private_key)) self.assertFalse(is_private_key(self.public_key_hex)) + + +class Test_mnemonic(unittest.TestCase): + + def test_mnemonic_to_seed_no_passphrase(self): + mnemonic = "remember you must" + passphrase = "" + expected = '\xa5\x05c!\x97\x8dv2\x11P\x00\x88\x1a\xfbn;\xa6m\xe4a\n"\xf7\x1a\x8e\x10\xbc\xa7\xf2c\xcfX\xa8v;F\x0f&0\x93\xd9l\xd4\xe0\x1a\xc3Y\xa0b\xbb\xd3\xa6=\x00|0\xb6\xd6\x87*Y\x02\xb5i' + result = mnemonic_to_seed(mnemonic, passphrase) + self.assertEqual(expected, result) + + def test_mnemonic_to_seed_with_passphrase(self): + mnemonic = "remember you must" + passphrase = "secret" + expected = '\x1c\x11u\xd0\xca$DsrK\xa8\xe63\x9e\xfa\x02|\xb4\xdb\xdc~\x86\xbf\xf2Z\xe6\xb6\x17D\x11S\xc0\xa1\x0f$m\xb8\xf3\xad\x12\x83@B]\xe8^\x82\x10z\xe8V\xba\x81.Ou\x1c\x93&\xe8\xac\xf6\x9a\xf9' + result = mnemonic_to_seed(mnemonic, passphrase) + self.assertEqual(expected, result) diff --git a/lib/tests/test_util.py b/lib/tests/test_util.py @@ -0,0 +1,19 @@ +import unittest +from lib.util import format_satoshis + +class TestUtil(unittest.TestCase): + + def test_format_satoshis(self): + result = format_satoshis(1234) + expected = "0.00001234" + self.assertEqual(expected, result) + + def test_format_satoshis_diff_positive(self): + result = format_satoshis(1234, is_diff=True) + expected = "+0.00001234" + self.assertEqual(expected, result) + + def test_format_satoshis_diff_negative(self): + result = format_satoshis(-1234, is_diff=True) + expected = "-0.00001234" + self.assertEqual(expected, result)