diff --git a/x/session/simulation/decoder.go b/x/session/simulation/decoder.go index f28b69e8..f0bb4539 100644 --- a/x/session/simulation/decoder.go +++ b/x/session/simulation/decoder.go @@ -49,7 +49,7 @@ func NewDecoderStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string { cdc.MustUnmarshalBinaryBare(kvB.Value, &activeSessionB) return fmt.Sprintf("%s\n%s", &activeSessionA, &activeSessionB) - case bytes.Equal(kvA.Key[:1], types.ActiveSessionAtKeyPrefix): + case bytes.Equal(kvA.Key[:1], types.InactiveSessionAtKeyPrefix): var activeSessionA, activeSessionB protobuf.BoolValue cdc.MustUnmarshalBinaryBare(kvA.Value, &activeSessionA) cdc.MustUnmarshalBinaryBare(kvB.Value, &activeSessionB) diff --git a/x/subscription/alias.go b/x/subscription/alias.go new file mode 100644 index 00000000..1b28cd2c --- /dev/null +++ b/x/subscription/alias.go @@ -0,0 +1,175 @@ +// aliases generated for the following subdirectories: +// ALIASGEN: github.com/sentinel-official/hub/x/subscription/keeper +// ALIASGEN: github.com/sentinel-official/hub/x/subscription/types +package subscription + +import ( + "github.com/sentinel-official/hub/x/subscription/keeper" + "github.com/sentinel-official/hub/x/subscription/types" +) + +const ( + ModuleName = types.ModuleName + QuerierRoute = types.QuerierRoute + DefaultInactiveDuration = types.DefaultInactiveDuration +) + +var ( + // functions aliases + NewKeeper = keeper.NewKeeper + NewMsgServiceServer = keeper.NewMsgServiceServer + NewQueryServiceServer = keeper.NewQueryServiceServer + RegisterLegacyAminoCodec = types.RegisterLegacyAminoCodec + RegisterInterfaces = types.RegisterInterfaces + NewGenesisState = types.NewGenesisState + DefaultGenesisState = types.DefaultGenesisState + SubscriptionKey = types.SubscriptionKey + GetSubscriptionForNodeKeyPrefix = types.GetSubscriptionForNodeKeyPrefix + SubscriptionForNodeKey = types.SubscriptionForNodeKey + GetSubscriptionForPlanKeyPrefix = types.GetSubscriptionForPlanKeyPrefix + SubscriptionForPlanKey = types.SubscriptionForPlanKey + GetActiveSubscriptionForAddressKeyPrefix = types.GetActiveSubscriptionForAddressKeyPrefix + ActiveSubscriptionForAddressKey = types.ActiveSubscriptionForAddressKey + GetInactiveSubscriptionForAddressKeyPrefix = types.GetInactiveSubscriptionForAddressKeyPrefix + InactiveSubscriptionForAddressKey = types.InactiveSubscriptionForAddressKey + GetInactiveSubscriptionAtKeyPrefix = types.GetInactiveSubscriptionAtKeyPrefix + InactiveSubscriptionAtKey = types.InactiveSubscriptionAtKey + GetQuotaKeyPrefix = types.GetQuotaKeyPrefix + QuotaKey = types.QuotaKey + IDFromSubscriptionForNodeKey = types.IDFromSubscriptionForNodeKey + IDFromSubscriptionForPlanKey = types.IDFromSubscriptionForPlanKey + IDFromStatusSubscriptionForAddressKey = types.IDFromStatusSubscriptionForAddressKey + IDFromInactiveSubscriptionAtKey = types.IDFromInactiveSubscriptionAtKey + NewMsgSubscribeToNodeRequest = types.NewMsgSubscribeToNodeRequest + NewMsgSubscribeToPlanRequest = types.NewMsgSubscribeToPlanRequest + NewMsgCancelRequest = types.NewMsgCancelRequest + NewMsgAddQuotaRequest = types.NewMsgAddQuotaRequest + NewMsgUpdateQuotaRequest = types.NewMsgUpdateQuotaRequest + NewMsgServiceClient = types.NewMsgServiceClient + RegisterMsgServiceServer = types.RegisterMsgServiceServer + NewParams = types.NewParams + DefaultParams = types.DefaultParams + ParamsKeyTable = types.ParamsKeyTable + NewQuerySubscriptionRequest = types.NewQuerySubscriptionRequest + NewQuerySubscriptionsRequest = types.NewQuerySubscriptionsRequest + NewQuerySubscriptionsForNodeRequest = types.NewQuerySubscriptionsForNodeRequest + NewQuerySubscriptionsForPlanRequest = types.NewQuerySubscriptionsForPlanRequest + NewQuerySubscriptionsForAddressRequest = types.NewQuerySubscriptionsForAddressRequest + NewQueryQuotaRequest = types.NewQueryQuotaRequest + NewQueryQuotasRequest = types.NewQueryQuotasRequest + NewQueryServiceClient = types.NewQueryServiceClient + RegisterQueryServiceServer = types.RegisterQueryServiceServer + RegisterQueryServiceHandlerServer = types.RegisterQueryServiceHandlerServer + RegisterQueryServiceHandlerFromEndpoint = types.RegisterQueryServiceHandlerFromEndpoint + RegisterQueryServiceHandler = types.RegisterQueryServiceHandler + RegisterQueryServiceHandlerClient = types.RegisterQueryServiceHandlerClient + + // variable aliases + ModuleCdc = types.ModuleCdc + ErrorMarshal = types.ErrorMarshal + ErrorUnmarshal = types.ErrorUnmarshal + ErrorUnknownMsgType = types.ErrorUnknownMsgType + ErrorUnknownQueryType = types.ErrorUnknownQueryType + ErrorInvalidFieldFrom = types.ErrorInvalidFieldFrom + ErrorPlanDoesNotExist = types.ErrorPlanDoesNotExist + ErrorNodeDoesNotExist = types.ErrorNodeDoesNotExist + ErrorUnauthorized = types.ErrorUnauthorized + ErrorInvalidPlanStatus = types.ErrorInvalidPlanStatus + ErrorPriceDoesNotExist = types.ErrorPriceDoesNotExist + ErrorInvalidNodeStatus = types.ErrorInvalidNodeStatus + ErrorSubscriptionDoesNotExist = types.ErrorSubscriptionDoesNotExist + ErrorInvalidSubscriptionStatus = types.ErrorInvalidSubscriptionStatus + ErrorCanNotSubscribe = types.ErrorCanNotSubscribe + ErrorInvalidQuota = types.ErrorInvalidQuota + ErrorDuplicateQuota = types.ErrorDuplicateQuota + ErrorQuotaDoesNotExist = types.ErrorQuotaDoesNotExist + ErrorCanNotAddQuota = types.ErrorCanNotAddQuota + ErrorInvalidFieldId = types.ErrorInvalidFieldId + ErrorInvalidFieldAddress = types.ErrorInvalidFieldAddress + ErrorInvalidFieldBytes = types.ErrorInvalidFieldBytes + ErrorInvalidFieldDenom = types.ErrorInvalidFieldDenom + ErrorInvalidFieldDeposit = types.ErrorInvalidFieldDeposit + ErrInvalidLengthEvents = types.ErrInvalidLengthEvents + ErrIntOverflowEvents = types.ErrIntOverflowEvents + ErrUnexpectedEndOfGroupEvents = types.ErrUnexpectedEndOfGroupEvents + ErrInvalidLengthGenesis = types.ErrInvalidLengthGenesis + ErrIntOverflowGenesis = types.ErrIntOverflowGenesis + ErrUnexpectedEndOfGroupGenesis = types.ErrUnexpectedEndOfGroupGenesis + ParamsSubspace = types.ParamsSubspace + RouterKey = types.RouterKey + StoreKey = types.StoreKey + EventModuleName = types.EventModuleName + CountKey = types.CountKey + SubscriptionKeyPrefix = types.SubscriptionKeyPrefix + SubscriptionForNodeKeyPrefix = types.SubscriptionForNodeKeyPrefix + SubscriptionForPlanKeyPrefix = types.SubscriptionForPlanKeyPrefix + ActiveSubscriptionForAddressKeyPrefix = types.ActiveSubscriptionForAddressKeyPrefix + InactiveSubscriptionForAddressKeyPrefix = types.InactiveSubscriptionForAddressKeyPrefix + InactiveSubscriptionAtKeyPrefix = types.InactiveSubscriptionAtKeyPrefix + QuotaKeyPrefix = types.QuotaKeyPrefix + ErrInvalidLengthMsg = types.ErrInvalidLengthMsg + ErrIntOverflowMsg = types.ErrIntOverflowMsg + ErrUnexpectedEndOfGroupMsg = types.ErrUnexpectedEndOfGroupMsg + KeyInactiveDuration = types.KeyInactiveDuration + ErrInvalidLengthParams = types.ErrInvalidLengthParams + ErrIntOverflowParams = types.ErrIntOverflowParams + ErrUnexpectedEndOfGroupParams = types.ErrUnexpectedEndOfGroupParams + ErrInvalidLengthQuerier = types.ErrInvalidLengthQuerier + ErrIntOverflowQuerier = types.ErrIntOverflowQuerier + ErrUnexpectedEndOfGroupQuerier = types.ErrUnexpectedEndOfGroupQuerier + ErrInvalidLengthQuota = types.ErrInvalidLengthQuota + ErrIntOverflowQuota = types.ErrIntOverflowQuota + ErrUnexpectedEndOfGroupQuota = types.ErrUnexpectedEndOfGroupQuota + ErrInvalidLengthSubscription = types.ErrInvalidLengthSubscription + ErrIntOverflowSubscription = types.ErrIntOverflowSubscription + ErrUnexpectedEndOfGroupSubscription = types.ErrUnexpectedEndOfGroupSubscription +) + +type ( + Keeper = keeper.Keeper + EventModule = types.EventModule + EventSetSubscriptionCount = types.EventSetSubscriptionCount + EventSubscribeToNode = types.EventSubscribeToNode + EventSubscribeToPlan = types.EventSubscribeToPlan + EventCancelSubscription = types.EventCancelSubscription + EventAddQuota = types.EventAddQuota + EventUpdateQuota = types.EventUpdateQuota + GenesisSubscriptions = types.GenesisSubscriptions + GenesisSubscription = types.GenesisSubscription + GenesisState = types.GenesisState + MsgSubscribeToNodeRequest = types.MsgSubscribeToNodeRequest + MsgSubscribeToPlanRequest = types.MsgSubscribeToPlanRequest + MsgCancelRequest = types.MsgCancelRequest + MsgAddQuotaRequest = types.MsgAddQuotaRequest + MsgUpdateQuotaRequest = types.MsgUpdateQuotaRequest + MsgSubscribeToNodeResponse = types.MsgSubscribeToNodeResponse + MsgSubscribeToPlanResponse = types.MsgSubscribeToPlanResponse + MsgCancelResponse = types.MsgCancelResponse + MsgAddQuotaResponse = types.MsgAddQuotaResponse + MsgUpdateQuotaResponse = types.MsgUpdateQuotaResponse + MsgServiceClient = types.MsgServiceClient + MsgServiceServer = types.MsgServiceServer + UnimplementedMsgServiceServer = types.UnimplementedMsgServiceServer + Params = types.Params + QuerySubscriptionsRequest = types.QuerySubscriptionsRequest + QuerySubscriptionsForNodeRequest = types.QuerySubscriptionsForNodeRequest + QuerySubscriptionsForPlanRequest = types.QuerySubscriptionsForPlanRequest + QuerySubscriptionsForAddressRequest = types.QuerySubscriptionsForAddressRequest + QuerySubscriptionRequest = types.QuerySubscriptionRequest + QueryQuotaRequest = types.QueryQuotaRequest + QueryQuotasRequest = types.QueryQuotasRequest + QuerySubscriptionsResponse = types.QuerySubscriptionsResponse + QuerySubscriptionsForNodeResponse = types.QuerySubscriptionsForNodeResponse + QuerySubscriptionsForPlanResponse = types.QuerySubscriptionsForPlanResponse + QuerySubscriptionsForAddressResponse = types.QuerySubscriptionsForAddressResponse + QuerySubscriptionResponse = types.QuerySubscriptionResponse + QueryQuotaResponse = types.QueryQuotaResponse + QueryQuotasResponse = types.QueryQuotasResponse + QueryServiceClient = types.QueryServiceClient + QueryServiceServer = types.QueryServiceServer + UnimplementedQueryServiceServer = types.UnimplementedQueryServiceServer + Quotas = types.Quotas + Quota = types.Quota + Subscriptions = types.Subscriptions + Subscription = types.Subscription +) diff --git a/x/subscription/types/errors.go b/x/subscription/types/errors.go index 2b091453..ff43e37e 100644 --- a/x/subscription/types/errors.go +++ b/x/subscription/types/errors.go @@ -5,18 +5,27 @@ import ( ) var ( - ErrorInvalidField = errors.Register(ModuleName, 101, "invalid field") - ErrorPlanDoesNotExist = errors.Register(ModuleName, 102, "plan does not exist") - ErrorNodeDoesNotExist = errors.Register(ModuleName, 103, "node does not exist") - ErrorUnauthorized = errors.Register(ModuleName, 104, "unauthorized") - ErrorInvalidPlanStatus = errors.Register(ModuleName, 105, "invalid plan status") - ErrorPriceDoesNotExist = errors.Register(ModuleName, 106, "price does not exist") - ErrorInvalidNodeStatus = errors.Register(ModuleName, 107, "invalid node status") - ErrorSubscriptionDoesNotExist = errors.Register(ModuleName, 108, "subscription does not exist") - ErrorInvalidSubscriptionStatus = errors.Register(ModuleName, 109, "invalid subscription status") - ErrorCanNotSubscribe = errors.Register(ModuleName, 110, "can not subscribe") - ErrorInvalidQuota = errors.Register(ModuleName, 111, "invalid quota") - ErrorDuplicateQuota = errors.Register(ModuleName, 112, "duplicate quota") - ErrorQuotaDoesNotExist = errors.Register(ModuleName, 113, "quota does not exist") - ErrorCanNotAddQuota = errors.Register(ModuleName, 114, "can not add quota") + ErrorMarshal = errors.Register(ModuleName, 101, "error occurred while marshalling") + ErrorUnmarshal = errors.Register(ModuleName, 102, "error occurred while unmarshalling") + ErrorUnknownMsgType = errors.Register(ModuleName, 103, "unknown message type") + ErrorUnknownQueryType = errors.Register(ModuleName, 104, "unknown query type") + ErrorInvalidFieldFrom = errors.Register(ModuleName, 105, "invalid value for field from; expected a valid address") + ErrorPlanDoesNotExist = errors.Register(ModuleName, 106, "plan does not exist") + ErrorNodeDoesNotExist = errors.Register(ModuleName, 107, "node does not exist") + ErrorUnauthorized = errors.Register(ModuleName, 108, "unauthorized") + ErrorInvalidPlanStatus = errors.Register(ModuleName, 109, "invalid plan status") + ErrorPriceDoesNotExist = errors.Register(ModuleName, 110, "price does not exist") + ErrorInvalidNodeStatus = errors.Register(ModuleName, 111, "invalid node status") + ErrorSubscriptionDoesNotExist = errors.Register(ModuleName, 112, "subscription does not exist") + ErrorInvalidSubscriptionStatus = errors.Register(ModuleName, 113, "invalid subscription status") + ErrorCanNotSubscribe = errors.Register(ModuleName, 114, "can not subscribe") + ErrorInvalidQuota = errors.Register(ModuleName, 115, "invalid quota") + ErrorDuplicateQuota = errors.Register(ModuleName, 116, "duplicate quota") + ErrorQuotaDoesNotExist = errors.Register(ModuleName, 117, "quota does not exist") + ErrorCanNotAddQuota = errors.Register(ModuleName, 118, "can not add quota") + ErrorInvalidFieldId = errors.Register(ModuleName, 119, "invalid value for field id; expected a value greater than 0") + ErrorInvalidFieldAddress = errors.Register(ModuleName, 120, "invalid value for field address; expected a valid address") + ErrorInvalidFieldBytes = errors.Register(ModuleName, 121, "invalid value for field bytes; expected a positive integer value") + ErrorInvalidFieldDenom = errors.Register(ModuleName, 122, "invalid value for field denom; expected a valid denom") + ErrorInvalidFieldDeposit = errors.Register(ModuleName, 123, "invalid value for field deposit; expected a positive integer value") ) diff --git a/x/subscription/types/msg.go b/x/subscription/types/msg.go index 006c2042..31b2c45f 100644 --- a/x/subscription/types/msg.go +++ b/x/subscription/types/msg.go @@ -4,7 +4,6 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" hubtypes "github.com/sentinel-official/hub/types" ) @@ -36,17 +35,17 @@ func (m *MsgSubscribeToNodeRequest) Type() string { func (m *MsgSubscribeToNodeRequest) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.From); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "from") + return ErrorInvalidFieldFrom } // Address should be valid if _, err := hubtypes.NodeAddressFromBech32(m.Address); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "address") + return ErrorInvalidFieldAddress } // Deposit should be valid and positive if !m.Deposit.IsValid() || !m.Deposit.IsPositive() { - return errors.Wrapf(ErrorInvalidField, "%s", "deposit") + return ErrorInvalidFieldDeposit } return nil @@ -83,17 +82,18 @@ func (m *MsgSubscribeToPlanRequest) Type() string { func (m *MsgSubscribeToPlanRequest) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.From); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "from") + return ErrorInvalidFieldFrom } // Id shouldn't be zero if m.Id == 0 { - return errors.Wrapf(ErrorInvalidField, "%s", "id") + return ErrorInvalidFieldId } // Denom should be valid - if err := sdk.ValidateDenom(m.Denom); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "denom") + err := sdk.ValidateDenom(m.Denom) + if err != nil { + return ErrorInvalidFieldDenom } return nil @@ -129,12 +129,12 @@ func (m *MsgCancelRequest) Type() string { func (m *MsgCancelRequest) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.From); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "from") + return ErrorInvalidFieldFrom } // Id shouldn't be zero if m.Id == 0 { - return errors.Wrapf(ErrorInvalidField, "%s", "id") + return ErrorInvalidFieldId } return nil @@ -172,22 +172,22 @@ func (m *MsgAddQuotaRequest) Type() string { func (m *MsgAddQuotaRequest) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.From); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "from") + return ErrorInvalidFieldFrom } // Id shouldn't be zero if m.Id == 0 { - return errors.Wrapf(ErrorInvalidField, "%s", "id") + return ErrorInvalidFieldId } // Address should be valid if _, err := sdk.AccAddressFromBech32(m.Address); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "address") + return ErrorInvalidFieldAddress } // Bytes should be positive if !m.Bytes.IsPositive() { - return errors.Wrapf(ErrorInvalidField, "%s", "bytes") + return ErrorInvalidFieldBytes } return nil @@ -225,22 +225,22 @@ func (m *MsgUpdateQuotaRequest) Type() string { func (m *MsgUpdateQuotaRequest) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.From); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "from") + return ErrorInvalidFieldFrom } // Id shouldn't be zero if m.Id == 0 { - return errors.Wrapf(ErrorInvalidField, "%s", "id") + return ErrorInvalidFieldId } // Address shouldn be valid if _, err := sdk.AccAddressFromBech32(m.Address); err != nil { - return errors.Wrapf(ErrorInvalidField, "%s", "address") + return ErrorInvalidFieldAddress } // Bytes should be positive if !m.Bytes.IsPositive() { - return errors.Wrapf(ErrorInvalidField, "%s", "bytes") + return ErrorInvalidFieldBytes } return nil diff --git a/x/subscription/types/msg_test.go b/x/subscription/types/msg_test.go new file mode 100644 index 00000000..8d6a0e4b --- /dev/null +++ b/x/subscription/types/msg_test.go @@ -0,0 +1,170 @@ +package types + +import ( + "errors" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + hubtypes "github.com/sentinel-official/hub/types" +) + +func TestMsgAddQuotaRequest_ValidateBasic(t *testing.T) { + correctAddress, err := sdk.AccAddressFromBech32("sent1grdunxx5jxd0ja75wt508sn6v39p70hhw53zs8") + if err != nil { + t.Errorf("invalid address: %s", err) + } + + tests := []struct { + name string + m *MsgAddQuotaRequest + want error + }{ + {"nil from address", NewMsgAddQuotaRequest(nil, 0, nil, sdk.NewInt(0)), ErrorInvalidFieldFrom}, + {"empty from address", NewMsgAddQuotaRequest(sdk.AccAddress{}, 0, nil, sdk.NewInt(0)), ErrorInvalidFieldFrom}, + {"zero id", NewMsgAddQuotaRequest(correctAddress, 0, nil, sdk.NewInt(0)), ErrorInvalidFieldId}, + {"nil address", NewMsgAddQuotaRequest(correctAddress, 10, nil, sdk.NewInt(0)), ErrorInvalidFieldAddress}, + {"empty address", NewMsgAddQuotaRequest(correctAddress, 10, sdk.AccAddress{}, sdk.NewInt(0)), ErrorInvalidFieldAddress}, + {"empty bytes", NewMsgAddQuotaRequest(correctAddress, 10, sdk.AccAddress{}, sdk.Int{}), ErrorInvalidFieldAddress}, + {"zero bytes", NewMsgAddQuotaRequest(correctAddress, 10, correctAddress, sdk.NewInt(0)), ErrorInvalidFieldBytes}, + {"valid", NewMsgAddQuotaRequest(correctAddress, 10, correctAddress, sdk.NewInt(1000)), nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.m.ValidateBasic(); !errors.Is(err, tt.want) { + t.Errorf("ValidateBasic() = %s, want %s", err, tt.want) + } + }) + } +} + +func TestMsgUpdateQuotaRequest_ValidateBasic(t *testing.T) { + correctAddress, err := sdk.AccAddressFromBech32("sent1grdunxx5jxd0ja75wt508sn6v39p70hhw53zs8") + if err != nil { + t.Errorf("invalid address: %s", err) + } + + tests := []struct { + name string + m *MsgUpdateQuotaRequest + want error + }{ + {"nil from address", NewMsgUpdateQuotaRequest(nil, 0, nil, sdk.NewInt(0)), ErrorInvalidFieldFrom}, + {"empty from address", NewMsgUpdateQuotaRequest(sdk.AccAddress{}, 0, nil, sdk.NewInt(0)), ErrorInvalidFieldFrom}, + {"zero id", NewMsgUpdateQuotaRequest(correctAddress, 0, nil, sdk.NewInt(0)), ErrorInvalidFieldId}, + {"nil address", NewMsgUpdateQuotaRequest(correctAddress, 10, nil, sdk.NewInt(0)), ErrorInvalidFieldAddress}, + {"empty address", NewMsgUpdateQuotaRequest(correctAddress, 10, sdk.AccAddress{}, sdk.NewInt(0)), ErrorInvalidFieldAddress}, + {"empty bytes", NewMsgUpdateQuotaRequest(correctAddress, 10, sdk.AccAddress{}, sdk.Int{}), ErrorInvalidFieldAddress}, + {"zero bytes", NewMsgUpdateQuotaRequest(correctAddress, 10, correctAddress, sdk.NewInt(0)), ErrorInvalidFieldBytes}, + {"valid", NewMsgUpdateQuotaRequest(correctAddress, 10, correctAddress, sdk.NewInt(1000)), nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.m.ValidateBasic(); !errors.Is(err, tt.want) { + t.Errorf("ValidateBasic() = %s, want %s", err, tt.want) + } + }) + } +} + +func TestMsgCancelRequest_ValidateBasic(t *testing.T) { + correctAddress, err := sdk.AccAddressFromBech32("sent1grdunxx5jxd0ja75wt508sn6v39p70hhw53zs8") + if err != nil { + t.Errorf("invalid address: %s", err) + } + + tests := []struct { + name string + m *MsgCancelRequest + want error + }{ + {"nil from address", NewMsgCancelRequest(nil, 0), ErrorInvalidFieldFrom}, + {"empty from address", NewMsgCancelRequest(sdk.AccAddress{}, 0), ErrorInvalidFieldFrom}, + {"zero id", NewMsgCancelRequest(correctAddress, 0), ErrorInvalidFieldId}, + {"valid", NewMsgCancelRequest(correctAddress, 10), nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.m.ValidateBasic(); !errors.Is(err, tt.want) { + t.Errorf("ValidateBasic() = %s, want %s", err, tt.want) + } + }) + } +} + +func TestMsgSubscribeToNodeRequest_ValidateBasic(t *testing.T) { + correctAddress, err := sdk.AccAddressFromBech32("sent1grdunxx5jxd0ja75wt508sn6v39p70hhw53zs8") + if err != nil { + t.Errorf("invalid address: %s", err) + } + + nodeAddress, err := hubtypes.NodeAddressFromBech32("sentnode1grdunxx5jxd0ja75wt508sn6v39p70hhczsm43") + if err != nil { + t.Errorf("invalid node address: %s", err) + } + + coinWithWrongDenom := sdk.Coin{ + Denom: "wrongdenom", + Amount: sdk.NewInt(0), + } + coinWithWrongAmount := sdk.Coin{ + Denom: "sent", + Amount: sdk.NewInt(-10), + } + validCoin := sdk.Coin{ + Denom: "sent", + Amount: sdk.NewInt(1000), + } + + tests := []struct { + name string + m *MsgSubscribeToNodeRequest + want error + }{ + {"nil from address", NewMsgSubscribeToNodeRequest(nil, nil, sdk.Coin{}), ErrorInvalidFieldFrom}, + {"empty from address", NewMsgSubscribeToNodeRequest(sdk.AccAddress{}, nil, sdk.Coin{}), ErrorInvalidFieldFrom}, + {"nil address", NewMsgSubscribeToNodeRequest(correctAddress, nil, sdk.Coin{}), ErrorInvalidFieldAddress}, + {"empty address", NewMsgSubscribeToNodeRequest(correctAddress, hubtypes.NodeAddress{}, sdk.Coin{}), ErrorInvalidFieldAddress}, + {"empty coin", NewMsgSubscribeToNodeRequest(correctAddress, nodeAddress, sdk.Coin{}), ErrorInvalidFieldDeposit}, + {"wrong coin denom", NewMsgSubscribeToNodeRequest(correctAddress, nodeAddress, coinWithWrongDenom), ErrorInvalidFieldDeposit}, + {"wrong coin amount", NewMsgSubscribeToNodeRequest(correctAddress, nodeAddress, coinWithWrongAmount), ErrorInvalidFieldDeposit}, + {"valid", NewMsgSubscribeToNodeRequest(correctAddress, nodeAddress, validCoin), nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.m.ValidateBasic(); !errors.Is(err, tt.want) { + t.Errorf("ValidateBasic() = %s, want %s", err, tt.want) + } + }) + } +} + +func TestMsgSubscribeToPlanRequest_ValidateBasic(t *testing.T) { + correctAddress, err := sdk.AccAddressFromBech32("sent1grdunxx5jxd0ja75wt508sn6v39p70hhw53zs8") + if err != nil { + t.Errorf("invalid address: %s", err) + } + + tests := []struct { + name string + m *MsgSubscribeToPlanRequest + want error + }{ + {"nil from address", NewMsgSubscribeToPlanRequest(nil, 0, ""), ErrorInvalidFieldFrom}, + {"empty from address", NewMsgSubscribeToPlanRequest(sdk.AccAddress{}, 0, ""), ErrorInvalidFieldFrom}, + {"zero id", NewMsgSubscribeToPlanRequest(correctAddress, 0, ""), ErrorInvalidFieldId}, + {"wrong denom", NewMsgSubscribeToPlanRequest(correctAddress, 10, "!!wrongdenom"), ErrorInvalidFieldDenom}, + {"valid", NewMsgSubscribeToPlanRequest(correctAddress, 10, "wrongdenom"), nil}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.m.ValidateBasic(); !errors.Is(err, tt.want) { + t.Errorf("ValidateBasic() = %s, want %s", err, tt.want) + } + }) + } +}