def test_votinginstruction():
    peer, proto, chain, cb_data, cb = setup()
    height = 1
    bh = '1' * 32
    round_lockset = LockSet(len(validators))
    for i, privkey in enumerate(privkeys):
        if i < len(validators) // 3 + 1:
            v = VoteBlock(height, 0, bh)
        else:
            v = VoteNil(height, 0)
        v.sign(privkey)
        round_lockset.add(v)
    bp = VotingInstruction(height=height, round=1, round_lockset=round_lockset)
    bp.sign(tester.k0)

    payload = bp

    proto.send_votinginstruction(payload)
    packet = peer.packets.pop()
    assert len(rlp.decode(packet.payload)) == 1

    def list_cb(proto, votinginstruction):
        cb_data.append((proto, votinginstruction))

    proto.receive_votinginstruction_callbacks.append(list_cb)
    proto._receive_votinginstruction(packet)

    _p, vi = cb_data.pop()
    assert vi == bp
Beispiel #2
0
def test_votinginstruction():
    peer, proto, chain, cb_data, cb = setup()
    height = 1
    round = 0
    bh = '1' * 32
    round_lockset = LockSet(len(validators))
    for i, privkey in enumerate(privkeys):
        if i < len(validators) // 3 + 1:
            v = VoteBlock(height, 0, bh)
        else:
            v = VoteNil(height, 0)
        v.sign(privkey)
        round_lockset.add(v)
    bp = VotingInstruction(height=height, round=1, round_lockset=round_lockset)
    bp.sign(tester.k0)

    payload = bp

    proto.send_votinginstruction(payload)
    packet = peer.packets.pop()
    assert len(rlp.decode(packet.payload)) == 1

    def list_cb(proto, votinginstruction):
        cb_data.append((proto, votinginstruction))

    proto.receive_votinginstruction_callbacks.append(list_cb)
    proto._receive_votinginstruction(packet)

    _p, vi = cb_data.pop()
    assert vi == bp
Beispiel #3
0
def test_VotingInstruction():
    rls = LockSet(len(validators))
    bh = "1" * 32
    for i, privkey in enumerate(privkeys):
        if i < 4:  # quorum possible
            v = VoteBlock(height=2, round=0, blockhash=bh)

        else:
            v = VoteNil(height=2, round=0)
        v.sign(privkey)
        rls.add(v)
    assert rls.has_quorum_possible
    bp = VotingInstruction(height=2, round=1, round_lockset=rls)
    bp.sign(privkeys[0])
    assert bh == bp.blockhash

    # noquorum
    rls = LockSet(len(validators))
    for i, privkey in enumerate(privkeys):
        if i < 3:  # noquorum possible
            v = VoteBlock(height=2, round=0, blockhash=bh)
        else:
            v = VoteNil(height=2, round=0)
        v.sign(privkey)
        rls.add(v)
    assert not rls.has_quorum_possible
    assert rls.has_noquorum
    with pytest.raises(InvalidProposalError):  # QuorumPossiblle necessary R0
        bp = VotingInstruction(height=2, round=1, round_lockset=rls)

    # noquorum
    rls = LockSet(len(validators))
    for i, privkey in enumerate(privkeys):
        if i < 3:  # noquorum possible
            v = VoteBlock(height=2, round=0, blockhash=bh)
        else:
            v = VoteNil(height=2, round=0)

        v.sign(privkey)
        rls.add(v)
    assert not rls.has_quorum_possible
    assert rls.has_noquorum
    with pytest.raises(InvalidProposalError):  # QuorumPossiblle necessary R0
        bp = VotingInstruction(height=2, round=1, round_lockset=rls)
Beispiel #4
0
def test_VotingInstruction():
    rls = LockSet(len(validators))
    bh = '1' * 32
    for i, privkey in enumerate(privkeys):
        if i < 4:  # quorum possible
            v = VoteBlock(height=2, round=0, blockhash=bh)

        else:
            v = VoteNil(height=2, round=0)
        v.sign(privkey)
        rls.add(v)
    assert rls.has_quorum_possible
    bp = VotingInstruction(height=2, round=1, round_lockset=rls)
    bp.sign(privkeys[0])
    assert bh == bp.blockhash

    # noquorum
    rls = LockSet(len(validators))
    for i, privkey in enumerate(privkeys):
        if i < 3:  # noquorum possible
            v = VoteBlock(height=2, round=0, blockhash=bh)
        else:
            v = VoteNil(height=2, round=0)
        v.sign(privkey)
        rls.add(v)
    assert not rls.has_quorum_possible
    assert rls.has_noquorum
    with pytest.raises(InvalidProposalError):  # QuorumPossiblle necessary R0
        bp = VotingInstruction(height=2, round=1, round_lockset=rls)

    # noquorum
    rls = LockSet(len(validators))
    for i, privkey in enumerate(privkeys):
        if i < 3:  # noquorum possible
            v = VoteBlock(height=2, round=0, blockhash=bh)
        else:
            v = VoteNil(height=2, round=0)

        v.sign(privkey)
        rls.add(v)
    assert not rls.has_quorum_possible
    assert rls.has_noquorum
    with pytest.raises(InvalidProposalError):  # QuorumPossiblle necessary R0
        bp = VotingInstruction(height=2, round=1, round_lockset=rls)