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

added switch case to detect blank pointers in keeper #2403

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fixed switch-case; added test cases
  • Loading branch information
alizahidraja committed Sep 28, 2022
commit 7af293bdc70b556294bed8767761aa2af4079db8
4 changes: 2 additions & 2 deletions modules/core/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewKeeper(
// switch case to detect blank pointers
switch reflect.TypeOf(stakingKeeper).Kind() {
case reflect.Ptr:
if reflect.ValueOf(&stakingKeeper).IsZero() {
if reflect.ValueOf(stakingKeeper).Elem().IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty staking keeper pointer"))
}
default:
Expand All @@ -65,7 +65,7 @@ func NewKeeper(

switch reflect.TypeOf(upgradeKeeper).Kind() {
case reflect.Ptr:
if reflect.ValueOf(&upgradeKeeper).IsZero() {
if reflect.ValueOf(upgradeKeeper).Elem().IsZero() {
panic(fmt.Errorf("cannot initialize IBC keeper: empty upgrade keeper pointer"))
}
default:
Expand Down
22 changes: 16 additions & 6 deletions modules/core/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,31 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
malleate func()
expPass bool
}{
{"failure: empty staking keeper", func() {
emptyStakingKeeper := stakingkeeper.Keeper{}
{"failure: empty staking keeper value", func() {
emptyStakingKeeperValue := stakingkeeper.Keeper{}

stakingKeeper = emptyStakingKeeper
stakingKeeper = emptyStakingKeeperValue
}, false},
{"failure: empty staking keeper pointer", func() {
emptyStakingKeeperPointer := &stakingkeeper.Keeper{}

stakingKeeper = emptyStakingKeeperPointer
}, false},
{"failure: empty mock staking keeper", func() {
// use a different implementation of clienttypes.StakingKeeper
emptyMockStakingKeeper := MockStakingKeeper{}

stakingKeeper = emptyMockStakingKeeper
}, false},
{"failure: empty upgrade keeper", func() {
emptyUpgradeKeeper := upgradekeeper.Keeper{}
{"failure: empty upgrade keeper value", func() {
emptyUpgradeKeeperValue := upgradekeeper.Keeper{}

upgradeKeeper = emptyUpgradeKeeperValue
}, false},
{"failure: empty upgrade keeper pointer", func() {
emptyUpgradeKeeperPointer := &upgradekeeper.Keeper{}

upgradeKeeper = emptyUpgradeKeeper
upgradeKeeper = emptyUpgradeKeeperPointer
}, false},
{"failure: empty scoped keeper", func() {
emptyScopedKeeper := capabilitykeeper.ScopedKeeper{}
Expand Down