Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/p2p/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 24 additions & 1 deletion test/unit/src/debug/config.test.ts
Original file line number Diff line number Diff line change
@@ -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'

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