public async Task ChecBlockFutureTimestamp_ValidationFailAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(Network.RegTest); BlockHeaderPowContextualRule rule = testContext.CreateRule <BlockHeaderPowContextualRule>(); RuleContext context = new PowRuleContext(new ValidationContext(), Network.RegTest.Consensus, testContext.Chain.Tip); context.ValidationContext.Block = TestRulesContextFactory.MineBlock(Network.RegTest, testContext.Chain); context.ValidationContext.ChainedHeader = new ChainedHeader(context.ValidationContext.Block.Header, context.ValidationContext.Block.Header.GetHash(), context.ConsensusTip); context.Time = DateTimeProvider.Default.GetTimeOffset(); // increment the bits. context.NextWorkRequired = context.ValidationContext.ChainedHeader.GetNextWorkRequired(Network.RegTest.Consensus); context.ValidationContext.Block.Header.BlockTime = context.Time.AddHours(3); var error = await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); Assert.Equal(ConsensusErrors.TimeTooNew, error.ConsensusError); }
public async Task CheckHeaderBits_ValidationFailAsync() { TestRulesContext testContext = TestRulesContextFactory.CreateAsync(Network.RegTest); BlockHeaderPowContextualRule rule = testContext.CreateRule <BlockHeaderPowContextualRule>(); RuleContext context = new RuleContext(new BlockValidationContext(), Network.RegTest.Consensus, testContext.Chain.Tip); context.BlockValidationContext.Block = TestRulesContextFactory.MineBlock(Network.RegTest, testContext.Chain); context.BlockValidationContext.ChainedBlock = new ChainedBlock(context.BlockValidationContext.Block.Header, context.BlockValidationContext.Block.Header.GetHash(), context.ConsensusTip); context.SetBestBlock(DateTimeProvider.Default.GetTimeOffset()); // increment the bits. context.NextWorkRequired = context.BlockValidationContext.ChainedBlock.GetNextWorkRequired(Network.RegTest.Consensus); context.BlockValidationContext.Block.Header.Bits += 1; var error = await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); Assert.Equal(ConsensusErrors.BadDiffBits, error.ConsensusError); }