Page MenuHomePhabricator

D14203.id41227.diff
No OneTemporary

D14203.id41227.diff

diff --git a/apps/alias-server/test/chronikWsHandlerTests.js b/apps/alias-server/test/chronikWsHandlerTests.js
--- a/apps/alias-server/test/chronikWsHandlerTests.js
+++ b/apps/alias-server/test/chronikWsHandlerTests.js
@@ -16,7 +16,11 @@
const MockAdapter = require('axios-mock-adapter');
const axios = require('axios');
// Mock mongodb
-const { initializeDb } = require('../src/db');
+const {
+ initializeDb,
+ updateServerState,
+ getAliasesFromDb,
+} = require('../src/db');
const { MongoClient } = require('mongodb');
const { MongoMemoryServer } = require('mongodb-memory-server');
const { generated } = require('./mocks/aliasMocks');
@@ -40,6 +44,27 @@
beforeEach(async () => {
// Initialize db before each unit test
testDb = await initializeDb(testMongoClient);
+ /*
+ Because the actual number of pages of txHistory of the IFP address is high and always rising
+ (12,011 as of 20220703)
+ And it's impractical to save thousands of pages of tx history before alias txs started being registered
+ Reset server state to 0,0 for this unit test
+ Only 8 pages of tx history are saved at generated.txHistory, enough to cover all test cases
+ To use default server state of
+ {
+ processedConfirmedTxs: 45587,
+ processedBlockheight: 785000,
+ }
+ We would need to save 1000s of pages of txHistory to allow getUnprocessedTxHistory to get the correct
+ number of pages to fetch
+
+ So, we either save 100 meg of mocks, or we run the unit tests at server state of 0
+
+ */
+ await updateServerState(testDb, {
+ processedBlockheight: 0,
+ processedConfirmedTxs: 0,
+ });
});
afterEach(async () => {
// Wipe the database after each unit test
@@ -158,6 +183,11 @@
result,
`Alias registrations updated to block ${wsMsg.blockHash} at height ${mockBlock.blockInfo.height}`,
);
+ // Verify that all expected valid aliases have been added to the database
+ assert.deepEqual(
+ await getAliasesFromDb(testDb),
+ generated.validAliasRegistrations,
+ );
});
it('parseWebsocketMessage calls handleBlockConnected, which exits if block is not avalanche finalized', async function () {
// Initialize chronik mock
@@ -197,6 +227,8 @@
);
assert.deepEqual(result, false);
+ // Verify that no aliases have been added to the database
+ assert.deepEqual(await getAliasesFromDb(testDb), []);
});
it('If parseWebsocketMessage is called before a previous call to handleBlockConnected has completed, the next call to handleBlockConnected will not enter until the first is completed', async function () {
// Initialize mocks for the first call to parseWebsocketMessage
@@ -295,5 +327,10 @@
`Alias registrations updated to block ${wsMsg.blockHash} at height ${mockBlock.blockInfo.height}`,
`Alias registrations updated to block ${nextWsMsg.blockHash} at height ${nextMockBlock.blockInfo.height}`,
]);
+ // Verify that all expected valid aliases have been added to the database
+ assert.deepEqual(
+ await getAliasesFromDb(testDb),
+ generated.validAliasRegistrations,
+ );
});
});
diff --git a/apps/alias-server/test/eventsTests.js b/apps/alias-server/test/eventsTests.js
--- a/apps/alias-server/test/eventsTests.js
+++ b/apps/alias-server/test/eventsTests.js
@@ -13,7 +13,11 @@
const MockAdapter = require('axios-mock-adapter');
const axios = require('axios');
// Mock mongodb
-const { initializeDb, updateServerState } = require('../src/db');
+const {
+ initializeDb,
+ updateServerState,
+ getAliasesFromDb,
+} = require('../src/db');
const { MongoClient } = require('mongodb');
const { MongoMemoryServer } = require('mongodb-memory-server');
const { generated } = require('./mocks/aliasMocks');
@@ -37,6 +41,28 @@
beforeEach(async () => {
// Initialize db before each unit test
testDb = await initializeDb(testMongoClient);
+
+ /*
+ Because the actual number of pages of txHistory of the IFP address is high and always rising
+ (12,011 as of 20220703)
+ And it's impractical to save thousands of pages of tx history before alias txs started being registered
+ Reset server state to 0,0 for this unit test
+ Only 8 pages of tx history are saved at generated.txHistory, enough to cover all test cases
+ To use default server state of
+ {
+ processedConfirmedTxs: 45587,
+ processedBlockheight: 785000,
+ }
+ We would need to save 1000s of pages of txHistory to allow getUnprocessedTxHistory to get the correct
+ number of pages to fetch
+
+ So, we either save 100 meg of mocks, or we run the unit tests at server state of 0
+
+ */
+ await updateServerState(testDb, {
+ processedBlockheight: 0,
+ processedConfirmedTxs: 0,
+ });
});
afterEach(async () => {
// Wipe the database after each unit test
@@ -95,6 +121,12 @@
result,
`Alias registrations updated to block ${mockBlockchaininfoResponse.tipHash} at height ${mockBlockchaininfoResponse.tipHeight}`,
);
+
+ // Verify that all expected valid aliases have been added to the database
+ assert.deepEqual(
+ await getAliasesFromDb(testDb),
+ generated.validAliasRegistrations,
+ );
});
it('handleAppStartup calls handleBlockConnected with tipHeight and returns false if block is not avalanche finalized', async function () {
// Initialize chronik mock
@@ -136,6 +168,8 @@
);
assert.deepEqual(result, false);
+ // Verify that no aliases have been added to the database
+ assert.deepEqual(await getAliasesFromDb(testDb), []);
});
it('handleAppStartup returns false on chronik error', async function () {
// Initialize chronik mock
@@ -170,6 +204,8 @@
);
assert.deepEqual(result, false);
+ // Verify that no aliases have been added to the database
+ assert.deepEqual(await getAliasesFromDb(testDb), []);
});
it('handleBlockConnected returns false if the function fails to obtain serverState', async function () {
// tipHash called with
@@ -230,6 +266,8 @@
);
assert.deepEqual(result, false);
+ // Verify that no aliases have been added to the database
+ assert.deepEqual(await getAliasesFromDb(testDb), []);
});
it('handleBlockConnected returns false if called with a block of height lower than serverState', async function () {
// tipHash called with
@@ -292,6 +330,8 @@
);
assert.deepEqual(result, false);
+ // Verify that no aliases have been added to the database
+ assert.deepEqual(await getAliasesFromDb(testDb), []);
});
it('handleBlockConnected returns false if called with a block of height equal to serverState', async function () {
// tipHash called with
@@ -354,5 +394,7 @@
);
assert.deepEqual(result, false);
+ // Verify that no aliases have been added to the database
+ assert.deepEqual(await getAliasesFromDb(testDb), []);
});
});
diff --git a/apps/alias-server/test/mainTests.js b/apps/alias-server/test/mainTests.js
--- a/apps/alias-server/test/mainTests.js
+++ b/apps/alias-server/test/mainTests.js
@@ -10,7 +10,11 @@
const MockAdapter = require('axios-mock-adapter');
const axios = require('axios');
const { generated } = require('./mocks/aliasMocks');
-const { initializeDb } = require('../src/db');
+const {
+ initializeDb,
+ updateServerState,
+ getAliasesFromDb,
+} = require('../src/db');
// Mock mongodb
const { MongoClient } = require('mongodb');
@@ -25,6 +29,27 @@
const mongoUri = mongoServer.getUri();
testMongoClient = new MongoClient(mongoUri);
db = await initializeDb(testMongoClient);
+ /*
+ Because the actual number of pages of txHistory of the IFP address is high and always rising
+ (12,011 as of 20220703)
+ And it's impractical to save thousands of pages of tx history before alias txs started being registered
+ Reset server state to 0,0 for this unit test
+ Only 8 pages of tx history are saved at generated.txHistory, enough to cover all test cases
+ To use default server state of
+ {
+ processedConfirmedTxs: 45587,
+ processedBlockheight: 785000,
+ }
+ We would need to save 1000s of pages of txHistory to allow getUnprocessedTxHistory to get the correct
+ number of pages to fetch
+
+ So, we either save 100 meg of mocks, or we run the unit tests at server state of 0
+
+ */
+ await updateServerState(db, {
+ processedBlockheight: 0,
+ processedConfirmedTxs: 0,
+ });
});
after(async () => {
@@ -92,5 +117,10 @@
result.appStartup,
`Alias registrations updated to block ${mockBlockchaininfoResponse.tipHash} at height ${mockBlockchaininfoResponse.tipHeight}`,
);
+ // Verify that all expected valid aliases have been added to the database
+ assert.deepEqual(
+ await getAliasesFromDb(db),
+ generated.validAliasRegistrations,
+ );
});
});

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 10:22 (11 h, 18 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187339
Default Alt Text
D14203.id41227.diff (9 KB)

Event Timeline