Exemple #1
0
        public override void ConfigureServices(IServiceCollection services)
        {
            base.ConfigureServices(services);

            // replace IRpcClientFactory and IRestClientFactory with same instance of mock version
            var serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IRpcClientFactory));

            services.Remove(serviceDescriptor);

            var rpcClientFactoryMock = new RpcClientFactoryMock();

            services.AddSingleton <IRpcClientFactory>(rpcClientFactoryMock);

            serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IClock));
            services.Remove(serviceDescriptor);
            services.AddSingleton <IClock, MockedClock>();

            serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IZMQEndpointChecker));
            services.Remove(serviceDescriptor);
            services.AddTransient <IZMQEndpointChecker, MockZMQEndpointChecker>();

            // We register  fee repository as singleton, so that we can modify the fee filename in individual tests
            serviceDescriptor = services.FirstOrDefault(descriptor => descriptor.ServiceType == typeof(IFeeQuoteRepository));
            services.Remove(serviceDescriptor);
            services.AddSingleton <IFeeQuoteRepository, FeeQuoteRepositoryMock>();

            // We register clock as singleton, so that we can set time in individual tests
            services.AddSingleton <IClock, MockedClock>();
            services.AddSingleton <CleanUpTxWithPauseHandlerForTest>();

            // use test implementation of IDbManager that uses test database
            services.AddTransient <IDbManager, MerchantAPITestDbManager>();
        }
Exemple #2
0
        public void TestInitialize()
        {
            Initialize(mockedServices: true);
            ApiKeyAuthentication = AppSettings.RestAdminAPIKey;

            rpcClientFactoryMock = server.Services.GetRequiredService <IRpcClientFactory>() as RpcClientFactoryMock;

            if (rpcClientFactoryMock != null)
            {
                rpcClientFactoryMock.AddKnownBlock(0, HelperTools.HexStringToByteArray(TestBase.genesisBlock));

                rpcClientFactoryMock.Reset(); // remove calls that are used to test node connection when adding a new node
            }
        }
Exemple #3
0
        public override void Initialize(bool mockedServices = false, IEnumerable <KeyValuePair <string, string> > overridenSettings = null)
        {
            base.Initialize(mockedServices, overridenSettings);
            // setup repositories
            NodeRepository       = server.Services.GetRequiredService <INodeRepository>() as NodeRepositoryPostgres;
            TxRepositoryPostgres = server.Services.GetRequiredService <ITxRepository>() as TxRepositoryPostgres;
            FeeQuoteRepository   = server.Services.GetRequiredService <IFeeQuoteRepository>() as FeeQuoteRepositoryPostgres;

            MinerId = server.Services.GetRequiredService <IMinerId>();

            // setup common services

            Nodes          = server.Services.GetRequiredService <INodes>();
            BlockChainInfo = server.Services.GetRequiredService <IBlockChainInfo>();
            RpcMultiClient = server.Services.GetRequiredService <IRpcMultiClient>();

            EventBus = server.Services.GetRequiredService <IEventBus>();

            rpcClientFactoryMock   = server.Services.GetRequiredService <IRpcClientFactory>() as RpcClientFactoryMock;
            feeQuoteRepositoryMock = server.Services.GetRequiredService <IFeeQuoteRepository>() as FeeQuoteRepositoryMock;
            FeeQuoteRepositoryMock.quoteExpiryMinutes = quoteExpiryMinutes;

            if (rpcClientFactoryMock != null)
            {
                rpcClientFactoryMock.SetUpTransaction(
                    txC3Hex,
                    txC2Hex,
                    txZeroFeeHex,
                    txZeroFeeInput1Hex,
                    txZeroFeeInput2Hex,
                    tx2Hex,
                    tx2Input1Hex,
                    tx2Input2Hex);

                rpcClientFactoryMock.AddKnownBlock(0, HelperTools.HexStringToByteArray(genesisBlock));

                rpcClientFactoryMock.Reset(); // remove calls that are used to test node connection when adding a new node
            }
        }
 public void Initialize()
 {
     rpcClientFactoryMock = new RpcClientFactoryMock();
     rpcClientFactoryMock.AddKnownBlock(0, HelperTools.HexStringToByteArray(TestBase.genesisBlock));
 }
        public void Initialize(bool mockedServices = false)
        {
            SyncTest.WaitOne(); // tests must not run in parallel since each test first deletes database
            try
            {
                // setup call back server
                serverCallback = CallbackServer.GetTestServer(Callback.Url, Callback);
                clientCallback = serverCallback.CreateClient();

                //setup server
                server = TestServerBase.CreateServer(mockedServices, serverCallback, dbConnectionString);
                client = server.CreateClient();

                // setup repositories
                NodeRepository       = server.Services.GetRequiredService <INodeRepository>() as NodeRepositoryPostgres;
                TxRepositoryPostgres = server.Services.GetRequiredService <ITxRepository>() as TxRepositoryPostgres;
                FeeQuoteRepository   = server.Services.GetRequiredService <IFeeQuoteRepository>() as FeeQuoteRepositoryPostgres;

                BlockChainInfo = server.Services.GetRequiredService <IBlockChainInfo>();
                MinerId        = server.Services.GetRequiredService <IMinerId>();

                // setup common services
                loggerFactory = server.Services.GetRequiredService <ILoggerFactory>();
                loggerTest    = loggerFactory.CreateLogger(LOG_CATEGORY);

                Nodes          = server.Services.GetRequiredService <INodes>();
                blockChainInfo = server.Services.GetRequiredService <IBlockChainInfo>();
                rpcMultiClient = server.Services.GetRequiredService <IRpcMultiClient>();

                eventBus = server.Services.GetRequiredService <IEventBus>();

                rpcClientFactoryMock   = server.Services.GetRequiredService <IRpcClientFactory>() as RpcClientFactoryMock;
                feeQuoteRepositoryMock = server.Services.GetRequiredService <IFeeQuoteRepository>() as FeeQuoteRepositoryMock;
                FeeQuoteRepositoryMock.quoteExpiryMinutes = quoteExpiryMinutes;

                if (rpcClientFactoryMock != null)
                {
                    rpcClientFactoryMock.SetUpTransaction(
                        txC3Hex,
                        txC2Hex,
                        txZeroFeeHex,
                        txZeroFeeInput1Hex,
                        txZeroFeeInput2Hex,
                        tx2Hex,
                        tx2Input1Hex,
                        tx2Input2Hex);

                    rpcClientFactoryMock.AddKnownBlock(0, HelperTools.HexStringToByteArray(genesisBlock));

                    rpcClientFactoryMock.Reset(); // remove calls that are used to test node connection when adding a new node
                }
                loggerTest.LogInformation($"Path: {Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)}");
                loggerTest.LogInformation($"ConnString: {dbConnectionString}");
            }
            catch
            {
                SyncTest.Reset();
                // If there was error during initialization, let the other tests run (although they will probably also fail)
                throw;
            }
        }