-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
(cherry picked from commit 8ad5585) Co-authored-by: Jaeseung Lee <[email protected]>
- Loading branch information
1 parent
3301445
commit 6bd10bb
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/require" | ||
|
||
authtypes "github.com/Finschia/finschia-sdk/x/auth/types" | ||
"github.com/Finschia/finschia-sdk/x/fbridge/keeper" | ||
"github.com/Finschia/finschia-sdk/x/fbridge/testutil" | ||
"github.com/Finschia/finschia-sdk/x/fbridge/types" | ||
"github.com/Finschia/finschia-sdk/x/foundation" | ||
govtypes "github.com/Finschia/finschia-sdk/x/gov/types" | ||
) | ||
|
||
func TestNewKeeper(t *testing.T) { | ||
key, memKey, _, encCfg, _, bankKeeper, _ := testutil.PrepareFbridgeTest(t, 0) | ||
authKeeper := testutil.NewMockAccountKeeper(gomock.NewController(t)) | ||
|
||
tcs := map[string]struct { | ||
malleate func() | ||
isPanic bool | ||
}{ | ||
"fbridge module account has not been set": { | ||
malleate: func() { | ||
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(nil).Times(1) | ||
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", types.DefaultAuthority().String()) | ||
}, | ||
isPanic: true, | ||
}, | ||
"fbridge authority must be the gov or foundation module account": { | ||
malleate: func() { | ||
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1) | ||
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", authtypes.NewModuleAddress("invalid").String()) | ||
}, | ||
isPanic: true, | ||
}, | ||
"success - gov authority": { | ||
malleate: func() { | ||
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1) | ||
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", authtypes.NewModuleAddress(govtypes.ModuleName).String()) | ||
}, | ||
isPanic: false, | ||
}, | ||
"success - foundation authority": { | ||
malleate: func() { | ||
authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1) | ||
keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, "stake", authtypes.NewModuleAddress(foundation.ModuleName).String()) | ||
}, | ||
isPanic: false, | ||
}, | ||
} | ||
|
||
for name, tc := range tcs { | ||
t.Run(name, func(t *testing.T) { | ||
if tc.isPanic { | ||
require.Panics(t, tc.malleate) | ||
} else { | ||
tc.malleate() | ||
} | ||
}) | ||
} | ||
} |