diff --git a/core/src/validation/index.ts b/core/src/validation/index.ts deleted file mode 100644 index b00a2f926..000000000 --- a/core/src/validation/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const' - -export const LOG4JS_CATEGORY_SCHEMA_ALIAS = `${LOG4JS_BASE_CATEGORY_NAME}.schema` diff --git a/core/src/validation/user.test.ts b/core/src/validation/user.test.ts index 4cfc76a7c..cd3bd1925 100644 --- a/core/src/validation/user.test.ts +++ b/core/src/validation/user.test.ts @@ -1,10 +1,10 @@ -import { LOG4JS_CATEGORY_SCHEMA_ALIAS } from '.' import { validateAlias } from './user' -import { getLogger, printLogs } from '../../../config-schema/test/testSetup.bun' +import { getLogger } from '../../../config-schema/test/testSetup.bun' import { describe, it, expect, beforeEach, mock, jest } from 'bun:test' import { aliasExists } from 'database' +import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const' -const logger = getLogger(`${LOG4JS_CATEGORY_SCHEMA_ALIAS}.alias`) +const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.validation.user`) mock.module('database', () => ({ aliasExists: jest.fn(), diff --git a/core/src/validation/user.ts b/core/src/validation/user.ts index b188e5d54..eebc34442 100644 --- a/core/src/validation/user.ts +++ b/core/src/validation/user.ts @@ -1,10 +1,10 @@ import { ZodError } from 'zod' import { getLogger } from 'log4js' -import { LOG4JS_CATEGORY_SCHEMA_ALIAS } from '.' +import { LOG4JS_BASE_CATEGORY_NAME } from '../config/const' import { aliasExists } from 'database' import { aliasSchema } from 'shared' -const logger = getLogger(`${LOG4JS_CATEGORY_SCHEMA_ALIAS}.alias`) +const logger = getLogger(`${LOG4JS_BASE_CATEGORY_NAME}.validation.user`) export async function validateAlias(alias: string): Promise { try { diff --git a/shared/src/logic/decay.test.ts b/shared/src/logic/decay.test.ts index 1db94c4fe..7678c945b 100644 --- a/shared/src/logic/decay.test.ts +++ b/shared/src/logic/decay.test.ts @@ -41,4 +41,13 @@ describe('utils/decay', () => { const now = new Date() expect(calculateDecay(new Decimal(100.0), now, now).balance.toString()).toBe('100') }) + + describe('calculateDecay called with invalid dates', () => { + it('throws an error when to is before from', () => { + const now = new Date() + const oneSecondAgo = new Date(now.getTime()) + oneSecondAgo.setSeconds(0) + expect(() => calculateDecay(new Decimal(1.0), now, oneSecondAgo)).toThrowError() + }) + }) }) diff --git a/shared/src/logic/decay.ts b/shared/src/logic/decay.ts index f75146515..35ab99803 100644 --- a/shared/src/logic/decay.ts +++ b/shared/src/logic/decay.ts @@ -1,11 +1,7 @@ import { Decimal } from 'decimal.js-light' -import { getLogger } from 'log4js' -import { LOG4JS_LOGIC_CATEGORY } from '.' import { DECAY_START_TIME } from '../const' -const logger = getLogger(`${LOG4JS_LOGIC_CATEGORY}.DecayLogic`) - Decimal.set({ precision: 25, rounding: Decimal.ROUND_HALF_UP, @@ -40,7 +36,7 @@ export function calculateDecay( const startBlockMs = DECAY_START_TIME.getTime() if (toMs < fromMs) { - logger.error('calculateDecay: to < from, reverse decay calculation is invalid', from, to) + // TODO: refactor, use custom Error Classes which contain context variables throw new Error('calculateDecay: to < from, reverse decay calculation is invalid') } diff --git a/shared/src/logic/index.ts b/shared/src/logic/index.ts deleted file mode 100644 index fca61a4b1..000000000 --- a/shared/src/logic/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { LOG4JS_BASE_CATEGORY_NAME } from '../const' - -export const LOG4JS_LOGIC_CATEGORY = `${LOG4JS_BASE_CATEGORY_NAME}.logic`