wownero-python/tests/test_seed.py

66 lines
3.7 KiB
Python
Raw Normal View History

Squashed commit of the following: commit 091aa668e194489e3a45e418941ea922c09f7024 Author: lance allen <lrallen03@gmail.com> Date: Mon Feb 19 09:32:50 2018 -0800 removing extraneous import commit 47d2dbcf4e20a4cbba1bb77caa39e8005db00042 Author: lance allen <lrallen03@gmail.com> Date: Mon Feb 19 00:18:19 2018 -0800 matching the version to emesik master and fixing the method name commit 63b5f5fae3a3125b36a6ed18f3f7e47e54cd1d1d Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 22:38:37 2018 -0800 adding unit file for seed class commit 515ccfe18663d6f52810d59ccdd9ab51e2be7d58 Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 22:38:17 2018 -0800 updating init files commit 6e0803661f08694a5a81a83a7fbeede6e18f741c Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 22:37:46 2018 -0800 updating init from assert to raise, set gte operator on checks commit e066039bf8ccf5128987e6d291864f3a9d61df28 Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 18:42:30 2018 -0800 move get_checksum outside of class and always return seed with checksum commit 1b0cb8adc6945d777abba18acfcaf8d3b6f4be42 Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 17:14:46 2018 -0800 removing extraneous seed_ prefixes from class vars and change class param to commit 9b60a34da554696f3cfbfd7cb3f0780dfc32bc55 Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 13:52:12 2018 -0800 move generate_hex function outside of class commit 162036cb38ff5a90cf515fd951d70299117866aa Author: lance allen <lrallen03@gmail.com> Date: Sun Feb 18 13:49:46 2018 -0800 adding string input to class constructor and determine validity commit 30f04ade1819b152fd600eff0b7364d9bd7aaab4 Author: lalanza808 <lrallen03@gmail.com> Date: Sat Feb 17 23:59:19 2018 -0800 adding commit hashes and revamping comments commit c46029fbc9bf74bf64231a1d4c4c6613be08bf00 Author: lalanza808 <lrallen03@gmail.com> Date: Sat Feb 17 23:18:07 2018 -0800 adding licensing, verb noun functions, checksum val, hex generation commit fa38d8aa1ea3aeb5ba7d03f89f9610a1b9b76e49 Author: lance allen <lrallen03@gmail.com> Date: Sat Feb 17 16:57:19 2018 -0800 adding seed class for encoding/decoding mnemonic phrases or hex strings commit d523e51a92c626a435aad64740d2fe04eb2f8b99 Author: lance allen <lrallen03@gmail.com> Date: Sat Feb 17 16:57:03 2018 -0800 adding english wordlist for mnemonic seeds commit f6d78a497a0d48b565f1a584b51150a03f9df7d6 Author: lance allen <lrallen03@gmail.com> Date: Sat Feb 17 16:56:48 2018 -0800 updating monero init file to include wordlists
2018-02-19 17:35:30 +00:00
#!/usr/bin/env python
import unittest
from monero.seed import Seed, get_checksum
class SeedTestCase(unittest.TestCase):
def test_mnemonic_seed(self):
# Known good 25 word seed phrases should construct a class, validate checksum, and register valid hex
seed = Seed("wedge going quick racetrack auburn physics lectures light waist axes whipped habitat square awkward together injury niece nugget guarded hive obnoxious waxing faked folding square")
self.assertTrue(seed.validate_checksum())
self.assertEqual(seed.hex, "8ffa9f586b86d294d93731765d192765311bddc76a4fa60311f8af36bbf6fb06")
# Known good 24 word seed phrases should construct a class, store phrase with valid checksum, and register valid hex
seed = Seed("wedge going quick racetrack auburn physics lectures light waist axes whipped habitat square awkward together injury niece nugget guarded hive obnoxious waxing faked folding")
seed.encode_seed()
self.assertTrue(seed.validate_checksum())
self.assertEqual(seed.hex, "8ffa9f586b86d294d93731765d192765311bddc76a4fa60311f8af36bbf6fb06")
# Known good 25 word hexadecimal strings should construct a class, store phrase with valid checksum, and register valid hex
seed = Seed("8ffa9f586b86d294d93731765d192765311bddc76a4fa60311f8af36bbf6fb06")
self.assertTrue(seed.validate_checksum())
self.assertEqual(seed.phrase, "wedge going quick racetrack auburn physics lectures light waist axes whipped habitat square awkward together injury niece nugget guarded hive obnoxious waxing faked folding square")
# Known good 13 word seed phrases should construct a class, validate checksum, and register valid hex
seed = Seed("ought knowledge upright innocent eldest nerves gopher fowls below exquisite aces basin fowls")
self.assertTrue(seed.validate_checksum())
self.assertEqual(seed.hex, "932d70711acc2d536ca11fcb79e05516")
# Known good 12 word seed phrases should construct a class, store phrase with valid checksum, and register valid hex
seed = Seed("ought knowledge upright innocent eldest nerves gopher fowls below exquisite aces basin")
seed.encode_seed()
self.assertTrue(seed.validate_checksum())
self.assertEqual(seed.hex, "932d70711acc2d536ca11fcb79e05516")
# Known good 13 word hexadecimal strings should construct a class, store phrase with valid checksum, and register valid hex
seed = Seed("932d70711acc2d536ca11fcb79e05516")
self.assertTrue(seed.validate_checksum())
self.assertEqual(seed.phrase, "ought knowledge upright innocent eldest nerves gopher fowls below exquisite aces basin fowls")
# Generated seed phrases should be 25 words, validate checksum, register valid hex, and return matching outputs for decode/encode
seed = Seed()
seed_split = seed.phrase.split(" ")
self.assertTrue(len(seed_split) == 25)
self.assertTrue(seed.validate_checksum())
self.assertTrue(len(seed.hex) % 8 == 0)
self.assertEqual(seed.hex, seed.decode_seed())
self.assertEqual(seed.phrase, seed.encode_seed())
# Invalid phrases should not be allowed
with self.assertRaises(ValueError) as ts:
Seed("oh damn you thought fool")
self.assertEqual(ts.expected, ValueError)
with self.assertRaises(ValueError) as ts:
Seed("Thi5isMyS3cr3tPa55w0rd")
self.assertEqual(ts.expected, ValueError)
with self.assertRaises(ValueError) as ts:
Seed(" ")
self.assertEqual(ts.expected, ValueError)
with self.assertRaises(ValueError) as ts:
Seed("\\x008")
self.assertEqual(ts.expected, ValueError)
if __name__ == "__main__":
unittest.main()