public void ComputeBlockVersion_UsingChainTipAndConsensus_NoBip9DeploymentActive_UpdatesHeightAndVersion()
        {
            this.ExecuteWithConsensusOptions(new PosConsensusOptions(), () =>
            {
                ConcurrentChain chain = GenerateChainWithHeight(5, this.stratisTest, new Key());
                this.SetupRulesEngine(chain);

                var posBlockAssembler = new PosTestBlockAssembler(this.consensusManager.Object, this.stratisTest, new MempoolSchedulerLock(), this.mempool.Object, this.minerSettings,
                                                                  this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, this.LoggerFactory.Object);

                (int Height, int Version)result = posBlockAssembler.ComputeBlockVersion(chain.GetBlock(4));

                Assert.Equal(5, result.Height);
                Assert.Equal((int)ThresholdConditionCache.VersionbitsTopBits, result.Version);
            });
        }
        public void ComputeBlockVersion_UsingChainTipAndConsensus_NoBip9DeploymentActive_UpdatesHeightAndVersion()
        {
            this.ExecuteWithConsensusOptions(new PosConsensusOptions(), () =>
            {
                var chain = GenerateChainWithHeight(5, this.network, new Key());

                var posBlockAssembler = new PosTestBlockAssembler(this.consensusLoop.Object, this.network, new MempoolSchedulerLock(), this.txMempool.Object,
                                                                  this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, chain.Tip, this.LoggerFactory.Object);

                var result = posBlockAssembler.ComputeBlockVersion(chain.GetBlock(4));

                Assert.Equal(5, result.Height);
                uint version = ThresholdConditionCache.VersionbitsTopBits;
                Assert.Equal((int)version, result.Version);
            });
        }
        public void ComputeBlockVersion_UsingChainTipAndConsensus_Bip9DeploymentActive_UpdatesHeightAndVersion()
        {
            ConsensusOptions options          = this.stratisTest.Consensus.Options;
            int minerConfirmationWindow       = this.stratisTest.Consensus.MinerConfirmationWindow;
            int ruleChangeActivationThreshold = this.stratisTest.Consensus.RuleChangeActivationThreshold;

            try
            {
                var newOptions = new PosConsensusOptions();
                this.stratisTest.Consensus.Options            = newOptions;
                this.stratisTest.Consensus.BIP9Deployments[0] = new BIP9DeploymentsParameters(19,
                                                                                              new DateTimeOffset(new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
                                                                                              new DateTimeOffset(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc)));

                // As we are effectively using StratisTest the other deployments need to be disabled
                this.stratisTest.Consensus.BIP9Deployments[BIP9Deployments.CSV]    = null;
                this.stratisTest.Consensus.BIP9Deployments[BIP9Deployments.Segwit] = null;

                this.stratisTest.Consensus.MinerConfirmationWindow       = 2;
                this.stratisTest.Consensus.RuleChangeActivationThreshold = 2;

                ConcurrentChain chain = GenerateChainWithHeightAndActivatedBip9(5, this.stratisTest, new Key(), this.stratisTest.Consensus.BIP9Deployments[0]);
                this.SetupRulesEngine(chain);

                var posBlockAssembler = new PosTestBlockAssembler(this.consensusManager.Object, this.stratisTest, new MempoolSchedulerLock(), this.mempool.Object, this.minerSettings.Object, this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, this.LoggerFactory.Object);

                (int Height, int Version)result = posBlockAssembler.ComputeBlockVersion(chain.GetBlock(4));

                Assert.Equal(5, result.Height);
                int expectedVersion = (int)(ThresholdConditionCache.VersionbitsTopBits | (((uint)1) << 19));
                Assert.Equal(expectedVersion, result.Version);
                Assert.NotEqual((int)ThresholdConditionCache.VersionbitsTopBits, result.Version);
            }
            finally
            {
                // This is a static in the global context so be careful updating it. I'm resetting it after being done testing so I don't influence other tests.
                this.stratisTest.Consensus.Options                       = options;
                this.stratisTest.Consensus.BIP9Deployments[0]            = null;
                this.stratisTest.Consensus.MinerConfirmationWindow       = minerConfirmationWindow;
                this.stratisTest.Consensus.RuleChangeActivationThreshold = ruleChangeActivationThreshold;
            }
        }
        public void ComputeBlockVersion_UsingChainTipAndConsensus_Bip9DeploymentActive_UpdatesHeightAndVersion()
        {
            var options = this.network.Consensus.Options;
            var minerConfirmationWindow       = this.network.Consensus.MinerConfirmationWindow;
            var ruleChangeActivationThreshold = this.network.Consensus.RuleChangeActivationThreshold;

            try
            {
                var newOptions = new PosConsensusOptions();
                this.network.Consensus.Options            = newOptions;
                this.network.Consensus.BIP9Deployments[0] = new BIP9DeploymentsParameters(19,
                                                                                          new DateTimeOffset(new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
                                                                                          new DateTimeOffset(new DateTime(2018, 1, 1, 0, 0, 0, DateTimeKind.Utc)));
                this.network.Consensus.MinerConfirmationWindow       = 2;
                this.network.Consensus.RuleChangeActivationThreshold = 2;

                var chain = GenerateChainWithHeightAndActivatedBip9(5, this.network, new Key(), this.network.Consensus.BIP9Deployments[0]);

                var posBlockAssembler = new PosTestBlockAssembler(this.consensusLoop.Object, this.network, new MempoolSchedulerLock(), this.txMempool.Object,
                                                                  this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, chain.Tip, this.LoggerFactory.Object);

                var result = posBlockAssembler.ComputeBlockVersion(chain.GetBlock(4));

                Assert.Equal(5, result.Height);
                uint version         = ThresholdConditionCache.VersionbitsTopBits;
                int  expectedVersion = (int)(version |= (((uint)1) << 19));
                Assert.Equal(expectedVersion, result.Version);
                Assert.NotEqual((int)ThresholdConditionCache.VersionbitsTopBits, result.Version);
            }
            finally
            {
                // This is a static in the global context so be careful updating it. I'm resetting it after being done testing so I don't influence other tests.
                this.network.Consensus.Options                       = options;
                this.network.Consensus.BIP9Deployments[0]            = null;
                this.network.Consensus.MinerConfirmationWindow       = minerConfirmationWindow;
                this.network.Consensus.RuleChangeActivationThreshold = ruleChangeActivationThreshold;
            }
        }
Example #5
0
        public void ComputeBlockVersion_UsingChainTipAndConsensus_Bip9DeploymentActive_UpdatesHeightAndVersion()
        {
            ConsensusOptions options    = this.stratisTest.Consensus.Options;
            int minerConfirmationWindow = this.stratisTest.Consensus.MinerConfirmationWindow;

            try
            {
                var newOptions = new PosConsensusOptions();
                this.stratisTest.Consensus.Options = newOptions;

                // Set the BIP9 activation to expire one day from now so that it is still signaled in the blocks.
                this.stratisTest.Consensus.BIP9Deployments[0] = new BIP9DeploymentsParameters("Test", 19,
                                                                                              new DateTimeOffset(new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc)),
                                                                                              new DateTimeOffset(DateTime.UtcNow + TimeSpan.FromDays(1)),
                                                                                              2);

                this.stratisTest.Consensus.MinerConfirmationWindow = 2;

                ChainIndexer chainIndexer = GenerateChainWithHeightAndActivatedBip9(5, this.stratisTest, new Key(), this.stratisTest.Consensus.BIP9Deployments[0]);
                this.SetupRulesEngine(chainIndexer);

                var posBlockAssembler = new PosTestBlockAssembler(this.consensusManager.Object, this.stratisTest, new MempoolSchedulerLock(), this.mempool.Object, this.minerSettings, this.dateTimeProvider.Object, this.stakeChain.Object, this.stakeValidator.Object, this.LoggerFactory.Object, new NodeDeployments(this.Network, chainIndexer));

                (int Height, int Version)result = posBlockAssembler.ComputeBlockVersion(chainIndexer.GetHeader(4));

                Assert.Equal(5, result.Height);
                int expectedVersion = (int)(ThresholdConditionCache.VersionbitsTopBits | (((uint)1) << 19));
                Assert.Equal(expectedVersion, result.Version);
                Assert.NotEqual((int)ThresholdConditionCache.VersionbitsTopBits, result.Version);
            }
            finally
            {
                // This is a static in the global context so be careful updating it. I'm resetting it after being done testing so I don't influence other tests.
                this.stratisTest.Consensus.Options                 = options;
                this.stratisTest.Consensus.BIP9Deployments[0]      = null;
                this.stratisTest.Consensus.MinerConfirmationWindow = minerConfirmationWindow;
            }
        }