def test_get_plaintext_tally_all_guardians_present(self, data,
                                                       parties: int,
                                                       contests: int):
        # Arrange
        description = data.draw(election_descriptions(parties, contests))
        builder = ElectionBuilder(self.NUMBER_OF_GUARDIANS, self.QUORUM,
                                  description)
        metadata, context = builder.set_public_key(
            self.joint_public_key).build()

        plaintext_ballots: List[PlaintextBallot] = data.draw(
            plaintext_voted_ballots(metadata, randrange(3, 6)))
        plaintext_tallies = accumulate_plaintext_ballots(plaintext_ballots)

        encrypted_tally = self._generate_encrypted_tally(
            metadata, context, plaintext_ballots)

        subject = DecryptionMediator(metadata, context, encrypted_tally)

        # act
        for guardian in self.guardians:
            self.assertIsNotNone(subject.announce(guardian))

        decrypted_tallies = subject.get_plaintext_tally()
        result = self._convert_to_selections(decrypted_tallies)

        # assert
        self.assertIsNotNone(result)
        self.assertEqual(plaintext_tallies, result)
Exemplo n.º 2
0
    def test_get_plaintext_tally_with_all_guardians_present(
            self, values, parties: int, contests: int):
        # Arrange
        description = values.draw(election_descriptions(parties, contests))
        builder = ElectionBuilder(self.NUMBER_OF_GUARDIANS, self.QUORUM,
                                  description)
        internal_manifest, context = (builder.set_public_key(
            self.joint_public_key.joint_public_key).set_commitment_hash(
                self.joint_public_key.commitment_hash).build())

        plaintext_ballots: List[PlaintextBallot] = values.draw(
            plaintext_voted_ballots(internal_manifest, randrange(3, 6)))
        expected_plaintext_tally = accumulate_plaintext_ballots(
            plaintext_ballots)

        encrypted_tally = self._generate_encrypted_tally(
            internal_manifest, context, plaintext_ballots)

        mediator = DecryptionMediator(self.decryption_mediator_id, context)
        available_guardians = self.guardians
        DecryptionHelper.perform_decryption_setup(available_guardians,
                                                  mediator, context,
                                                  encrypted_tally, [])

        # Act
        plaintext_tally = mediator.get_plaintext_tally(encrypted_tally)
        selections = _convert_to_selections(plaintext_tally)

        # Assert
        self.assertIsNotNone(plaintext_tally)
        self.assertIsNotNone(selections)
        self.assertEqual(expected_plaintext_tally, selections)