github.com/Finschia/finschia-sdk@v0.49.1/x/fbridge/keeper/keeper_test.go (about)

     1  package keeper_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/golang/mock/gomock"
     7  	"github.com/stretchr/testify/require"
     8  
     9  	authtypes "github.com/Finschia/finschia-sdk/x/auth/types"
    10  	"github.com/Finschia/finschia-sdk/x/fbridge/keeper"
    11  	"github.com/Finschia/finschia-sdk/x/fbridge/testutil"
    12  	"github.com/Finschia/finschia-sdk/x/fbridge/types"
    13  	"github.com/Finschia/finschia-sdk/x/foundation"
    14  	govtypes "github.com/Finschia/finschia-sdk/x/gov/types"
    15  )
    16  
    17  func TestNewKeeper(t *testing.T) {
    18  	key, memKey, _, encCfg, _, bankKeeper, _ := testutil.PrepareFbridgeTest(t, 0)
    19  	authKeeper := testutil.NewMockAccountKeeper(gomock.NewController(t))
    20  
    21  	tcs := map[string]struct {
    22  		malleate func()
    23  		isPanic  bool
    24  	}{
    25  		"fbridge module account has not been set": {
    26  			malleate: func() {
    27  				authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(nil).Times(1)
    28  				keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, types.DefaultAuthority().String())
    29  			},
    30  			isPanic: true,
    31  		},
    32  		"fbridge authority must be the gov or foundation module account": {
    33  			malleate: func() {
    34  				authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1)
    35  				keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, authtypes.NewModuleAddress("invalid").String())
    36  			},
    37  			isPanic: true,
    38  		},
    39  		"success - gov authority": {
    40  			malleate: func() {
    41  				authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1)
    42  				keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
    43  			},
    44  			isPanic: false,
    45  		},
    46  		"success - foundation authority": {
    47  			malleate: func() {
    48  				authKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).Times(1)
    49  				keeper.NewKeeper(encCfg.Codec, key, memKey, authKeeper, bankKeeper, authtypes.NewModuleAddress(foundation.ModuleName).String())
    50  			},
    51  			isPanic: false,
    52  		},
    53  	}
    54  
    55  	for name, tc := range tcs {
    56  		t.Run(name, func(t *testing.T) {
    57  			if tc.isPanic {
    58  				require.Panics(t, tc.malleate)
    59  			} else {
    60  				tc.malleate()
    61  			}
    62  		})
    63  	}
    64  }