Skip to content

Commit be49763

Browse files
mergify[bot]tqin7
andauthored
[CORE-715] fix bridge client tests and add test on empty eth rpc endpoint (#728) (#729)
* fix bridge client tests and add test on empty eth rpc endpoint (cherry picked from commit 4d60e8d) Co-authored-by: Tian <tian@dydx.exchange>
1 parent d08c8e0 commit be49763

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

protocol/daemons/bridge/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func Start(
3636
"Starting bridge daemon with flags",
3737
"BridgeFlags", flags.Bridge,
3838
)
39+
3940
// Panic if EthRpcEndpoint is empty.
4041
if flags.Bridge.EthRpcEndpoint == "" {
4142
return fmt.Errorf("flag %s is not set", daemonflags.FlagBridgeDaemonEthRpcEndpoint)

protocol/daemons/bridge/client/client_test.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
appflags "github.com/dydxprotocol/v4-chain/protocol/app/flags"
1111
"github.com/dydxprotocol/v4-chain/protocol/daemons/bridge/client"
1212
d_constants "github.com/dydxprotocol/v4-chain/protocol/daemons/constants"
13-
"github.com/dydxprotocol/v4-chain/protocol/daemons/flags"
13+
daemonflags "github.com/dydxprotocol/v4-chain/protocol/daemons/flags"
1414
"github.com/dydxprotocol/v4-chain/protocol/mocks"
1515
"github.com/dydxprotocol/v4-chain/protocol/testutil/appoptions"
1616
"github.com/dydxprotocol/v4-chain/protocol/testutil/constants"
@@ -21,18 +21,38 @@ import (
2121
"github.com/stretchr/testify/require"
2222
)
2323

24+
func TestStart_EthRpcEndpointNotSet(t *testing.T) {
25+
errorMsg := "flag bridge-daemon-eth-rpc-endpoint is not set"
26+
27+
require.EqualError(
28+
t,
29+
client.Start(
30+
grpc.Ctx,
31+
daemonflags.GetDefaultDaemonFlags(),
32+
appflags.GetFlagValuesFromOptions(appoptions.GetDefaultTestAppOptions("", nil)),
33+
log.NewNopLogger(),
34+
&mocks.GrpcClient{},
35+
),
36+
errorMsg,
37+
)
38+
}
39+
2440
func TestStart_TcpConnectionFails(t *testing.T) {
2541
errorMsg := "Failed to create connection"
2642

2743
// Mock the gRPC client to return an error when creating a TCP connection.
2844
mockGrpcClient := &mocks.GrpcClient{}
2945
mockGrpcClient.On("NewTcpConnection", grpc.Ctx, d_constants.DefaultGrpcEndpoint).Return(nil, errors.New(errorMsg))
3046

47+
// Override default daemon flags with a non-empty EthRpcEndpoint.
48+
daemonFlagsWithEthRpcEndpoint := daemonflags.GetDefaultDaemonFlags()
49+
daemonFlagsWithEthRpcEndpoint.Bridge.EthRpcEndpoint = "http://localhost:8545"
50+
3151
require.EqualError(
3252
t,
3353
client.Start(
3454
grpc.Ctx,
35-
flags.GetDefaultDaemonFlags(),
55+
daemonFlagsWithEthRpcEndpoint,
3656
appflags.GetFlagValuesFromOptions(appoptions.GetDefaultTestAppOptions("", nil)),
3757
log.NewNopLogger(),
3858
mockGrpcClient,
@@ -56,11 +76,15 @@ func TestStart_UnixSocketConnectionFails(t *testing.T) {
5676
mockGrpcClient.On("NewGrpcConnection", grpc.Ctx, grpc.SocketPath).Return(nil, errors.New(errorMsg))
5777
mockGrpcClient.On("CloseConnection", grpc.GrpcConn).Return(nil)
5878

79+
// Override default daemon flags with a non-empty EthRpcEndpoint.
80+
daemonFlagsWithEthRpcEndpoint := daemonflags.GetDefaultDaemonFlags()
81+
daemonFlagsWithEthRpcEndpoint.Bridge.EthRpcEndpoint = "http://localhost:8545"
82+
5983
require.EqualError(
6084
t,
6185
client.Start(
6286
grpc.Ctx,
63-
flags.GetDefaultDaemonFlags(),
87+
daemonFlagsWithEthRpcEndpoint,
6488
appflags.GetFlagValuesFromOptions(appoptions.GetDefaultTestAppOptions("", nil)),
6589
log.NewNopLogger(),
6690
mockGrpcClient,

0 commit comments

Comments
 (0)