public TestContext() { this.Network = KnownNetworks.RegTest; this.chainIndexer = new ChainIndexer(this.Network); this.dateTimeProvider = new DateTimeProvider(); this.hashStore = new InvalidBlockHashStore(this.dateTimeProvider); this.coinView = new TestInMemoryCoinView(this.chainIndexer.Tip.HashBlock); this.HeaderValidator = new Mock <IHeaderValidator>(); this.HeaderValidator.Setup(hv => hv.ValidateHeader(It.IsAny <ChainedHeader>())).Returns(new ValidationContext()); this.nodeLifetime = new NodeLifetime(); this.ibd = new Mock <IInitialBlockDownloadState>(); this.BlockPuller = new Mock <IBlockPuller>(); this.BlockPuller.Setup(b => b.Initialize(It.IsAny <BlockPuller.OnBlockDownloadedCallback>())) .Callback <BlockPuller.OnBlockDownloadedCallback>((d) => { this.blockPullerBlockDownloadCallback = d; }); this.BlockStore = new Mock <IBlockStore>(); this.checkpoints = new Mock <ICheckpoints>(); this.ChainState = new Mock <IChainState>(); string[] param = new string[] { }; this.nodeSettings = new NodeSettings(this.Network, args: param); this.ConsensusSettings = new ConsensusSettings(this.nodeSettings); this.loggerFactory = this.nodeSettings.LoggerFactory; this.nodeStats = new NodeStats(this.dateTimeProvider, this.loggerFactory); var connectionSettings = new ConnectionManagerSettings(this.nodeSettings); this.selfEndpointTracker = new SelfEndpointTracker(this.loggerFactory, connectionSettings); this.Network.Consensus.Options = new ConsensusOptions(); this.signals = new Bitcoin.Signals.Signals(this.loggerFactory, null); this.asyncProvider = new AsyncProvider(this.loggerFactory, this.signals, this.nodeLifetime); // Dont check PoW of a header in this test. this.Network.Consensus.ConsensusRules.HeaderValidationRules.RemoveAll(x => x.GetType() == typeof(CheckDifficultyPowRule)); this.ChainedHeaderTree = new ChainedHeaderTree( this.Network, this.loggerFactory, this.HeaderValidator.Object, this.checkpoints.Object, this.ChainState.Object, this.FinalizedBlockMock.Object, this.ConsensusSettings, this.hashStore); this.peerAddressManager = new PeerAddressManager(DateTimeProvider.Default, this.nodeSettings.DataFolder, this.loggerFactory, this.selfEndpointTracker); this.networkPeerFactory = new NetworkPeerFactory(this.Network, this.dateTimeProvider, this.loggerFactory, new PayloadProvider().DiscoverPayloads(), this.selfEndpointTracker, this.ibd.Object, new ConnectionManagerSettings(this.nodeSettings), this.asyncProvider, this.peerAddressManager); var peerDiscovery = new PeerDiscovery(this.asyncProvider, this.loggerFactory, this.Network, this.networkPeerFactory, this.nodeLifetime, this.nodeSettings, this.peerAddressManager); this.connectionManager = new ConnectionManager(this.dateTimeProvider, this.loggerFactory, this.Network, this.networkPeerFactory, this.nodeSettings, this.nodeLifetime, new NetworkPeerConnectionParameters(), this.peerAddressManager, new IPeerConnector[] { }, peerDiscovery, this.selfEndpointTracker, connectionSettings, new VersionProvider(), this.nodeStats, this.asyncProvider); this.deployments = new NodeDeployments(this.Network, this.chainIndexer); this.consensusRules = new PowConsensusRuleEngine(this.Network, this.loggerFactory, this.dateTimeProvider, this.chainIndexer, this.deployments, this.ConsensusSettings, this.checkpoints.Object, this.coinView, this.ChainState.Object, this.hashStore, this.nodeStats, this.asyncProvider, new ConsensusRulesContainer()); this.consensusRules.SetupRulesEngineParent(); var tree = new ChainedHeaderTree(this.Network, this.loggerFactory, this.HeaderValidator.Object, this.checkpoints.Object, this.ChainState.Object, this.FinalizedBlockMock.Object, this.ConsensusSettings, this.hashStore); this.PartialValidator = new Mock <IPartialValidator>(); this.FullValidator = new Mock <IFullValidator>(); this.peerBanning = new PeerBanning(this.connectionManager, this.loggerFactory, this.dateTimeProvider, this.peerAddressManager); this.IntegrityValidator.Setup(i => i.VerifyBlockIntegrity(It.IsAny <ChainedHeader>(), It.IsAny <Block>())) .Returns(new ValidationContext()); ConsensusManager consensusManager = new ConsensusManager(tree, this.Network, this.loggerFactory, this.ChainState.Object, this.IntegrityValidator.Object, this.PartialValidator.Object, this.FullValidator.Object, this.consensusRules, this.FinalizedBlockMock.Object, this.signals, this.peerBanning, this.ibd.Object, this.chainIndexer, this.BlockPuller.Object, this.BlockStore.Object, this.connectionManager, this.nodeStats, this.nodeLifetime, this.ConsensusSettings, this.dateTimeProvider); this.TestConsensusManager = new TestConsensusManager(consensusManager); }
public void Initialize(BlockPuller.OnBlockDownloadedCallback callback) { this.puller.Initialize(callback); }
public void SetCallback(BlockPuller.OnBlockDownloadedCallback callback) => this.puller.SetPrivateVariableValue("onDownloadedCallback", callback);
public ExtendedBlockPuller(BlockPuller.OnBlockDownloadedCallback callback, IChainState chainState, ProtocolVersion protocolVersion, IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory) { this.puller = new BlockPuller(callback, chainState, protocolVersion, dateTimeProvider, loggerFactory); }