Esempio n. 1
0
def test_get_proof_key_does_not_exist():
    trie = HexaryTrie({})
    trie[b"hello"] = b"world"
    trie[b"hi"] = b"there"
    proof = trie.get_proof(b"hey")

    assert len(proof) > 0
    assert HexaryTrie.get_from_proof(trie.root_hash, b"hey", proof) == b''
Esempio n. 2
0
def test_trie_using_fixtures(fixture_name, fixture):

    keys_and_values = fixture['in']
    deletes = tuple(k for k, v in keys_and_values if v is None)
    remaining = {
        k: v
        for k, v
        in keys_and_values
        if k not in deletes
    }

    for kv_permutation in itertools.islice(itertools.permutations(keys_and_values), 100):
        print("in it")
        trie = HexaryTrie(db={})

        for key, value in kv_permutation:
            if value is None:
                del trie[key]
            else:
                trie[key] = value
        for key in deletes:
            del trie[key]

        for key, expected_value in remaining.items():
            assert key in trie
            actual_value = trie[key]
            assert actual_value == expected_value

        for key in deletes:
            assert key not in trie

        expected_root = fixture['root']
        actual_root = trie.root_hash

        assert actual_root == expected_root
Esempio n. 3
0
def test_get_from_proof_key_exists():
    from .sample_proof_key_exists import key, state_root, proof
    assert HexaryTrie.get_from_proof(state_root, key, proof) != b''
Esempio n. 4
0
def test_get_from_proof_empty():
    state_root = keccak(b'state root')
    key = keccak(b'some key')
    proof = []
    with pytest.raises(BadTrieProof):
        HexaryTrie.get_from_proof(state_root, key, proof)
Esempio n. 5
0
def test_get_from_proof_invalid():
    from .sample_proof_key_exists import key, state_root, proof
    proof[5][3] = b''
    with pytest.raises(BadTrieProof):
        HexaryTrie.get_from_proof(state_root, key, proof)
Esempio n. 6
0
def test_get_from_proof_key_does_not_exist():
    from .sample_proof_key_does_not_exist import key, state_root, proof
    assert HexaryTrie.get_from_proof(state_root, key, proof) == b''