Skip to content

test(ut): added tests to check the existing behaviour for block/manager.go - #1550

Merged
MSevey merged 4 commits into
evstack:mainfrom
arhamj:1530
Mar 18, 2024
Merged

test(ut): added tests to check the existing behaviour for block/manager.go#1550
MSevey merged 4 commits into
evstack:mainfrom
arhamj:1530

Conversation

@arhamj

@arhamj arhamj commented Feb 19, 2024

Copy link
Copy Markdown
Contributor

Overview

This MR has changes which potentially add the missing tests to manager_test.go. Currently, the tests only validate the existing behaviours, i.e.:

  1. If there are A, B and C blocks which are in the pending blocks list and C has a marshal error. We currently throw an error.
  2. If A is too big, A never gets submitted.
  3. If A itself has a marshal error which is a unit case of (1), we also throw an error.

Closes: #1530

From the code, it looks like marshal errors would be caught earlier at SaveBlock to the store stage. That said I would like the following change:

  • Offloading block aggregation from da.go to manager.go to avoid retries in cases where there are such issues and also for better error logging.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • Tests
    • Enhanced testing for block submission, including cases with marshalling errors and size limit exceedances.
  • Chores
    • Added a mockery command for generating mocks of the Store entity to facilitate testing.
    • Introduced a mock Store type to simulate store interactions in tests.

@coderabbitai

coderabbitai Bot commented Feb 19, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

This update focuses on enhancing the robustness of block submission testing in a blockchain context, particularly addressing issues related to block size and marshalling errors. By expanding test coverage in manager_test.go and introducing a new mock for the Store entity, the changes aim to ensure that the system gracefully handles blocks that are too large or encounter marshalling issues, thereby improving the overall reliability of block submission processes.

Changes

Files Summary
block/manager_test.go Expanded test cases for TestSubmitBlocksToDA to include scenarios of marshalling errors and size limits. Introduced invalidateBlockHeader function.
Makefile Added mockery command for generating mocks for Store entity.
test/mocks/Store.go Introduced autogenerated mock Store for enhanced testing capabilities.

Assessment against linked issues

