def test_set_k(self): # tests that setting the k-th element has exactly the same effect as adding a new element mt1 = MerkleTree() mt2 = MerkleTree() for i in range(len(elements)): mt1.add(elements[i]) mt2.set(mt2.k, elements[i]) self.assertMerkleTreesEqual(mt1, mt2)
def test_set(self): new_el = H("something new") for i in range(len(elements)): # check if the Merkle trees obtained by adding the first i elements, and then setting the i # or constructing directing with the first i elements, are identical. mt1 = MerkleTree(elements) mt1.set(i, new_el) elements_modified = elements[:i] + [new_el] + elements[i + 1:] mt2 = MerkleTree(elements_modified) self.assertMerkleTreesEqual(mt1, mt2)