diff --git a/__tests__/utils/config.test.ts b/__tests__/utils/config.test.ts index 40efe98e6..4aa8b6e44 100644 --- a/__tests__/utils/config.test.ts +++ b/__tests__/utils/config.test.ts @@ -89,8 +89,8 @@ describe('Configuration', () => { describe('Edge Cases', () => { it('should handle undefined values with default in get()', () => { - config.set('logLevel', undefined); - expect(config.get('logLevel', 'DEFAULT')).toBe('DEFAULT'); + config.set('someKey', undefined); + expect(config.get('someKey', 'DEFAULT')).toBe('DEFAULT'); }); it('should treat keys as case-sensitive', () => { diff --git a/src/channel/rpc_0_6.ts b/src/channel/rpc_0_6.ts index f2d658e73..8874f50e8 100644 --- a/src/channel/rpc_0_6.ts +++ b/src/channel/rpc_0_6.ts @@ -1,4 +1,4 @@ -import { NetworkName, StarknetChainId } from '../global/constants'; +import { NetworkName, StarknetChainId, SYSTEM_MESSAGES } from '../global/constants'; import { LibraryError, RpcError } from '../utils/errors'; import { AccountInvocationItem, @@ -450,10 +450,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V1, type: RPC.ETransactionType.INVOKE } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V1, + type: RPC.ETransactionType.INVOKE, + }); } else { // V3 promise = this.fetchEndpoint('starknet_addInvokeTransaction', { @@ -500,10 +500,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V1, type: RPC.ETransactionType.DECLARE } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V1, + type: RPC.ETransactionType.DECLARE, + }); } else if (isSierra(contract) && !isV3Tx(details)) { // V2 Cairo1 promise = this.fetchEndpoint('starknet_addDeclareTransaction', { @@ -524,10 +524,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V2, type: RPC.ETransactionType.DECLARE } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V2, + type: RPC.ETransactionType.DECLARE, + }); } else if (isSierra(contract) && isV3Tx(details)) { // V3 Cairo1 promise = this.fetchEndpoint('starknet_addDeclareTransaction', { @@ -579,10 +579,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V1, type: RPC.ETransactionType.DEPLOY_ACCOUNT } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V1, + type: RPC.ETransactionType.DEPLOY_ACCOUNT, + }); } else { // v3 promise = this.fetchEndpoint('starknet_addDeployAccountTransaction', { @@ -672,10 +672,10 @@ export class RpcChannel { max_fee: toHex(invocation.maxFee || 0), }; - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: invocation.version, type: invocation.type } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: invocation.version, + type: invocation.type, + }); } else { // V3 details = { diff --git a/src/channel/rpc_0_7.ts b/src/channel/rpc_0_7.ts index fbc9bb8b8..1dbb1a971 100644 --- a/src/channel/rpc_0_7.ts +++ b/src/channel/rpc_0_7.ts @@ -1,4 +1,4 @@ -import { NetworkName, StarknetChainId } from '../global/constants'; +import { NetworkName, StarknetChainId, SYSTEM_MESSAGES } from '../global/constants'; import { LibraryError, RpcError } from '../utils/errors'; import { AccountInvocationItem, @@ -455,10 +455,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V1, type: RPC.ETransactionType.INVOKE } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V1, + type: RPC.ETransactionType.INVOKE, + }); } else { // V3 promise = this.fetchEndpoint('starknet_addInvokeTransaction', { @@ -505,10 +505,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V1, type: RPC.ETransactionType.DECLARE } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V1, + type: RPC.ETransactionType.DECLARE, + }); } else if (isSierra(contract) && !isV3Tx(details)) { // V2 Cairo1 promise = this.fetchEndpoint('starknet_addDeclareTransaction', { @@ -529,10 +529,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V2, type: RPC.ETransactionType.DECLARE } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V2, + type: RPC.ETransactionType.DECLARE, + }); } else if (isSierra(contract) && isV3Tx(details)) { // V3 Cairo1 promise = this.fetchEndpoint('starknet_addDeclareTransaction', { @@ -584,10 +584,10 @@ export class RpcChannel { }, }); - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: RPC.ETransactionVersion.V1, type: RPC.ETransactionType.DEPLOY_ACCOUNT } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: RPC.ETransactionVersion.V1, + type: RPC.ETransactionType.DEPLOY_ACCOUNT, + }); } else { // v3 promise = this.fetchEndpoint('starknet_addDeployAccountTransaction', { @@ -677,10 +677,10 @@ export class RpcChannel { max_fee: toHex(invocation.maxFee || 0), }; - logger.warn( - 'You are using deprecated transaction version (V0,V1,V2)!, \n Update to the latest V3 transactions!', - { version: invocation.version, type: invocation.type } - ); + logger.warn(SYSTEM_MESSAGES.legacyTxWarningMessage, { + version: invocation.version, + type: invocation.type, + }); } else { // V3 details = { diff --git a/src/global/config.ts b/src/global/config.ts index ed39c3d5a..9c45f3f79 100644 --- a/src/global/config.ts +++ b/src/global/config.ts @@ -2,7 +2,7 @@ import { DEFAULT_GLOBAL_CONFIG } from './constants'; type ConfigData = { [key: string]: any; -}; +} & typeof DEFAULT_GLOBAL_CONFIG; class Configuration { private static instance: Configuration; diff --git a/src/global/constants.ts b/src/global/constants.ts index 12453dd2d..5b2a5fc32 100644 --- a/src/global/constants.ts +++ b/src/global/constants.ts @@ -91,7 +91,16 @@ export const HARDENING_BYTE = 128; export const HARDENING_4BYTES = 2147483648n; // Default initial global config -export const DEFAULT_GLOBAL_CONFIG: { legacyMode: boolean; logLevel: LogLevel } = { +export const DEFAULT_GLOBAL_CONFIG: { + legacyMode: boolean; + logLevel: LogLevel; +} = { legacyMode: false, logLevel: 'INFO', }; + +// Default system messages +export const SYSTEM_MESSAGES = { + legacyTxWarningMessage: + 'You are using a deprecated transaction version (V0,V1,V2)!\nUpdate to the latest V3 transactions!', +}; diff --git a/src/global/logger.ts b/src/global/logger.ts index d01cc0d9a..537c30d22 100644 --- a/src/global/logger.ts +++ b/src/global/logger.ts @@ -44,7 +44,7 @@ class Logger { try { formattedMessage += `\n${JSON.stringify(data, null, 2)}`; } catch (error) { - formattedMessage += `\n[JSON.stringify Error/Circular]`; + formattedMessage += `\n[JSON.stringify Error/Circular]: ${error}`; } } @@ -145,14 +145,9 @@ class Logger { * @returns logs levels displayed on the configured LogLevel */ public getEnabledLogLevels() { - const logLevelStringKeys = Object.keys(LogLevelIndex).filter( - (v) => Number.isNaN(Number(v)) && v !== 'OFF' - ); - const logLevels = logLevelStringKeys.filter((s) => { - return this.shouldLog(LogLevelIndex[s as LogLevel]); + return Object.keys(LogLevelIndex).filter((s) => { + return this.shouldLog(LogLevelIndex[s as LogLevel]) && s !== 'OFF'; }); - - return logLevels; } }