Skip to content

Commit

Permalink
working simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
dssei committed Nov 7, 2024
1 parent eb1db8d commit fe6fc5e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 53 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import (
"github.com/sei-protocol/sei-chain/utils/metrics"
"github.com/sei-protocol/sei-chain/wasmbinding"
ctkeeper "github.com/sei-protocol/sei-chain/x/confidentialtransfers/keeper"
cttypes "github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
epochmodule "github.com/sei-protocol/sei-chain/x/epoch"
epochmodulekeeper "github.com/sei-protocol/sei-chain/x/epoch/keeper"
epochmoduletypes "github.com/sei-protocol/sei-chain/x/epoch/types"
Expand Down Expand Up @@ -414,6 +415,7 @@ func New(
evmtypes.StoreKey, wasm.StoreKey,
epochmoduletypes.StoreKey,
tokenfactorytypes.StoreKey,
cttypes.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientStoreKey)
Expand Down
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *KeeperTestHelper) SetupTokenFactory() {

// SetupTokenFactory sets up a token module account for the TokenFactoryKeeper.
func (s *KeeperTestHelper) SetupConfidentialTransfers() {
s.App.TokenFactoryKeeper.CreateModuleAccount(s.Ctx)
s.App.ConfidentialTransfersKeeper.CreateModuleAccount(s.Ctx)
}

// EndBlock ends the block.
Expand Down
51 changes: 11 additions & 40 deletions x/confidentialtransfers/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,18 @@
package keeper
package keeper_test

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

func (suite *IntegrationTestSuite) TestExportGenesis() {
app, ctx := suite.app, suite.ctx
func (suite *KeeperTestSuite) TestDefaultGenesisState() {
genesisState := types.DefaultGenesisState()

expectedMetadata := suite.getTestMetadata()
expectedBalances, totalSupply := suite.getTestBalancesAndSupply()
for i := range []int{1, 2} {
app.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))
suite.
Require().
NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, accAddr, expectedBalances[i].Coins))
}
suite.
Require().
NoError(
app.BankKeeper.SendCoinsAndWei(ctx, expectedBalances[0].GetAddress(), expectedBalances[1].GetAddress(), sdk.ZeroInt(), sdk.OneInt()))
app.BankKeeper.SetParams(ctx, types.DefaultParams())
app := suite.App
suite.Ctx = app.BaseApp.NewContext(false, tmproto.Header{})

exportGenesis := app.BankKeeper.ExportGenesis(ctx)

suite.Require().Len(exportGenesis.Params.SendEnabled, 0)
suite.Require().Equal(types.DefaultParams().DefaultSendEnabled, exportGenesis.Params.DefaultSendEnabled)
suite.Require().Equal(totalSupply, exportGenesis.Supply)
expectedBalances[0].Coins = expectedBalances[0].Coins.Sub(sdk.NewCoins(sdk.NewCoin(sdk.MustGetBaseDenom(), sdk.OneInt())))
expectedWeiBalances := []types.WeiBalance{
{Amount: keeper.OneUseiInWei.Sub(sdk.OneInt()), Address: expectedBalances[0].Address},
{Amount: sdk.OneInt(), Address: expectedBalances[1].Address},
}
suite.Require().Equal(expectedBalances, exportGenesis.Balances)
suite.Require().Equal(expectedMetadata, exportGenesis.DenomMetadata)
suite.Require().Equal(expectedWeiBalances, exportGenesis.WeiBalances)
suite.App.ConfidentialTransfersKeeper.InitGenesis(suite.Ctx, genesisState)
exportedGenesis := suite.App.ConfidentialTransfersKeeper.ExportGenesis(suite.Ctx)
suite.Require().NotNil(exportedGenesis)
suite.Require().Equal(genesisState, exportedGenesis)
}
23 changes: 12 additions & 11 deletions x/confidentialtransfers/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/store/prefix"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"

