Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Fix node status unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed May 18, 2019
1 parent 1fca674 commit 7425530
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 4 additions & 3 deletions framework/src/modules/http_api/controllers/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function NodeController(scope) {
components: {
storage: scope.components.storage,
cache: scope.components.cache,
logger: scope.components.logger,
},
config: scope.config,
channel: scope.channel,
Expand Down Expand Up @@ -354,10 +355,10 @@ async function getConfirmedTransactionCount() {
}
return confirmed;
} catch (error) {
library.logger.warn("Transaction count wasn't cached", error);
library.components.logger.warn("Transaction count wasn't cached", error);
}
}
const confirmed = await library.storage.entities.Transaction.count();
const confirmed = await library.components.storage.entities.Transaction.count();
// only update cache if ready
if (library.components.cache.cacheReady) {
try {
Expand All @@ -369,7 +370,7 @@ async function getConfirmedTransactionCount() {
);
} catch (error) {
// Ignore error and just put warn
library.logger.warn("Transaction count wasn't cached", error);
library.components.logger.warn("Transaction count wasn't cached", error);
}
}
return confirmed;
Expand Down
23 changes: 19 additions & 4 deletions framework/test/mocha/unit/modules/http_api/controllers/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const NodeController = rewire(
);

describe('node/api', () => {
const confirmedTransactions = 10;

let library;
let privateLibrary;
let channelStub;
let cacheStub;
let loggerStub;
let storageStub;
let configStub;
let getStatus;
Expand All @@ -33,17 +37,30 @@ describe('node/api', () => {
invoke: sinonSandbox.stub().resolves(),
};

loggerStub = {
warn: sinonSandbox.stub(),
};

cacheStub = {
cacheReady: sinonSandbox.stub(),
};

storageStub = {
entities: {
Block: {
get: sinonSandbox.stub().resolves([]),
},
Transaction: {
count: sinonSandbox.stub().resolves(confirmedTransactions),
},
},
};

library = {
components: {
storage: storageStub,
cache: cacheStub,
logger: loggerStub,
},
config: configStub,
channel: channelStub,
Expand Down Expand Up @@ -106,15 +123,13 @@ describe('node/api', () => {
},
loaded: true,
syncing: false,
transactions: {
confirmed: 10,
unconfirmedTransactions: {
unconfirmed: 0,
unprocessed: 0,
unsigned: 0,
total: 10,
},
};

const now = Date.now();

const expectedStatus = {
Expand All @@ -127,7 +142,7 @@ describe('node/api', () => {
networkHeight: 456,
syncing: false,
transactions: {
confirmed: 10,
confirmed: confirmedTransactions,
unconfirmed: 0,
unprocessed: 0,
unsigned: 0,
Expand Down

0 comments on commit 7425530

Please sign in to comment.