Пример #1
0
        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();
        }
Пример #2
0
        public virtual void Setup(TestContext output)
        {
            Guard.Argument(output, nameof(output)).NotNull();

            Output          = output;
            CurrentTestName = Output.Test.MethodName;

            CreateUniqueTestDirectory();

            ConfigFilesUsed = new List <string>
            {
                Path.Combine(Constants.ConfigSubFolder, Constants.SerilogJsonConfigFile),
                Path.Combine(Constants.ConfigSubFolder, Constants.NetworkConfigFile(_network == default ? NetworkType.Devnet : _network))
            };

            _configFilesUsed?.ToList().ForEach(config =>
            {
                ConfigFilesUsed.Add(config);
            });

            ContainerProvider = new ContainerProvider(ConfigFilesUsed, FileSystem, Output);
            ContainerProvider.ConfigureContainerBuilder(true, true);

            TestContext.WriteLine("test running in folder {0}", TestDirectory.FullName);
        }
Пример #3
0
        protected FileSystemBasedTest(ITestOutputHelper output,
                                      IEnumerable <string> configFilesUsed = default,
                                      NetworkType network = default)
        {
            Guard.Argument(output, nameof(output)).NotNull();
            Output = output;
            var currentTest = Output.GetType().GetField("test", BindingFlags.Instance | BindingFlags.NonPublic)
                              .GetValue(Output) as ITest;

            if (currentTest == null)
            {
                throw new ArgumentNullException(
                          $"Failed to reflect current test as {nameof(ITest)} from {nameof(output)}");
            }

            CurrentTestName = currentTest.TestCase.TestMethod.Method.Name;

            CreateUniqueTestDirectory();

            ConfigFilesUsed = new List <string>
            {
                Path.Combine(Constants.ConfigSubFolder, Constants.SerilogJsonConfigFile),
                Path.Combine(Constants.ConfigSubFolder, Constants.NetworkConfigFile(network == default ? NetworkType.Devnet : network))
            };

            configFilesUsed?.ToList().ForEach(config =>
            {
                ConfigFilesUsed.Add(config);
            });

            ContainerProvider = new ContainerProvider(ConfigFilesUsed, FileSystem, Output);
            ContainerProvider.ConfigureContainerBuilder(true, true);

            Output.WriteLine("test running in folder {0}", _testDirectory.FullName);
        }