Skip to content

Commit

Permalink
Update streamChain tests to use fluxdClient
Browse files Browse the repository at this point in the history
  • Loading branch information
MorningLightMountain713 committed Jan 10, 2025
1 parent aa0df0e commit 2e54a3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ZelBack/src/services/fluxService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ async function streamChainPreparation(req, res) {
}

// on non Arcane, we check if the stop commands return successfully, as there is no guarantee that the
// node is running using zelcash or pm2 stc
// node is running using zelcash or pm2 etc

// stop services
if (isArcane) {
Expand Down
22 changes: 15 additions & 7 deletions tests/unit/fluxService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const appsService = require('../../ZelBack/src/services/appsService');
const daemonServiceControlRpcs = require('../../ZelBack/src/services/daemonService/daemonServiceControlRpcs');
const daemonServiceBenchmarkRpcs = require('../../ZelBack/src/services/daemonService/daemonServiceBenchmarkRpcs');
const daemonServiceFluxnodeRpcs = require('../../ZelBack/src/services/daemonService/daemonServiceFluxnodeRpcs');
const daemonServiceBlockchainRpcs = require('../../ZelBack/src/services/daemonService/daemonServiceBlockchainRpcs');
const daemonServiceUtils = require('../../ZelBack/src/services/daemonService/daemonServiceUtils');
const serviceHelper = require('../../ZelBack/src/services/serviceHelper');
const syncthingService = require('../../ZelBack/src/services/syncthingService');
const packageJson = require('../../package.json');
Expand Down Expand Up @@ -2881,15 +2881,15 @@ describe('fluxService tests', () => {
let osStub;
let statStub;
let readdirStub;
let blockchainInfoStub;
let daemonServiceUtilsStub;
let tarPackStub;

beforeEach(() => {
osStub = sinon.stub(os, 'homedir');
statStub = sinon.stub(fs, 'stat');
readdirStub = sinon.stub(fs, 'readdir');

blockchainInfoStub = sinon.stub(daemonServiceBlockchainRpcs, 'getBlockchainInfo');
daemonServiceUtilsStub = sinon.stub(daemonServiceUtils, 'buildFluxdClient');
tarPackStub = sinon.stub(tar, 'create');
});

Expand Down Expand Up @@ -2971,7 +2971,7 @@ describe('fluxService tests', () => {

osStub.returns('/home/testuser');
statStub.resolves({ isDirectory: () => true });
blockchainInfoStub.resolves({ status: 'success', blocks: 1635577 });
daemonServiceUtilsStub.resolves({ run: async () => 123456 });

await fluxService.streamChain(req, res);

Expand Down Expand Up @@ -3019,14 +3019,17 @@ describe('fluxService tests', () => {
const totalFileSize = testFiles.length * testFileSize * folderCount;
const expectedSize = headerSize + totalFileSize + eof;

const daemonServiceError = new Error();
daemonServiceError.code = 'ECONNREFUSED';

statStub.resolves({
isDirectory: () => true,
size: testFileSize,
});

readdirStub.resolves(testFiles);

blockchainInfoStub.resolves({ status: 'error', data: { code: 'ECONNREFUSED' } });
daemonServiceUtilsStub.resolves({ run: async () => daemonServiceError });
tarPackStub.returns(readable);

await fluxService.streamChain(req, res);
Expand All @@ -3037,6 +3040,8 @@ describe('fluxService tests', () => {
const received = [];

const req = { socket: { remoteAddress: '10.20.30.40' } };
const daemonServiceError = new Error();
daemonServiceError.code = 'ECONNREFUSED';

const res = new Writable({
write(chunk, encoding, done) {
Expand All @@ -3058,7 +3063,7 @@ describe('fluxService tests', () => {

osStub.returns('/home/testuser');
statStub.resolves({ isDirectory: () => true });
blockchainInfoStub.resolves({ status: 'error', data: { code: 'ECONNREFUSED' } });
daemonServiceUtilsStub.resolves({ run: async () => daemonServiceError });
tarPackStub.returns(readable);

await fluxService.streamChain(req, res);
Expand All @@ -3070,6 +3075,9 @@ describe('fluxService tests', () => {

const req = { socket: { remoteAddress: '10.20.30.40' }, body: { compress: true } };

const daemonServiceError = new Error();
daemonServiceError.code = 'ECONNREFUSED';

const res = zlib.createGunzip();
res.setHeader = sinon.stub();

Expand All @@ -3091,7 +3099,7 @@ describe('fluxService tests', () => {

osStub.returns('/home/testuser');
statStub.resolves({ isDirectory: () => true });
blockchainInfoStub.resolves({ status: 'error', data: { code: 'ECONNREFUSED' } });
daemonServiceUtilsStub.resolves({ run: async () => daemonServiceError });
tarPackStub.returns(readable);

await fluxService.streamChain(req, res);
Expand Down

0 comments on commit 2e54a3b

Please sign in to comment.