示例#1
0
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)
    )
示例#2
0
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
示例#3
0
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
示例#4
0
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
示例#5
0
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)
示例#6
0
def test_invalid_proof(tree_data):
    tree = build_tree(tree_data)

    item = next(iter(tree_data))
    assert not validate_proof(item, [], tree.root.hash)
示例#7
0
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)
示例#8
0
def test_in_tree(tree_data):
    tree = build_tree(tree_data)

    assert all(in_tree(item, tree.root) for item in tree_data)
示例#9
0
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)
示例#10
0
def root_hash_for_tree_data_small_values(tree_data_small_values):
    tree = build_tree(tree_data_small_values)
    return tree.root.hash
示例#11
0
def root_hash_for_tree_data(tree_data):
    tree = build_tree(tree_data)
    return tree.root.hash