public CheckCollateralFullValidationRuleTests()
        {
            this.ibdMock = new Mock <IInitialBlockDownloadState>();
            this.collateralCheckerMock = new Mock <ICollateralChecker>();
            this.slotsManagerMock      = new Mock <ISlotsManager>();


            this.ibdMock.Setup(x => x.IsInitialBlockDownload()).Returns(false);
            this.slotsManagerMock
            .Setup(x => x.GetFederationMemberForTimestamp(It.IsAny <uint>(), null))
            .Returns(new CollateralFederationMember(new Key().PubKey, false, new Money(1), "addr1"));

            this.ruleContext = new RuleContext(new ValidationContext(), DateTimeOffset.Now);
            this.ruleContext.ValidationContext.BlockToValidate = new Block(new BlockHeader()
            {
                Time = 5234
            });

            Block block = this.ruleContext.ValidationContext.BlockToValidate;

            block.AddTransaction(new Transaction());

            var     loggerFactory = new ExtendedLoggerFactory();
            ILogger logger        = loggerFactory.CreateLogger(this.GetType().FullName);

            var votingDataEncoder = new VotingDataEncoder(loggerFactory);
            var votes             = new List <VotingData>
            {
                new VotingData()
                {
                    Key  = VoteKey.WhitelistHash,
                    Data = new uint256(0).ToBytes()
                }
            };

            byte[] encodedVotingData = votingDataEncoder.Encode(votes);

            var votingData = new List <byte>(VotingDataEncoder.VotingOutputPrefixBytes);

            votingData.AddRange(encodedVotingData);

            var votingOutputScript = new Script(OpcodeType.OP_RETURN, Op.GetPushOp(votingData.ToArray()));

            block.Transactions[0].AddOutput(Money.Zero, votingOutputScript);

            var commitmentHeightEncoder = new CollateralHeightCommitmentEncoder(logger);

            byte[] encodedHeight        = commitmentHeightEncoder.EncodeCommitmentHeight(1000);
            var    commitmentHeightData = new Script(OpcodeType.OP_RETURN, Op.GetPushOp(encodedHeight));

            block.Transactions[0].AddOutput(Money.Zero, commitmentHeightData);

            this.rule = new CheckCollateralFullValidationRule(this.ibdMock.Object, this.collateralCheckerMock.Object, this.slotsManagerMock.Object, new Mock <IDateTimeProvider>().Object, new PoANetwork())
            {
                Logger = logger
            };

            this.rule.Initialize();
        }
Exemple #2
0
        public void ThrowsIfEmptyList()
        {
            var encoder = new VotingDataEncoder(new ExtendedLoggerFactory());

            byte[] bytes = encoder.Encode(new List <VotingData>());

            List <byte> votingData = new List <byte>(VotingDataEncoder.VotingOutputPrefixBytes);

            votingData.AddRange(bytes);

            var votingOutputScript = new Script(OpcodeType.OP_RETURN, Op.GetPushOp(votingData.ToArray()));

            var block = new Block();

            block.Transactions.Add(new Transaction());
            block.Transactions[0].AddOutput(Money.COIN, votingOutputScript);

            Assert.Throws <ConsensusErrorException>(() =>
                                                    this.votingFormatRule.RunAsync(new RuleContext(new ValidationContext()
            {
                BlockToValidate = block
            }, DateTimeOffset.Now)).GetAwaiter().GetResult());
        }