This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd63adc
commit 6b8dc0e
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
services/blockchain-indexer/tests/unit/shared/dataservice/business/generators.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* LiskHQ/lisk-service | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
* | ||
*/ | ||
/* eslint-disable import/no-dynamic-require */ | ||
const { resolve } = require('path'); | ||
|
||
const mockValidatorUtilsPath = resolve(`${__dirname}/../../../../../shared/utils/validator`); | ||
const mockRequestPath = resolve(`${__dirname}/../../../../../shared/utils/request`); | ||
const mockedGeneratorsPath = resolve( | ||
`${__dirname}/../../../../../shared/dataService/business/generators`, | ||
); | ||
const mockedPosPath = resolve(`${__dirname}/../../../../../shared/dataService/business/pos`); | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
jest.mock('lisk-service-framework', () => { | ||
const actual = jest.requireActual('lisk-service-framework'); | ||
return { | ||
...actual, | ||
DB: { | ||
MySQL: { | ||
getTableInstance: jest.fn(() => ({ | ||
find: jest.fn(() => [ | ||
{ publicKey: 'fe50ee28b084414499465ff823e7d651c9d19d75d33a82c44b2a15e3dc62bac9' }, | ||
]), | ||
})), | ||
KVStore: { | ||
...actual.DB.MySQL.KVStore, | ||
configureKeyValueTable: jest.fn(), | ||
getKeyValueTable: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
CacheRedis: jest.fn(), | ||
CacheLRU: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('getGeneratorsInfo', () => { | ||
it('should return generators list', async () => { | ||
jest.mock(mockRequestPath, () => ({ | ||
requestConnector: jest.fn(() => ({ | ||
list: [ | ||
{ | ||
address: 'lsky2j2fnmhxushe5ywvdw4ouvxg8s4aeo4a7bpxb', | ||
nextAllocatedTime: 1699615180, | ||
}, | ||
], | ||
})), | ||
})); | ||
|
||
jest.mock(mockValidatorUtilsPath, () => ({ | ||
getNameByAddress: jest.fn(() => 'testGenerator_1'), | ||
})); | ||
|
||
const { getGeneratorsInfo } = require(mockedGeneratorsPath); | ||
const generators = await getGeneratorsInfo(); | ||
const expectedResponse = [ | ||
{ | ||
address: 'lsky2j2fnmhxushe5ywvdw4ouvxg8s4aeo4a7bpxb', | ||
name: 'testGenerator_1', | ||
nextAllocatedTime: 1699615180, | ||
publicKey: 'fe50ee28b084414499465ff823e7d651c9d19d75d33a82c44b2a15e3dc62bac9', | ||
}, | ||
]; | ||
expect(generators.length).toBeGreaterThanOrEqual(1); | ||
expect(generators).toEqual(expectedResponse); | ||
}); | ||
}); | ||
|
||
describe('getNumberOfGenerators', () => { | ||
it('should return number of generators in one round', async () => { | ||
jest.mock(mockedPosPath, () => ({ | ||
getPosConstants: jest.fn(() => ({ | ||
data: { | ||
numberActiveValidators: 101, | ||
numberStandbyValidators: 2, | ||
}, | ||
})), | ||
})); | ||
|
||
const { getNumberOfGenerators } = require(mockedGeneratorsPath); | ||
const numOfGenerators = await getNumberOfGenerators(); | ||
expect(numOfGenerators).toBe(103); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
services/blockchain-indexer/tests/unit/shared/dataservice/business/legacy/legacy.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* LiskHQ/lisk-service | ||
* Copyright © 2023 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
* | ||
*/ | ||
/* eslint-disable import/no-dynamic-require */ | ||
const { resolve } = require('path'); | ||
|
||
const mockRequestPath = resolve(`${__dirname}/../../../../../../shared/utils/request`); | ||
const dataServicePath = resolve(`${__dirname}/../../../../../../shared/dataService`); | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
jest.mock('lisk-service-framework', () => { | ||
const actual = jest.requireActual('lisk-service-framework'); | ||
return { | ||
...actual, | ||
DB: { | ||
MySQL: { | ||
getTableInstance: jest.fn(), | ||
KVStore: { | ||
...actual.DB.MySQL.KVStore, | ||
configureKeyValueTable: jest.fn(), | ||
getKeyValueTable: jest.fn(), | ||
}, | ||
}, | ||
}, | ||
CacheRedis: jest.fn(), | ||
CacheLRU: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('getGeneratorsInfo', () => { | ||
const publicKey = 'fe50ee28b084414499465ff823e7d651c9d19d75d33a82c44b2a15e3dc62bac9'; | ||
|
||
it('should return generators list', async () => { | ||
jest.mock(mockRequestPath, () => ({ | ||
requestConnector: jest.fn(() => ({ | ||
balance: 100000000000, | ||
})), | ||
})); | ||
|
||
const { getLegacyAccountInfo } = require(dataServicePath); | ||
const legacyAccountInfo = await getLegacyAccountInfo({ publicKey }); | ||
const expectedResponse = { | ||
data: { | ||
balance: 100000000000, | ||
legacyAddress: '4823075312309157000L', | ||
}, | ||
meta: { | ||
address: 'lskyvfv3esyznwkpxcp4u7rnsoqwv55y82vw4yh7b', | ||
publicKey: 'fe50ee28b084414499465ff823e7d651c9d19d75d33a82c44b2a15e3dc62bac9', | ||
}, | ||
}; | ||
expect(legacyAccountInfo).toEqual(expectedResponse); | ||
}); | ||
}); |