Ejemplo n.º 1
0
        //Method related to announcing changes regarding ballot-statuses.
        #region Ballots
        /// <summary>
        /// Announce to all that they should revoke this update!
        /// </summary>
        /// <param name="voterNumber">The voternumber to revoke a ballot for.</param>
        /// <param name="cpr">The CPR number to revoke a ballot for.</param>
        public void AnnounceRevokeBallot(VoterNumber voterNumber, CPR cpr)
        {
            Contract.Requires(IsManager);
            Contract.Requires(Database[voterNumber, cpr] == BallotStatus.Received);
            var cmd = new RevokeBallotCommand(Address, voterNumber, cpr);

            Peers.Keys.ForEach(peer => Communicator.Send(cmd, peer));
            cmd.Execute(this);
            if (Logger != null)
            {
                Logger.Log("Announcing that this ballot should be revoked: voternumber=" + voterNumber + "; CPR=" + cpr, Level.Warn);
            }
        }
Ejemplo n.º 2
0
        public void BallotReceivedCommandAndRevokeBallotCommandTest()
        {
            var vn  = new VoterNumber(250000);
            var cpr = new CPR(2312881234);

            Assert.That(Station.Database[vn, cpr] == BallotStatus.Unavailable);

            Station.Database.Import(new List <EncryptedVoterData> {
                new EncryptedVoterData(new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(vn.Value), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value), Station.Crypto.VoterDataEncryptionKey)), new CipherText(Station.Crypto.AsymmetricEncrypt(Bytes.From(cpr.Value + (uint)BallotStatus.NotReceived), Station.Crypto.VoterDataEncryptionKey)))
            });

            var cmd = new BallotReceivedCommand(Manager.Address, Station.Address, vn, cpr);

            Assert.That(cmd.Sender == Manager.Address);
            Assert.That(Station.Database[vn, cpr] == BallotStatus.NotReceived);
            cmd.Execute(Station);
            Assert.That(Station.Database[vn, cpr] == BallotStatus.Received);

            var revoke = new RevokeBallotCommand(Manager.Address, vn, cpr);

            revoke.Execute(Station);
            Assert.That(Station.Database[vn, cpr] == BallotStatus.NotReceived);
        }
Ejemplo n.º 3
0
        public void ManagerRequirementCheckTest()
        {
            var start = new StartElectionCommand(NewPeer.Address);
            var end   = new EndElectionCommand(NewPeer.Address);

            Assert.That(!((TestUi)Station.UI).OngoingElection);
            start.Execute(Station);
            Assert.That(!((TestUi)Station.UI).OngoingElection);
            Station.StartElection();
            Assert.That(Station.ElectionInProgress);
            end.Execute(Station);
            Assert.That(Station.ElectionInProgress);

            var vn            = new VoterNumber(5);
            var cpr           = new CPR(5);
            var req           = new RequestBallotCommand(NewPeer.Address, vn, cpr);
            var reqCPROnly    = new RequestBallotCPROnlyCommand(NewPeer.Address, cpr, "sup homey");
            var revoke        = new RevokeBallotCommand(NewPeer.Address, vn, cpr);
            var revokeCPROnly = new RevokeBallotCPROnlyCommand(NewPeer.Address, cpr, "sup homey");

            req.Execute(Station);
            reqCPROnly.Execute(Station);
            revoke.Execute(Station);
            revokeCPROnly.Execute(Station);
            Assert.That(Station.Database[vn, cpr] == BallotStatus.Unavailable);

            NewPeer.Crypto.VoterDataEncryptionKey = Manager.Crypto.VoterDataEncryptionKey;
            var sync = new SyncCommand(NewPeer);

            sync.Execute(Station);

            var promoteManager = new PromoteNewManagerCommand(NewPeer.Address, NewPeer.Address);

            promoteManager.Execute(Station);
            Assert.That(!Station.Manager.Equals(NewPeer.Address));
        }