コード例 #1
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_add_event('sawtooth.settings.vote.proposals')

        self._expect_ok()
コード例 #2
0
    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()
コード例 #3
0
    def test_vote_rejected(self):
        """
        Tests voting on a given setting, where the setting is rejected.
        """
        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),
                SettingCandidate.VoteRecord(
                    public_key='a_rejectors_public_key',
                    vote=SettingVote.REJECT)
            ])

        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,a_rejectors_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_add_event('sawtooth.settings.vote.proposals')

        self._expect_ok()