public PoAMiner( IConsensusManager consensusManager, IDateTimeProvider dateTimeProvider, Network network, INodeLifetime nodeLifetime, ILoggerFactory loggerFactory, IInitialBlockDownloadState ibdState, BlockDefinition blockDefinition, ISlotsManager slotsManager, IConnectionManager connectionManager, PoABlockHeaderValidator poaHeaderValidator, IFederationManager federationManager, IFederationHistory federationHistory, IIntegrityValidator integrityValidator, IWalletManager walletManager, INodeStats nodeStats, VotingManager votingManager, PoASettings poAMinerSettings, IAsyncProvider asyncProvider, IIdleFederationMembersKicker idleFederationMembersKicker, NodeSettings nodeSettings) { this.consensusManager = consensusManager; this.dateTimeProvider = dateTimeProvider; this.network = network as PoANetwork; this.ibdState = ibdState; this.blockDefinition = blockDefinition; this.slotsManager = slotsManager; this.connectionManager = connectionManager; this.poaHeaderValidator = poaHeaderValidator; this.federationManager = federationManager; this.federationHistory = federationHistory; this.integrityValidator = integrityValidator; this.walletManager = walletManager; this.votingManager = votingManager; this.poaSettings = poAMinerSettings; this.asyncProvider = asyncProvider; this.idleFederationMembersKicker = idleFederationMembersKicker; this.nodeLifetime = nodeLifetime; this.logger = loggerFactory.CreateLogger(this.GetType().FullName); this.cancellation = CancellationTokenSource.CreateLinkedTokenSource(new[] { nodeLifetime.ApplicationStopping }); this.votingDataEncoder = new VotingDataEncoder(); this.nodeSettings = nodeSettings; this.miningStatistics = new MiningStatisticsModel(); nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component, this.GetType().Name); }
public VotingManagerTests() { string dir = TestBase.CreateTestDir(this); var keyValueRepo = new KeyValueRepository(dir, new DBreezeSerializer(this.network)); this.resultExecutorMock = new Mock <IPollResultExecutor>(); this.encoder = new VotingDataEncoder(this.loggerFactory); this.changesApplied = new List <VotingData>(); this.changesReverted = new List <VotingData>(); this.resultExecutorMock.Setup(x => x.ApplyChange(It.IsAny <VotingData>())).Callback((VotingData data) => this.changesApplied.Add(data)); this.resultExecutorMock.Setup(x => x.RevertChange(It.IsAny <VotingData>())).Callback((VotingData data) => this.changesReverted.Add(data)); this.federationManager.SetPrivatePropertyValue(nameof(FederationManager.IsFederationMember), true); this.votingManager = new VotingManager(this.federationManager, this.loggerFactory, keyValueRepo, this.slotsManager, this.resultExecutorMock.Object); this.votingManager.Initialize(); }
public PoAMiner( IConsensusManager consensusManager, IDateTimeProvider dateTimeProvider, Network network, INodeLifetime nodeLifetime, ILoggerFactory loggerFactory, IInitialBlockDownloadState ibdState, BlockDefinition blockDefinition, ISlotsManager slotsManager, IConnectionManager connectionManager, PoABlockHeaderValidator poaHeaderValidator, IFederationManager federationManager, IIntegrityValidator integrityValidator, IWalletManager walletManager, INodeStats nodeStats, VotingManager votingManager, PoAMinerSettings poAMinerSettings, IAsyncProvider asyncProvider) { this.consensusManager = consensusManager; this.dateTimeProvider = dateTimeProvider; this.network = network as PoANetwork; this.ibdState = ibdState; this.blockDefinition = blockDefinition; this.slotsManager = slotsManager; this.connectionManager = connectionManager; this.poaHeaderValidator = poaHeaderValidator; this.federationManager = federationManager; this.integrityValidator = integrityValidator; this.walletManager = walletManager; this.votingManager = votingManager; this.settings = poAMinerSettings; this.asyncProvider = asyncProvider; this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode"); this.cancellation = CancellationTokenSource.CreateLinkedTokenSource(new[] { nodeLifetime.ApplicationStopping }); this.votingDataEncoder = new VotingDataEncoder(loggerFactory); nodeStats.RegisterStats(this.AddComponentStats, StatsType.Component); }
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()); }
public override void Initialize() { this.votingDataEncoder = new VotingDataEncoder(); base.Initialize(); }
public override void Initialize() { this.votingDataEncoder = new VotingDataEncoder(this.Parent.LoggerFactory); base.Initialize(); }
public VotingDataEncoderTests() { this.encoder = new VotingDataEncoder(new ExtendedLoggerFactory()); }
public VotingDataEncoderTests() { this.encoder = new VotingDataEncoder(); }
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.ruleContext = new RuleContext(new ValidationContext(), DateTimeOffset.Now); var header = new BlockHeader() { Time = 5234 }; this.ruleContext.ValidationContext.BlockToValidate = new Block(header); this.ruleContext.ValidationContext.ChainedHeaderToValidate = new ChainedHeader(header, header.GetHash(), 0); 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); var fullnode = new Mock <IFullNode>(); fullnode.Setup(x => x.NodeService <CounterChainNetworkWrapper>(false)).Returns(new CounterChainNetworkWrapper(new StraxMain())); var consensusManager = new Mock <IConsensusManager>(); fullnode.Setup(x => x.NodeService <IConsensusManager>(false)).Returns(consensusManager.Object); var federationHistory = new Mock <IFederationHistory>(); federationHistory .Setup(x => x.GetFederationMemberForBlock(It.IsAny <ChainedHeader>())) .Returns(new CollateralFederationMember(new Key().PubKey, false, new Money(1), "addr1")); this.rule = new CheckCollateralFullValidationRule(this.ibdMock.Object, this.collateralCheckerMock.Object, new Mock <IDateTimeProvider>().Object, new PoANetwork(), federationHistory.Object) { Logger = logger }; this.rule.Initialize(); }