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
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/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)

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)
testMarshalYAML(t, &acc, res, acc.MarshalYAML, res.UnmarshalYAML)
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate to L24

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


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