public void CanExpireAndUnExpirePollViaNodeRewind()
        {
            // Create add federation member vote.
            var votingData = new VotingData()
            {
                Key  = VoteKey.AddFederationMember,
                Data = new Key().PubKey.ToBytes()
            };

            // Create a single pending poll.
            ChainedHeaderBlock[] blocks = GetBlocksWithVotingData(1, votingData, new ChainedHeader(this.network.GetGenesis().Header, this.network.GetGenesis().GetHash(), 0));
            this.TriggerOnBlockConnected(blocks[0]);
            Assert.Single(this.votingManager.GetPendingPolls());

            // Advance the chain so that the poll expires.
            blocks = PoaTestHelper.GetEmptyBlocks(this.ChainIndexer, this.network, 10);
            for (int i = 0; i < blocks.Length; i++)
            {
                this.TriggerOnBlockConnected(blocks[i]);
            }

            // Assert that the poll expired.
            Assert.Single(this.votingManager.GetExpiredPolls());

            // Fake a rewind via setting the node's tip back (this will generally happen via the api/node/rewind call)
            this.ChainIndexer.Remove(this.ChainIndexer.Tip);

            // Re-initialize the voting manager
            this.votingManager.Initialize(this.federationHistory);

            // Assert that the poll was "un-expired".
            Assert.Single(this.votingManager.GetPendingPolls());
        }
        public void CanExpireAndUnExpirePollViaBlockDisconnected()
        {
            // Create add federation member vote.
            var votingData = new VotingData()
            {
                Key  = VoteKey.AddFederationMember,
                Data = new Key().PubKey.ToBytes()
            };

            // Create a single pending poll.
            ChainedHeaderBlock[] blocks = GetBlocksWithVotingData(1, votingData, new ChainedHeader(this.network.GetGenesis().Header, this.network.GetGenesis().GetHash(), 0));
            this.TriggerOnBlockConnected(blocks[0]);
            Assert.Single(this.votingManager.GetPendingPolls());

            // Advance the chain so that the poll expires.
            blocks = PoaTestHelper.GetEmptyBlocks(this.ChainIndexer, this.network, 10);

            for (int i = 0; i < blocks.Length; i++)
            {
                this.TriggerOnBlockConnected(blocks[i]);
            }

            // Assert that the poll expired.
            Assert.Single(this.votingManager.GetExpiredPolls());

            // Fake a rewind via block disconnected (this will generally happen via a re-org)
            this.TriggerOnBlockDisconnected(blocks[9]);

            // Assert that the poll was "un-expired".
            Assert.Single(this.votingManager.GetPendingPolls());
        }