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(types/address): add unit tests for the file types/address.go #20237

Merged
merged 15 commits into from
Jun 13, 2024
1 change: 1 addition & 0 deletions fuzz/oss-fuzz-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ go get github.com/AdamKorcz/go-118-fuzz-build/testing
# 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

build_go_fuzzer FuzzCryptoHDDerivePrivateKeyForPath fuzz_crypto_hd_deriveprivatekeyforpath
build_go_fuzzer FuzzCryptoHDNewParamsFromPath fuzz_crypto_hd_newparamsfrompath
Expand Down
38 changes: 38 additions & 0 deletions types/address_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package types_test

import (
"encoding/hex"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/types"
)

func FuzzBech32AccAddrConsistencyYAML(f *testing.F) {
if testing.Short() {
f.Skip("running in -short mode")
}
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a comment to explain the purpose of skipping the test in short mode.

Adding a comment will help other developers understand why the test is skipped in short mode.

if testing.Short() {
    // Skip this test in short mode to save time
    f.Skip("running in -short mode")
}


f.Add([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19})
f.Add([]byte{16, 1, 2, 3, 4, 5, 16, 27, 58, 9, 51, 11, 12, 13, 14, 15, 16, 17, 20, 21})
f.Add([]byte{19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0})

f.Fuzz(func(t *testing.T, input []byte) {
acc := types.AccAddress(input)
res := &types.AccAddress{}

testMarshalYAML(t, &acc, res, acc.MarshalYAML, res.UnmarshalYAML)

str := acc.String()
var err error
*res, err = types.AccAddressFromBech32(str)
require.NoError(t, err)
require.Equal(t, acc, *res)

str = hex.EncodeToString(acc)
*res, err = types.AccAddressFromHexUnsafe(str)
require.NoError(t, err)
require.Equal(t, acc, *res)
})
}
Loading
Loading