Skip to content
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
7 changes: 4 additions & 3 deletions packages/wallet-service/src/nodeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ServerlessMysql } from 'serverless-mysql';
import { getVersionData, updateVersionData } from '@src/db';
import { FullNodeVersionData, FullNodeApiVersionResponse } from '@src/types';
import fullnode from '@src/fullnode';
import { constants } from '@hathor/wallet-lib';

const VERSION_CHECK_MAX_DIFF = 60 * 60; // 1 hour

Expand Down Expand Up @@ -48,9 +49,9 @@ export function convertApiVersionData(data: FullNodeApiVersionResponse): FullNod
rewardSpendMinBlocks: data.reward_spend_min_blocks,
maxNumberInputs: data.max_number_inputs,
maxNumberOutputs: data.max_number_outputs,
decimalPlaces: data.decimal_places,
nativeTokenName: data.native_token.name,
nativeTokenSymbol: data.native_token.symbol,
decimalPlaces: data.decimal_places ?? constants.DECIMAL_PLACES,
nativeTokenName: data.native_token?.name ?? constants.DEFAULT_NATIVE_TOKEN_CONFIG.name,
nativeTokenSymbol: data.native_token?.symbol ?? constants.DEFAULT_NATIVE_TOKEN_CONFIG.symbol,
};
}

Expand Down
10 changes: 5 additions & 5 deletions packages/wallet-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export interface FullNodeApiVersionResponse {
reward_spend_min_blocks: number;
max_number_inputs: number;
max_number_outputs: number;
decimal_places: number;
genesis_block_hash: string,
genesis_tx1_hash: string,
genesis_tx2_hash: string,
native_token: { name: string, symbol: string};
decimal_places?: number;
genesis_block_hash?: string,
genesis_tx1_hash?: string,
genesis_tx2_hash?: string,
native_token?: { name: string, symbol: string};
}

export interface TxProposal {
Expand Down
94 changes: 94 additions & 0 deletions packages/wallet-service/tests/nodeConfig.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
closeDbConnection,
getDbConnection,
getUnixTimestamp,
} from '@src/utils';
import { addToVersionDataTable, cleanDatabase } from '@tests/utils';
import { FullNodeApiVersionResponse } from '@src/types';
import { convertApiVersionData, getRawFullnodeData } from '@src/nodeConfig';

const mysql = getDbConnection();

const VERSION_DATA: FullNodeApiVersionResponse = {
version: '0.63.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: 300,
max_number_inputs: 255,
max_number_outputs: 255,
decimal_places: 2,
genesis_block_hash: '000006cb93385b8b87a545a1cbb6197e6caff600c12cc12fc54250d39c8088fc',
genesis_tx1_hash: '0002d4d2a15def7604688e1878ab681142a7b155cbe52a6b4e031250ae96db0a',
genesis_tx2_hash: '0002ad8d1519daaddc8e1a37b14aac0b045129c01832281fb1c02d873c7abbf9',
native_token: {
name: 'Hathor-new',
symbol: 'nHTR'
}
};

const OLD_VERSION_DATA: FullNodeApiVersionResponse = {
version: '0.63.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: 300,
max_number_inputs: 255,
max_number_outputs: 255,
};

beforeEach(async () => {
jest.resetModules();
await cleanDatabase(mysql);
});

afterAll(async () => {
await closeDbConnection(mysql);
});

test('getRawFullnodeData', async () => {
const now = getUnixTimestamp();
await addToVersionDataTable(mysql, now, VERSION_DATA);

await expect(getRawFullnodeData(mysql)).resolves.toStrictEqual(VERSION_DATA);
});

test('convertApiVersionData', async () => {
expect(convertApiVersionData(OLD_VERSION_DATA)).toStrictEqual({
version: OLD_VERSION_DATA.version,
network: OLD_VERSION_DATA.network,
minWeight: OLD_VERSION_DATA.min_weight,
minTxWeight: OLD_VERSION_DATA.min_tx_weight,
minTxWeightCoefficient: OLD_VERSION_DATA.min_tx_weight_coefficient,
minTxWeightK: OLD_VERSION_DATA.min_tx_weight_k,
tokenDepositPercentage: OLD_VERSION_DATA.token_deposit_percentage,
rewardSpendMinBlocks: OLD_VERSION_DATA.reward_spend_min_blocks,
maxNumberInputs: OLD_VERSION_DATA.max_number_inputs,
maxNumberOutputs: OLD_VERSION_DATA.max_number_outputs,
decimalPlaces: 2,
nativeTokenName: 'Hathor',
nativeTokenSymbol: 'HTR',
});

expect(convertApiVersionData(VERSION_DATA)).toStrictEqual({
version: VERSION_DATA.version,
network: VERSION_DATA.network,
minWeight: VERSION_DATA.min_weight,
minTxWeight: VERSION_DATA.min_tx_weight,
minTxWeightCoefficient: VERSION_DATA.min_tx_weight_coefficient,
minTxWeightK: VERSION_DATA.min_tx_weight_k,
tokenDepositPercentage: VERSION_DATA.token_deposit_percentage,
rewardSpendMinBlocks: VERSION_DATA.reward_spend_min_blocks,
maxNumberInputs: VERSION_DATA.max_number_inputs,
maxNumberOutputs: VERSION_DATA.max_number_outputs,
decimalPlaces: VERSION_DATA.decimal_places,
nativeTokenName: VERSION_DATA.native_token.name,
nativeTokenSymbol: VERSION_DATA.native_token.symbol,
});
});