def respond(self, data_hash, position): ''' Respond to a challenge ''' try: data = self.data[data_hash].data except: # You don't have this data. Can implement code to cheat? return None values = [data[i:i+split_n] for i in range(0, len(data), split_n)] merkle = MerkleTree(values) return merkle.prove(position)
def test_merkle(): # Handle some data filename = 'merkle.txt' data = read_data(filename) size = check_filesize(filename) # Test Merkle tree first # Split into 8 parts values = data.splitlines() # Test the address is root address is always the same merkle = MerkleTree(values) # print(merkle.address()) # Test contain text merkle_1 in merkle (should have) test_1 = merkle.prove(0) # Prove is correct # Need to check for contains print(merkle.contains(test_1)) return