diff --git a/x/knowledge/types/errors.go b/x/knowledge/types/errors.go index 00ba8828..69cb2d11 100644 --- a/x/knowledge/types/errors.go +++ b/x/knowledge/types/errors.go @@ -9,4 +9,5 @@ import ( // x/knowledge module sentinel errors. var ( ErrEntityAlreadyExists = sdkerrors.Register(ModuleName, 1100, "entity already exists") + ErrInvalidURI = sdkerrors.Register(ModuleName, 1101, "invalid uri") ) diff --git a/x/knowledge/types/message_trigger_service.go b/x/knowledge/types/message_trigger_service.go index e4ded6dd..32854f87 100644 --- a/x/knowledge/types/message_trigger_service.go +++ b/x/knowledge/types/message_trigger_service.go @@ -1,6 +1,8 @@ package types import ( + "net/url" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -42,5 +44,9 @@ func (msg *MsgTriggerService) ValidateBasic() error { if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address (%s)", err) } + + if _, err := url.Parse(msg.Uri); err != nil { + return sdkerrors.Wrapf(ErrInvalidURI, "invalid service uri (%s)", err) + } return nil } diff --git a/x/knowledge/types/message_trigger_service_test.go b/x/knowledge/types/message_trigger_service_test.go index acfc6fd0..966bfa7d 100644 --- a/x/knowledge/types/message_trigger_service_test.go +++ b/x/knowledge/types/message_trigger_service_test.go @@ -26,6 +26,20 @@ func TestMsgTriggerService_ValidateBasic(t *testing.T) { Creator: sample.AccAddress(), }, }, + { + name: "invalid uri", + msg: MsgTriggerService{ + Creator: sample.AccAddress(), + Uri: "é:// ", + }, + err: ErrInvalidURI, + }, { + name: "valid uri", + msg: MsgTriggerService{ + Creator: sample.AccAddress(), + Uri: "okp4:service#coucou?target=okp4", + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {