Exemplo n.º 1
0
        public CheckCollateralFullValidationRuleTests()
        {
            this.ibdMock = new Mock <IInitialBlockDownloadState>();
            this.collateralCheckerMock      = new Mock <ICollateralChecker>();
            this.slotsManagerMock           = new Mock <ISlotsManager>();
            this.counterChainNetworkWrapper = new CounterChainNetworkWrapper(Networks.Stratis.Mainnet());

            this.ibdMock.Setup(x => x.IsInitialBlockDownload()).Returns(false);
            this.slotsManagerMock
            .Setup(x => x.GetFederationMemberForTimestamp(It.IsAny <uint>(), null))
            .Returns(new CollateralFederationMember(new Key().PubKey, 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());

            CollateralHeightCommitmentEncoder encoder = new CollateralHeightCommitmentEncoder();

            byte[] encodedHeight = encoder.EncodeWithPrefix(1000);

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

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

            this.rule        = new CheckCollateralFullValidationRule(this.ibdMock.Object, this.collateralCheckerMock.Object, this.slotsManagerMock.Object, new Mock <IDateTimeProvider>().Object, new PoANetwork(), this.counterChainNetworkWrapper);
            this.rule.Logger = new ExtendedLoggerFactory().CreateLogger(this.rule.GetType().FullName);
            this.rule.Initialize();
        }
        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();
        }
        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, new Money(1), "addr1"));

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

            this.rule        = new CheckCollateralFullValidationRule(this.ibdMock.Object, this.collateralCheckerMock.Object, this.slotsManagerMock.Object);
            this.rule.Logger = new ExtendedLoggerFactory().CreateLogger(this.rule.GetType().FullName);
            this.rule.Initialize();
        }