Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: decouple bank from simapp #12258

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions simapp/params/weights.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package params

// Default simulation operation weights for messages and gov proposals
// Deprecated: use the DefaultWeight* constants instead located in testuitl/sims
const (
DefaultWeightMsgSend int = 100
DefaultWeightMsgMultiSend int = 10
Expand Down
24 changes: 12 additions & 12 deletions x/bank/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ import (
)

func (suite *IntegrationTestSuite) TestExportGenesis() {
app, ctx := suite.app, suite.ctx
ctx := suite.ctx

expectedMetadata := suite.getTestMetadata()
expectedBalances, expTotalSupply := suite.getTestBalancesAndSupply()

// Adding genesis supply to the expTotalSupply
genesisSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit})
genesisSupply, _, err := suite.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit})
suite.Require().NoError(err)
expTotalSupply = expTotalSupply.Add(genesisSupply...)

for i := range []int{1, 2} {
app.BankKeeper.SetDenomMetaData(ctx, expectedMetadata[i])
suite.BankKeeper.SetDenomMetaData(ctx, expectedMetadata[i])
accAddr, err1 := sdk.AccAddressFromBech32(expectedBalances[i].Address)
if err1 != nil {
panic(err1)
}
// set balances via mint and send
suite.
Require().
NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedBalances[i].Coins))
NoError(suite.BankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedBalances[i].Coins))
suite.
Require().
NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, accAddr, expectedBalances[i].Coins))
NoError(suite.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, accAddr, expectedBalances[i].Coins))
}
app.BankKeeper.SetParams(ctx, types.DefaultParams())
suite.BankKeeper.SetParams(ctx, types.DefaultParams())

exportGenesis := app.BankKeeper.ExportGenesis(ctx)
exportGenesis := suite.BankKeeper.ExportGenesis(ctx)

suite.Require().Len(exportGenesis.Params.SendEnabled, 0)
suite.Require().Equal(types.DefaultParams().DefaultSendEnabled, exportGenesis.Params.DefaultSendEnabled)
Expand Down Expand Up @@ -62,7 +62,7 @@ func (suite *IntegrationTestSuite) TestInitGenesis() {
m := types.Metadata{Description: sdk.DefaultBondDenom, Base: sdk.DefaultBondDenom, Display: sdk.DefaultBondDenom}
g := types.DefaultGenesisState()
g.DenomMetadata = []types.Metadata{m}
bk := suite.app.BankKeeper
bk := suite.BankKeeper
bk.InitGenesis(suite.ctx, g)

m2, found := bk.GetDenomMetaData(suite.ctx, m.Base)
Expand All @@ -80,7 +80,7 @@ func (suite *IntegrationTestSuite) TestTotalSupply() {
}
totalSupply := sdk.NewCoins(sdk.NewCoin("foocoin", sdk.NewInt(11)), sdk.NewCoin("barcoin", sdk.NewInt(21)))

genesisSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit})
genesisSupply, _, err := suite.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit})
suite.Require().NoError(err)

testcases := []struct {
Expand Down Expand Up @@ -111,10 +111,10 @@ func (suite *IntegrationTestSuite) TestTotalSupply() {
tc := tc
suite.Run(tc.name, func() {
if tc.expPanic {
suite.PanicsWithError(tc.expPanicMsg, func() { suite.app.BankKeeper.InitGenesis(suite.ctx, tc.genesis) })
suite.PanicsWithError(tc.expPanicMsg, func() { suite.BankKeeper.InitGenesis(suite.ctx, tc.genesis) })
} else {
suite.app.BankKeeper.InitGenesis(suite.ctx, tc.genesis)
totalSupply, _, err := suite.app.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit})
suite.BankKeeper.InitGenesis(suite.ctx, tc.genesis)
totalSupply, _, err := suite.BankKeeper.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{Limit: query.MaxLimit})
suite.Require().NoError(err)

// adding genesis supply to expected supply
Expand Down
56 changes: 33 additions & 23 deletions x/bank/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
Expand All @@ -17,7 +19,7 @@ import (
)

func (suite *IntegrationTestSuite) TestQueryBalance() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
ctx, queryClient := suite.ctx, suite.queryClient
_, _, addr := testdata.KeyTestPubAddr()

_, err := queryClient.Balance(gocontext.Background(), &types.QueryBalanceRequest{})
Expand All @@ -33,10 +35,10 @@ func (suite *IntegrationTestSuite) TestQueryBalance() {
suite.True(res.Balance.IsZero())

origCoins := sdk.NewCoins(newFooCoin(50), newBarCoin(30))
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addr)

app.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, acc.GetAddress(), origCoins))
suite.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(testutil.FundAccount(suite.BankKeeper, ctx, acc.GetAddress(), origCoins))

res, err = queryClient.Balance(gocontext.Background(), req)
suite.Require().NoError(err)
Expand All @@ -45,7 +47,7 @@ func (suite *IntegrationTestSuite) TestQueryBalance() {
}

func (suite *IntegrationTestSuite) TestQueryAllBalances() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
ctx, queryClient := suite.ctx, suite.queryClient
_, _, addr := testdata.KeyTestPubAddr()
_, err := queryClient.AllBalances(gocontext.Background(), &types.QueryAllBalancesRequest{})
suite.Require().Error(err)
Expand All @@ -65,10 +67,10 @@ func (suite *IntegrationTestSuite) TestQueryAllBalances() {
barCoins := newBarCoin(30)

origCoins := sdk.NewCoins(fooCoins, barCoins)
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addr)

app.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, acc.GetAddress(), origCoins))
suite.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(testutil.FundAccount(suite.BankKeeper, ctx, acc.GetAddress(), origCoins))

res, err = queryClient.AllBalances(gocontext.Background(), req)
suite.Require().NoError(err)
Expand All @@ -90,7 +92,7 @@ func (suite *IntegrationTestSuite) TestQueryAllBalances() {
}

func (suite *IntegrationTestSuite) TestSpendableBalances() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
ctx, queryClient := suite.ctx, suite.queryClient
_, _, addr := testdata.KeyTestPubAddr()
ctx = ctx.WithBlockTime(time.Now())

Expand All @@ -113,21 +115,29 @@ func (suite *IntegrationTestSuite) TestSpendableBalances() {
barCoins := newBarCoin(30)

origCoins := sdk.NewCoins(fooCoins, barCoins)
acc := app.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc := suite.AccountKeeper.NewAccountWithAddress(ctx, addr)
acc = vestingtypes.NewContinuousVestingAccount(
acc.(*authtypes.BaseAccount),
sdk.NewCoins(fooCoins),
ctx.BlockTime().Unix(),
ctx.BlockTime().Add(time.Hour).Unix(),
)

app.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(testutil.FundAccount(app.BankKeeper, ctx, acc.GetAddress(), origCoins))
suite.AccountKeeper.SetAccount(ctx, acc)
suite.Require().NoError(testutil.FundAccount(suite.BankKeeper, ctx, acc.GetAddress(), origCoins))

var interfaceRegistry codectypes.InterfaceRegistry

_, err = simtestutil.Setup(
testutil.AppConfig,
&interfaceRegistry,
)
suite.Require().NoError(err)

// move time forward for some tokens to vest
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(30 * time.Minute))
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
types.RegisterQueryServer(queryHelper, app.BankKeeper)
queryHelper := baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry)
types.RegisterQueryServer(queryHelper, suite.BankKeeper)
queryClient = types.NewQueryClient(queryHelper)

res, err = queryClient.SpendableBalances(sdk.WrapSDKContext(ctx), req)
Expand All @@ -140,15 +150,15 @@ func (suite *IntegrationTestSuite) TestSpendableBalances() {
}

func (suite *IntegrationTestSuite) TestQueryTotalSupply() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
ctx, queryClient := suite.ctx, suite.queryClient
res, err := queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{})
suite.Require().NoError(err)
genesisSupply := res.Supply

testCoins := sdk.NewCoins(sdk.NewInt64Coin("test", 400000000))
suite.
Require().
NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, testCoins))
NoError(suite.BankKeeper.MintCoins(ctx, minttypes.ModuleName, testCoins))

res, err = queryClient.TotalSupply(gocontext.Background(), &types.QueryTotalSupplyRequest{})
suite.Require().NoError(err)
Expand All @@ -160,14 +170,14 @@ func (suite *IntegrationTestSuite) TestQueryTotalSupply() {
}

func (suite *IntegrationTestSuite) TestQueryTotalSupplyOf() {
app, ctx, queryClient := suite.app, suite.ctx, suite.queryClient
ctx, queryClient := suite.ctx, suite.queryClient

test1Supply := sdk.NewInt64Coin("test1", 4000000)
test2Supply := sdk.NewInt64Coin("test2", 700000000)
expectedTotalSupply := sdk.NewCoins(test1Supply, test2Supply)
suite.
Require().
NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedTotalSupply))
NoError(suite.BankKeeper.MintCoins(ctx, minttypes.ModuleName, expectedTotalSupply))

_, err := queryClient.SupplyOf(gocontext.Background(), &types.QuerySupplyOfRequest{})
suite.Require().Error(err)
Expand All @@ -183,7 +193,7 @@ func (suite *IntegrationTestSuite) TestQueryParams() {
res, err := suite.queryClient.Params(gocontext.Background(), &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(suite.app.BankKeeper.GetParams(suite.ctx), res.GetParams())
suite.Require().Equal(suite.BankKeeper.GetParams(suite.ctx), res.GetParams())
}

func (suite *IntegrationTestSuite) QueryDenomsMetadataRequest() {
Expand Down Expand Up @@ -254,8 +264,8 @@ func (suite *IntegrationTestSuite) QueryDenomsMetadataRequest() {
Display: "eth",
}

suite.app.BankKeeper.SetDenomMetaData(suite.ctx, metadataAtom)
suite.app.BankKeeper.SetDenomMetaData(suite.ctx, metadataEth)
suite.BankKeeper.SetDenomMetaData(suite.ctx, metadataAtom)
suite.BankKeeper.SetDenomMetaData(suite.ctx, metadataEth)
expMetadata = []types.Metadata{metadataAtom, metadataEth}
req = &types.QueryDenomsMetadataRequest{
Pagination: &query.PageRequest{
Expand Down Expand Up @@ -336,7 +346,7 @@ func (suite *IntegrationTestSuite) QueryDenomMetadataRequest() {
Display: "atom",
}

suite.app.BankKeeper.SetDenomMetaData(suite.ctx, expMetadata)
suite.BankKeeper.SetDenomMetaData(suite.ctx, expMetadata)
req = &types.QueryDenomMetadataRequest{
Denom: expMetadata.Base,
}
Expand Down Expand Up @@ -455,7 +465,7 @@ func (suite *IntegrationTestSuite) TestGRPCDenomOwners() {
}

func (suite *IntegrationTestSuite) TestQuerySendEnabled() {
ctx, bankKeeper := suite.ctx, suite.app.BankKeeper
ctx, bankKeeper := suite.ctx, suite.BankKeeper

bankKeeper.SetSendEnabled(ctx, "falsestcoin", false)
bankKeeper.SetSendEnabled(ctx, "truestcoin", true)
Expand Down
Loading