コード例 #1
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_wellformed():
    resources = [hexlify(urandom(16)) for _ in range(1000)]
    # def packageTx(data, deps, num_out)
    transactions = []
    for x in range(100):
        deps = sample(resources,2)
        data = json.dumps({"ID":x})
        tx = packageTx(data, deps, 2)
        transactions.append((tx, data))
    # [(hexlify(urandom(16)), sample(resources,2), []) for x in range(300)]

    n = Node(resources, 1)
    n.quiet = True
    shuffle(transactions)
    # tx_list = sample(transactions, 100)

    with Timer() as t:
        for tx, data in transactions:
            idx, deps, out, txdata = tx

            ## First perform the Tx checks
            assert packageTx(data, deps, 2) == tx

            ## Now process this transaction
            n.process(tx)
            
    print "Time taken: %2.2f sec" % (t.interval) 
コード例 #2
0
def test_wellformed():
    resources = [hexlify(urandom(16)) for _ in range(1000)]
    # def packageTx(data, deps, num_out)
    transactions = []
    for x in range(100):
        deps = sample(resources, 2)
        data = json.dumps({"ID": x})
        tx = packageTx(data, deps, 2)
        transactions.append((tx, data))
    # [(hexlify(urandom(16)), sample(resources,2), []) for x in range(300)]

    n = Node(resources, 1)
    n.quiet = True
    shuffle(transactions)
    # tx_list = sample(transactions, 100)

    with Timer() as t:
        for tx, data in transactions:
            idx, deps, out, txdata = tx

            ## First perform the Tx checks
            assert packageTx(data, deps, 2) == tx

            ## Now process this transaction
            n.process(tx)

    print "Time taken: %2.2f sec" % (t.interval)
コード例 #3
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_small_chain():
    T1 = ("T1", ["A"], ["B"], "")
    T2 = ("T2", ["B"], ["C"], "")

    n = Node(["A"],1)
    n.process(T1)
    n.process(T2)
    assert "C" in n.pending_available
コード例 #4
0
def test_small_chain():
    T1 = ("T1", ["A"], ["B"], "")
    T2 = ("T2", ["B"], ["C"], "")

    n = Node(["A"], 1)
    n.process(T1)
    n.process(T2)
    assert "C" in n.pending_available
コード例 #5
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_chain_conflict():
    T1 = ("T1", ["A"], ["B"], "")
    T2 = ("T2", ["A"], ["C"], "")
    T3 = ("T3", ["B"], ["D"], "")
    T4 = ("T4", ["C"], ["F"], "")

    n = Node(["A"],1)
    for tx in [T1, T2, T3, T4]:
        n.process(tx)
コード例 #6
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_small():
    T1 = ("T1", ["A", "B"], [], "")
    T2 = ("T2", ["B", "C"], [], "")

    n = Node(["A", "B", "C"],1)
    n.process(T1)
    n.process(T2)
    assert "T1" in n.commit_yes
    assert "T2" not in n.commit_yes
コード例 #7
0
def test_chain_conflict():
    T1 = ("T1", ["A"], ["B"], "")
    T2 = ("T2", ["A"], ["C"], "")
    T3 = ("T3", ["B"], ["D"], "")
    T4 = ("T4", ["C"], ["F"], "")

    n = Node(["A"], 1)
    for tx in [T1, T2, T3, T4]:
        n.process(tx)
コード例 #8
0
def test_small():
    T1 = ("T1", ["A", "B"], [], "")
    T2 = ("T2", ["B", "C"], [], "")

    n = Node(["A", "B", "C"], 1)
    n.process(T1)
    n.process(T2)
    assert "T1" in n.commit_yes
    assert "T2" not in n.commit_yes
コード例 #9
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_random():
    resources = [hexlify(urandom(16)) for _ in range(300)]
    transactions = [(hexlify(urandom(16)), sample(resources,2), [], "") for _ in range(300)]

    n = Node(resources, 2)
    shuffle(transactions)
    tx_list = sample(transactions, 100)
    for tx in transactions:
        n.process(tx)

    n2 = Node(resources,2)
    n.gossip_towards(n2)
    for tx in transactions:
        n2.process(tx)
コード例 #10
0
def test_random():
    resources = [hexlify(urandom(16)) for _ in range(300)]
    transactions = [(hexlify(urandom(16)), sample(resources, 2), [], "")
                    for _ in range(300)]

    n = Node(resources, 2)
    shuffle(transactions)
    tx_list = sample(transactions, 100)
    for tx in transactions:
        n.process(tx)

    n2 = Node(resources, 2)
    n.gossip_towards(n2)
    for tx in transactions:
        n2.process(tx)
