Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F10615008
D13599.id39356.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D13599.id39356.diff
View Options
diff --git a/apps/alias-server/scripts/generateMocks.js b/apps/alias-server/scripts/generateMocks.js
--- a/apps/alias-server/scripts/generateMocks.js
+++ b/apps/alias-server/scripts/generateMocks.js
@@ -18,6 +18,9 @@
getAliasBytecount,
} = require('../src/utils');
+const { ChronikClient } = require('chronik-client');
+const chronik = new ChronikClient(config.chronik);
+
async function generateMocks() {
// Directory for mocks. Relative to /scripts, ../test/mocks/generated/
const mocksDir = path.join(__dirname, '..', 'test', 'mocks', 'generated');
@@ -29,6 +32,7 @@
// chronik tx history of alias registration address
const aliasTxHistory = await getAllTxHistory(
+ chronik,
config.aliasConstants.registrationHash160,
);
fs.writeFileSync(
diff --git a/apps/alias-server/src/chronik.js b/apps/alias-server/src/chronik.js
--- a/apps/alias-server/src/chronik.js
+++ b/apps/alias-server/src/chronik.js
@@ -5,12 +5,9 @@
'use strict';
const config = require('../config');
const log = require('./log');
-const { ChronikClient } = require('chronik-client');
-const chronik = new ChronikClient(config.chronik);
module.exports = {
- chronik,
- getTxHistoryPage: async function (hash160, page = 0) {
+ getTxHistoryPage: async function (chronik, hash160, page = 0) {
let txHistoryPage;
try {
txHistoryPage = await chronik
@@ -22,7 +19,7 @@
log(`Error in getTxHistoryPage(${hash160})`, err);
}
},
- returnGetTxHistoryPagePromise: async function (hash160, page = 0) {
+ returnGetTxHistoryPagePromise: async function (chronik, hash160, page = 0) {
/*
Unlike getTxHistoryPage, this function will reject and
fail Promise.all() if there is an error in the chronik call
@@ -42,6 +39,7 @@
});
},
getUnprocessedTxHistory: async function (
+ chronik,
hash160,
processedBlockheight,
processedTxCount,
@@ -57,7 +55,7 @@
// Get first page of most recent chronik tx history
const txHistoryFirstPageResponse = optionalMocks
? optionalMocks.txHistoryFirstPageResponse
- : await module.exports.getTxHistoryPage(hash160);
+ : await module.exports.getTxHistoryPage(chronik, hash160);
const { txs, numPages } = txHistoryFirstPageResponse;
// This first page of results contains the most recent chronik txs at the address
@@ -93,7 +91,11 @@
const txHistoryPageResponsePromises = [];
for (let i = 1; i < numPagesToFetch; i += 1) {
const txHistoryPageResponsePromise =
- module.exports.returnGetTxHistoryPagePromise(hash160, i);
+ module.exports.returnGetTxHistoryPagePromise(
+ chronik,
+ hash160,
+ i,
+ );
txHistoryPageResponsePromises.push(
txHistoryPageResponsePromise,
);
@@ -149,10 +151,10 @@
return unprocessedTxs;
}
},
- getAllTxHistory: async function (hash160) {
+ getAllTxHistory: async function (chronik, hash160) {
let allTxHistory = [];
const txHistoryFirstPageResponse =
- await module.exports.getTxHistoryPage(hash160);
+ await module.exports.getTxHistoryPage(chronik, hash160);
const { txs, numPages } = txHistoryFirstPageResponse;
// Add first page of results to allTxHistory
@@ -164,7 +166,11 @@
const txHistoryPageResponsePromises = [];
for (let i = 1; i < numPages; i += 1) {
const txHistoryPageResponsePromise =
- module.exports.returnGetTxHistoryPagePromise(hash160, i);
+ module.exports.returnGetTxHistoryPagePromise(
+ chronik,
+ hash160,
+ i,
+ );
txHistoryPageResponsePromises.push(txHistoryPageResponsePromise);
}
diff --git a/apps/alias-server/test/chronikTests.js b/apps/alias-server/test/chronikTests.js
--- a/apps/alias-server/test/chronikTests.js
+++ b/apps/alias-server/test/chronikTests.js
@@ -31,6 +31,7 @@
};
const result = await getUnprocessedTxHistory(
+ null,
config.aliasConstants.registrationHash160,
processedBlockheight,
processedTxCount,
@@ -67,6 +68,7 @@
};
const result = await getUnprocessedTxHistory(
+ null,
config.aliasConstants.registrationHash160,
processedBlockheight,
processedTxCount,
@@ -103,6 +105,7 @@
};
const result = await getUnprocessedTxHistory(
+ null,
config.aliasConstants.registrationHash160,
processedBlockheight,
processedTxCount,
@@ -222,6 +225,7 @@
};
const result = await getUnprocessedTxHistory(
+ null,
config.aliasConstants.registrationHash160,
processedBlockheight,
processedTxCount,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 09:55 (10 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4558920
Default Alt Text
D13599.id39356.diff (5 KB)
Attached To
D13599: [alias-server] Chronik functions take chronik as a param to support future mocking
Event Timeline
Log In to Comment