Skip to content

Commit

Permalink
fix: review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Jan 29, 2025
1 parent 2447173 commit 33902b9
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 54 deletions.
4 changes: 2 additions & 2 deletions __tests__/utils/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
42 changes: 21 additions & 21 deletions src/channel/rpc_0_6.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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', {
Expand All @@ -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', {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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 = {
Expand Down
42 changes: 21 additions & 21 deletions src/channel/rpc_0_7.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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', {
Expand All @@ -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', {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/global/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/global/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!',
};
11 changes: 3 additions & 8 deletions src/global/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}

Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 33902b9

Please sign in to comment.