コード例 #11
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_quorum_simple():
    T1 = ("T1", ["A", "B"], [], "")
    T2 = ("T2", ["B", "C"], [], "")

    n1 = Node(["A", "B", "C"], 2)
    n2 = Node(["A", "B", "C"], 2)
    n3 = Node(["A", "B", "C"], 2)

    n1.process(T1)
    n2.process(T2)
    n2.process(T1)
    n3.process(T1)

    n1.gossip_towards(n2)
    n3.gossip_towards(n2)

    n2.process(T1)
    assert "T1" in n2.commit_yes
コード例 #12
0
def test_quorum_simple():
    T1 = ("T1", ["A", "B"], [], "")
    T2 = ("T2", ["B", "C"], [], "")

    n1 = Node(["A", "B", "C"], 2)
    n2 = Node(["A", "B", "C"], 2)
    n3 = Node(["A", "B", "C"], 2)

    n1.process(T1)
    n2.process(T2)
    n2.process(T1)
    n3.process(T1)

    n1.gossip_towards(n2)
    n3.gossip_towards(n2)

    n2.process(T1)
    assert "T1" in n2.commit_yes
コード例 #13
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_shard_simple():
    T1 = ("333", ["444", "ccc"], [], "")
    T2 = ("bbb", ["444", "ddd"], [], "")

    n1 = Node(["444"], 1, name="n1", shard=["000", "aaa"])
    n2 = Node(["ccc", "ddd"], 1, name="n2", shard=["aaa", "fff"])

    n1.process(T1)
    n1.process(T2)
    print n1.pending_vote
    n2.process(T2)
    n2.process(T1)

    n1.gossip_towards(n2)

    n2.process(T1)
    n2.process(T2)
    
    assert '333' in n2.commit_yes
コード例 #14
0
def test_shard_simple():
    T1 = ("333", ["444", "ccc"], [], "")
    T2 = ("bbb", ["444", "ddd"], [], "")

    n1 = Node(["444"], 1, name="n1", shard=["000", "aaa"])
    n2 = Node(["ccc", "ddd"], 1, name="n2", shard=["aaa", "fff"])

    n1.process(T1)
    n1.process(T2)
    print n1.pending_vote
    n2.process(T2)
    n2.process(T1)

    n1.gossip_towards(n2)

    n2.process(T1)
    n2.process(T2)

    assert '333' in n2.commit_yes
コード例 #15
0
ファイル: test_consensus.py プロジェクト: hhalpin/updatechain
def test_quorum_threesome():
    T1 = ("T1", ["A", "B"], [], "")
    T2 = ("T2", ["B", "C"], [], "")
    T3 = ("T3", ["A", "C"], [], "")

    n1 = Node(["A", "B", "C"], 2)
    n2 = Node(["A", "B", "C"], 2)
    n3 = Node(["A", "B", "C"], 2)

    n1.process(T1)
    n2.process(T2)
    n3.process(T3)

    n1.process(T2)
    n1.process(T3)
    n2.process(T1)
    n2.process(T3)
    n3.process(T1)
    n3.process(T2)

    n1.gossip_towards(n3)
    n2.gossip_towards(n3)

    n3.process(T1)
    n3.process(T2)  
    n3.process(T3)
    assert "T1" in n3.commit_no
    assert "T2" in n3.commit_no
    assert "T3" in n3.commit_no
コード例 #16
0
def test_quorum_threesome():
    T1 = ("T1", ["A", "B"], [], "")
    T2 = ("T2", ["B", "C"], [], "")
    T3 = ("T3", ["A", "C"], [], "")

    n1 = Node(["A", "B", "C"], 2)
    n2 = Node(["A", "B", "C"], 2)
    n3 = Node(["A", "B", "C"], 2)

    n1.process(T1)
    n2.process(T2)
    n3.process(T3)

    n1.process(T2)
    n1.process(T3)
    n2.process(T1)
    n2.process(T3)
    n3.process(T1)
    n3.process(T2)

    n1.gossip_towards(n3)
    n2.gossip_towards(n3)

    n3.process(T1)
    n3.process(T2)
    n3.process(T3)
    assert "T1" in n3.commit_no
    assert "T2" in n3.commit_no
    assert "T3" in n3.commit_no