forked from cerc-io/laconicd-deprecated
cb632c6bef
* [WIP] EIP-712 Signature Refactor * Debug and add ante tests * Add tests for failure cases * Add changelog entry * Code cleanup * Add tests for MsgDelegate and MsgWithdrawDelegationReward * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Code cleanup * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Minor codefix * Update ethereum/eip712/encoding.go * Minor code revision updates * Refactor EIP712 unit tests to use test suite * Address import cycle and implement minor refactors * Fix lint issues * Add EIP712 unit suite test function * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update ethereum/eip712/encoding.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Add minor refactors; increase test coverage * Correct ante_test for change in payload * Add single-signer util and tests * Update ethereum/eip712/encoding.go * Update ethereum/eip712/encoding.go * fix build Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: Freddy Caceres <facs95@gmail.com>
145 lines
2.5 KiB
Go
145 lines
2.5 KiB
Go
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) {
|
|
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, types.IsZeroAddress(tc.address), tc.name)
|
|
}
|
|
}
|
|
|
|
func TestValidateAddress(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
address string
|
|
expError bool
|
|
}{
|
|
{
|
|
"empty string", "", true,
|
|
},
|
|
{
|
|
"invalid address", "0x", true,
|
|
},
|
|
{
|
|
"zero address", common.Address{}.String(), false,
|
|
},
|
|
{
|
|
"valid address", tests.GenerateAddress().Hex(), false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
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) {
|
|
testCases := []struct {
|
|
name string
|
|
address string
|
|
expError bool
|
|
}{
|
|
{
|
|
"empty string", "", true,
|
|
},
|
|
{
|
|
"invalid address", "0x", true,
|
|
},
|
|
{
|
|
"zero address", common.Address{}.String(), true,
|
|
},
|
|
{
|
|
"valid address", tests.GenerateAddress().Hex(), false,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
err := types.ValidateNonZeroAddress(tc.address)
|
|
|
|
if tc.expError {
|
|
require.Error(t, err, tc.name)
|
|
} else {
|
|
require.NoError(t, err, tc.name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSafeInt64(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
value uint64
|
|
expError bool
|
|
}{
|
|
{
|
|
"no overflow", 10, false,
|
|
},
|
|
{
|
|
"overflow", 18446744073709551615, true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
value, err := types.SafeInt64(tc.value)
|
|
if tc.expError {
|
|
require.Error(t, err, tc.name)
|
|
continue
|
|
}
|
|
|
|
require.NoError(t, err, tc.name)
|
|
require.Equal(t, int64(tc.value), value, tc.name)
|
|
}
|
|
}
|