public async Task BlockReceived_NotNextBlock_ValidationFailAsync() { var testContext = TestRulesContextFactory.CreateAsync(Network.RegTest); BlockHeaderRule blockHeaderRule = testContext.CreateRule <BlockHeaderRule>(); var context = new RuleContext(new BlockValidationContext(), Network.RegTest.Consensus, testContext.Chain.Tip); context.BlockValidationContext.Block = new Block(new BlockHeader { HashPrevBlock = uint256.Zero }); var error = await Assert.ThrowsAsync <ConsensusErrorException>(async() => await blockHeaderRule.RunAsync(context)); Assert.Equal(ConsensusErrors.InvalidPrevTip, error.ConsensusError); }
public async Task BlockReceived_IsNextBlock_ValidationSucessAsync() { var testContext = TestRulesContextFactory.CreateAsync(Network.RegTest); BlockHeaderRule blockHeaderRule = testContext.CreateRule <BlockHeaderRule>(); var context = new RuleContext(new BlockValidationContext(), Network.RegTest.Consensus, testContext.Chain.Tip); context.BlockValidationContext.Block = new Block(new BlockHeader { HashPrevBlock = testContext.Chain.Tip.HashBlock }); await blockHeaderRule.RunAsync(context); Assert.NotNull(context.BlockValidationContext.ChainedBlock); Assert.NotNull(context.BestBlock); Assert.NotNull(context.Flags); }
public async Task ChecBlockFutureTimestamp_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(NetworkOptions.TemporaryOptions), context.ConsensusTip); context.SetBestBlock(DateTimeProvider.Default.GetTimeOffset()); // increment the bits. context.NextWorkRequired = context.BlockValidationContext.ChainedBlock.GetNextWorkRequired(Network.RegTest.Consensus); context.BlockValidationContext.Block.Header.BlockTime = context.Time.AddHours(3); var error = await Assert.ThrowsAsync <ConsensusErrorException>(async() => await rule.RunAsync(context)); Assert.Equal(ConsensusErrors.TimeTooNew, error.ConsensusError); }