2019-08-15 06:53:37 -07:00
|
|
|
package keeper_test
|
2019-04-01 10:28:36 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2019-04-04 07:36:39 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-08-15 06:53:37 -07:00
|
|
|
keep "github.com/cosmos/cosmos-sdk/x/mint/internal/keeper"
|
2019-06-08 09:17:21 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint/internal/types"
|
2019-04-04 07:36:39 -07:00
|
|
|
|
2019-04-01 10:28:36 -07:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewQuerier(t *testing.T) {
|
2019-08-15 06:53:37 -07:00
|
|
|
app, ctx := createTestApp(true)
|
|
|
|
querier := keep.NewQuerier(app.MintKeeper)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: "",
|
|
|
|
Data: []byte{},
|
|
|
|
}
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
_, err := querier(ctx, []string{types.QueryParameters}, query)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
_, err = querier(ctx, []string{types.QueryInflation}, query)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
_, err = querier(ctx, []string{types.QueryAnnualProvisions}, query)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
_, err = querier(ctx, []string{"foo"}, query)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestQueryParams(t *testing.T) {
|
2019-08-15 06:53:37 -07:00
|
|
|
app, ctx := createTestApp(true)
|
|
|
|
querier := keep.NewQuerier(app.MintKeeper)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
2019-06-08 09:17:21 -07:00
|
|
|
var params types.Params
|
2019-04-01 10:28:36 -07:00
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
res, sdkErr := querier(ctx, []string{types.QueryParameters}, abci.RequestQuery{})
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, sdkErr)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
err := app.Codec().UnmarshalJSON(res, ¶ms)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
require.Equal(t, app.MintKeeper.GetParams(ctx), params)
|
2019-04-01 10:28:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestQueryInflation(t *testing.T) {
|
2019-08-15 06:53:37 -07:00
|
|
|
app, ctx := createTestApp(true)
|
|
|
|
querier := keep.NewQuerier(app.MintKeeper)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
|
|
|
var inflation sdk.Dec
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
res, sdkErr := querier(ctx, []string{types.QueryInflation}, abci.RequestQuery{})
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, sdkErr)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
err := app.Codec().UnmarshalJSON(res, &inflation)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
require.Equal(t, app.MintKeeper.GetMinter(ctx).Inflation, inflation)
|
2019-04-01 10:28:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestQueryAnnualProvisions(t *testing.T) {
|
2019-08-15 06:53:37 -07:00
|
|
|
app, ctx := createTestApp(true)
|
|
|
|
querier := keep.NewQuerier(app.MintKeeper)
|
2019-04-01 10:28:36 -07:00
|
|
|
|
|
|
|
var annualProvisions sdk.Dec
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
res, sdkErr := querier(ctx, []string{types.QueryAnnualProvisions}, abci.RequestQuery{})
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, sdkErr)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
err := app.Codec().UnmarshalJSON(res, &annualProvisions)
|
2019-04-01 10:28:36 -07:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2019-08-15 06:53:37 -07:00
|
|
|
require.Equal(t, app.MintKeeper.GetMinter(ctx).AnnualProvisions, annualProvisions)
|
2019-04-01 10:28:36 -07:00
|
|
|
}
|