laconicd-deprecated/types/validation_test.go

55 lines
944 B
Go
Raw Normal View History

package types
import (
"testing"
2021-09-03 18:06:36 +00:00
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func TestIsEmptyHash(t *testing.T) {
testCases := []struct {
name string
hash string
expEmpty bool
}{
{
"empty string", "", true,
},
{
2021-09-03 18:06:36 +00:00
"zero hash", common.Hash{}.String(), true,
},
{
2021-09-03 18:06:36 +00:00
"non-empty hash", common.BytesToHash([]byte{1, 2, 3, 4}).String(), false,
},
}
for _, tc := range testCases {
require.Equal(t, tc.expEmpty, IsEmptyHash(tc.hash), tc.name)
}
}
func TestIsZeroAddress(t *testing.T) {
testCases := []struct {
name string
address string
expEmpty bool
}{
{
"empty string", "", true,
},
{
2021-09-03 18:06:36 +00:00
"zero address", common.Address{}.String(), true,
},
{
2021-09-03 18:06:36 +00:00
"non-empty address", common.BytesToAddress([]byte{1, 2, 3, 4}).String(), false,
},
}
for _, tc := range testCases {
require.Equal(t, tc.expEmpty, IsZeroAddress(tc.address), tc.name)
}
}