Skip to content

Commit

Permalink
add client test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanut Lertwarachai authored and Tanut Lertwarachai committed Jan 28, 2025
1 parent b21cca9 commit f595c7b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
6 changes: 3 additions & 3 deletions relayer/band/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (c *client) GetTunnel(ctx context.Context, tunnelID uint64) (*types.Tunnel,
}

if res.Tunnel.Route.TypeUrl != "/band.tunnel.v1beta1.TSSRoute" {
return nil, fmt.Errorf("unsupported route type: %s", res.Tunnel.Route.TypeUrl)
return nil, ErrUnsupportedRouteType(res.Tunnel.Route.TypeUrl)
}

// Extract route information
Expand All @@ -153,7 +153,7 @@ func (c *client) GetTunnel(ctx context.Context, tunnelID uint64) (*types.Tunnel,

tssRoute, ok := route.(*tunneltypes.TSSRoute)
if !ok {
return nil, fmt.Errorf("unsupported route type: %T", route)
return nil, ErrUnsupportedRouteType(route.String())
}

return types.NewTunnel(
Expand Down Expand Up @@ -199,7 +199,7 @@ func (c *client) GetTunnelPacket(ctx context.Context, tunnelID uint64, sequence

tssPacketReceipt, ok := packetReceipt.(*tunneltypes.TSSPacketReceipt)
if !ok {
return nil, fmt.Errorf("unsupported packet content type: %T", packetReceipt)
return nil, ErrUnsupportedPacketContentType(packetReceipt)
}
signingID := uint64(tssPacketReceipt.SigningID)

Expand Down
4 changes: 2 additions & 2 deletions relayer/band/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (s *ClientTestSuite) TestGetTunnel() {
{
name: "unsupported route type",
in: 2,
err: fmt.Errorf("unsupported route type"),
err: band.ErrUnsupportedRouteType(""),
preprocess: func(c context.Context) {
s.bandQueryClient.EXPECT().Tunnel(s.ctx, &tunneltypes.QueryTunnelRequest{
TunnelId: uint64(2),
Expand Down Expand Up @@ -286,7 +286,7 @@ func (s *ClientTestSuite) TestGetOtherTunnelPacket() {

// actual result
_, err = s.client.GetTunnelPacket(s.ctx, uint64(1), uint64(100))
s.Require().ErrorContains(err, "unsupported packet content type")
s.Require().ErrorContains(err, band.ErrUnsupportedPacketContentType(msg).Error())
}

func (s *ClientTestSuite) TestGetTunnels() {
Expand Down
18 changes: 16 additions & 2 deletions relayer/band/errors.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package band

import "fmt"
import (
"fmt"

var ErrBandChainNotConnect = fmt.Errorf("cannot connect to bandchain")
tunneltypes "github.com/bandprotocol/falcon/internal/bandchain/tunnel"
)

var (
ErrBandChainNotConnect = fmt.Errorf("cannot connect to Bandchain")

ErrUnsupportedRouteType = func(route string) error {
return fmt.Errorf("unsupported route type: %s", route)
}

ErrUnsupportedPacketContentType = func(packetReceipt tunneltypes.PacketReceiptI) error {
return fmt.Errorf("unsupported packet content type: %T", packetReceipt)
}
)
2 changes: 1 addition & 1 deletion relayer/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestParseChainProviderConfig(t *testing.T) {
"chain_type": "evms",
"endpoints": []string{"http://localhost:8545"},
},
err: fmt.Errorf("unsupported chain type: evms"),
err: relayer.ErrUnsupportedChainType("evms"),
},
{
name: "missing chain type",
Expand Down
32 changes: 17 additions & 15 deletions relayer/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ package relayer

import "fmt"

func ErrConfigNotExist(homePath string) error {
return fmt.Errorf("config does not exist: %s", homePath)
}
var (
ErrConfigNotExist = func(homePath string) error {
return fmt.Errorf("config does not exist: %s", homePath)
}

func ErrConfigExist(cfgPath string) error {
return fmt.Errorf("config already exists: %s", cfgPath)
}
ErrConfigExist = func(cfgPath string) error {
return fmt.Errorf("config already exists: %s", cfgPath)
}

func ErrChainNameExist(chainName string) error {
return fmt.Errorf("chain name already exists: %s", chainName)
}
ErrChainNameExist = func(chainName string) error {
return fmt.Errorf("chain name already exists: %s", chainName)
}

func ErrChainNameNotExist(chainName string) error {
return fmt.Errorf("chain name does not exist: %s", chainName)
}
ErrChainNameNotExist = func(chainName string) error {
return fmt.Errorf("chain name does not exist: %s", chainName)
}

func ErrUnsupportedChainType(typeName string) error {
return fmt.Errorf("unsupported chain type: %s", typeName)
}
ErrUnsupportedChainType = func(typeName string) error {
return fmt.Errorf("unsupported chain type: %s", typeName)
}
)

0 comments on commit f595c7b

Please sign in to comment.