package types_test
import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/tests"
"github.com/evmos/ethermint/types"
"github.com/stretchr/testify/require"
)
func TestIsEmptyHash(t *testing.T) {
testCases := []struct {
name string
hash string
expEmpty bool
}{
{
"empty string", "", true,
},
"zero hash", common.Hash{}.String(), true,
"non-empty hash", common.BytesToHash([]byte{1, 2, 3, 4}).String(), false,
}
for _, tc := range testCases {
require.Equal(t, tc.expEmpty, types.IsEmptyHash(tc.hash), tc.name)
func TestIsZeroAddress(t *testing.T) {
address string
"zero address", common.Address{}.String(), true,
"non-empty address", common.BytesToAddress([]byte{1, 2, 3, 4}).String(), false,
require.Equal(t, tc.expEmpty, types.IsZeroAddress(tc.address), tc.name)
func TestValidateAddress(t *testing.T) {
expError bool
"invalid address", "0x", true,
"zero address", common.Address{}.String(), false,
"valid address", tests.GenerateAddress().Hex(), false,
err := types.ValidateAddress(tc.address)
if tc.expError {
require.Error(t, err, tc.name)
} else {
require.NoError(t, err, tc.name)
func TestValidateNonZeroAddress(t *testing.T) {
err := types.ValidateNonZeroAddress(tc.address)
func TestSafeInt64(t *testing.T) {
value uint64
"no overflow", 10, false,
"overflow", 18446744073709551615, true,
value, err := types.SafeInt64(tc.value)
continue
require.Equal(t, int64(tc.value), value, tc.name)