def test_chain_negative(): c = Chain() for i in range(0, 99): items = [ "%s|%s" % (i,j) for j in range(100) ] c.multi_add(items) with pytest.raises(Exception) as IX: assert c.get(150, 30) == "50|30" with pytest.raises(Exception) as IX: assert c.get(50, 130) == "50|30"
def test_chain_pre_commit(): c = Chain() items = ["main"] def add_aux_data(block): block.aux = ["aux"] c.multi_add(items, pre_commit_fn=add_aux_data) block = c.store[c.head] assert block.items == ["main"] assert block.aux == ["aux"] assert block.hash() in c.store
def test_chain_default_store(): c = Chain() c.multi_add(["test"]) assert c.get(0, 0) is not None c2 = Chain() assert c2.get(0, 0) is None
def test_chain_empty_store(): store = {} c = Chain(store) c.multi_add(["test"]) assert c.get(0, 0) == "test" c2 = Chain(store, root_hash=c.head) assert c2.get(0, 0) == "test"
def test_chain_evidence(): c = Chain() for i in range(0, 99): items = list( map(lambda x: x.encode(), ["%s|%s" % (i, j) for j in range(100)])) c.multi_add(items) evidence = {} res1 = c.get(50, 30, evidence) c2 = Chain(evidence, root_hash=c.head) assert c2.get(50, 30) == b"50|30"
def test_chain_evidence(): c = Chain() for i in range(0, 99): items = [ "%s|%s" % (i,j) for j in range(100) ] c.multi_add(items) evidence = {} res1 = c.get(50, 30, evidence) c2 = Chain(evidence, root_hash = c.head) assert c2.get(50, 30) == "50|30"
def test_chain_negative(): c = Chain() for i in range(0, 99): items = list( map(lambda x: x.encode(), ["%s|%s" % (i, j) for j in range(100)])) c.multi_add(items) with pytest.raises(Exception) as IX: assert c.get(150, 30) == b"50|30" with pytest.raises(Exception) as IX: assert c.get(50, 130) == b"50|30"
def test_chain(): vals = [] c = Chain() for i in range(0, 99): vals += [(i, j, ("%s|%s" % (i, j)).encode()) for j in range(100)] items = list( map(lambda x: x.encode(), ["%s|%s" % (i, j) for j in range(100)])) c.multi_add(items) res1 = c.get(50, 30) assert res1 == b"50|30" assert c.get(0, 1) == b"0|1" for i, j, v in vals: assert c.get(i, j) == v
def test_chain(): vals = [] c = Chain() for i in range(0, 99): vals += [ (i,j,"%s|%s" % (i,j)) for j in range(100)] items = [ "%s|%s" % (i,j) for j in range(100) ] c.multi_add(items) res1 = c.get(50, 30) assert res1 == "50|30" assert c.get(0, 1) == "0|1" for i, j, v in vals: assert c.get(i, j) == v