-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
diff --git a/types/address_test.go b/types/address_test.go | ||
index 014a48b73..99f9a1a86 100644 | ||
--- a/types/address_test.go | ||
+++ b/types/address_test.go | ||
@@ -26,10 +26,6 @@ type addressTestSuite struct { | ||
suite.Suite | ||
} | ||
|
||
-func TestAddressTestSuite(t *testing.T) { | ||
- suite.Run(t, new(addressTestSuite)) | ||
-} | ||
- | ||
func (s *addressTestSuite) SetupSuite() { | ||
s.T().Parallel() | ||
} | ||
@@ -403,65 +399,6 @@ func (s *addressTestSuite) TestAddressInterface() { | ||
} | ||
} | ||
|
||
-func (s *addressTestSuite) TestBech32ifyAddressBytes() { | ||
- type args struct { | ||
- prefix string | ||
- bs []byte | ||
- } | ||
- tests := []struct { | ||
- name string | ||
- args args | ||
- want string | ||
- wantErr 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) { | ||
- got, err := types.Bech32ifyAddressBytes(tt.args.prefix, tt.args.bs) | ||
- if (err != nil) != tt.wantErr { | ||
- t.Errorf("Bech32ifyBytes() error = %v, wantErr %v", err, tt.wantErr) | ||
- return | ||
- } | ||
- require.Equal(t, tt.want, got) | ||
- }) | ||
- } | ||
-} | ||
- | ||
-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)) | ||
- }) | ||
- } | ||
-} | ||
Comment on lines
+50
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Additional tests for The removal of
🔗 Analysis chainVerify coverage for MustBech32ifyAddressBytes functionality The removal of Let's verify if this functionality is tested elsewhere: If no other tests are found, consider adding a minimal test for 🏁 Scripts executedThe 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 |
||
- | ||
func (s *addressTestSuite) TestAddressTypesEquals() { | ||
addr1 := secp256k1.GenPrivKey().PubKey().Address() | ||
accAddr1 := types.AccAddress(addr1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
#!/bin/bash | ||
|
||
set -o nounset | ||
set -o pipefail | ||
set -o errexit | ||
set -x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove The |
||
|
||
cd $SRC | ||
wget https://go.dev/dl/go1.23.1.linux-amd64.tar.gz | ||
mkdir $SRC/new-go | ||
rm -rf /root/.go && tar -C $SRC/new-go/ -xzf go1.23.1.linux-amd64.tar.gz | ||
mv $SRC/new-go/go /root/.go | ||
Comment on lines
+11
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using Using |
||
ls /root/.go | ||
|
||
cd $SRC/go-118-fuzz-build | ||
go build . | ||
mv go-118-fuzz-build /root/go/bin/ | ||
cd $SRC/cosmos-sdk | ||
git apply ./fuzz/fuzz.patch | ||
|
||
mkdir $SRC/cosmos-sdk/types/fuzzing | ||
mv $SRC/cosmos-sdk/types/address*_test.go $SRC/cosmos-sdk/types/fuzzing/ | ||
sed 's/package types_test/package fuzzing/g' -i "$SRC"/cosmos-sdk/types/fuzzing/* | ||
|
||
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 | ||
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assess the impact of removing test files on code coverage Removing test files like |
||
|
||
set -euo pipefail | ||
|
||
export FUZZ_ROOT="github.com/cosmos/cosmos-sdk" | ||
|
@@ -18,25 +47,22 @@ build_go_fuzzer() { | |
compile_native_go_fuzzer cosmossdk.io/math FuzzLegacyNewDecFromStr fuzz_math_legacy_new_dec_from_str | ||
) | ||
|
||
go get github.com/AdamKorcz/go-118-fuzz-build/testing | ||
printf "package types \nimport _ \"github.com/AdamKorcz/go-118-fuzz-build/testing\"\n" > ./types/fuzz-register.go | ||
go mod edit -replace github.com/AdamKorcz/go-118-fuzz-build=$SRC/go-118-fuzz-build | ||
go mod tidy | ||
|
||
# TODO: fails to build with | ||
# main.413864645.go:12:2: found packages query (collections_pagination.go) and query_test (fuzz_test.go_fuzz.go) in /src/cosmos-sdk/types/query | ||
# because of the separate query_test package. | ||
# compile_native_go_fuzzer "$FUZZ_ROOT"/types/query FuzzPagination fuzz_types_query_pagination | ||
compile_native_go_fuzzer "$FUZZ_ROOT"/types FuzzCoinUnmarshalJSON fuzz_types_coin_unmarshal_json | ||
compile_native_go_fuzzer "$FUZZ_ROOT"/types FuzzBech32AccAddrConsistencyYAML fuzz_types_bech32_acc_addr_consistency_yaml | ||
|
||
compile_native_go_fuzzer "$FUZZ_ROOT"/types/fuzzing FuzzBech32AccAddrConsistencyYAML fuzz_types_bech32_acc_addr_consistency_yaml | ||
build_go_fuzzer FuzzCryptoHDDerivePrivateKeyForPath fuzz_crypto_hd_deriveprivatekeyforpath | ||
build_go_fuzzer FuzzCryptoHDNewParamsFromPath fuzz_crypto_hd_newparamsfrompath | ||
|
||
build_go_fuzzer FuzzCryptoTypesCompactbitarrayMarshalUnmarshal fuzz_crypto_types_compactbitarray_marshalunmarshal | ||
|
||
build_go_fuzzer FuzzTendermintAminoDecodeTime fuzz_tendermint_amino_decodetime | ||
|
||
build_go_fuzzer FuzzTypesParseCoin fuzz_types_parsecoin | ||
build_go_fuzzer FuzzTypesParseDecCoin fuzz_types_parsedeccoin | ||
build_go_fuzzer FuzzTypesParseTimeBytes fuzz_types_parsetimebytes | ||
build_go_fuzzer FuzzTypesDecSetString fuzz_types_dec_setstring | ||
|
||
build_go_fuzzer FuzzUnknownProto fuzz_unknownproto |
There was a problem hiding this comment.
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 likeTestBech32ifyAddressBytes
still exist intypes/address_test.go
, their execution may be compromised without a suite runner, potentially reducing overall test coverage.🔗 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:
Length of output: 7093