Skip to content

Commit

Permalink
add tests to cli and grpc exg rates with timestamp req
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Sep 27, 2023
1 parent b7dbf92 commit f833b63
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
3 changes: 0 additions & 3 deletions x/oracle/client/tests/cli_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build norace
// +build norace

package tests

import (
Expand Down
53 changes: 53 additions & 0 deletions x/oracle/client/tests/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,56 @@ func (s *IntegrationTestSuite) TestQueryExchangeRate() {
})
}
}

func (s *IntegrationTestSuite) TestQueryExchangeRateWithTimestamp() {
val := s.network.Validators[0]
clientCtx := val.ClientCtx

testCases := []struct {
name string
args []string
expectErr bool
respType proto.Message
}{
{
name: "valid",
args: []string{
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: false,
respType: &types.QueryExgRatesWithTimestampResponse{},
},
{
name: "valid denom",
args: []string{
"UMEE",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: false,
respType: &types.QueryExgRatesWithTimestampResponse{},
},
{
name: "invalid denom",
args: []string{
"ABCD",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
expectErr: true,
respType: &types.QueryExgRatesWithTimestampResponse{},
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
out, err := clitestutil.ExecTestCLICmd(clientCtx, cli.QueryExchangeRatesWithTimestamp(), tc.args)
if tc.expectErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)
s.Require().NoError(clientCtx.Codec.UnmarshalJSON(out.Bytes(), tc.respType), out.String())
}
})
}
}
25 changes: 25 additions & 0 deletions x/oracle/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"math/rand"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tendermint/tendermint/crypto/secp256k1"
Expand Down Expand Up @@ -373,3 +374,27 @@ func (s *IntegrationTestSuite) TestQuerier_AvgPrice() {
_, err = s.queryClient.AvgPrice(ctx.Context(), &types.QueryAvgPrice{Denom: "12"})
s.Require().ErrorContains(err, "malformed denom")
}

func (s *IntegrationTestSuite) TestQuerier_ExchangeRatesWithTimestamp() {
s.ctx = s.ctx.WithBlockTime(time.Now())
s.app.OracleKeeper.SetExchangeRate(s.ctx, displayDenom, sdk.OneDec())
res, err := s.queryClient.ExgRatesWithTimestamp(s.ctx.Context(), &types.QueryExgRatesWithTimestamp{})
s.Require().NoError(err)
s.Require().Equal([]types.DenomExchangeRate{
{
Denom: displayDenom,
Rate: sdk.OneDec(),
Timestamp: s.ctx.BlockTime(),
},
}, res.ExgRates)

res, err = s.queryClient.ExgRatesWithTimestamp(s.ctx.Context(), &types.QueryExgRatesWithTimestamp{
Denom: displayDenom,
})
s.Require().NoError(err)
s.Require().Equal(types.DenomExchangeRate{
Denom: displayDenom,
Rate: sdk.OneDec(),
Timestamp: s.ctx.BlockTime(),
}, res.ExgRates[0])
}

0 comments on commit f833b63

Please sign in to comment.