Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Move slinky daemon tests into single suite #1198

Closed
Closed
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
65 changes: 1 addition & 64 deletions protocol/daemons/slinky/client/price_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,20 @@ package client_test
import (
"context"
"fmt"
"net"
"sync"
"testing"
"time"

"cosmossdk.io/log"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"google.golang.org/grpc"

"github.com/skip-mev/slinky/service/servers/oracle/types"

appflags "github.com/dydxprotocol/v4-chain/protocol/app/flags"
daemonflags "github.com/dydxprotocol/v4-chain/protocol/daemons/flags"
pricefeed_types "github.com/dydxprotocol/v4-chain/protocol/daemons/pricefeed/types"
daemonserver "github.com/dydxprotocol/v4-chain/protocol/daemons/server"
pricefeedserver_types "github.com/dydxprotocol/v4-chain/protocol/daemons/server/types/pricefeed"
"github.com/dydxprotocol/v4-chain/protocol/daemons/slinky/client"
daemontypes "github.com/dydxprotocol/v4-chain/protocol/daemons/types"
"github.com/dydxprotocol/v4-chain/protocol/mocks"
"github.com/dydxprotocol/v4-chain/protocol/testutil/appoptions"
)

func TestPriceFetcherTestSuite(t *testing.T) {
suite.Run(t, &PriceFetcherTestSuite{})
}

type PriceFetcherTestSuite struct {
suite.Suite
daemonFlags daemonflags.DaemonFlags
appFlags appflags.Flags
daemonServer *daemonserver.Server
pricesGrpcServer *grpc.Server
wg sync.WaitGroup
}

func (p *PriceFetcherTestSuite) SetupTest() {
// Setup daemon and grpc servers.
p.daemonFlags = daemonflags.GetDefaultDaemonFlags()
p.appFlags = appflags.GetFlagValuesFromOptions(appoptions.GetDefaultTestAppOptions("", nil))

// Configure and run daemon server.
p.daemonServer = daemonserver.NewServer(
log.NewNopLogger(),
grpc.NewServer(),
&daemontypes.FileHandlerImpl{},
p.daemonFlags.Shared.SocketAddress,
)
p.daemonServer.WithPriceFeedMarketToExchangePrices(
pricefeedserver_types.NewMarketToExchangePrices(5 * time.Second),
)

p.wg.Add(1)
go func() {
defer p.wg.Done()
p.daemonServer.Start()
}()

// Create a gRPC server running on the default port and attach the mock prices query response.
p.pricesGrpcServer = grpc.NewServer()

p.wg.Add(1)
go func() {
defer p.wg.Done()
ls, err := net.Listen("tcp", p.appFlags.GrpcAddress)
p.Require().NoError(err)
_ = p.pricesGrpcServer.Serve(ls)
}()
}

func (p *PriceFetcherTestSuite) TearDownTest() {
p.daemonServer.Stop()
p.pricesGrpcServer.Stop()
p.wg.Wait()
}

func (p *PriceFetcherTestSuite) TestPriceFetcher() {
func (p *ClientTestSuite) TestPriceFetcher() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test cases within ClientTestSuite are comprehensive, covering a wide range of scenarios. It's commendable that the tests are designed to ensure the functionality of the PriceFetcher under various conditions. However, consider reviewing the error handling to ensure consistency and clarity across test cases. Additionally, using constants for repeated strings, such as error messages and currency pairs, could enhance maintainability and readability.

logger := log.NewTestLogger(p.T())
mpf := mocks.NewMarketPairFetcher(p.T())
slinky := mocks.NewOracleClient(p.T())
Expand Down
Loading