Skip to content

Commit

Permalink
oracle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toteki committed Oct 12, 2023
1 parent 2906101 commit 0787cae
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/e2e/e2e_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,40 @@ import (
"time"

"github.com/umee-network/umee/v6/tests/grpc"
leveragetypes "github.com/umee-network/umee/v6/x/leverage/types"
)

// TestAllPrices wairs for all tokens in the leverage registry to have prices.
func (s *E2ETest) TestAllPrices() {
tokens := []leveragetypes.Token{}
s.Require().Eventually(
func() bool {
var err error
tokens, err = s.QueryRegisteredTokens(s.UmeeREST())
if err != nil {
return false
}
return true
},
time.Minute, time.Second, "get registered tokens",
)
s.Require().Eventually(
func() bool {
exchangeRates, err := s.QueryExchangeRate(s.UmeeREST(), "")
if err != nil {
return false
}
for _, t := range tokens {
if exchangeRates.AmountOf(t.SymbolDenom).IsZero() {
return false
}
}
return true
},
time.Minute, time.Second, "ensure all tokens have prices",
)
}

// TestMedians queries for the oracle params, collects historical
// prices based on those params, checks that the stored medians and
// medians deviations are correct, updates the oracle params with
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/setup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

appparams "github.com/umee-network/umee/v6/app/params"
"github.com/umee-network/umee/v6/client"
leveragetypes "github.com/umee-network/umee/v6/x/leverage/types"
oracletypes "github.com/umee-network/umee/v6/x/oracle/types"
"github.com/umee-network/umee/v6/x/uibc"
)
Expand Down Expand Up @@ -207,6 +208,16 @@ func (s *E2ETestSuite) QueryExchangeRate(endpoint, denom string) (sdk.DecCoins,
return resp.ExchangeRates, nil
}

func (s *E2ETestSuite) QueryRegisteredTokens(endpoint string) ([]leveragetypes.Token, error) {
endpoint = fmt.Sprintf("%s/umee/leverage/v1/registered_tokens", endpoint)
var resp leveragetypes.QueryRegisteredTokensResponse
if err := s.QueryREST(endpoint, &resp); err != nil {
return nil, err
}

return resp.Registry, nil
}

func (s *E2ETestSuite) QueryHistAvgPrice(endpoint, denom string) (sdk.Dec, error) {
endpoint = fmt.Sprintf("%s/umee/historacle/v1/avg_price/%s", endpoint, strings.ToUpper(denom))
var resp oracletypes.QueryAvgPriceResponse
Expand Down

0 comments on commit 0787cae

Please sign in to comment.