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

fix: fbridge auth checking bug (backport #1361) #1362

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig
* (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation
* (x/server) [\#1337](https://github.com/Finschia/finschia-sdk/pull/1337) fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter (backport cosmos/cosmos-sdk#18537)
* (x/fbridge) [\#1361](https://github.com/Finschia/finschia-sdk/pull/1361) Fixes fbridge auth checking bug

### Removed

Expand Down
5 changes: 5 additions & 0 deletions x/fbridge/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ func NewKeeper(
panic(errors.New("fbridge module account has not been set"))
}

found := false
for _, addr := range types.AuthorityCandiates() {
if authority == addr.String() {
found = true
break
}
}

if !found {
panic("x/bridge authority must be the gov or foundation module account")
}

Expand Down
64 changes: 64 additions & 0 deletions x/fbridge/keeper/keeper_test.go
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()
}
})
}
}
Loading