From 7799d29bcfa761b1c3712535de0f4eac772cb249 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 26 Feb 2024 15:01:18 -0800 Subject: [PATCH] Lints, more tests --- protocol/daemons/slinky/client/client_test.go | 1 - .../slinky/client/market_pair_fetcher_test.go | 1 - .../slinky/client/price_fetcher_test.go | 15 ++++---- protocol/lib/slinky/utils.go | 3 +- protocol/lib/slinky/utils_test.go | 34 +++++++++++++++++++ 5 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 protocol/lib/slinky/utils_test.go diff --git a/protocol/daemons/slinky/client/client_test.go b/protocol/daemons/slinky/client/client_test.go index 94e5491484..1a29031aa0 100644 --- a/protocol/daemons/slinky/client/client_test.go +++ b/protocol/daemons/slinky/client/client_test.go @@ -33,7 +33,6 @@ type ClientTestSuite struct { daemonFlags daemonflags.DaemonFlags appFlags appflags.Flags daemonServer *daemonserver.Server - exchangePriceCache *pricefeed_types.MarketToExchangePrices grpcServer *grpc.Server pricesMockQueryServer *mocks.QueryServer wg sync.WaitGroup diff --git a/protocol/daemons/slinky/client/market_pair_fetcher_test.go b/protocol/daemons/slinky/client/market_pair_fetcher_test.go index c23799dab7..18c511ec82 100644 --- a/protocol/daemons/slinky/client/market_pair_fetcher_test.go +++ b/protocol/daemons/slinky/client/market_pair_fetcher_test.go @@ -88,5 +88,4 @@ func TestMarketPairFetcher(t *testing.T) { err := fetcher.FetchIdMappings(context.Background()) require.Error(t, err, "test error") }) - } diff --git a/protocol/daemons/slinky/client/price_fetcher_test.go b/protocol/daemons/slinky/client/price_fetcher_test.go index 9e638a333c..b727978181 100644 --- a/protocol/daemons/slinky/client/price_fetcher_test.go +++ b/protocol/daemons/slinky/client/price_fetcher_test.go @@ -31,12 +31,11 @@ func TestPriceFetcherTestSuite(t *testing.T) { type PriceFetcherTestSuite struct { suite.Suite - daemonFlags daemonflags.DaemonFlags - appFlags appflags.Flags - daemonServer *daemonserver.Server - exchangePriceCache *pricefeed_types.MarketToExchangePrices - pricesGrpcServer *grpc.Server - wg sync.WaitGroup + daemonFlags daemonflags.DaemonFlags + appFlags appflags.Flags + daemonServer *daemonserver.Server + pricesGrpcServer *grpc.Server + wg sync.WaitGroup } func (p *PriceFetcherTestSuite) SetupTest() { @@ -189,7 +188,9 @@ func (p *PriceFetcherTestSuite) TestPriceFetcher() { logger, ) p.Require().NoError(fetcher.Start(context.Background())) - p.Require().Errorf(fetcher.FetchPrices(context.Background()), "slinky client returned price %s not parsable as uint64", "abc123") + p.Require().Errorf( + fetcher.FetchPrices(context.Background()), + "slinky client returned price %s not parsable as uint64", "abc123") fetcher.Stop() }) diff --git a/protocol/lib/slinky/utils.go b/protocol/lib/slinky/utils.go index b86c60b0b2..5b5c6a5eff 100644 --- a/protocol/lib/slinky/utils.go +++ b/protocol/lib/slinky/utils.go @@ -2,8 +2,9 @@ package slinky import ( "fmt" - "github.com/skip-mev/slinky/x/oracle/types" "strings" + + "github.com/skip-mev/slinky/x/oracle/types" ) /* diff --git a/protocol/lib/slinky/utils_test.go b/protocol/lib/slinky/utils_test.go new file mode 100644 index 0000000000..7756cacc39 --- /dev/null +++ b/protocol/lib/slinky/utils_test.go @@ -0,0 +1,34 @@ +package slinky_test + +import ( + "fmt" + "testing" + + "github.com/skip-mev/slinky/x/oracle/types" + "github.com/stretchr/testify/require" + + "github.com/dydxprotocol/v4-chain/protocol/lib/slinky" +) + +func TestMarketPairToCurrencyPair(t *testing.T) { + testCases := []struct { + mp string + cp types.CurrencyPair + err error + }{ + {mp: "FOO-BAR", cp: types.CurrencyPair{Base: "FOO", Quote: "BAR"}, err: nil}, + {mp: "FOOBAR", cp: types.CurrencyPair{}, err: fmt.Errorf("incorrectly formatted CurrencyPair: FOOBAR")}, + {mp: "FOO/BAR", cp: types.CurrencyPair{}, err: fmt.Errorf("incorrectly formatted CurrencyPair: FOOBAR")}, + } + for _, tc := range testCases { + t.Run(fmt.Sprintf("TestMarketPair %s", tc.mp), func(t *testing.T) { + cp, err := slinky.MarketPairToCurrencyPair(tc.mp) + if tc.err != nil { + require.Error(t, err, tc.err) + } else { + require.NoError(t, err) + require.Equal(t, tc.cp, cp) + } + }) + } +}