public PowMiningTest(PowMiningTestFixture fixture) { this.fixture = fixture; this.network = fixture.Network; this.initialNetworkOptions = this.network.Consensus.Options; if (this.initialNetworkOptions == null) { this.network.Consensus.Options = new PowConsensusOptions(); } this.asyncLoopFactory = new Mock <IAsyncLoopFactory>(); this.consensusLoop = new Mock <IConsensusLoop>(); this.consensusLoop.SetupGet(c => c.Tip).Returns(() => this.chain.Tip); this.mempool = new Mock <ITxMempool>(); this.mempool.SetupGet(mp => mp.MapTx).Returns(new TxMempool.IndexedTransactionSet()); this.chain = fixture.Chain; this.nodeLifetime = new Mock <INodeLifetime>(); this.nodeLifetime.Setup(n => n.ApplicationStopping).Returns(new CancellationToken()).Verifiable(); this.mempoolLock = new MempoolSchedulerLock(); }
private void ExecuteWithConsensusOptions(PowConsensusOptions newOptions, Action action) { NBitcoin.Consensus.ConsensusOptions options = this.network.Consensus.Options; try { this.network.Consensus.Options = newOptions; action(); } 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; } }
public void ComputeBlockVersion_UsingChainTipAndConsensus_Bip9DeploymentActive_UpdatesHeightAndVersion() { NBitcoin.Consensus.ConsensusOptions options = this.network.Consensus.Options; int minerConfirmationWindow = this.network.Consensus.MinerConfirmationWindow; int ruleChangeActivationThreshold = this.network.Consensus.RuleChangeActivationThreshold; try { var newOptions = new PowConsensusOptions(); 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; ConcurrentChain chain = GenerateChainWithHeightAndActivatedBip9(5, this.network, new Key(), this.network.Consensus.BIP9Deployments[0]); var blockDefinition = new PowTestBlockDefinition(this.consensusLoop.Object, this.dateTimeProvider.Object, this.LoggerFactory.Object, this.txMempool.Object, new MempoolSchedulerLock(), this.network, this.consensusRules.Object); (int Height, int Version)result = blockDefinition.ComputeBlockVersion(chain.GetBlock(4)); Assert.Equal(5, result.Height); uint version = ThresholdConditionCache.VersionbitsTopBits; int expectedVersion = (int)(version |= (((uint)1) << 19)); //Assert.Equal(version, 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; } }