Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions x/dex/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,26 @@ func TestMsgMultiHopSwapValidate(t *testing.T) {
},
types.ErrZeroExitPrice,
},
{
"single hop",
types.MsgMultiHopSwap{
Creator: sample.AccAddress(),
Receiver: sample.AccAddress(),
Routes: []*types.MultiHopRoute{{Hops: []string{"TokenA"}}},
AmountIn: sdkmath.OneInt(),
},
types.ErrRouteWithoutExitToken,
},
{
"no hops",
types.MsgMultiHopSwap{
Creator: sample.AccAddress(),
Receiver: sample.AccAddress(),
Routes: []*types.MultiHopRoute{{Hops: []string{}}},
AmountIn: sdkmath.OneInt(),
},
types.ErrRouteWithoutExitToken,
},
}

for _, tt := range tests {
Expand Down
8 changes: 4 additions & 4 deletions x/dex/types/message_multi_hop_swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ func validateRoutes(routes []*MultiHopRoute) error {
}

func validateHops(hops []string) error {
// check that route has at least entry and exit token
if len(hops) < 2 {
return ErrRouteWithoutExitToken
}
existingHops := make(map[string]bool, len(hops))
for _, hop := range hops {
// check that route has at least entry and exit token
if len(hop) < 2 {
return ErrRouteWithoutExitToken
}
// check if we find cycles in the route
if existingHops[hop] {
return ErrCycleInHops
Expand Down
Loading