Skip to content

Commit d7b6d1c

Browse files
authored
[Tss] fix router (#207)
* add isInternal in Content interface * fix error types
1 parent f4e856c commit d7b6d1c

File tree

8 files changed

+35
-4
lines changed

8 files changed

+35
-4
lines changed

x/bandtss/keeper/msg_server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ func (k msgServer) RequestSignature(
143143
}
144144

145145
content := req.GetContent()
146-
if content.OrderRoute() == types.RouterKey && content.OrderType() == types.GroupTransitionPath {
147-
return nil, types.ErrInvalidRequestSignature.Wrapf(
148-
"invalid request order route: %s order type: %s", content.OrderRoute(), content.OrderType())
146+
if content.IsInternal() {
147+
return nil, types.ErrContentNotAllowed.Wrapf(
148+
"order route: %s, type: %s", content.OrderRoute(), content.OrderType(),
149+
)
149150
}
150151

151152
// Execute the handler to process the request.

x/bandtss/keeper/msg_server_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,23 @@ func (s *AppTestSuite) TestSuccessRequestSignatureOnCurrentGroup() {
446446
s.Require().Equal(bandtssSigningID, bandtssSigningIDMapping)
447447
}
448448

449+
func (s *AppTestSuite) TestFailRequestSignatureInternalMessage() {
450+
ctx, msgSrvr, k := s.ctx, s.msgSrvr, s.app.BandtssKeeper
451+
452+
_ = s.SetupNewGroup(5, 3)
453+
k.DeleteGroupTransition(ctx)
454+
455+
msg, err := types.NewMsgRequestSignature(
456+
types.NewGroupTransitionSignatureOrder([]byte("msg")),
457+
sdk.NewCoins(sdk.NewInt64Coin("uband", 100)),
458+
bandtesting.FeePayer.Address,
459+
)
460+
s.Require().NoError(err)
461+
462+
_, err = msgSrvr.RequestSignature(ctx, msg)
463+
s.Require().ErrorIs(err, types.ErrContentNotAllowed)
464+
}
465+
449466
func (s *AppTestSuite) TestSuccessRequestSignatureOnIncomingGroup() {
450467
ctx, msgSrvr := s.ctx, s.msgSrvr
451468

x/bandtss/types/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
ErrMemberAlreadyActive = errorsmod.Register(ModuleName, 11, "member already active")
1717
ErrMemberDuplicate = errorsmod.Register(ModuleName, 12, "duplicated member found within the list")
1818
ErrInvalidSigningThreshold = errorsmod.Register(ModuleName, 13, "invalid signing threshold number")
19-
ErrInvalidRequestSignature = errorsmod.Register(ModuleName, 14, "request signature is invalid")
19+
ErrContentNotAllowed = errorsmod.Register(ModuleName, 14, "content not allowed")
2020
ErrInvalidIncomingGroup = errorsmod.Register(ModuleName, 15, "invalid incoming group")
2121
ErrNoActiveGroup = errorsmod.Register(ModuleName, 16, "no active group supported")
2222
ErrNoIncomingGroup = errorsmod.Register(ModuleName, 17, "no incoming group")

x/bandtss/types/signature_order.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ func (rs *GroupTransitionSignatureOrder) OrderType() string {
2929
return GroupTransitionPath
3030
}
3131

32+
// IsInternal returns true for GroupTransitionSignatureOrder (internal module-based request signature).
33+
func (rs *GroupTransitionSignatureOrder) IsInternal() bool { return true }
34+
3235
// ValidateBasic performs no-op for this type
3336
func (rs *GroupTransitionSignatureOrder) ValidateBasic() error { return nil }
3437

x/feeds/types/signature_order.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func (f *FeedsSignatureOrder) OrderType() string {
3030
return SignatureOrderTypeFeeds
3131
}
3232

33+
// IsInternal returns false for FeedsSignatureOrder (allow user to submit this content type).
34+
func (f *FeedsSignatureOrder) IsInternal() bool { return false }
35+
3336
// ValidateBasic validates the request's title and description of the request signature
3437
func (f *FeedsSignatureOrder) ValidateBasic() error {
3538
if len(f.SignalIDs) == 0 {

x/oracle/types/signature_order.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func (o *OracleResultSignatureOrder) OrderType() string {
3030
return SignatureOrderTypeOracleResult
3131
}
3232

33+
// IsInternal returns false for OracleResultSignatureOrder (allow user to submit this content type).
34+
func (o *OracleResultSignatureOrder) IsInternal() bool { return false }
35+
3336
// ValidateBasic validates the request's title and description of the request signature
3437
func (o *OracleResultSignatureOrder) ValidateBasic() error {
3538
if o.RequestID == 0 {

x/tss/types/content.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func wrapHandler(path string, handler Handler) Handler {
8383
type Content interface {
8484
OrderRoute() string
8585
OrderType() string
86+
IsInternal() bool
8687

8788
ValidateBasic() error
8889
String() string

x/tss/types/signature_order.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ func (rs *TextSignatureOrder) OrderType() string {
2020
return SignatureOrderTypeText
2121
}
2222

23+
// IsInternal returns false for TextSignatureOrder (allow user to submit this content type).
24+
func (rs *TextSignatureOrder) IsInternal() bool { return false }
25+
2326
// ValidateBasic performs no-op for this type
2427
func (rs *TextSignatureOrder) ValidateBasic() error { return nil }

0 commit comments

Comments
 (0)