コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }