Skip to content

Commit 334805c

Browse files
committed
feat(1670): review chagnes
Signed-off-by: mmyslblocky <michal.myslinski@blockydevs.com>
1 parent cd2550b commit 334805c

File tree

16 files changed

+83
-67
lines changed

16 files changed

+83
-67
lines changed

src/__tests__/mocks/fixtures.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ export const MOCK_EVM_ADDRESS = '0x' + MOCK_EVM_ADDRESS_RAW;
4747
export const MOCK_EVM_ADDRESS_ALT = '0x' + 'b'.repeat(40);
4848
export const MOCK_EVM_ADDRESS_ALT_2 = '0x' + 'c'.repeat(40);
4949
export const MOCK_TX_ID = '0.0.1234@1234567890.123456789';
50-
export const DAY_IN_SECONDS = 24 * 60 * 60 * 1000;

src/core/schemas/__tests__/unit/common-schemas.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
DAY_IN_SECONDS,
32
ED25519_DER_PRIVATE_KEY,
43
ED25519_HEX_PRIVATE_KEY,
54
ED25519_HEX_PRIVATE_KEY_WITH_0X,
@@ -15,6 +14,7 @@ import {
1514
ExpirationTimeSchema,
1615
} from '@/core/schemas/common-schemas';
1716
import { INVALID_KEY } from '@/core/services/topic/__tests__/unit/mocks';
17+
import { DAY_IN_SECONDS } from '@/core/shared/constants';
1818

1919
describe('AccountIdWithPrivateKeySchema', () => {
2020
const accountId = TEST_ACCOUNT_ID;

src/core/schemas/common-schemas.ts

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
CredentialType,
1616
KeyManager,
1717
} from '@/core/services/kms/kms-types.interface';
18-
import { HederaTokenType, KeyAlgorithm } from '@/core/shared/constants';
18+
import {
19+
DAY_IN_SECONDS,
20+
HederaTokenType,
21+
KeyAlgorithm,
22+
} from '@/core/shared/constants';
1923
import {
2024
EntityReferenceType,
2125
SupplyType,
@@ -475,6 +479,8 @@ export const TokenAliasNameSchema = AliasNameSchema.describe(
475479
'Token alias name (local identifier, not on-chain name)',
476480
);
477481

482+
export const TokenFreezeDefaultSchema = z.boolean().default(false);
483+
478484
/**
479485
* Memo Input
480486
* Optional memo field for transactions
@@ -950,15 +956,16 @@ export const ResolvedPublicKeySchema = z.object({
950956
* Hedera network allows auto-renew period between 30 and 92 days (inclusive), in seconds.
951957
* @see https://docs.hedera.com/hedera/core-concepts/smart-contracts/tokens#auto-renewal
952958
*/
953-
export const HEDERA_AUTO_RENEW_PERIOD_SECONDS_MIN = 2592000; // 30 days
954-
export const HEDERA_AUTO_RENEW_PERIOD_SECONDS_MAX = 8000001; // 92 days (per network rules)
959+
const HEDERA_AUTO_RENEW_PERIOD_MIN = 30 * DAY_IN_SECONDS; // 30 days
960+
const HEDERA_AUTO_RENEW_PERIOD_MAX = 92 * DAY_IN_SECONDS; // 92 days (per network rules)
961+
const HEDERA_EXPIRATION_TIME_MAX = 92 * DAY_IN_SECONDS * 1000; // 92 days (per network rules)
955962

956963
/** Output / mirror fields: optional seconds, validated when present. */
957964
export const HederaAutoRenewPeriodSecondsOptionalSchema = z
958965
.number()
959966
.int()
960-
.min(HEDERA_AUTO_RENEW_PERIOD_SECONDS_MIN)
961-
.max(HEDERA_AUTO_RENEW_PERIOD_SECONDS_MAX)
967+
.min(HEDERA_AUTO_RENEW_PERIOD_MIN)
968+
.max(HEDERA_AUTO_RENEW_PERIOD_MAX)
962969
.optional();
963970

964971
/**
@@ -977,18 +984,15 @@ export const AutoRenewPeriodSecondsSchema: z.ZodType<number | undefined> = z
977984
z
978985
.number()
979986
.optional()
980-
.superRefine((sec, ctx) => {
981-
if (sec === undefined) return;
982-
if (
983-
sec < HEDERA_AUTO_RENEW_PERIOD_SECONDS_MIN ||
984-
sec > HEDERA_AUTO_RENEW_PERIOD_SECONDS_MAX
985-
) {
986-
ctx.addIssue({
987-
code: z.ZodIssueCode.custom,
988-
message: `Auto-renew period must be between ${HEDERA_AUTO_RENEW_PERIOD_SECONDS_MIN} and ${HEDERA_AUTO_RENEW_PERIOD_SECONDS_MAX} seconds (30–92 days inclusive).`,
989-
});
990-
}
991-
}),
987+
.refine(
988+
(sec) =>
989+
!sec ||
990+
(sec >= HEDERA_AUTO_RENEW_PERIOD_MIN &&
991+
sec <= HEDERA_AUTO_RENEW_PERIOD_MAX),
992+
{
993+
message: `Auto-renew period must be between ${HEDERA_AUTO_RENEW_PERIOD_MIN} and ${HEDERA_AUTO_RENEW_PERIOD_MAX} seconds (30–92 days inclusive).`,
994+
},
995+
),
992996
);
993997

994998
/**
@@ -998,25 +1002,23 @@ export const AutoRenewPeriodSecondsSchema: z.ZodType<number | undefined> = z
9981002
export const ExpirationTimeSchema: z.ZodType<Date | undefined> = z
9991003
.string()
10001004
.optional()
1001-
.superRefine((s, ctx) => {
1002-
if (!s || s.trim() === '') {
1003-
return;
1004-
}
1005-
if (Number.isNaN(new Date(s).getTime())) {
1006-
ctx.addIssue({
1007-
code: z.ZodIssueCode.custom,
1008-
message:
1009-
'Invalid expiration time. Use an ISO 8601 datetime (e.g. 2026-12-31T23:59:59.000Z).',
1010-
});
1011-
}
1005+
.refine((s) => !s || !Number.isNaN(new Date(s).getTime()), {
1006+
message:
1007+
'Invalid expiration time. Use an ISO 8601 datetime (e.g. 2026-12-31T23:59:59.000Z).',
10121008
})
10131009
.transform((s): Date | undefined => {
1014-
if (!s || s.trim() === '') {
1010+
if (!s) {
10151011
return undefined;
10161012
}
10171013
return new Date(s);
10181014
})
1019-
.refine((d) => d === undefined || d.getTime() > Date.now(), {
1020-
message:
1021-
'Expiration time must be in the future (strictly after the current time).',
1022-
});
1015+
.refine(
1016+
(d) =>
1017+
!d ||
1018+
(d.getTime() > Date.now() &&
1019+
d.getTime() <=
1020+
new Date(Date.now() + HEDERA_EXPIRATION_TIME_MAX).getTime()),
1021+
{
1022+
message: 'Expiration time must be set in 92 days period.',
1023+
},
1024+
);

src/core/services/token/__tests__/unit/token-service.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import type { Logger } from '@/core/services/logger/logger-service.interface';
77

88
import { AccountId, Hbar, TokenId, TokenType } from '@hashgraph/sdk';
99

10-
import { ECDSA_HEX_PUBLIC_KEY } from '@/__tests__/mocks/fixtures';
10+
import {
11+
ECDSA_HEX_PUBLIC_KEY,
12+
MOCK_ACCOUNT_ID,
13+
} from '@/__tests__/mocks/fixtures';
1114
import { makeLogger } from '@/__tests__/mocks/mocks';
1215
import { TokenServiceImpl } from '@/core/services/token/token-service';
13-
import { HederaTokenType } from '@/core/shared/constants';
16+
import { DAY_IN_SECONDS, HederaTokenType } from '@/core/shared/constants';
1417
import { SupplyType } from '@/core/types/shared.types';
1518
import {
1619
type CustomFee,
@@ -637,8 +640,8 @@ describe('TokenServiceImpl', () => {
637640
it('should set auto-renew account and period when both provided', () => {
638641
const params = {
639642
...baseParams,
640-
autoRenewAccountId: '0.0.7777',
641-
autoRenewPeriodSeconds: 2592000,
643+
autoRenewAccountId: MOCK_ACCOUNT_ID,
644+
autoRenewPeriodSeconds: 30 * DAY_IN_SECONDS,
642645
};
643646

644647
tokenService.createTokenTransaction(params);
@@ -648,7 +651,7 @@ describe('TokenServiceImpl', () => {
648651
).toHaveBeenCalledWith(mockAccountIdInstance);
649652
expect(
650653
mockTokenCreateTransaction.setAutoRenewPeriod,
651-
).toHaveBeenCalledWith(2592000);
654+
).toHaveBeenCalledWith(30 * DAY_IN_SECONDS);
652655
expect(
653656
mockTokenCreateTransaction.setExpirationTime,
654657
).not.toHaveBeenCalled();
@@ -674,16 +677,16 @@ describe('TokenServiceImpl', () => {
674677
it('should prefer auto-renew over expiration when both are passed', () => {
675678
const params = {
676679
...baseParams,
677-
autoRenewAccountId: '0.0.7777',
678-
autoRenewPeriodSeconds: 2592000,
680+
autoRenewAccountId: MOCK_ACCOUNT_ID,
681+
autoRenewPeriodSeconds: 30 * DAY_IN_SECONDS,
679682
expirationTime: new Date('2028-01-01T00:00:00.000Z'),
680683
};
681684

682685
tokenService.createTokenTransaction(params);
683686

684687
expect(
685688
mockTokenCreateTransaction.setAutoRenewPeriod,
686-
).toHaveBeenCalledWith(2592000);
689+
).toHaveBeenCalledWith(30 * DAY_IN_SECONDS);
687690
expect(
688691
mockTokenCreateTransaction.setExpirationTime,
689692
).not.toHaveBeenCalled();

src/core/services/token/token-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ export class TokenServiceImpl implements TokenService {
190190
tokenCreateTx
191191
.setAutoRenewAccountId(AccountId.fromString(autoRenewAccountId))
192192
.setAutoRenewPeriod(autoRenewPeriodSeconds);
193+
console.log('BLA BLA');
194+
console.log(autoRenewPeriodSeconds);
193195
this.logger.debug(
194196
`[TOKEN SERVICE] Set auto-renew: account ${autoRenewAccountId}, period ${String(autoRenewPeriodSeconds)}s`,
195197
);

src/core/shared/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,7 @@ export const MirrorTokenTypeToHederaTokenType = {
3737
[TokenType.FungibleCommon.toString()]: HederaTokenType.FUNGIBLE_COMMON,
3838
[TokenType.NonFungibleUnique.toString()]: HederaTokenType.NON_FUNGIBLE_TOKEN,
3939
} satisfies Record<string, HederaTokenType>;
40+
41+
export const MINUTE_IN_SECONDS = 60;
42+
export const HOUR_IN_SECONDS = 60 * MINUTE_IN_SECONDS;
43+
export const DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS;

src/core/utils/parse-auto-renew-period.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import {
2+
DAY_IN_SECONDS,
3+
HOUR_IN_SECONDS,
4+
MINUTE_IN_SECONDS,
5+
} from '@/core/shared/constants';
6+
17
const DURATION_SUFFIX_SECONDS: Record<string, number> = {
28
s: 1,
3-
m: 60,
4-
h: 3600,
5-
d: 86400,
9+
m: MINUTE_IN_SECONDS,
10+
h: HOUR_IN_SECONDS,
11+
d: DAY_IN_SECONDS,
612
};
713

814
/**

src/plugins/token/__tests__/unit/view.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import type { CommandHandlerArgs } from '@/core/plugins/plugin.interface';
22

33
import '@/core/utils/json-serialize';
44

5+
import { MOCK_ACCOUNT_ID } from '@/__tests__/mocks/fixtures';
56
import { assertOutput } from '@/__tests__/utils/assert-output';
67
import { AliasType } from '@/core/services/alias/alias-service.interface';
8+
import { DAY_IN_SECONDS } from '@/core/shared/constants';
79
import {
810
tokenView,
911
TokenViewOutputSchema,
@@ -38,11 +40,10 @@ describe('tokenViewHandler', () => {
3840
max_supply: '0',
3941
type: 'FUNGIBLE_COMMON',
4042
supply_type: 'INFINITE',
41-
treasury_account_id: '0.0.789012',
43+
treasury_account_id: MOCK_ACCOUNT_ID,
4244
freeze_default: true,
43-
auto_renew_period: 2592000,
44-
auto_renew_account: '0.0.789012',
45-
expiry_timestamp: 1893456000000000000,
45+
auto_renew_period: 30 * DAY_IN_SECONDS,
46+
auto_renew_account: MOCK_ACCOUNT_ID,
4647
admin_key: null,
4748
supply_key: null,
4849
memo: 'Test memo',
@@ -77,10 +78,9 @@ describe('tokenViewHandler', () => {
7778
expect(output.symbol).toBe('TEST');
7879
expect(output.type).toBe('FUNGIBLE_COMMON');
7980
expect(output.freezeDefault).toBe(true);
80-
expect(output.treasury).toBe('0.0.789012');
81-
expect(output.autoRenewPeriodSeconds).toBe(2592000);
82-
expect(output.autoRenewAccountId).toBe('0.0.789012');
83-
expect(output.expirationTime).toBe('2030-01-01T00:00:00.000Z');
81+
expect(output.treasury).toBe(MOCK_ACCOUNT_ID);
82+
expect(output.autoRenewPeriodSeconds).toBe(30 * DAY_IN_SECONDS);
83+
expect(output.autoRenewAccountId).toBe(MOCK_ACCOUNT_ID);
8484
});
8585

8686
test('should view token using alias', async () => {
@@ -93,7 +93,7 @@ describe('tokenViewHandler', () => {
9393
max_supply: '0',
9494
type: 'FUNGIBLE_COMMON',
9595
supply_type: 'INFINITE',
96-
treasury_account_id: '0.0.789012',
96+
treasury_account_id: MOCK_ACCOUNT_ID,
9797
admin_key: null,
9898
supply_key: null,
9999
memo: 'Test memo',

src/plugins/token/commands/create-ft-from-file/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { readAndValidateTokenFile } from '@/plugins/token/utils/token-file-helpe
2020
import {
2121
resolveOptionalKey,
2222
toPublicKey,
23-
} from '@/plugins/token/utils/token-resolve-optional-key';
23+
} from '@/plugins/token/utils/token-key-resolver';
2424
import { ZustandTokenStateHelper } from '@/plugins/token/zustand-state-helper';
2525

2626
import { TokenCreateFtFromFileInputSchema } from './input';

src/plugins/token/commands/create-ft/handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
import {
2323
resolveOptionalKey,
2424
toPublicKey,
25-
} from '@/plugins/token/utils/token-resolve-optional-key';
25+
} from '@/plugins/token/utils/token-key-resolver';
2626
import { ZustandTokenStateHelper } from '@/plugins/token/zustand-state-helper';
2727

2828
import { type TokenCreateFtInput, TokenCreateFtInputSchema } from './input';

0 commit comments

Comments
 (0)