Skip to content

Commit c53423f

Browse files
authored
Merge pull request #1027 from neutron-org/fix/hop_validation
fix: hop length validation
2 parents d52ede9 + 775f237 commit c53423f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

x/dex/keeper/msg_server_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,26 @@ func TestMsgMultiHopSwapValidate(t *testing.T) {
25002500
},
25012501
types.ErrZeroExitPrice,
25022502
},
2503+
{
2504+
"single hop",
2505+
types.MsgMultiHopSwap{
2506+
Creator: sample.AccAddress(),
2507+
Receiver: sample.AccAddress(),
2508+
Routes: []*types.MultiHopRoute{{Hops: []string{"TokenA"}}},
2509+
AmountIn: sdkmath.OneInt(),
2510+
},
2511+
types.ErrRouteWithoutExitToken,
2512+
},
2513+
{
2514+
"no hops",
2515+
types.MsgMultiHopSwap{
2516+
Creator: sample.AccAddress(),
2517+
Receiver: sample.AccAddress(),
2518+
Routes: []*types.MultiHopRoute{{Hops: []string{}}},
2519+
AmountIn: sdkmath.OneInt(),
2520+
},
2521+
types.ErrRouteWithoutExitToken,
2522+
},
25032523
}
25042524

25052525
for _, tt := range tests {

x/dex/types/message_multi_hop_swap.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ func validateRoutes(routes []*MultiHopRoute) error {
114114
}
115115

116116
func validateHops(hops []string) error {
117+
// check that route has at least entry and exit token
118+
if len(hops) < 2 {
119+
return ErrRouteWithoutExitToken
120+
}
117121
existingHops := make(map[string]bool, len(hops))
118122
for _, hop := range hops {
119-
// check that route has at least entry and exit token
120-
if len(hop) < 2 {
121-
return ErrRouteWithoutExitToken
122-
}
123123
// check if we find cycles in the route
124124
if existingHops[hop] {
125125
return ErrCycleInHops

0 commit comments

Comments
 (0)