Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetchMinRewardBlocks fails when reward_min_blocks is 0 #177

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion packages/daemon/__tests__/services/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ afterEach(() => {
});

describe('fetchInitialState', () => {
beforeAll(() => {
beforeEach(() => {
const mockUrl = 'http://mock-host:8080/v1a/';
(getFullnodeHttpUrl as jest.Mock).mockReturnValue(mockUrl);

Expand Down Expand Up @@ -166,6 +166,46 @@ describe('fetchInitialState', () => {
expect(mockDb.destroy).toHaveBeenCalled();
});

it('should not fail if reward spend min blocks is 0', async () => {
// Mock the return values of the dependencies
const mockDb = { destroy: jest.fn() };

// @ts-ignore
axios.get.mockResolvedValue({
status: 200,
data: {
version: '0.58.0-rc.1',
network: 'mainnet',
min_weight: 14,
min_tx_weight: 14,
min_tx_weight_coefficient: 1.6,
min_tx_weight_k: 100,
token_deposit_percentage: 0.01,
reward_spend_min_blocks: 0,
max_number_inputs: 255,
max_number_outputs: 255
}
});

// @ts-ignore
getDbConnection.mockReturnValue(mockDb);
// @ts-ignore
getLastSyncedEvent.mockResolvedValue({
id: 0,
last_event_id: 123,
updated_at: Date.now(),
});

const result = await fetchInitialState();

expect(result).toEqual({
lastEventId: expect.any(Number),
rewardMinBlocks: 0,
});

expect(mockDb.destroy).toHaveBeenCalled();
});

it('should return undefined if no last event is found', async () => {
const mockDb = { destroy: jest.fn() };
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/daemon/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ export const fetchMinRewardBlocks = async () => {

const rewardSpendMinBlocks = get(response, 'data.reward_spend_min_blocks');

if (!rewardSpendMinBlocks) {
if (rewardSpendMinBlocks == null) {
throw new Error('Failed to fetch reward spend min blocks');
}

Expand Down
Loading