diff --git a/src/p2p/Context.ts b/src/p2p/Context.ts index 266382f91..08db6e291 100644 --- a/src/p2p/Context.ts +++ b/src/p2p/Context.ts @@ -63,6 +63,14 @@ export function setConfig(conf: ShardusTypes.StrictServerConfiguration) { config = conf } +export function getConfig(): ShardusTypes.StrictServerConfiguration | undefined { + return config +} + +export function isNonceMode(): boolean { + return !!config?.nonceMode +} + export function setDefaultConfigs(conf) { defaultConfigs = conf } diff --git a/test/unit/src/debug/config.test.ts b/test/unit/src/debug/config.test.ts index 4af3fd5fe..253cd51fc 100644 --- a/test/unit/src/debug/config.test.ts +++ b/test/unit/src/debug/config.test.ts @@ -1,5 +1,5 @@ import SERVER_CONFIG from '../../../../src/config/server' -import { setConfig } from '../../../../src/p2p/Context' +import { setConfig, getConfig, isNonceMode } from '../../../../src/p2p/Context' import { ServerMode, StrictServerConfiguration } from '../../../../src/shardus/shardus-types' import { DebugConfigurations, isDebugMode, isDebugModeAnd } from '../../../../src/debug/index' @@ -107,3 +107,26 @@ test('debug > isDebugModeAnd > Should return true if predicate is false', () => expect(result).toEqual(false) }) + +test('context > setConfig/getConfig > nonceMode propagates correctly', () => { + const config = { ...SERVER_CONFIG, nonceMode: false } + + setConfig(config as StrictServerConfiguration) + + const updated = getConfig() + + expect(updated?.nonceMode).toBe(false) +}) + +test('context > isNonceMode > reflects config changes', () => { + const config = { ...SERVER_CONFIG, nonceMode: true } + + setConfig(config as StrictServerConfiguration) + + expect(isNonceMode()).toBe(true) + + config.nonceMode = false + setConfig(config as StrictServerConfiguration) + + expect(isNonceMode()).toBe(false) +})