github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/24-host/parse_test.go (about) 1 package host_test 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 connectiontypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/types" 10 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 11 ) 12 13 func TestParseIdentifier(t *testing.T) { 14 testCases := []struct { 15 name string 16 identifier string 17 prefix string 18 expSeq uint64 19 expPass bool 20 }{ 21 {"valid 0", "connection-0", "connection-", 0, true}, 22 {"valid 1", "connection-1", "connection-", 1, true}, 23 {"valid large sequence", connectiontypes.FormatConnectionIdentifier(math.MaxUint64), "connection-", math.MaxUint64, true}, 24 // one above uint64 max 25 {"invalid uint64", "connection-18446744073709551616", "connection-", 0, false}, 26 // uint64 == 20 characters 27 {"invalid large sequence", "connection-2345682193567182931243", "connection-", 0, false}, 28 {"capital prefix", "Connection-0", "connection-", 0, false}, 29 {"double prefix", "connection-connection-0", "connection-", 0, false}, 30 {"doesn't have prefix", "connection-0", "prefix", 0, false}, 31 {"missing dash", "connection0", "connection-", 0, false}, 32 {"blank id", " ", "connection-", 0, false}, 33 {"empty id", "", "connection-", 0, false}, 34 {"negative sequence", "connection--1", "connection-", 0, false}, 35 } 36 37 for _, tc := range testCases { 38 39 seq, err := host.ParseIdentifier(tc.identifier, tc.prefix) 40 require.Equal(t, tc.expSeq, seq) 41 42 if tc.expPass { 43 require.NoError(t, err, tc.name) 44 } else { 45 require.Error(t, err, tc.name) 46 } 47 } 48 }