示例#1
0
    def test_add_vote_fail_before_add_peer(self):
        # GIVEN
        peer_manager = PeerManager(conf.LOOPCHAIN_DEFAULT_CHANNEL)
        self.__add_peer_to_peer_manager(peer_manager, 3)
        peer_manager.add_peer(
            PeerInfo("peerid-4",
                     "groupid-3",
                     "peerid-4_target",
                     cert=self.__cert))
        peer_manager.add_peer(
            PeerInfo("peerid-5",
                     "groupid-3",
                     "peerid-5_target",
                     cert=self.__cert))

        vote = Vote("block_hash", peer_manager)
        logging.debug("votes: " + str(vote.votes))

        # WHEN
        vote.add_vote("groupid-1", "peerid-1", None)
        vote.add_vote("groupid-3", "peerid-4", None)
        ret1 = vote.add_vote("groupid-4", "peerid-1", None)
        ret2 = vote.add_vote("groupid-1", "peerid-9", None)
        self.assertFalse(ret1)
        self.assertFalse(ret2)

        # THEN
        ret = vote.get_result_detail("block_hash", 0.51)
        self.assertEqual(ret[5], 5)
示例#2
0
    def test_add_vote_fail_before_add_peer(self):
        # GIVEN
        peer_manager = PeerManager()
        peer_manager.add_peer("peerid-1", "groupid-1", "peerid-1_target")
        peer_manager.add_peer("peerid-2", "groupid-2", "peerid-2_target")
        peer_manager.add_peer("peerid-3", "groupid-3", "peerid-3_target")
        peer_manager.add_peer("peerid-4", "groupid-3", "peerid-4_target")
        peer_manager.add_peer("peerid-5", "groupid-3", "peerid-5_target")
        vote = Vote("block_hash", peer_manager)
        logging.debug("votes: " + str(vote.votes))

        # WHEN
        vote.add_vote("groupid-1", "peerid-1", None)
        vote.add_vote("groupid-3", "peerid-4", None)
        ret1 = vote.add_vote("groupid-4", "peerid-1", None)
        ret2 = vote.add_vote("groupid-1", "peerid-9", None)
        self.assertFalse(ret1)
        self.assertFalse(ret2)

        # THEN
        ret = vote.get_result_detail("block_hash", 0.51)
        self.assertEqual(ret[5], 5)