laconicd/types/validation_test.go
2021-09-03 18:06:36 +00:00

55 lines
944 B
Go

package types
import (
"testing"
"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,
},
{
"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, IsEmptyHash(tc.hash), tc.name)
}
}
func TestIsZeroAddress(t *testing.T) {
testCases := []struct {
name string
address string
expEmpty bool
}{
{
"empty string", "", true,
},
{
"zero address", common.Address{}.String(), true,
},
{
"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)
}
}