Skip to content

Commit

Permalink
fix-test
Browse files Browse the repository at this point in the history
  • Loading branch information
aljo242 committed Jan 16, 2025
1 parent 44d36c2 commit ae7be7b
Showing 1 changed file with 75 additions and 1 deletion.
76 changes: 75 additions & 1 deletion tests/integration/connect_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,81 @@ func QueryCurrencyPairs(chain *cosmos.CosmosChain) (*oracletypes.GetAllCurrencyP
client := oracletypes.NewQueryClient(cc)

// query the currency pairs
return client.GetAllCurrencyPairs(context.Background(), &oracletypes.GetAllCurrencyPairsRequest{})
resp, err := client.GetAllCurrencyPairs(context.Background(), &oracletypes.GetAllCurrencyPairsRequest{})

// check that there is a correspondence between mappings and the raw response
mappingResp, err := QueryCurrencyPairMappings(chain)
if err != nil {
return nil, err
}

if len(resp.CurrencyPairs) != len(mappingResp.CurrencyPairMapping) {
return nil, fmt.Errorf("list and map responses should be the same length: got %d list, %d map",
len(resp.CurrencyPairs),
len(mappingResp.CurrencyPairMapping),
)
}
for _, v := range mappingResp.CurrencyPairMapping {
found := false
for _, cp := range resp.CurrencyPairs {
if v.Equal(cp) {
found = true
}
}

if !found {
return nil, fmt.Errorf("currency pair %v was found in mapping response but not in currency pair list", v)
}
}

return resp, err
}

// QueryCurrencyPairMappings queries the chain for the given currency pair mappings
func QueryCurrencyPairMappings(chain *cosmos.CosmosChain) (*oracletypes.GetCurrencyPairMappingResponse, error) {
// get grpc address
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 oracle client
client := oracletypes.NewQueryClient(cc)

// query the currency pairs map
mapRes, err := client.GetCurrencyPairMapping(context.Background(), &oracletypes.GetCurrencyPairMappingRequest{})
if err != nil {
return nil, err
}

// query the currency pairs list
listRes, err := client.GetCurrencyPairMappingList(context.Background(), &oracletypes.GetCurrencyPairMappingListRequest{})
if err != nil {
return nil, err
}

if len(listRes.Mappings) != len(mapRes.CurrencyPairMapping) {
return nil, fmt.Errorf("map and list responses should be the same length: got %d list, %d map",
len(listRes.Mappings),
len(mapRes.CurrencyPairMapping),
)
}
for _, m := range listRes.Mappings {
cp, found := mapRes.CurrencyPairMapping[m.Id]
if !found {
return nil, fmt.Errorf("mapping for %d not found", m.Id)
}

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

return mapRes, nil
}

// QueryCurrencyPair queries the price for the given currency-pair given a desired height to query from
Expand Down

0 comments on commit ae7be7b

Please sign in to comment.