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

test(fuzz): fix broken OSS-Fuz build #21940

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

Conversation

AdamKorcz
Copy link
Contributor

@AdamKorcz AdamKorcz commented Sep 26, 2024

Description

This fixes the broken OSS-Fuzz build. It is quite a hacky fix and the goal is to enable OSS-Fuzz to build the fuzzers.

I plan to work on the OSS-Fuzz infrastructure side to make this less hacky, but it will take a few weeks, so I suggest we fix the build so the fuzzers at least run.

I will keep an eye on the build in case it breaks to minimize downtime.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • Bug Fixes

    • Removed outdated test functions to streamline the testing process.
  • New Features

    • Enhanced the fuzz testing build script with improved error handling and a reorganized directory structure for better clarity.
  • Chores

    • Updated Go version and refined the build process for fuzzing components.

Signed-off-by: Adam Korczynski <Adam@adalogics.com>
@AdamKorcz AdamKorcz requested a review from a team as a code owner September 26, 2024 21:20
Copy link
Contributor

coderabbitai bot commented Sep 26, 2024

📝 Walkthrough

Walkthrough

The changes involve the removal of several test functions from the addressTestSuite in the types/address_test.go file, specifically targeting the TestAddressTestSuite, TestBech32ifyAddressBytes, and TestMustBech32ifyAddressBytes functions. Additionally, the fuzz/oss-fuzz-build.sh script has been significantly modified to enhance error handling, streamline the fuzzing build process, and reorganize test files into a new fuzzing directory, while ensuring proper management of Go modules.

Changes

Files Change Summary
types/address_test.go Removed TestAddressTestSuite, TestBech32ifyAddressBytes, and TestMustBech32ifyAddressBytes functions from the addressTestSuite.
fuzz/oss-fuzz-build.sh Enhanced error handling, installed Go version 1.23.1, reorganized fuzzing components, applied patches, and updated Go module handling.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BuildScript
    participant GoEnv
    participant FuzzingComponents

    User->>BuildScript: Initiate build process
    BuildScript->>GoEnv: Install Go 1.23.1
    BuildScript->>FuzzingComponents: Apply patches and reorganize files
    BuildScript->>GoEnv: Run go mod tidy
    BuildScript->>User: Build complete
Loading

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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (2)
fuzz/fuzz.patch (1)

1-81: Summary of changes and recommendations

The changes in this patch involve the removal of several test functions from types/address_test.go, including TestAddressTestSuite, TestBech32ifyAddressBytes, and TestMustBech32ifyAddressBytes. While these removals may be necessary to fix the OSS-Fuzz build as mentioned in the PR objectives, they could potentially impact the overall test coverage and reliability of the codebase.

Recommendations:

  1. Document the reasons for removing these tests in the code or commit message.
  2. Ensure that the functionalities tested by the removed functions are covered elsewhere in the codebase.
  3. Consider adding minimal tests that don't interfere with the OSS-Fuzz build but still provide some coverage for the affected functions.
  4. Monitor the impact of these changes on the overall test coverage and system stability.
  5. Plan for reintroducing comprehensive tests for these functions in the future, possibly as part of the mentioned improvements to the OSS-Fuzz infrastructure.

As the PR author mentioned that this is a temporary, "hacky" solution, it's crucial to create a follow-up task or issue to revisit these changes and restore proper test coverage once the OSS-Fuzz infrastructure improvements are implemented.

fuzz/oss-fuzz-build.sh (1)

17-17: Avoid moving binaries to /root/go/bin/; use a user-local bin directory

Moving the go-118-fuzz-build binary to /root/go/bin/ requires root privileges and may not be necessary. It's better to place binaries in a user-local directory, such as $HOME/go/bin or $SRC/go/bin, to avoid permission issues and improve portability.

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 648ef5f and 69230f4.

📒 Files selected for processing (2)
  • fuzz/fuzz.patch (1 hunks)
  • fuzz/oss-fuzz-build.sh (2 hunks)
🔇 Additional comments (3)
fuzz/fuzz.patch (1)

20-48: Verify coverage for Bech32ifyAddressBytes functionality

The removal of TestBech32ifyAddressBytes function eliminates tests for the Bech32ifyAddressBytes functionality. This could potentially leave this critical function untested, risking future undetected bugs.

Let's verify if this functionality is tested elsewhere:

#!/bin/bash
# Description: Check for other tests covering Bech32ifyAddressBytes functionality

# Search for other tests of Bech32ifyAddressBytes
echo "Searching for other tests of Bech32ifyAddressBytes:"
rg --type go 'func Test.*Bech32ifyAddressBytes'

# Look for usage of Bech32ifyAddressBytes in the codebase
echo "Checking usage of Bech32ifyAddressBytes:"
rg --type go 'Bech32ifyAddressBytes'

If no other tests are found, consider adding a minimal test for Bech32ifyAddressBytes that doesn't interfere with the OSS-Fuzz build. Alternatively, document why this test was removed and how the functionality is ensured to work correctly without these specific tests.

fuzz/oss-fuzz-build.sh (2)

21-23: Verify that moving test files does not impact test execution

Moving test files to types/fuzzing and changing their package from types_test to fuzzing may affect how tests are discovered and executed. Ensure that the tests in the new location are still being run as part of your test suite.


59-59: Verify that FuzzBech32AccAddrConsistencyYAML is properly defined

Ensure that the function FuzzBech32AccAddrConsistencyYAML exists in the types/fuzzing package and is correctly implemented for fuzzing purposes.

You can run the following script to confirm the function's existence:

✅ Verification successful

[/run_scripts]


<!-- [monologue]
[task verify_comment_1/1]
[observations]
- The shell script successfully found the definition of `FuzzBech32AccAddrConsistencyYAML` in `types/address_fuzz_test.go`.
- The function signature `func FuzzBech32AccAddrConsistencyYAML(f *testing.F)` indicates it is set up for fuzz testing.
- The implementation includes a test case addition, which aligns with fuzzing purposes.
[analysis]
- The function exists and is correctly defined for fuzzing within the `types` package.
- The initial concern about the function's existence is addressed.
- No additional verification is necessary unless there's a requirement to ensure it's in a specific subdirectory.
[actions]
- Conclude that the verification is successful.
-->

FuzzBech32AccAddrConsistencyYAML function is properly defined

The function FuzzBech32AccAddrConsistencyYAML was found in types/address_fuzz_test.go and is correctly implemented for fuzzing purposes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for the definition of FuzzBech32AccAddrConsistencyYAML in the types/fuzzing package.

# Test: Expect to find the function definition in Go files within the types/fuzzing directory.
rg --type go -A 5 -B 5 'func FuzzBech32AccAddrConsistencyYAML' $SRC/cosmos-sdk/types/fuzzing

Length of output: 156


Script:

#!/bin/bash
# Description: Recursively search for the definition of FuzzBech32AccAddrConsistencyYAML across all Go files in the repository.

# Test: Expect to find the function definition in relevant Go files.
rg --type go -A 5 -B 5 'func FuzzBech32AccAddrConsistencyYAML' .

Length of output: 666

Comment on lines +50 to +77
-func (s *addressTestSuite) TestMustBech32ifyAddressBytes() {
- type args struct {
- prefix string
- bs []byte
- }
- tests := []struct {
- name string
- args args
- want string
- wantPanic bool
- }{
- {"empty address", args{"prefixa", []byte{}}, "", false},
- {"empty prefix", args{"", addr20byte}, "", true},
- {"10-byte address", args{"prefixa", addr10byte}, "prefixa1qqqsyqcyq5rqwzqf3953cc", false},
- {"10-byte address", args{"prefixb", addr10byte}, "prefixb1qqqsyqcyq5rqwzqf20xxpc", false},
- {"20-byte address", args{"prefixa", addr20byte}, "prefixa1qqqsyqcyq5rqwzqfpg9scrgwpugpzysn7hzdtn", false},
- {"20-byte address", args{"prefixb", addr20byte}, "prefixb1qqqsyqcyq5rqwzqfpg9scrgwpugpzysnrujsuw", false},
- }
- for _, tt := range tests {
- s.T().Run(tt.name, func(t *testing.T) {
- if tt.wantPanic {
- require.Panics(t, func() { types.MustBech32ifyAddressBytes(tt.args.prefix, tt.args.bs) })
- return
- }
- require.Equal(t, tt.want, types.MustBech32ifyAddressBytes(tt.args.prefix, tt.args.bs))
- })
- }
-}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Additional tests for MustBech32ifyAddressBytes are needed

The removal of TestMustBech32ifyAddressBytes reduces the test coverage for the MustBech32ifyAddressBytes function, particularly its panic conditions. While there is usage in client/keys/show_test.go, it may not comprehensively cover all test cases previously handled.

  • Ensure that all critical scenarios, including different prefixes, byte lengths, and panic conditions, are adequately tested.
  • If necessary, reintroduce or create new test functions to maintain full coverage of MustBech32ifyAddressBytes.
🔗 Analysis chain

Verify coverage for MustBech32ifyAddressBytes functionality

The removal of TestMustBech32ifyAddressBytes function eliminates tests for the MustBech32ifyAddressBytes functionality, including its panic behavior. This could potentially leave this critical function untested, risking unexpected runtime errors if the function's panic conditions are not properly maintained.

Let's verify if this functionality is tested elsewhere:

If no other tests are found, consider adding a minimal test for MustBech32ifyAddressBytes that doesn't interfere with the OSS-Fuzz build, especially focusing on its panic behavior. Alternatively, document why this test was removed and how the functionality, particularly the panic conditions, is ensured to work correctly without these specific tests.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other tests covering MustBech32ifyAddressBytes functionality

# Search for other tests of MustBech32ifyAddressBytes
echo "Searching for other tests of MustBech32ifyAddressBytes:"
rg --type go 'func Test.*MustBech32ifyAddressBytes'

# Look for usage of MustBech32ifyAddressBytes in the codebase
echo "Checking usage of MustBech32ifyAddressBytes:"
rg --type go 'MustBech32ifyAddressBytes'

Length of output: 943

Comment on lines +9 to +11
-func TestAddressTestSuite(t *testing.T) {
- suite.Run(t, new(addressTestSuite))
-}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Potential Test Coverage Reduction Due to Removal of Test Suite Runner

The TestAddressTestSuite function has been removed, and no alternative test suite runners were found for address-related tests. While individual tests like TestBech32ifyAddressBytes still exist in types/address_test.go, their execution may be compromised without a suite runner, potentially reducing overall test coverage.

  • Ensure that individual tests are invoked through other test runners or frameworks.
  • Consider reintroducing a suite runner or alternative mechanism to execute these tests.
  • Add comments to clarify the rationale behind removing the suite runner and how test coverage is maintained.
🔗 Analysis chain

Verify the impact of removing TestAddressTestSuite

The removal of TestAddressTestSuite function, which was responsible for running the entire address test suite, could significantly impact the test coverage. While this might be necessary to fix the OSS-Fuzz build as per the PR objectives, we need to ensure that critical tests are still being run elsewhere.

Let's verify if there are other test suite runners or if these tests are covered elsewhere:

Consider adding a comment explaining why these tests were removed and how the functionality is being tested now, if applicable. This will help maintain clarity for future developers working on this code.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other test suite runners and coverage of address tests

# Search for other potential test suite runners
echo "Searching for other test suite runners:"
rg --type go 'func Test.*Suite\(' -g '!*_test.go'

# Check for other files that might be testing address functionality
echo "Checking for other address test files:"
fd -e go | rg 'address.*test'

# Look for any TODO or FIXME comments related to testing
echo "Searching for TODO/FIXME comments related to testing:"
rg -i 'todo|fixme' -g '*test*.go'

Length of output: 7093

set -o nounset
set -o pipefail
set -o errexit
set -x
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove set -x to prevent verbose logging in production

The set -x command enables shell debugging by printing each command before execution. This can clutter logs and potentially expose sensitive information. It's recommended to remove set -x or conditionally enable it only during debugging sessions.

Comment on lines +11 to +12
rm -rf /root/.go && tar -C $SRC/new-go/ -xzf go1.23.1.linux-amd64.tar.gz
mv $SRC/new-go/go /root/.go
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using rm -rf /root/.go; consider safer installation methods

Using rm -rf /root/.go is risky and can lead to accidental deletion if misused. Additionally, modifying files in /root requires elevated privileges and may affect other processes. Consider installing Go in a local directory within your workspace or using the existing Go installation available in the environment.

Comment on lines +25 to +30
rm $SRC/cosmos-sdk/math/dec_internal_test.go
rm $SRC/cosmos-sdk/math/int_internal_test.go
rm $SRC/cosmos-sdk/math/uint_internal_test.go
mv $SRC/cosmos-sdk/types/fuzz_test.go $SRC/cosmos-sdk/types/fuzz.go
rm $SRC/cosmos-sdk/types/*_test.go
mv $SRC/cosmos-sdk/types/fuzz.go $SRC/cosmos-sdk/types/fuzz_test.go
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Assess the impact of removing test files on code coverage

Removing test files like dec_internal_test.go, int_internal_test.go, uint_internal_test.go, and all *_test.go files in the types directory could significantly reduce test coverage. This might lead to undetected bugs and decreased code reliability. Please evaluate the necessity of deleting these tests and consider retaining critical ones.

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.

1 participant