"github.com/tendermint/tendermint/libs/log"
Expand All @@ -15,7 +16,6 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// TODO: This is just scaffolding. To be implemented.
type Keeper interface {
InitGenesis(sdk.Context, *types.GenesisState)
ExportGenesis(sdk.Context) *types.GenesisState
Expand All @@ -25,16 +25,17 @@ type Keeper interface {

GetParams(ctx sdk.Context) types.Params
SetParams(ctx sdk.Context, params types.Params)

CreateModuleAccount(ctx sdk.Context)
}

type BaseKeeper struct {
storeKey sdk.StoreKey

cdc codec.Codec

paramSpace paramtypes.Subspace
// TODO: Add any required keepers here
// accountKeeper types.AccountKeeper
paramSpace paramtypes.Subspace
accountKeeper types.AccountKeeper
}

func (k BaseKeeper) TestQuery(ctx context.Context, request *types.TestQueryRequest) (*types.TestQueryResponse, error) {

Check warning on line 41 in x/confidentialtransfers/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/confidentialtransfers/keeper/keeper.go#L41

Added line #L41 was not covered by tests
Expand All @@ -47,15 +48,17 @@ func NewKeeper(
codec codec.Codec,
storeKey sdk.StoreKey,
paramSpace paramtypes.Subspace,
accountKeeper types.AccountKeeper,
) Keeper {

if !paramSpace.HasKeyTable() {
paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable())

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning

This definition of paramSpace is never used.
}

return BaseKeeper{
cdc: codec,
storeKey: storeKey,
cdc: codec,
storeKey: storeKey,
accountKeeper: accountKeeper,
}
}

Expand Down Expand Up @@ -129,9 +132,7 @@ func (k BaseKeeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

// getAccountStore gets the account store of the given address.
func (k BaseKeeper) getCtAccountStore(ctx sdk.Context, addr sdk.AccAddress) prefix.Store {
store := ctx.KVStore(k.storeKey)

return prefix.NewStore(store, types.CreateAccountBalancesPrefix(addr))
func (k BaseKeeper) CreateModuleAccount(ctx sdk.Context) {
moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName, authtypes.Minter, authtypes.Burner)
k.accountKeeper.SetModuleAccount(ctx, moduleAcc)

Check warning on line 137 in x/confidentialtransfers/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/confidentialtransfers/keeper/keeper.go#L135-L137

Added lines #L135 - L137 were not covered by tests
}
5 changes: 5 additions & 0 deletions x/confidentialtransfers/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ func (suite *KeeperTestSuite) SetupTest() {
suite.SetupTokenFactory()

suite.queryClient = types.NewQueryClient(suite.QueryHelper)
suite.App.ConfidentialTransfersKeeper = keeper.NewKeeper(
suite.App.AppCodec(),
suite.App.GetKey(types.StoreKey),
suite.App.GetSubspace(types.ModuleName),
suite.App.AccountKeeper)
suite.msgServer = keeper.NewMsgServerImpl(suite.App.ConfidentialTransfersKeeper)
}
12 changes: 12 additions & 0 deletions x/confidentialtransfers/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

type AccountKeeper interface {
GetModuleAddress(name string) sdk.AccAddress
SetModuleAccount(ctx sdk.Context, macc authtypes.ModuleAccountI)
GetAccount(sdk.Context, sdk.AccAddress) authtypes.AccountI
}
2 changes: 1 addition & 1 deletion x/confidentialtransfers/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (gs GenesisState) Validate() error {

accounts := make(map[string]bool)
for _, genesisCtAccount := range gs.Accounts {
if genesisCtAccount.Key == "" {
if genesisCtAccount.Key == nil {
return fmt.Errorf("genesisCtAccount key cannot be empty")
}

Check warning on line 21 in x/confidentialtransfers/types/genesis.go

View check run for this annotation

Codecov / codecov/patch

x/confidentialtransfers/types/genesis.go#L17-L21

Added lines #L17 - L21 were not covered by tests

Expand Down

0 comments on commit fe6fc5e

Please sign in to comment.