Skip to content
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

Fix/mock reset #434

Merged
merged 7 commits into from
Mar 18, 2025
Merged

Fix/mock reset #434

merged 7 commits into from
Mar 18, 2025

Conversation

BelfordZ
Copy link
Contributor

@BelfordZ BelfordZ commented Mar 17, 2025

PR Type

enhancement, configuration changes


Description

  • Enable automatic clearing and resetting of mocks in Jest.

  • Add ignore patterns for test paths in Jest configuration.


Changes walkthrough 📝

Relevant files
Configuration changes
jest.config.js
Enhance Jest configuration for mock management and path ignoring

jest.config.js

  • Enabled clearMocks and resetMocks options.
  • Added testPathIgnorePatterns for node_modules, dist, and build
    directories.
  • +8/-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

    github-actions bot commented Mar 17, 2025

    PR Reviewer Guide 🔍

    (Review updated until commit 65a74d5)

    Here are some key observations to aid the review process:

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

    Mock Reset

    Ensure that the new approach to resetting mocks in beforeEach is correctly implemented and does not introduce any side effects or issues with test isolation.

    describe('RepairOOSAccountsReq', () => {
      beforeEach(() => {
        (stateManager as any) = {
          app: {
            binarySerializeObject: jest.fn((_, data: any) =>
              Buffer.from(Utils.safeStringify(data), 'utf8')
            ),
            binaryDeserializeObject: jest.fn((_, buffer: Buffer) =>
              Utils.safeJsonParse(buffer.toString('utf8'))
            ),
          },
        }
      })
    Serialization Change

    Verify that the change from using stateManager.app.binarySerializeObject to Buffer.from(Utils.safeStringify(...)) does not affect the integrity or performance of the serialization process.

        expectedStream.writeString(obj.executionShardKey)
        expectedStream.writeUInt32(obj.cachedAppData.cycle)
        expectedStream.writeBuffer(
          Buffer.from(Utils.safeStringify(obj.cachedAppData.appData), 'utf8')
        )
        expectedStream.writeString(obj.cachedAppData.dataID)
        expect(stream.getBuffer()).toEqual(expectedStream.getBuffer())
      })
    
      test('should serialize with root false', () => {
        const obj: SendCachedAppDataReq = {
          topic: 'test',
          txId: 'test',
          executionShardKey: 'test',
          cachedAppData: {
            cycle: 1,
            appData: { data: 'test' },
            dataID: 'test',
          },
        }
    
        const stream = new VectorBufferStream(0)
        serializeSendCachedAppDataReq(stream, obj, false)
    
        const expectedStream = new VectorBufferStream(0)
        expectedStream.writeUInt8(cSendCachedAppDataReqVersion)
        expectedStream.writeString(obj.topic)
        expectedStream.writeString(obj.txId)
        expectedStream.writeString(obj.executionShardKey)
        expectedStream.writeUInt32(obj.cachedAppData.cycle)
        expectedStream.writeBuffer(
          Buffer.from(Utils.safeStringify(obj.cachedAppData.appData), 'utf8')
        )
        expectedStream.writeString(obj.cachedAppData.dataID)
        expect(stream.getBuffer()).toEqual(expectedStream.getBuffer())
      })
    })
    
    describe('deserializeSendCachedAppDataReq Deserialization', () => {
      test('should deserialize', () => {
        const obj: SendCachedAppDataReq = {
          topic: 'test',
          txId: 'test',
          executionShardKey: 'test',
          cachedAppData: {
            cycle: 1,
            appData: { data: 'test' },
            dataID: 'test',
          },
        }
    
        const stream = new VectorBufferStream(0)
        stream.writeUInt8(cSendCachedAppDataReqVersion)
        stream.writeString(obj.topic)
        stream.writeString(obj.txId)
        stream.writeString(obj.executionShardKey)
        stream.writeUInt32(obj.cachedAppData.cycle)
        stream.writeBuffer(
          Buffer.from(Utils.safeStringify(obj.cachedAppData.appData), 'utf8')
        )

    Copy link

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    @BelfordZ
    Copy link
    Contributor Author

    /review

    Copy link

    Persistent review updated to latest commit 65a74d5

    @BelfordZ BelfordZ merged commit 5d172e4 into mainnet-launch Mar 18, 2025
    5 checks passed
    @mhanson-github mhanson-github deleted the fix/mock-reset branch March 19, 2025 02:35
    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.

    2 participants