mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
a073238f34
* module files * proto types * types and generated proto types * keeper * client scaffold * add savings module to app * remove placeholder types file * implement rest and add to module * update proto types * validation for supported denoms * generate updates proto types * update comments * update comments * remove unused imports from proto files * regenerate proto files * update proto types * client * deposit type and generated proto types * deposit keeper methods + tests * update savings module file * update app.go + test common * remove abci * remove refs to other modules * remove endblocker call * genesis init test for module account * update genesis test with params * add get/set params test * fix up keeper test * use params getter * simplify if/else statement * fix: add msgServer to keeper * fix: register deposit message * update deposit test * wrap invalid deposit denom error msg Co-authored-by: karzak <kjydavis3@gmail.com>
102 lines
3.0 KiB
Go
102 lines
3.0 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
tmtime "github.com/tendermint/tendermint/types/time"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
"github.com/kava-labs/kava/app"
|
|
"github.com/kava-labs/kava/x/savings/keeper"
|
|
"github.com/kava-labs/kava/x/savings/types"
|
|
)
|
|
|
|
// Test suite used for all keeper tests
|
|
type KeeperTestSuite struct {
|
|
suite.Suite
|
|
keeper keeper.Keeper
|
|
app app.TestApp
|
|
ctx sdk.Context
|
|
addrs []sdk.AccAddress
|
|
}
|
|
|
|
// The default state used by each test
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
config := sdk.GetConfig()
|
|
app.SetBech32AddressPrefixes(config)
|
|
|
|
tApp := app.NewTestApp()
|
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
|
tApp.InitializeFromGenesisStates()
|
|
_, addrs := app.GeneratePrivKeyAddressPairs(1)
|
|
keeper := tApp.GetSavingsKeeper()
|
|
suite.app = tApp
|
|
suite.ctx = ctx
|
|
suite.keeper = keeper
|
|
suite.addrs = addrs
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) TestGetSetDeleteDeposit() {
|
|
dep := types.NewDeposit(sdk.AccAddress("test"), sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))))
|
|
|
|
_, f := suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"))
|
|
suite.Require().False(f)
|
|
|
|
suite.keeper.SetDeposit(suite.ctx, dep)
|
|
|
|
testDeposit, f := suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"))
|
|
suite.Require().True(f)
|
|
suite.Require().Equal(dep, testDeposit)
|
|
|
|
suite.Require().NotPanics(func() { suite.keeper.DeleteDeposit(suite.ctx, dep) })
|
|
_, f = suite.keeper.GetDeposit(suite.ctx, sdk.AccAddress("test"))
|
|
suite.Require().False(f)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) TestIterateDeposits() {
|
|
for i := 0; i < 5; i++ {
|
|
dep := types.NewDeposit(sdk.AccAddress("test"+fmt.Sprint(i)), sdk.NewCoins(sdk.NewCoin("bnb", sdk.NewInt(100))))
|
|
suite.Require().NotPanics(func() { suite.keeper.SetDeposit(suite.ctx, dep) })
|
|
}
|
|
var deposits []types.Deposit
|
|
suite.keeper.IterateDeposits(suite.ctx, func(d types.Deposit) bool {
|
|
deposits = append(deposits, d)
|
|
return false
|
|
})
|
|
suite.Require().Equal(5, len(deposits))
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) getAccountCoins(acc authtypes.AccountI) sdk.Coins {
|
|
bk := suite.app.GetBankKeeper()
|
|
return bk.GetAllBalances(suite.ctx, acc.GetAddress())
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) getAccount(addr sdk.AccAddress) authtypes.AccountI {
|
|
ak := suite.app.GetAccountKeeper()
|
|
return ak.GetAccount(suite.ctx, addr)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) getAccountAtCtx(addr sdk.AccAddress, ctx sdk.Context) authtypes.AccountI {
|
|
ak := suite.app.GetAccountKeeper()
|
|
return ak.GetAccount(ctx, addr)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) getModuleAccount(name string) authtypes.ModuleAccountI {
|
|
ak := suite.app.GetAccountKeeper()
|
|
return ak.GetModuleAccount(suite.ctx, name)
|
|
}
|
|
|
|
func (suite *KeeperTestSuite) getModuleAccountAtCtx(name string, ctx sdk.Context) authtypes.ModuleAccountI {
|
|
ak := suite.app.GetAccountKeeper()
|
|
return ak.GetModuleAccount(ctx, name)
|
|
}
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
}
|