]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
test_hashtree.py: get full coverage for hashtree.py
authorBrian Warner <warner@allmydata.com>
Fri, 13 Apr 2007 02:58:13 +0000 (19:58 -0700)
committerBrian Warner <warner@allmydata.com>
Fri, 13 Apr 2007 02:58:13 +0000 (19:58 -0700)
src/allmydata/test/test_hashtree.py

index b2907a6132cfd30e3bf6054e8d1cd3cbc8177b9a..f5bbb49ba05849325cfdd9e8bf5e62b8baca69cc 100644 (file)
@@ -23,6 +23,8 @@ class Complete(unittest.TestCase):
         self.failUnlessEqual(ht.get_leaf(0), tagged_hash("tag", "0"))
         self.failUnlessRaises(IndexError, ht.get_leaf, 8)
         self.failUnlessEqual(ht.get_leaf_index(0), 7)
+        self.failUnlessRaises(IndexError, ht.parent, 0)
+        self.failUnlessRaises(IndexError, ht.needed_for, -1)
 
     def test_needed_hashes(self):
         ht = make_tree(8)
@@ -82,8 +84,8 @@ class Incomplete(unittest.TestCase):
         iht = hashtree.IncompleteHashTree(6)
 
         current_hashes = list(iht)
+        # this should fail because there aren't enough hashes known
         try:
-            # this should fail because there aren't enough hashes known
             iht.set_hashes(leaves={0: tagged_hash("tag", "0")})
         except hashtree.NotEnoughHashesError:
             pass
@@ -96,14 +98,23 @@ class Incomplete(unittest.TestCase):
         self.failUnlessEqual(iht.needed_hashes(0), set([8, 4, 2]))
 
         chain = {0: ht[0], 2: ht[2], 4: ht[4], 8: ht[8]}
+        # this should fail because the leaf hash is just plain wrong
         try:
-            # this should fail because the leaf hash is just plain wrong
             iht.set_hashes(chain, leaves={0: tagged_hash("bad tag", "0")})
         except hashtree.BadHashError:
             pass
         else:
             self.fail("didn't catch bad hash")
 
+        # this should fail because we give it conflicting hashes: one as an
+        # internal node, another as a leaf
+        try:
+            iht.set_hashes(chain, leaves={1: tagged_hash("bad tag", "1")})
+        except hashtree.BadHashError:
+            pass
+        else:
+            self.fail("didn't catch bad hash")
+
         bad_chain = chain.copy()
         bad_chain[2] = ht[2] + "BOGUS"
 
@@ -130,6 +141,15 @@ class Incomplete(unittest.TestCase):
         except hashtree.BadHashError:
             self.fail("bad hash")
 
+        # this should fail because we give it hashes that conflict with some
+        # that we added successfully before
+        try:
+            iht.set_hashes(leaves={1: tagged_hash("bad tag", "1")})
+        except hashtree.BadHashError:
+            pass
+        else:
+            self.fail("didn't catch bad hash")
+
         # now that leaves 0 and 1 are known, some of the internal nodes are
         # known
         self.failUnlessEqual(iht.needed_hashes(4), set([12, 6]))