def test_valid_proof(tree_data): tree = build_tree(tree_data) proofs = [create_proof(item, tree) for item in tree_data] assert all( validate_proof(item, proof, tree.root.hash) for item, proof in zip(tree_data, proofs) )
def proofs_for_tree_data_small_values(tree_data_small_values): tree = build_tree(tree_data_small_values) proofs = [create_proof(item, tree) for item in tree_data_small_values] assert all( validate_proof(item, proof, tree.root.hash) for item, proof in zip(tree_data_small_values, proofs) ) return proofs
def proofs_for_tree_data(tree_data): tree = build_tree(tree_data) proofs = [create_proof(item, tree) for item in tree_data] assert all( validate_proof(item, proof, tree.root.hash) for item, proof in zip(tree_data, proofs) ) return proofs
def init( airdrop_filename: str, decay_start_time_param: int, decay_duration_in_seconds_param: int, ): global airdrop_dict global airdrop_tree global decay_start_time global decay_duration_in_seconds decay_start = pendulum.from_timestamp(decay_start_time_param) decay_end = pendulum.from_timestamp( decay_start_time_param + decay_duration_in_seconds_param ) app.logger.info(f"Initializing merkle tree from file {airdrop_filename}") app.logger.info(f"Decay from {decay_start} to {decay_end}") airdrop_dict = load_airdrop_file(airdrop_filename) app.logger.info(f"Building merkle tree from {len(airdrop_dict)} entries") airdrop_tree = build_tree(to_items(airdrop_dict)) decay_start_time = decay_start_time_param decay_duration_in_seconds = decay_duration_in_seconds_param
def test_wrong_proof(tree_data): tree = build_tree(tree_data) proofs = [create_proof(item, tree) for item in tree_data] item = next(iter(tree_data)) assert not validate_proof(item, proofs[4], tree.root.hash)
def test_invalid_proof(tree_data): tree = build_tree(tree_data) item = next(iter(tree_data)) assert not validate_proof(item, [], tree.root.hash)
def test_not_in_tree(tree_data, other_data): tree = build_tree(tree_data) assert not any(in_tree(item, tree.root) for item in other_data)
def test_in_tree(tree_data): tree = build_tree(tree_data) assert all(in_tree(item, tree.root) for item in tree_data)
def test_can_not_create_proof_for_missing_item(tree_data, other_data): tree = build_tree(tree_data) with pytest.raises(ValueError): create_proof(other_data[0], tree)
def root_hash_for_tree_data_small_values(tree_data_small_values): tree = build_tree(tree_data_small_values) return tree.root.hash
def root_hash_for_tree_data(tree_data): tree = build_tree(tree_data) return tree.root.hash