Skip to content

Commit

Permalink
working tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jan 14, 2025
1 parent f599851 commit dfa22af
Showing 1 changed file with 63 additions and 2 deletions.
65 changes: 63 additions & 2 deletions tests/integration/connect_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ func QueryMarket(chain *cosmos.CosmosChain, cp connecttypes.CurrencyPair) (mmtyp
return res.Market, nil
}

// QueryMarketMap queries the market map.
// QueryMarketMap queries the market map. This query util provides an additional query to the list endpoint
// and ensures that the response data in both queries is equal.
func QueryMarketMap(chain *cosmos.CosmosChain) (*mmtypes.MarketMapResponse, error) {
grpcAddr := chain.GetHostGRPCAddress()

Expand All @@ -349,7 +350,57 @@ func QueryMarketMap(chain *cosmos.CosmosChain) (*mmtypes.MarketMapResponse, erro
ctx := context.Background()

// query the currency pairs
res, err := client.MarketMap(ctx, &mmtypes.MarketMapRequest{})
mapRes, err := client.MarketMap(ctx, &mmtypes.MarketMapRequest{})
if err != nil {
return nil, err
}

if mapRes == nil {
return nil, fmt.Errorf("map response is nil")
}

// query markets to check that there is 1-1 correspondence to the map query
listRes, err := QueryMarkets(chain)
if err != nil {
return nil, err
}

if listRes == nil {
return nil, fmt.Errorf("list response is nil")
}

for _, market := range listRes.Markets {
mapMarket, found := mapRes.MarketMap.Markets[market.Ticker.String()]
if !found {
return nil, fmt.Errorf("market %s not found", market.Ticker.String())
}

if !market.Equal(mapMarket) {
return nil, fmt.Errorf("market %s is not equal to %s", market.Ticker.String(), mapMarket.String())
}
}

return mapRes, nil
}

// QueryMarkets queries all markets .
func QueryMarkets(chain *cosmos.CosmosChain) (*mmtypes.MarketsResponse, error) {
grpcAddr := chain.GetHostGRPCAddress()

// create the client
cc, err := grpc.Dial(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
defer cc.Close()

// create the mm client
client := mmtypes.NewQueryClient(cc)

ctx := context.Background()

// query the currency pairs
res, err := client.Markets(ctx, &mmtypes.MarketsRequest{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -498,6 +549,16 @@ func (s *ConnectIntegrationSuite) RemoveMarket(
return fmt.Errorf(resp.TxResult.Log)
}

// check market map and lastUpdated
mmResp, err := QueryMarketMap(chain)
s.Require().NoError(err)

// ensure that the market no longer exist
for _, market := range markets {
_, found := mmResp.MarketMap.Markets[market.String()]
s.Require().False(found)
}

return nil
}

Expand Down

0 comments on commit dfa22af

Please sign in to comment.