Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use exp error in test TestParseClientIdentifier #7779

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions modules/core/02-client/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package types_test

import (
"errors"
"math"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
)

// tests ParseClientIdentifier and IsValidClientID
Expand All @@ -16,32 +18,32 @@ func TestParseClientIdentifier(t *testing.T) {
clientID string
clientType string
expSeq uint64
expPass bool
expErr error
}{
{"valid 0", "tendermint-0", "tendermint", 0, true},
{"valid 1", "tendermint-1", "tendermint", 1, true},
{"valid solemachine", "solomachine-v1-1", "solomachine-v1", 1, true},
{"valid large sequence", types.FormatClientIdentifier("tendermint", math.MaxUint64), "tendermint", math.MaxUint64, true},
{"valid short client type", "t-0", "t", 0, true},
{"valid 0", "tendermint-0", "tendermint", 0, nil},
{"valid 1", "tendermint-1", "tendermint", 1, nil},
{"valid solemachine", "solomachine-v1-1", "solomachine-v1", 1, nil},
{"valid large sequence", types.FormatClientIdentifier("tendermint", math.MaxUint64), "tendermint", math.MaxUint64, nil},
{"valid short client type", "t-0", "t", 0, nil},
// one above uint64 max
{"invalid uint64", "tendermint-18446744073709551616", "tendermint", 0, false},
{"invalid uint64", "tendermint-18446744073709551616", "tendermint", 0, errors.New("failed to parse client identifier sequence")},
// uint64 == 20 characters
{"invalid large sequence", "tendermint-2345682193567182931243", "tendermint", 0, false},
{"invalid newline in clientID", "tendermin\nt-1", "tendermin\nt", 0, false},
{"invalid newline character before dash", "tendermint\n-1", "tendermint", 0, false},
{"missing dash", "tendermint0", "tendermint", 0, false},
{"blank id", " ", " ", 0, false},
{"empty id", "", "", 0, false},
{"negative sequence", "tendermint--1", "tendermint", 0, false},
{"invalid format", "tendermint-tm", "tendermint", 0, false},
{"empty clientype", " -100", "tendermint", 0, false},
{"with in the middle tabs", "a\t\t\t-100", "tendermint", 0, false},
{"leading tabs", "\t\t\ta-100", "tendermint", 0, false},
{"with whitespace", " a-100", "tendermint", 0, false},
{"leading hyphens", "-----a-100", "tendermint", 0, false},
{"with slash", "tendermint/-100", "tendermint", 0, false},
{"non-ASCII:: emoji", "🚨😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎-100", "tendermint", 0, false},
{"non-ASCII:: others", "世界-100", "tendermint", 0, false},
{"invalid large sequence", "tendermint-2345682193567182931243", "tendermint", 0, host.ErrInvalidID},
{"invalid newline in clientID", "tendermin\nt-1", "tendermin\nt", 0, host.ErrInvalidID},
{"invalid newline character before dash", "tendermint\n-1", "tendermint", 0, host.ErrInvalidID},
{"missing dash", "tendermint0", "tendermint", 0, host.ErrInvalidID},
{"blank id", " ", " ", 0, host.ErrInvalidID},
{"empty id", "", "", 0, host.ErrInvalidID},
{"negative sequence", "tendermint--1", "tendermint", 0, host.ErrInvalidID},
{"invalid format", "tendermint-tm", "tendermint", 0, host.ErrInvalidID},
{"empty clientype", " -100", "tendermint", 0, host.ErrInvalidID},
{"with in the middle tabs", "a\t\t\t-100", "tendermint", 0, host.ErrInvalidID},
{"leading tabs", "\t\t\ta-100", "tendermint", 0, host.ErrInvalidID},
{"with whitespace", " a-100", "tendermint", 0, host.ErrInvalidID},
{"leading hyphens", "-----a-100", "tendermint", 0, host.ErrInvalidID},
{"with slash", "tendermint/-100", "tendermint", 0, host.ErrInvalidID},
{"non-ASCII:: emoji", "🚨😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎😎-100", "tendermint", 0, host.ErrInvalidID},
{"non-ASCII:: others", "世界-100", "tendermint", 0, host.ErrInvalidID},
}

for _, tc := range testCases {
Expand All @@ -51,14 +53,15 @@ func TestParseClientIdentifier(t *testing.T) {
valid := types.IsValidClientID(tc.clientID)
require.Equal(t, tc.expSeq, seq, tc.clientID)

if tc.expPass {
if tc.expErr == nil {
require.NoError(t, err, tc.name)
require.True(t, valid)
require.Equal(t, tc.clientType, clientType)
} else {
require.Error(t, err, tc.name, tc.clientID)
require.False(t, valid)
require.Equal(t, "", clientType)
require.ErrorContains(t, err, tc.expErr.Error())
}
})
}
Expand Down
Loading