Changeset View
Changeset View
Standalone View
Standalone View
apps/alias-server/test/mainTests.js
// Copyright (c) 2023 The Bitcoin developers | // Copyright (c) 2023 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
'use strict'; | 'use strict'; | ||||
const assert = require('assert'); | const assert = require('assert'); | ||||
const cashaddr = require('ecashaddrjs'); | const cashaddr = require('ecashaddrjs'); | ||||
const { main } = require('../src/main'); | const { main } = require('../src/main'); | ||||
const config = require('../config'); | const config = require('../config'); | ||||
const mockSecrets = require('../secrets.sample'); | const mockSecrets = require('../secrets.sample'); | ||||
const MockAdapter = require('axios-mock-adapter'); | const MockAdapter = require('axios-mock-adapter'); | ||||
const axios = require('axios'); | const axios = require('axios'); | ||||
const { testAddressAliases } = require('./mocks/aliasMocks'); | const { generated } = require('./mocks/aliasMocks'); | ||||
// Mock mongodb | // Mock mongodb | ||||
const { MongoClient } = require('mongodb'); | const { MongoClient } = require('mongodb'); | ||||
const { MongoMemoryServer } = require('mongodb-memory-server'); | const { MongoMemoryServer } = require('mongodb-memory-server'); | ||||
// Mock chronik | // Mock chronik | ||||
const { MockChronikClient } = require('./mocks/chronikMock'); | const { MockChronikClient } = require('./mocks/chronikMock'); | ||||
describe('alias-server main.js', async function () { | describe('alias-server main.js', async function () { | ||||
Show All 27 Lines | it('main() intializes database correctly, connects to a websocket, and runs handleAppStartup() correctly', async function () { | ||||
// Add tx history to mockedChronik | // Add tx history to mockedChronik | ||||
// Set the script | // Set the script | ||||
const { type, hash } = cashaddr.decode( | const { type, hash } = cashaddr.decode( | ||||
config.aliasConstants.registrationAddress, | config.aliasConstants.registrationAddress, | ||||
true, | true, | ||||
); | ); | ||||
mockedChronik.setScript(type, hash); | mockedChronik.setScript(type, hash); | ||||
// Set the mock tx history | // Set the mock tx history | ||||
mockedChronik.setTxHistory(testAddressAliases.txHistory); | mockedChronik.setTxHistory(generated.txHistory); | ||||
// Mock avalanche RPC call | // Mock avalanche RPC call | ||||
// onNoMatch: 'throwException' helps to debug if mock is not being used | // onNoMatch: 'throwException' helps to debug if mock is not being used | ||||
const mock = new MockAdapter(axios, { onNoMatch: 'throwException' }); | const mock = new MockAdapter(axios, { onNoMatch: 'throwException' }); | ||||
// Mock response for rpc return of true for isfinalblock method | // Mock response for rpc return of true for isfinalblock method | ||||
mock.onPost().reply(200, { | mock.onPost().reply(200, { | ||||
result: true, | result: true, | ||||
error: null, | error: null, | ||||
Show All 33 Lines |