From 6bc81a7b14cce6a8ac7e41edde4bcaa9cd4e9f9d Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Wed, 8 Aug 2012 02:11:43 -0400 Subject: [PATCH] fixed natural_to_string's encoding of 0 --- p2pool/test/util/test_math.py | 6 +++++- p2pool/util/math.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/p2pool/test/util/test_math.py b/p2pool/test/util/test_math.py index d81d9a0..226b8e5 100644 --- a/p2pool/test/util/test_math.py +++ b/p2pool/test/util/test_math.py @@ -21,7 +21,11 @@ class Test(unittest.TestCase): for i in xrange(10): alphabet = generate_alphabet() for i in xrange(100): - n = random.randrange(100000000000000000000000000000) + n = random.choice([ + random.randrange(3), + random.randrange(300), + random.randrange(100000000000000000000000000000), + ]) s = math.natural_to_string(n, alphabet) n2 = math.string_to_natural(s, alphabet) #print n, s.encode('hex'), n2 diff --git a/p2pool/util/math.py b/p2pool/util/math.py index c13494f..c45d1ec 100644 --- a/p2pool/util/math.py +++ b/p2pool/util/math.py @@ -179,7 +179,7 @@ def natural_to_string(n, alphabet=None): if n < 0: raise TypeError('n must be a natural') if alphabet is None: - s = '%x' % (n,) + s = ('%x' % (n,)).lstrip('0') if len(s) % 2: s = '0' + s return s.decode('hex') -- 1.7.1