def test_store_tree(rstore): t = Tree(store=rstore) from os import urandom for _ in range(100): item = urandom(32) t.add(item, item) assert t.is_in(item) assert not t.is_in(urandom(32))
def test_massive(): t = Tree() from os import urandom for _ in range(100): item = urandom(32) t.add(item) assert t.is_in(item) assert not t.is_in(urandom(32))
def test_add_isin(): t = Tree() # Test positive case t.add("Hello") assert t.is_in("Hello") == True # Infix operator assert "Hello" in t
def test_add_isin(): t = Tree() # Test positive case t.add(b"Hello") assert t.is_in(b"Hello") == True # Infix operator assert b"Hello" in t
def main(): t = Tree() from os import urandom for _ in range(1000): item = urandom(32) t.add(item) assert t.is_in(item) assert not t.is_in(urandom(32))
def main(): r = RedisStore() t = Tree(store=r) from os import urandom for _ in range(1000): item = urandom(32) t.add(item) assert t.is_in(item) assert not t.is_in(urandom(32))
def test_evidence(): from hippiehug import Tree t = Tree() t.add(b"Hello") t.add(b"World") root, E = t.evidence(b"World") assert root == t.root() store = dict((e.identity(), e) for e in E) t2 = Tree(store, root) assert b"World" in t2
def test_store(): import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) r.flushdb() from hippiehug import Tree, RedisStore r = RedisStore(host="localhost", port=6379, db=0) t = Tree(store = r) t.add(b"Hello") assert b"Hello" in t
def test_store(): import redis r = redis.StrictRedis(host='localhost', port=6379, db=0) r.flushdb() from hippiehug import Tree, RedisStore r = RedisStore(host="localhost", port=6379, db=0) t = Tree(store = r) t.add("Hello") assert "Hello" in t
def test_evidence(): from hippiehug import Tree t = Tree() t.add("Hello") t.add("World") root, E = t.evidence("World") assert root == t.root() store = dict((e.identity(), e) for e in E) t2 = Tree(store, root) assert "World" in t2
def test_store_tree(): _flushDB() r = RedisStore() t = Tree(store = r) from os import urandom for _ in range(100): item = urandom(32) t.add(item) assert t.is_in(item) assert not t.is_in(urandom(32))
def test_store_tree(): _flushDB() r = RedisStore() t = Tree(store=r) from os import urandom for _ in range(100): item = urandom(32) t.add(item, item) assert t.is_in(item) assert not t.is_in(urandom(32))
def test_evidence(): t = Tree() # Test positive case t.add(b"Hello", b"Hello") t.add(b"World", b"World") root, E = t.evidence(b"World") assert len(E) == 2 store = dict((e.identity(), e) for e in E) t2 = Tree(store, root) assert t2.is_in(b"World")
def test_evidence(): t = Tree() # Test positive case t.add("Hello") t.add("World") root, E = t.evidence("World") assert len(E) == 2 store = dict((e.identity(), e) for e in E) t2 = Tree(store, root) assert t2.is_in("World")
def test_e2e_timings(): friends_graph, all_data = generate_test_data() (labels, heads, pubkeys, privkeys) = all_data with LocalParams.generate().as_default() as params: nonce = os.urandom(PublicParams.get_default().nonce_size) # Encode claims t0 = time.time() c0 = 0 enc_claims = [] vrfs = [] for claim_label, claim_body in zip(labels, heads): c0 += 1 c0 += 1 enc = encode_claim(nonce, claim_label, claim_body) vrf_value, lookup_key, encrypted_claim = enc enc_claims += [(lookup_key, encrypted_claim)] vrfs += [vrf_value] t1 = time.time() print("\n\t\tTiming per encoded claim: %1.1f ms" % ((t1 - t0) / c0 * 1000)) # Encode capabilities t0 = time.time() c0 = 0 capabilities = [] cap_index = {} for friend in friends_graph: friend_dh_pk = pubkeys[friend] for fof in friends_graph[friend]: c0 += 1 claim_label = labels[fof] vrf_value = vrfs[fof] cap_lookup_key, encrypted_cap = encode_capability( friend_dh_pk, nonce, claim_label, vrf_value) capabilities += [(cap_lookup_key, encrypted_cap)] cap_index[(friend, fof)] = (cap_lookup_key, encrypted_cap) t1 = time.time() print("\t\tTiming per encoded capab: %1.1f ms" % ((t1 - t0) / c0 * 1000)) data = encode([enc_claims, capabilities]) print("\t\tData length: %1.1f kb" % (len(data) / 1024.0)) # Build our non-equivocable tree t0 = time.time() tree = Tree() for lookup_key, enc_item in enc_claims + capabilities: tree.add(key=lookup_key, item=enc_item) _, evidence = tree.evidence(key=lookup_key) assert tree.is_in(enc_item, key=lookup_key) enc_item_hash = evidence[-1].item tree.store[enc_item_hash] = enc_item t1 = time.time() print("\t\tTiming for building non-equiv. tree: %1.1f ms" % ((t1 - t0) * 1000)) # Build a chain and a block t0 = time.time() c0 = 200 for _ in range(c0): chain = Chain(tree.store) payload = Payload.build(tree, nonce).export() def sign_block(block): sig = sign(block.hash()) block.aux = pet2ascii(sig) chain.multi_add([payload], pre_commit_fn=sign_block) # Pack block block = chain.store[chain.head] packed_block = packb( ("S", block.index, block.fingers, block.items, block.aux)) t1 = time.time() print("\t\tTiming for building a block: %1.1f ms" % ((t1 - t0) / c0 * 1000)) print("\t\tPacked block size: %d bytes" % (len(packed_block))) t0 = time.time() c0 = 0 # Pick a random reader for reader in friends_graph: reader_params = LocalParams( dh=Keypair(sk=privkeys[reader], pk=pubkeys[reader])) for reader_friend in friends_graph[reader]: claim_label = labels[reader_friend] with reader_params.as_default(): view = View(chain) c0 += 1 head = view[labels[reader_friend]] assert head == heads[reader_friend] t1 = time.time() print("\t\tTiming for retrieving a claim by label: %1.1f ms" % ((t1 - t0) / c0 * 1000)) # Pick a target proof to produce f1 = random.choice(list(friends_graph.keys())) f2 = random.choice(list(friends_graph[f1])) (cap_lookup_key, encrypted_cap) = cap_index[(f1, f2)] (claim_lookup_key, encrypted_claim) = enc_claims[f2] root, e1 = tree.evidence(key=cap_lookup_key) _, e2 = tree.evidence(key=claim_lookup_key) evidence_store = {e.identity(): e for e in e1 + e2} t2 = Tree(evidence_store, root) assert t2.is_in(key=cap_lookup_key, item=encrypted_cap) assert t2.is_in(key=claim_lookup_key, item=encrypted_claim) # Serialize evidence: evidence = [] for e in e1 + e2: if isinstance(e, Leaf): evidence += [(e.key, e.item, tree.store[e.item])] elif isinstance(e, Branch): evidence += [(e.pivot, e.left_branch, e.right_branch)] else: pass import zlib bin_evidence = encode(evidence) bin_evidence_compressed = zlib.compress(bin_evidence, 9) print("\t\tSize for one proof: %s bytes (compressed %s bytes)" % (len(bin_evidence), len(bin_evidence_compressed))) print("\t\tPayload:") pprint(payload)
def test_store(rstore): from hippiehug import Tree t = Tree(store=rstore) t.add(b"Hello") assert b"Hello" in t
def test_basic(): from hippiehug import Tree t = Tree() t.add(b"Hello") assert b"Hello" in t assert b"World" not in t
def test_basic(): from hippiehug import Tree t = Tree() t.add("Hello") assert "Hello" in t assert "World" not in t