Skip to content
Closed
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
16 changes: 16 additions & 0 deletions packages/wallet-service/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,41 @@ export interface TokenBalance {
transactions: number;
}

/**
* Token version used to identify the type of token during the token creation process.
*/
export enum TokenVersion {
NATIVE = 0,

DEPOSIT = 1,

FEE = 2,
}
Comment on lines +176 to +185
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc comment for the TokenVersion enum mentions it's used "during the token creation process," but this doesn't fully explain what each version type means or when each should be used. Consider expanding the documentation to clarify:

  • What differentiates NATIVE, DEPOSIT, and FEE tokens
  • Which version should be used for which scenarios
  • Any implications or restrictions for each version type

This will help future developers understand how to properly use these token version types.

Copilot uses AI. Check for mistakes.

export class TokenInfo {
id: string;

name: string;

symbol: string;

version: TokenVersion;

transactions: number;

constructor(id: string, name: string, symbol: string, transactions?: number) {
this.id = id;
this.name = name;
this.symbol = symbol;
this.version = TokenVersion.DEPOSIT; // Hardcoded for now, while the Fee Tokens implementation is not complete
Comment on lines +194 to +202
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new version property is not covered by existing tests. The test at line 1260 in tests/db.test.ts uses toStrictEqual to compare TokenInfo objects, which will now include the version field in the comparison. However, since both the stored and retrieved TokenInfo objects will have the same hardcoded TokenVersion.DEPOSIT value (due to the bug where version is not persisted), the test will pass even though the version functionality is not working correctly.

Consider adding explicit test cases that:

  1. Verify the version field is correctly set for native tokens (should be NATIVE)
  2. Verify the version field is correctly set for custom tokens (should match what was stored)
  3. Test that different token versions can be stored and retrieved correctly

Copilot uses AI. Check for mistakes.
this.transactions = transactions || 0;

const hathorConfig = hathorLib.constants.DEFAULT_NATIVE_TOKEN_CONFIG;

if (this.id === hathorLib.constants.NATIVE_TOKEN_UID) {
this.name = hathorConfig.name;
this.symbol = hathorConfig.symbol;
this.version = TokenVersion.NATIVE;
}
}

Expand All @@ -201,6 +216,7 @@ export class TokenInfo {
id: this.id,
name: this.name,
symbol: this.symbol,
version: this.version,
};
}
}
Expand Down
22 changes: 15 additions & 7 deletions packages/wallet-service/tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import * as Db from '@src/db';
import { ApiError } from '@src/api/errors';
import { closeDbConnection, getDbConnection, getUnixTimestamp, getWalletId } from '@src/utils';
import { STATUS_CODE_TABLE } from '@src/api/utils';
import { WalletStatus, FullNodeApiVersionResponse } from '@src/types';
import { WalletStatus, FullNodeApiVersionResponse, TokenVersion } from '@src/types';
import { walletUtils, addressUtils, constants, network, HathorWalletServiceWallet } from '@hathor/wallet-lib';
import bitcore from 'bitcore-lib';
import {
Expand Down Expand Up @@ -431,6 +431,14 @@ test('GET /balances', async () => {
const token2 = { id: 'token2', name: 'MyToken2', symbol: 'MT2' };
const token3 = { id: 'token3', name: 'MyToken3', symbol: 'MT3' };
const token4 = { id: 'token4', name: 'MyToken4', symbol: 'MT4' };
/**
* Adds a version property to the token object, replicating the behavior of getTokenDetails
* It's a workaround while the full implementation of fee based tokens are completed
* @param token
*/
const addVersionToToken = (token) => {
return { ...token, version: TokenVersion.DEPOSIT }
}
await addToTokenTable(mysql, [
{ ...htrToken, transactions: 0 },
{ id: token1.id, name: token1.name, symbol: token1.symbol, transactions: 0 },
Expand Down Expand Up @@ -487,14 +495,14 @@ test('GET /balances', async () => {
expect(returnBody.success).toBe(true);
expect(returnBody.balances).toHaveLength(2);
expect(returnBody.balances).toContainEqual({
token: token1,
token: addVersionToToken(token1),
transactions: 3,
balance: { unlocked: 10, locked: 0 },
lockExpires: null,
tokenAuthorities: { unlocked: { mint: true, melt: false }, locked: { mint: false, melt: true } },
});
expect(returnBody.balances).toContainEqual({
token: token2,
token: addVersionToToken(token2),
transactions: 1,
balance: { unlocked: 3, locked: 2 },
lockExpires,
Expand All @@ -509,7 +517,7 @@ test('GET /balances', async () => {
expect(returnBody.success).toBe(true);
expect(returnBody.balances).toHaveLength(1);
expect(returnBody.balances).toContainEqual({
token: token1,
token: addVersionToToken(token1),
transactions: 3,
balance: { unlocked: 10, locked: 0 },
lockExpires: null,
Expand Down Expand Up @@ -554,7 +562,7 @@ test('GET /balances', async () => {
expect(returnBody.success).toBe(true);
expect(returnBody.balances).toHaveLength(1);
expect(returnBody.balances).toContainEqual({
token: token3,
token: addVersionToToken(token3),
transactions: 2,
balance: { unlocked: 6, locked: 0 },
lockExpires: null,
Expand Down Expand Up @@ -603,7 +611,7 @@ test('GET /balances', async () => {
expect(returnBody.success).toBe(true);
expect(returnBody.balances).toHaveLength(1);
expect(returnBody.balances).toContainEqual({
token: token4,
token: addVersionToToken(token4),
transactions: 3,
balance: { unlocked: 13, locked: 2 },
lockExpires,
Expand All @@ -629,7 +637,7 @@ test('GET /balances', async () => {
expect(returnBody.success).toBe(true);
expect(returnBody.balances).toHaveLength(1);
expect(returnBody.balances).toContainEqual({
token: { id: '00', name: 'Hathor', symbol: 'HTR' },
token: { id: '00', name: 'Hathor', symbol: 'HTR', version: TokenVersion.NATIVE },
transactions: 3,
balance: { unlocked: 10, locked: 0 },
lockExpires: null,
Expand Down
Loading