Example #1
0
    def test_vote_in_ballot_mode_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 = ConfigProposal(setting='my.config.setting',
                                  value='myvalue',
                                  nonce='somenonce')
        proposal_id = _to_hash(proposal.SerializeToString())
        candidate = ConfigCandidate(proposal_id=proposal_id,
                                    proposal=proposal,
                                    votes=[
                                        ConfigCandidate.VoteRecord(
                                            public_key='some_other_pubkey',
                                            vote=ConfigVote.ACCEPT),
                                    ])

        candidates = ConfigCandidates(candidates=[candidate])

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

        self._expect_get('sawtooth.config.authorization_type', 'Ballot')
        self._expect_get('sawtooth.config.vote.authorized_keys', '')
        self._expect_get('sawtooth.config.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.config.vote.approval_threshold', '2')

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

        self._expect_ok()
Example #2
0
    def test_vote_in_ballot_mode_approved(self):
        """
        Tests voting on a given setting, where the setting is approved
        """
        proposal = ConfigProposal(setting='my.config.setting',
                                  value='myvalue',
                                  nonce='somenonce')
        proposal_id = _to_hash(proposal.SerializeToString())
        record = ConfigCandidate.VoteRecord(public_key="some_other_pubkey",
                                            vote=ConfigVote.ACCEPT)
        candidate = ConfigCandidate(proposal_id=proposal_id,
                                    proposal=proposal,
                                    votes=[record])

        candidates = ConfigCandidates(candidates=[candidate])

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

        self._expect_get('sawtooth.config.authorization_type', 'Ballot')
        self._expect_get('sawtooth.config.vote.authorized_keys', '')
        self._expect_get('sawtooth.config.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.config.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.config.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_set('sawtooth.config.vote.proposals',
                         base64.b64encode(EMPTY_CANDIDATES))

        self._expect_ok()
Example #3
0
    def test_vote_counted(self):
        """
        Tests voting on a given setting, where the vote is counted only.
        """
        proposal = ConfigProposal(
            setting='my.config.setting',
            value='myvalue',
            nonce='somenonce'
        )
        proposal_id = _to_hash(proposal.SerializeToString())
        record = ConfigCandidate.VoteRecord(
            public_key="some_other_pubkey",
            vote=ConfigVote.ACCEPT)
        candidate = ConfigCandidate(
            proposal_id=proposal_id,
            proposal=proposal,
            votes=[record])

        candidates = ConfigCandidates(candidates=[candidate])

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

        self._expect_get('sawtooth.config.vote.authorized_keys',
                         self._public_key + ',some_other_pubkey,third_pubkey')
        self._expect_get('sawtooth.config.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.config.vote.approval_threshold', '3')

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

        record = ConfigCandidate.VoteRecord(
            public_key="some_other_pubkey",
            vote=ConfigVote.ACCEPT)
        new_record = ConfigCandidate.VoteRecord(
            public_key=self._public_key,
            vote=ConfigVote.ACCEPT)
        candidate = ConfigCandidate(
            proposal_id=proposal_id,
            proposal=proposal,
            votes=[record, new_record])

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

        self._expect_ok()
Example #4
0
    def test_propose_in_ballot_mode(self):
        """
        Tests proposing a value in ballot mode.
        """
        self._propose('my.config.setting', 'myvalue')

        self._expect_get('sawtooth.config.authorization_type', 'Ballot')
        self._expect_get('sawtooth.config.vote.authorized_keys', '')
        self._expect_get('sawtooth.config.vote.approval_threshold', '2')
        self._expect_get('sawtooth.config.vote.proposals')

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

        candidates = ConfigCandidates(candidates=[candidate])

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

        self._expect_ok()
Example #5
0
    def test_vote_rejected(self):
        """
        Tests voting on a given setting, where the setting is rejected.
        """
        proposal = ConfigProposal(
            setting='my.config.setting',
            value='myvalue',
            nonce='somenonce'
        )
        proposal_id = _to_hash(proposal.SerializeToString())
        candidate = ConfigCandidate(
            proposal_id=proposal_id,
            proposal=proposal,
            votes=[
                ConfigCandidate.VoteRecord(
                    public_key='some_other_pubkey',
                    vote=ConfigVote.ACCEPT),
                ConfigCandidate.VoteRecord(
                    public_key='a_rejectors_pubkey',
                    vote=ConfigVote.REJECT)
            ])

        candidates = ConfigCandidates(candidates=[candidate])

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

        self._expect_get(
            'sawtooth.config.vote.authorized_keys',
            self._public_key + ',some_other_pubkey,a_rejectors_pubkey')
        self._expect_get('sawtooth.config.vote.proposals',
                         base64.b64encode(candidates.SerializeToString()))
        self._expect_get('sawtooth.config.vote.approval_threshold', '2')

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

        self._expect_ok()