Esempio n. 1
0
    def test_vote_rejects_a_tie(self):
        """
        Tests voting on a given setting, where there is a tie for accept and
        for reject, with no remaining auth keys.
        """
        proposal = SettingProposal(setting='my.config.setting',
                                   value='myvalue',
                                   nonce='somenonce')
        proposal_id = _to_hash(proposal.SerializeToString())
        candidate = SettingCandidate(
            proposal_id=proposal_id,
            proposal=proposal,
            votes=[
                SettingCandidate.VoteRecord(public_key='some_other_public_key',
                                            vote=SettingVote.ACCEPT),
            ])

        candidates = SettingCandidates(candidates=[candidate])

        self._vote(proposal_id, 'my.config.setting', SettingVote.REJECT)

        self._expect_get('sawtooth.settings.vote.authorized_keys',
                         self._public_key + ',some_other_public_key')
        self._expect_get('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.settings.vote.approval_threshold', '2')

        # expect to update the proposals
        self._expect_get('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_set('sawtooth.settings.vote.proposals',
                         base64.b64encode(EMPTY_CANDIDATES))

        self._expect_ok()
Esempio n. 2
0
    def test_vote_approved(self):
        """
        Tests voting on a given setting, where the setting is approved
        """
        proposal = SettingProposal(setting='my.config.setting',
                                   value='myvalue',
                                   nonce='somenonce')
        proposal_id = _to_hash(proposal.SerializeToString())
        record = SettingCandidate.VoteRecord(
            public_key="some_other_public_key", vote=SettingVote.ACCEPT)
        candidate = SettingCandidate(proposal_id=proposal_id,
                                     proposal=proposal,
                                     votes=[record])

        candidates = SettingCandidates(candidates=[candidate])

        self._vote(proposal_id, 'my.config.setting', SettingVote.ACCEPT)

        self._expect_get('sawtooth.settings.vote.authorized_keys',
                         self._public_key + ',some_other_public_key')
        self._expect_get('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.settings.vote.approval_threshold', '2')

        # the vote should pass
        self._expect_get('my.config.setting')
        self._expect_set('my.config.setting', 'myvalue')

        # expect to update the proposals
        self._expect_get('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_set('sawtooth.settings.vote.proposals',
                         base64.b64encode(EMPTY_CANDIDATES))

        self._expect_ok()
Esempio n. 3
0
    def test_propose(self):
        """
        Tests proposing a value in ballot mode.
        """
        self._propose('my.config.setting', 'myvalue')

        self._expect_get('sawtooth.settings.vote.authorized_keys',
                         self._public_key)
        self._expect_get('sawtooth.settings.vote.approval_threshold', '2')
        self._expect_get('sawtooth.settings.vote.proposals')

        proposal = SettingProposal(setting='my.config.setting',
                                   value='myvalue',
                                   nonce='somenonce')
        proposal_id = _to_hash(proposal.SerializeToString())
        record = SettingCandidate.VoteRecord(public_key=self._public_key,
                                             vote=SettingVote.ACCEPT)
        candidate = SettingCandidate(proposal_id=proposal_id,
                                     proposal=proposal,
                                     votes=[record])

        candidates = SettingCandidates(candidates=[candidate])

        # Get's again to update the entry
        self._expect_get('sawtooth.settings.vote.proposals')
        self._expect_set('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))

        self._expect_ok()
    def test_vote_counted(self):
        """
        Tests voting on a given setting, where the vote is counted only.
        """
        proposal = SettingProposal(setting='my.config.setting',
                                   value='myvalue',
                                   nonce='somenonce')
        proposal_id = _to_hash(proposal.SerializeToString())
        record = SettingCandidate.VoteRecord(
            public_key="some_other_public_key", vote=SettingVote.ACCEPT)
        candidate = SettingCandidate(proposal_id=proposal_id,
                                     proposal=proposal,
                                     votes=[record])

        candidates = SettingCandidates(candidates=[candidate])

        self._vote(proposal_id, 'my.config.setting', SettingVote.ACCEPT)

        self._expect_get(
            'sawtooth.settings.vote.authorized_keys',
            self._public_key + ',some_other_public_key,third_public_key')
        self._expect_get('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.settings.vote.approval_threshold', '3')

        # expect to update the proposals
        self._expect_get('sawtooth.settings.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))

        record = SettingCandidate.VoteRecord(
            public_key="some_other_public_key", vote=SettingVote.ACCEPT)
        new_record = SettingCandidate.VoteRecord(public_key=self._public_key,
                                                 vote=SettingVote.ACCEPT)
        candidate = SettingCandidate(proposal_id=proposal_id,
                                     proposal=proposal,
                                     votes=[record, new_record])

        updated_candidates = SettingCandidates(candidates=[candidate])
        self._expect_set(
            'sawtooth.settings.vote.proposals',
            base64.b64encode(updated_candidates.SerializeToString()))

        self._expect_add_event('sawtooth.settings.vote.proposals')

        self._expect_ok()