Objective Addressed Explanation
Add test cases for various block submission scenarios (#1530)
Clarify outcome for problematic subsequent blocks in submission (#1530)
Enhance testing for submitBlocksToDA function (#1530)

Poem

In the realm of code, where blocks align,
A rabbit hopped, through tests divine.
With each leap, a bug it'd find,
Marshalling errors, size too grand, left behind.
🐇💻✨
"Fear not," it whispered, with wisdom so bright,
"For every problem, there's a test in sight."
In a world of bytes, it danced with delight,
Ensuring the blockchain, robust and tight.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@arhamj arhamj changed the title test(ut): added unit tests to check the existing behaviour for manage… test(ut): added tests to check the existing behaviour for block/manager.go Feb 19, 2024

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8736541 and b2c0894.
Files selected for processing (1)
  • block/manager_test.go (2 hunks)

Comment thread block/manager_test.go
Comment thread block/manager_test.go Outdated

@MSevey MSevey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking up this issue!
I left some comments to update the tests to match the desired state.
There is a good change that once written properly, the tests will actually fail. This is one of the goals of the issue. If the tests are failing, we will need to investigate the changes required to the code itself to handle those edge cases and/ore discuss internally what the right direction to go is.

Comment thread block/manager_test.go Outdated
Comment thread block/manager_test.go Outdated
Comment thread block/manager_test.go
Comment thread block/manager_test.go Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b2c0894 and 94c1e1c.
Files selected for processing (2)
  • block/manager_test.go (2 hunks)
  • da/da.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • block/manager_test.go
Additional comments: 4
da/da.go (4)
  • 97-100: The declaration of submitted and breakErr variables is clear and follows good naming conventions. However, it's important to ensure that breakErr is only used in scenarios where breaking the loop is necessary due to an error, which seems to be the case here.
  • 104-106: Logging the error when failing to marshal a block is a good practice for debugging. However, wrapping the original error with additional context before breaking the loop enhances error handling by providing more detailed information about the failure.
  • 110-110: Setting breakErr to ErrBlobSizeOverLimit when the blob size limit is reached and then breaking the loop is an effective way to handle size constraints. This approach ensures that the method does not attempt to submit blobs that exceed the maximum allowed size, which is a good practice for maintaining system stability.
  • 117-121: The check for submitted == 0 && breakErr != nil before returning an error is a logical way to handle cases where no blocks were submitted due to an error. This ensures that the method returns a meaningful error message in such scenarios, improving the error handling mechanism.

@arhamj

arhamj commented Feb 22, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for picking up this issue! I left some comments to update the tests to match the desired state. There is a good change that once written properly, the tests will actually fail. This is one of the goals of the issue. If the tests are failing, we will need to investigate the changes required to the code itself to handle those edge cases and/ore discuss internally what the right direction to go is.

@MSevey can you please have a look again when you find time?

@arhamj
arhamj requested a review from MSevey February 22, 2024 08:50
Comment thread da/da.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bec9ad0 and f071d04.
Files selected for processing (1)
  • block/manager_test.go (2 hunks)
Additional comments: 2
block/manager_test.go (2)
  • 230-271: The test cases added for submitting blocks to the DA component cover the scenarios outlined in the PR objectives well. However, it's important to ensure that the isErrExpected flag accurately reflects the expected outcome of each test case. For instance, in the case where a block is too big on its own, it might be beneficial to verify that the error thrown is specifically related to the size limit. This could involve checking the error message or type to ensure it's what's expected.

Consider adding assertions to verify the specific type or message of the expected errors in test cases where isErrExpected is true. This will ensure that the tests are failing for the right reasons and improve the robustness of the test suite.

  • 267-267: As per the existing comment from MSevey, it's crucial to call invalidateBlockHeader on block A in the relevant test case to simulate a marshalling error. This action has been correctly implemented in the test case "A itself has a marshalling error. So A, B and C never get submitted", ensuring that the test setup aligns with the intended scenario.

@MSevey MSevey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright this is great. let's update the test case to have it pass and then I'll create some follow up issues to improve how these test cases are handled. At least now the full functionality is documented in these tests.

Comment thread block/manager_test.go Outdated
@Manav-Aggarwal

Copy link
Copy Markdown
Member

Hey @arhamj, thanks for submitting this! It seems like the first test you added is failing in the unit test, could you make sure it's passing?

@arhamj

arhamj commented Mar 7, 2024

Copy link
Copy Markdown
Contributor Author

Hey @arhamj, thanks for submitting this! It seems like the first test you added is failing in the unit test, could you make sure it's passing?

@Manav-Aggarwal I had added a fix to handle the failing case, but @MSevey asked me to revert it to see what the failures were.

@MSevey

MSevey commented Mar 7, 2024

Copy link
Copy Markdown
Contributor

Hey @arhamj, thanks for submitting this! It seems like the first test you added is failing in the unit test, could you make sure it's passing?

@Manav-Aggarwal I had added a fix to handle the failing case, but @MSevey asked me to revert it to see what the failures were.

@arhamj yes and then my last review was to update the test so that it passes with the current code.
I captured the feature request for changing on to handle that test case here in #1590 since It will require some more discussion and I didn't want to block this PR any longer as it address the original issue request of adding the test cases.

@arhamj

arhamj commented Mar 7, 2024

Copy link
Copy Markdown
Contributor Author

Sorry, I missed it completely @MSevey 😄. Updating.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b4e4db6 and 9072e88.
Files selected for processing (1)
  • block/manager_test.go (2 hunks)

Comment thread block/manager_test.go
Comment thread block/manager_test.go
@arhamj

arhamj commented Mar 11, 2024

Copy link
Copy Markdown
Contributor Author

Hey, sorry for the delay. @MSevey I think the marshalling error tests no longer make sense as we have gotten rid of the in-memory queue for the blocks. The store.SaveBlock() to add data to the DB takes care of MarshalErrors when writing and if there were a read error, store.GetBlock() would catch it. I've updated the PR. Let me know what you think.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9072e88 and dff93ba.
Files selected for processing (1)
  • block/manager_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • block/manager_test.go

@codecov

codecov Bot commented Mar 11, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.10%. Comparing base (c9d8467) to head (6d8c307).
Report is 47 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1550      +/-   ##
==========================================
+ Coverage   50.23%   52.10%   +1.87%     
==========================================
  Files          52       52              
  Lines        6762     5600    -1162     
==========================================
- Hits         3397     2918     -479     
+ Misses       3024     2345     -679     
+ Partials      341      337       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tzdybal tzdybal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test case makes sense 👍

Comment thread block/manager_test.go

@tzdybal tzdybal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the unused function.

@MSevey

MSevey commented Mar 12, 2024

Copy link
Copy Markdown
Contributor

Hey, sorry for the delay. @MSevey I think the marshalling error tests no longer make sense as we have gotten rid of the in-memory queue for the blocks. The store.SaveBlock() to add data to the DB takes care of MarshalErrors when writing and if there were a read error, store.GetBlock() would catch it. I've updated the PR. Let me know what you think.

we should add this test back in. the reason is that we want to test functions in isolation.
If there is an error path, we should test it, since external code is constantly changing.
Not testing a code path based on assumptions of external code, leaves the code vulnerable to failing in the future if the external code changes again.

arhamj added 2 commits March 13, 2024 14:17
…r_test.go

refactor(manager): update test cases and refactored da submission method

fix(revert): da changes to observe breaking test cases

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b708321 and 6d8c307.
Files selected for processing (3)
  • Makefile (1 hunks)
  • block/manager_test.go (3 hunks)
  • test/mocks/Store.go (1 hunks)
Check Runs (4)
lint / hadolint / hadolint completed (1)
lint / golangci-lint completed (1)
lint / markdown-lint completed (1)
lint / yamllint completed (1)
Files skipped from review due to trivial changes (1)
  • test/mocks/Store.go
Files skipped from review as they are similar to previous changes (1)
  • block/manager_test.go
Additional comments: 1
Makefile (1)
  • 87-87: The addition of the mock-gen command for generating mocks for the Store entity is correctly implemented and follows the established pattern for mock generation in this Makefile.

Please ensure to verify the successful generation of mocks and their integration within the testing framework.

@arhamj
arhamj requested a review from MSevey March 13, 2024 11:29

@MSevey MSevey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert back to just the new test cases to TestSubmitBlocksToDA. We don't need the new mocks or the separate tests. Only the new test cases.

Comment thread block/manager_test.go
Comment thread Makefile
Comment thread test/mocks/Store.go
@MSevey
MSevey enabled auto-merge March 15, 2024 14:43
@MSevey
MSevey added this pull request to the merge queue Mar 18, 2024
Merged via the queue into evstack:main with commit e2f60bc Mar 18, 2024
@tac0turtle tac0turtle removed this from Evolve Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more test cases for submitBlocksToDA in manager_test.go

5 participants