Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Mar 15, 2024
1 parent ea7112f commit d48e062
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions x/foundation/keeper/internal/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/Finschia/finschia-sdk/crypto/keys/secp256k1"
"github.com/Finschia/finschia-sdk/simapp"
"github.com/Finschia/finschia-sdk/testutil/testdata"
sdk "github.com/Finschia/finschia-sdk/types"
authtypes "github.com/Finschia/finschia-sdk/x/auth/types"
"github.com/Finschia/finschia-sdk/x/foundation"
"github.com/Finschia/finschia-sdk/x/foundation/keeper/internal"
)

func workingPolicy() foundation.DecisionPolicy {
Expand Down Expand Up @@ -285,3 +288,58 @@ func TestImportExportGenesis(t *testing.T) {
require.Equal(t, tc.export, actual, name)
}
}

func TestShouldPanicWhenFailToGenerateFoundationModuleAccountInInitGenesis(t *testing.T) {
checkTx := false
app := simapp.Setup(checkTx)
testdata.RegisterInterfaces(app.InterfaceRegistry())
testdata.RegisterMsgServer(app.MsgServiceRouter(), testdata.MsgServerImpl{})
gs := &foundation.GenesisState{
Params: foundation.DefaultParams(),
Foundation: foundation.DefaultFoundation(),
}
ctx := app.BaseApp.NewContext(checkTx, tmproto.Header{})

testCases := map[string]struct {
mockAccKeeper *stubAccKeeper
}{
"failed to generate foundation module account=" + foundation.ModuleName: {
mockAccKeeper: &stubAccKeeper{name: foundation.ModuleName},
},
"failed to generate foundation module account=" + foundation.TreasuryName: {
mockAccKeeper: &stubAccKeeper{name: foundation.TreasuryName},
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert.Panics(t, func() {
k := internal.NewKeeper(
app.AppCodec(),
app.GetKey(foundation.ModuleName),
app.MsgServiceRouter(),
tc.mockAccKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
foundation.DefaultConfig(),
foundation.DefaultAuthority().String(),
app.GetSubspace(foundation.ModuleName),
)

_ = k.InitGenesis(ctx, gs)
assert.FailNow(t, "not supposed to reach here, should panic before")
})
})
}
}

type stubAccKeeper struct {
name string
}

func (s *stubAccKeeper) GetModuleAccount(_ sdk.Context, name string) authtypes.ModuleAccountI {
if s.name == name {
return authtypes.NewEmptyModuleAccount("dontcare")
}
return nil
}

0 comments on commit d48e062

Please sign in to comment.