Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangchiqing committed Nov 21, 2020
1 parent 708d1c2 commit e9add88
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions model/encodable/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func isHexString(enc []byte) error {
return fmt.Errorf("invalid hex: %v", str)
}

if str == "null" {
return nil
}

// remove the "
str = str[1 : len(str)-1]
_, err := hex.DecodeString(str)
Expand All @@ -30,6 +34,7 @@ func isHexString(enc []byte) error {
func TestIsHexString(t *testing.T) {
require.NoError(t, isHexString([]byte("abcd")))
require.NoError(t, isHexString([]byte("\"\"")))
require.NoError(t, isHexString([]byte("null")))
require.Error(t, isHexString([]byte("\"")))
require.Error(t, isHexString([]byte("QEVX=")))
}
Expand Down Expand Up @@ -62,6 +67,8 @@ func TestEncodableNetworkPubKeyNil(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, key, dec)

require.NoError(t, isHexString(enc))
}

func TestEncodableNetworkPrivKey(t *testing.T) {
Expand All @@ -77,6 +84,8 @@ func TestEncodableNetworkPrivKey(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.True(t, key.Equals(dec.PrivateKey))

require.NoError(t, isHexString(enc))
}

func TestEncodableNetworkPrivKeyNil(t *testing.T) {
Expand All @@ -90,6 +99,8 @@ func TestEncodableNetworkPrivKeyNil(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, key, dec)

require.NoError(t, isHexString(enc))
}

func TestEncodableStakingPubKey(t *testing.T) {
Expand All @@ -105,6 +116,8 @@ func TestEncodableStakingPubKey(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.True(t, key.Equals(dec.PublicKey))

require.NoError(t, isHexString(enc))
}

func TestEncodableStakingPubKeyNil(t *testing.T) {
Expand All @@ -118,6 +131,8 @@ func TestEncodableStakingPubKeyNil(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, key, dec)

require.NoError(t, isHexString(enc))
}

func TestEncodableStakingPrivKey(t *testing.T) {
Expand All @@ -134,6 +149,8 @@ func TestEncodableStakingPrivKey(t *testing.T) {
require.NoError(t, err)

require.True(t, key.Equals(dec.PrivateKey), "encoded/decoded key equality check failed")

require.NoError(t, isHexString(enc))
}

func TestEncodableStakingPrivKeyNil(t *testing.T) {
Expand All @@ -147,6 +164,8 @@ func TestEncodableStakingPrivKeyNil(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, key, dec)

require.NoError(t, isHexString(enc))
}

func TestEncodableRandomBeaconPubKey(t *testing.T) {
Expand All @@ -162,6 +181,8 @@ func TestEncodableRandomBeaconPubKey(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.True(t, key.Equals(dec.PublicKey))

require.NoError(t, isHexString(enc))
}

func TestEncodableRandomBeaconPubKeyNil(t *testing.T) {
Expand All @@ -175,6 +196,8 @@ func TestEncodableRandomBeaconPubKeyNil(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, key, dec)

require.NoError(t, isHexString(enc))
}

func TestEncodableRandomBeaconPrivKey(t *testing.T) {
Expand All @@ -191,6 +214,8 @@ func TestEncodableRandomBeaconPrivKey(t *testing.T) {
require.NoError(t, err)

require.True(t, key.Equals(dec.PrivateKey), "encoded/decoded key equality check failed")

require.NoError(t, isHexString(enc))
}

func TestEncodableRandomBeaconPrivKeyNil(t *testing.T) {
Expand All @@ -204,6 +229,8 @@ func TestEncodableRandomBeaconPrivKeyNil(t *testing.T) {
err = json.Unmarshal(enc, &dec)
require.NoError(t, err)
require.Equal(t, key, dec)

require.NoError(t, isHexString(enc))
}

func generateRandomSeed(t *testing.T) []byte {
Expand Down

0 comments on commit e9add88

Please sign in to comment.