public PoaTestNode(string name, IPrivateKey privateKey, IPeerSettings nodeSettings, IDfsService dfsService, IEnumerable <PeerId> knownPeerIds, IFileSystem parentTestFileSystem) { Name = name; _nodeSettings = nodeSettings; _nodeDirectory = parentTestFileSystem.GetCatalystDataDir(); _dfsService = dfsService; _rpcSettings = RpcSettingsHelper.GetRpcServerSettings(nodeSettings.Port + 100); _nodePeerId = nodeSettings.PeerId; _memPool = new Mempool(new MempoolService(new InMemoryRepository <PublicEntryDao, string>())); _peerRepository = new PeerRepository(new InMemoryRepository <Peer, string>()); var peersInRepo = knownPeerIds.Select(p => new Peer { PeerId = p, IsPoaNode = true, LastSeen = DateTime.UtcNow }).ToList(); _peerRepository.Add(peersInRepo); _deltaByNumber = new DeltaByNumberRepository(new InMemoryRepository <DeltaByNumber, string>()); _containerProvider = new ContainerProvider(new[] { Constants.NetworkConfigFile(NetworkType.Devnet), Constants.SerilogJsonConfigFile } .Select(f => Path.Combine(Constants.ConfigSubFolder, f)), parentTestFileSystem, TestContext.CurrentContext); RegisterNodeDependencies(_containerProvider.ContainerBuilder, excludedModules: new List <Type> { typeof(ApiModule), typeof(RpcServerModule) } ); _containerProvider.ConfigureContainerBuilder(true, true); OverrideContainerBuilderRegistrations(); _scope = _containerProvider.Container.BeginLifetimeScope(Name); _node = _scope.Resolve <ICatalystNode>(); var keyStore = _scope.Resolve <IKeyStore>(); var keyRegistry = _scope.Resolve <IKeyRegistry>(); keyRegistry.RemoveItemFromRegistry(KeyRegistryTypes.DefaultKey); keyRegistry.AddItemToRegistry(KeyRegistryTypes.DefaultKey, privateKey); keyStore.KeyStoreEncryptAsync(privateKey, nodeSettings.NetworkType, KeyRegistryTypes.DefaultKey) .ConfigureAwait(false).GetAwaiter() .GetResult(); }
public RpcServer(IRpcServerSettings settings, ILogger logger, ITcpServerChannelFactory channelFactory, ICertificateStore certificateStore, IEnumerable <IRpcRequestObserver> requestHandlers, ITcpServerEventLoopGroupFactory eventEventLoopGroupFactory) : base(channelFactory, logger, eventEventLoopGroupFactory) { _requestHandlers = requestHandlers; Settings = settings; _cancellationSource = new CancellationTokenSource(); _certificate = certificateStore.ReadOrCreateCertificateFile(settings.PfxFileName); }
public PoaTestNode(string name, IPrivateKey privateKey, IPeerSettings nodeSettings, IEnumerable <PeerId> knownPeerIds, IFileSystem parentTestFileSystem, ITestOutputHelper output) { Name = name; _nodeSettings = nodeSettings; _nodeDirectory = parentTestFileSystem.GetCatalystDataDir().SubDirectoryInfo(Name); var nodeFileSystem = Substitute.ForPartsOf <FileSystem>(); nodeFileSystem.GetCatalystDataDir().Returns(_nodeDirectory); _rpcSettings = RpcSettingsHelper.GetRpcServerSettings(nodeSettings.Port + 100); _nodePeerId = nodeSettings.PeerId; var baseDfsFolder = Path.Combine(parentTestFileSystem.GetCatalystDataDir().FullName, "dfs"); var hashProvider = new HashProvider(HashingAlgorithm.GetAlgorithmMetadata("blake2b-256")); _dfs = new DevDfs(parentTestFileSystem, hashProvider, baseDfsFolder); _memPool = new Mempool(new TestMempoolRepository(new InMemoryRepository <TransactionBroadcastDao, string>())); _peerRepository = Substitute.For <IPeerRepository>(); var peersInRepo = knownPeerIds.Select(p => new Peer { PeerId = p }).ToList(); _peerRepository.AsQueryable().Returns(peersInRepo.AsQueryable()); _peerRepository.GetAll().Returns(peersInRepo); _peerRepository.Get(Arg.Any <string>()).Returns(ci => { return(peersInRepo.First(p => p.DocumentId.Equals((string)ci[0]))); }); _containerProvider = new ContainerProvider(new[] { Constants.NetworkConfigFile(NetworkType.Devnet), Constants.SerilogJsonConfigFile } .Select(f => Path.Combine(Constants.ConfigSubFolder, f)), parentTestFileSystem, output); Program.RegisterNodeDependencies(_containerProvider.ContainerBuilder, excludedModules: new List <Type> { typeof(ApiModule), typeof(RpcServerModule) } ); _containerProvider.ConfigureContainerBuilder(true, true); OverrideContainerBuilderRegistrations(); _scope = _containerProvider.Container.BeginLifetimeScope(Name); _node = _scope.Resolve <ICatalystNode>(); var keyStore = _scope.Resolve <IKeyStore>(); var keyRegistry = _scope.Resolve <IKeyRegistry>(); keyRegistry.AddItemToRegistry(KeyRegistryTypes.DefaultKey, privateKey); keyStore.KeyStoreEncryptAsync(privateKey, nodeSettings.NetworkType, KeyRegistryTypes.DefaultKey).ConfigureAwait(false).GetAwaiter() .GetResult(); }