Skip to content

Add nonce mode helpers and tests #508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

BelfordZ
Copy link
Contributor

@BelfordZ BelfordZ commented May 22, 2025

User description

Summary

  • expose nonce mode helpers in Context
  • validate config updates in unit tests

Testing

  • npm test

PR Type

Enhancement, Tests


Description

  • Added getConfig and isNonceMode helpers to Context

  • Improved nonce mode configuration handling and exposure

  • Introduced unit tests for nonce mode helpers

  • Ensured config updates propagate correctly in tests


Changes walkthrough 📝

Relevant files
Enhancement
Context.ts
Add nonce mode helpers and config getter to Context           

src/p2p/Context.ts

  • Added getConfig function to retrieve current config
  • Added isNonceMode function to check nonce mode status
  • Improved configuration handling for nonce mode
  • +8/-0     
    Tests
    config.test.ts
    Add unit tests for nonce mode helpers in Context                 

    test/unit/src/debug/config.test.ts

  • Added tests for setConfig, getConfig, and isNonceMode
  • Verified nonce mode propagation and config update reflection
  • +24/-1   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🏅 Score: 93
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Type Safety

    The getConfig function returns a possibly undefined value, but the isNonceMode helper uses optional chaining and double negation to coerce to boolean. Ensure that all usages of isNonceMode and getConfig in the codebase handle potential undefined values safely.

    export function getConfig(): ShardusTypes.StrictServerConfiguration | undefined {
      return config
    }
    
    export function isNonceMode(): boolean {
      return !!config?.nonceMode
    }
    Test Isolation

    The tests mutate the shared SERVER_CONFIG object directly, which may lead to side effects between tests. Consider cloning or resetting configuration objects between tests to ensure isolation and prevent flaky test behavior.

    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)
    })

    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant