Add unit tests for the backend: Config
This commit is contained in:
		
							parent
							
								
									451e36e288
								
							
						
					
					
						commit
						f36fa62569
					
				
							
								
								
									
										89
									
								
								backend/src/__fixtures__/mempool-config.template.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								backend/src/__fixtures__/mempool-config.template.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,89 @@
 | 
			
		||||
{
 | 
			
		||||
  "MEMPOOL": {
 | 
			
		||||
    "NETWORK": "__MEMPOOL_NETWORK__",
 | 
			
		||||
    "BACKEND": "__MEMPOOL_BACKEND__",
 | 
			
		||||
    "BLOCKS_SUMMARIES_INDEXING": true,
 | 
			
		||||
    "HTTP_PORT": 1,
 | 
			
		||||
    "SPAWN_CLUSTER_PROCS": 2,
 | 
			
		||||
    "API_URL_PREFIX": "__MEMPOOL_API_URL_PREFIX__",
 | 
			
		||||
    "POLL_RATE_MS": 3,
 | 
			
		||||
    "CACHE_DIR": "__MEMPOOL_CACHE_DIR__",
 | 
			
		||||
    "CLEAR_PROTECTION_MINUTES": 4,
 | 
			
		||||
    "RECOMMENDED_FEE_PERCENTILE": 5,
 | 
			
		||||
    "BLOCK_WEIGHT_UNITS": 6,
 | 
			
		||||
    "INITIAL_BLOCKS_AMOUNT": 7,
 | 
			
		||||
    "MEMPOOL_BLOCKS_AMOUNT": 8,
 | 
			
		||||
    "PRICE_FEED_UPDATE_INTERVAL": 9,
 | 
			
		||||
    "USE_SECOND_NODE_FOR_MINFEE": 10,
 | 
			
		||||
    "EXTERNAL_ASSETS": 11,
 | 
			
		||||
    "EXTERNAL_MAX_RETRY": 12,
 | 
			
		||||
    "EXTERNAL_RETRY_INTERVAL": 13,
 | 
			
		||||
    "USER_AGENT": "__MEMPOOL_USER_AGENT__",
 | 
			
		||||
    "STDOUT_LOG_MIN_PRIORITY": "__MEMPOOL_STDOUT_LOG_MIN_PRIORITY__",
 | 
			
		||||
    "INDEXING_BLOCKS_AMOUNT": 14
 | 
			
		||||
  },
 | 
			
		||||
  "CORE_RPC": {
 | 
			
		||||
    "HOST": "__CORE_RPC_HOST__",
 | 
			
		||||
    "PORT": 15,
 | 
			
		||||
    "USERNAME": "__CORE_RPC_USERNAME__",
 | 
			
		||||
    "PASSWORD": "__CORE_RPC_PASSWORD__"
 | 
			
		||||
  },
 | 
			
		||||
  "ELECTRUM": {
 | 
			
		||||
    "HOST": "__ELECTRUM_HOST__",
 | 
			
		||||
    "PORT": 16,
 | 
			
		||||
    "TLS_ENABLED": true
 | 
			
		||||
  },
 | 
			
		||||
  "ESPLORA": {
 | 
			
		||||
    "REST_API_URL": "__ESPLORA_REST_API_URL__"
 | 
			
		||||
  },
 | 
			
		||||
  "SECOND_CORE_RPC": {
 | 
			
		||||
    "HOST": "__SECOND_CORE_RPC_HOST__",
 | 
			
		||||
    "PORT": 17,
 | 
			
		||||
    "USERNAME": "__SECOND_CORE_RPC_USERNAME__",
 | 
			
		||||
    "PASSWORD": "__SECOND_CORE_RPC_PASSWORD__"
 | 
			
		||||
  },
 | 
			
		||||
  "DATABASE": {
 | 
			
		||||
    "ENABLED": false,
 | 
			
		||||
    "HOST": "__DATABASE_HOST__",
 | 
			
		||||
    "SOCKET": "__DATABASE_SOCKET__",
 | 
			
		||||
    "PORT": 18,
 | 
			
		||||
    "DATABASE": "__DATABASE_DATABASE__",
 | 
			
		||||
    "USERNAME": "__DATABASE_USERNAME__",
 | 
			
		||||
    "PASSWORD": "__DATABASE_PASSWORD__"
 | 
			
		||||
  },
 | 
			
		||||
  "SYSLOG": {
 | 
			
		||||
    "ENABLED": false,
 | 
			
		||||
    "HOST": "__SYSLOG_HOST__",
 | 
			
		||||
    "PORT": 19,
 | 
			
		||||
    "MIN_PRIORITY": "__SYSLOG_MIN_PRIORITY__",
 | 
			
		||||
    "FACILITY": "__SYSLOG_FACILITY__"
 | 
			
		||||
  },
 | 
			
		||||
  "STATISTICS": {
 | 
			
		||||
    "ENABLED": false,
 | 
			
		||||
    "TX_PER_SECOND_SAMPLE_PERIOD": 20
 | 
			
		||||
  },
 | 
			
		||||
  "BISQ": {
 | 
			
		||||
    "ENABLED": true,
 | 
			
		||||
    "DATA_PATH": "__BISQ_DATA_PATH__"
 | 
			
		||||
  },
 | 
			
		||||
  "SOCKS5PROXY": {
 | 
			
		||||
    "ENABLED": true,
 | 
			
		||||
    "USE_ONION": true,
 | 
			
		||||
    "HOST": "__SOCKS5PROXY_HOST__",
 | 
			
		||||
    "PORT": "__SOCKS5PROXY_PORT__",
 | 
			
		||||
    "USERNAME": "__SOCKS5PROXY_USERNAME__",
 | 
			
		||||
    "PASSWORD": "__SOCKS5PROXY_PASSWORD__"
 | 
			
		||||
  },
 | 
			
		||||
  "PRICE_DATA_SERVER": {
 | 
			
		||||
    "TOR_URL": "__PRICE_DATA_SERVER_TOR_URL__",
 | 
			
		||||
    "CLEARNET_URL": "__PRICE_DATA_SERVER_CLEARNET_URL__"
 | 
			
		||||
  },
 | 
			
		||||
  "EXTERNAL_DATA_SERVER": {
 | 
			
		||||
    "MEMPOOL_API": "__EXTERNAL_DATA_SERVER_MEMPOOL_API__",
 | 
			
		||||
    "MEMPOOL_ONION": "__EXTERNAL_DATA_SERVER_MEMPOOL_ONION__",
 | 
			
		||||
    "LIQUID_API": "__EXTERNAL_DATA_SERVER_LIQUID_API__",
 | 
			
		||||
    "LIQUID_ONION": "__EXTERNAL_DATA_SERVER_LIQUID_ONION__",
 | 
			
		||||
    "BISQ_URL": "__EXTERNAL_DATA_SERVER_BISQ_URL__",
 | 
			
		||||
    "BISQ_ONION": "__EXTERNAL_DATA_SERVER_BISQ_ONION__"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										137
									
								
								backend/src/__tests__/config.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								backend/src/__tests__/config.test.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,137 @@
 | 
			
		||||
import * as fs from 'fs';
 | 
			
		||||
 | 
			
		||||
describe('Mempool Backend Config', () => {
 | 
			
		||||
  beforeEach(() => {
 | 
			
		||||
    jest.resetAllMocks();
 | 
			
		||||
    jest.resetModules();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should return defaults when no file is present', () => {
 | 
			
		||||
    jest.isolateModules(() => {
 | 
			
		||||
      jest.mock('../../mempool-config.json', () => ({}), { virtual: true });
 | 
			
		||||
 | 
			
		||||
      const config = jest.requireActual('../config').default;
 | 
			
		||||
 | 
			
		||||
      expect(config.MEMPOOL).toStrictEqual({
 | 
			
		||||
        NETWORK: 'mainnet',
 | 
			
		||||
        BACKEND: 'none',
 | 
			
		||||
        BLOCKS_SUMMARIES_INDEXING: false,
 | 
			
		||||
        HTTP_PORT: 8999,
 | 
			
		||||
        SPAWN_CLUSTER_PROCS: 0,
 | 
			
		||||
        API_URL_PREFIX: '/api/v1/',
 | 
			
		||||
        POLL_RATE_MS: 2000,
 | 
			
		||||
        CACHE_DIR: './cache',
 | 
			
		||||
        CLEAR_PROTECTION_MINUTES: 20,
 | 
			
		||||
        RECOMMENDED_FEE_PERCENTILE: 50,
 | 
			
		||||
        BLOCK_WEIGHT_UNITS: 4000000,
 | 
			
		||||
        INITIAL_BLOCKS_AMOUNT: 8,
 | 
			
		||||
        MEMPOOL_BLOCKS_AMOUNT: 8,
 | 
			
		||||
        INDEXING_BLOCKS_AMOUNT: 11000,
 | 
			
		||||
        PRICE_FEED_UPDATE_INTERVAL: 600,
 | 
			
		||||
        USE_SECOND_NODE_FOR_MINFEE: false,
 | 
			
		||||
        EXTERNAL_ASSETS: [],
 | 
			
		||||
        EXTERNAL_MAX_RETRY: 1,
 | 
			
		||||
        EXTERNAL_RETRY_INTERVAL: 0,
 | 
			
		||||
        USER_AGENT: 'mempool',
 | 
			
		||||
        STDOUT_LOG_MIN_PRIORITY: 'debug'
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.ELECTRUM).toStrictEqual({ HOST: '127.0.0.1', PORT: 3306, TLS_ENABLED: true });
 | 
			
		||||
 | 
			
		||||
      expect(config.ESPLORA).toStrictEqual({ REST_API_URL: 'http://127.0.0.1:3000' });
 | 
			
		||||
 | 
			
		||||
      expect(config.CORE_RPC).toStrictEqual({
 | 
			
		||||
        HOST: '127.0.0.1',
 | 
			
		||||
        PORT: 8332,
 | 
			
		||||
        USERNAME: 'mempool',
 | 
			
		||||
        PASSWORD: 'mempool'
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.SECOND_CORE_RPC).toStrictEqual({
 | 
			
		||||
        HOST: '127.0.0.1',
 | 
			
		||||
        PORT: 8332,
 | 
			
		||||
        USERNAME: 'mempool',
 | 
			
		||||
        PASSWORD: 'mempool'
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.DATABASE).toStrictEqual({
 | 
			
		||||
        ENABLED: true,
 | 
			
		||||
        HOST: '127.0.0.1',
 | 
			
		||||
        SOCKET: '',
 | 
			
		||||
        PORT: 3306,
 | 
			
		||||
        DATABASE: 'mempool',
 | 
			
		||||
        USERNAME: 'mempool',
 | 
			
		||||
        PASSWORD: 'mempool'
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.SYSLOG).toStrictEqual({
 | 
			
		||||
        ENABLED: true,
 | 
			
		||||
        HOST: '127.0.0.1',
 | 
			
		||||
        PORT: 514,
 | 
			
		||||
        MIN_PRIORITY: 'info',
 | 
			
		||||
        FACILITY: 'local7'
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.STATISTICS).toStrictEqual({ ENABLED: true, TX_PER_SECOND_SAMPLE_PERIOD: 150 });
 | 
			
		||||
 | 
			
		||||
      expect(config.BISQ).toStrictEqual({ ENABLED: false, DATA_PATH: '/bisq/statsnode-data/btc_mainnet/db' });
 | 
			
		||||
 | 
			
		||||
      expect(config.SOCKS5PROXY).toStrictEqual({
 | 
			
		||||
        ENABLED: false,
 | 
			
		||||
        USE_ONION: true,
 | 
			
		||||
        HOST: '127.0.0.1',
 | 
			
		||||
        PORT: 9050,
 | 
			
		||||
        USERNAME: '',
 | 
			
		||||
        PASSWORD: ''
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.PRICE_DATA_SERVER).toStrictEqual({
 | 
			
		||||
        TOR_URL: 'http://wizpriceje6q5tdrxkyiazsgu7irquiqjy2dptezqhrtu7l2qelqktid.onion/getAllMarketPrices',
 | 
			
		||||
        CLEARNET_URL: 'https://price.bisq.wiz.biz/getAllMarketPrices'
 | 
			
		||||
      });
 | 
			
		||||
 | 
			
		||||
      expect(config.EXTERNAL_DATA_SERVER).toStrictEqual({
 | 
			
		||||
        MEMPOOL_API: 'https://mempool.space/api/v1',
 | 
			
		||||
        MEMPOOL_ONION: 'http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/api/v1',
 | 
			
		||||
        LIQUID_API: 'https://liquid.network/api/v1',
 | 
			
		||||
        LIQUID_ONION: 'http://liquidmom47f6s3m53ebfxn47p76a6tlnxib3wp6deux7wuzotdr6cyd.onion/api/v1',
 | 
			
		||||
        BISQ_URL: 'https://bisq.markets/api',
 | 
			
		||||
        BISQ_ONION: 'http://bisqmktse2cabavbr2xjq7xw3h6g5ottemo5rolfcwt6aly6tp5fdryd.onion/api'
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  test('should override the default values with the passed values', () => {
 | 
			
		||||
    jest.isolateModules(() => {
 | 
			
		||||
      const fixture = JSON.parse(fs.readFileSync(`${__dirname}/../__fixtures__/mempool-config.template.json`, 'utf8'));
 | 
			
		||||
      jest.mock('../../mempool-config.json', () => (fixture), { virtual: true });
 | 
			
		||||
 | 
			
		||||
      const config = jest.requireActual('../config').default;
 | 
			
		||||
 | 
			
		||||
      expect(config.MEMPOOL).toStrictEqual(fixture.MEMPOOL);
 | 
			
		||||
 | 
			
		||||
      expect(config.ELECTRUM).toStrictEqual(fixture.ELECTRUM);
 | 
			
		||||
 | 
			
		||||
      expect(config.ESPLORA).toStrictEqual(fixture.ESPLORA);
 | 
			
		||||
 | 
			
		||||
      expect(config.CORE_RPC).toStrictEqual(fixture.CORE_RPC);
 | 
			
		||||
 | 
			
		||||
      expect(config.SECOND_CORE_RPC).toStrictEqual(fixture.SECOND_CORE_RPC);
 | 
			
		||||
 | 
			
		||||
      expect(config.DATABASE).toStrictEqual(fixture.DATABASE);
 | 
			
		||||
 | 
			
		||||
      expect(config.SYSLOG).toStrictEqual(fixture.SYSLOG);
 | 
			
		||||
 | 
			
		||||
      expect(config.STATISTICS).toStrictEqual(fixture.STATISTICS);
 | 
			
		||||
 | 
			
		||||
      expect(config.BISQ).toStrictEqual(fixture.BISQ);
 | 
			
		||||
 | 
			
		||||
      expect(config.SOCKS5PROXY).toStrictEqual(fixture.SOCKS5PROXY);
 | 
			
		||||
 | 
			
		||||
      expect(config.PRICE_DATA_SERVER).toStrictEqual(fixture.PRICE_DATA_SERVER);
 | 
			
		||||
 | 
			
		||||
      expect(config.EXTERNAL_DATA_SERVER).toStrictEqual(fixture.EXTERNAL_DATA_SERVER);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
});
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user