-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: upgrade handler missing burn permissions for feecollector account (
#437) * passing account keeper to upgrade handlers * adding the upgrade handler to provide burn permission to feecollector module account * bumping version to v4.0.1 * Update CHANGELOG.md * add upgrade test * Adding interchain test - TestFeeCollectorBurnChainUpgrade * fixing linting
- Loading branch information
Showing
17 changed files
with
272 additions
and
55 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
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
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
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,40 @@ | ||
package upgrade4_0_1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
"github.com/archway-network/archway/app/upgrades" | ||
) | ||
|
||
const Name = "v4.0.1" | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: Name, | ||
CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator, accountKeeper keeper.AccountKeeper) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { | ||
fcAccount := accountKeeper.GetModuleAccount(ctx, authtypes.FeeCollectorName) | ||
account, ok := fcAccount.(*authtypes.ModuleAccount) | ||
if !ok { | ||
return nil, fmt.Errorf("feeCollector account is not *authtypes.ModuleAccount") | ||
} | ||
if !account.HasPermission(authtypes.Burner) { | ||
account.Permissions = append(account.Permissions, authtypes.Burner) | ||
} | ||
err := accountKeeper.ValidatePermissions(account) | ||
if err != nil { | ||
return nil, fmt.Errorf("Could not validate feeCollectors permissions") | ||
} | ||
accountKeeper.SetModuleAccount(ctx, account) | ||
|
||
return mm.RunMigrations(ctx, cfg, fromVM) | ||
} | ||
}, | ||
StoreUpgrades: storetypes.StoreUpgrades{}, | ||
} |
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,95 @@ | ||
package upgrade4_0_1_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
"github.com/stretchr/testify/suite" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
|
||
e2eTesting "github.com/archway-network/archway/e2e/testing" | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
suite.Suite | ||
|
||
archway *e2eTesting.TestChain | ||
} | ||
|
||
func (s *UpgradeTestSuite) SetupTest() { | ||
s.archway = e2eTesting.NewTestChain(s.T(), 1) | ||
} | ||
|
||
func TestUpgradeTestSuite(t *testing.T) { | ||
suite.Run(t, new(UpgradeTestSuite)) | ||
} | ||
|
||
const ( | ||
dummyUpgradeHeight = 5 | ||
) | ||
|
||
func (suite *UpgradeTestSuite) TestUpgrade() { | ||
testCases := []struct { | ||
name string | ||
pre_upgrade func() | ||
post_upgrade func() | ||
}{ | ||
{ | ||
"Feecollector does not have burn permissions, we ensure upgrade happens and account gets the burn permissions", | ||
func() { | ||
accountKeeper := suite.archway.GetApp().AccountKeeper | ||
fcAccount := accountKeeper.GetModuleAccount(suite.archway.GetContext(), authtypes.FeeCollectorName) | ||
|
||
account, ok := fcAccount.(*authtypes.ModuleAccount) | ||
suite.Require().True(ok) | ||
account.Permissions = []string{} | ||
accountKeeper.SetModuleAccount(suite.archway.GetContext(), account) | ||
|
||
fcAccount = accountKeeper.GetModuleAccount(suite.archway.GetContext(), authtypes.FeeCollectorName) | ||
suite.Require().False(fcAccount.HasPermission(authtypes.Burner)) | ||
}, | ||
func() { | ||
accountKeeper := suite.archway.GetApp().AccountKeeper | ||
fcAccount := accountKeeper.GetModuleAccount(suite.archway.GetContext(), authtypes.FeeCollectorName) | ||
suite.Require().True(fcAccount.HasPermission(authtypes.Burner)) | ||
}, | ||
}, | ||
{ | ||
"Feecollector already has burn permissions, we ensure upgrade happens smoothly", | ||
func() { | ||
accountKeeper := suite.archway.GetApp().AccountKeeper | ||
fcAccount := accountKeeper.GetModuleAccount(suite.archway.GetContext(), authtypes.FeeCollectorName) | ||
suite.Require().True(fcAccount.HasPermission(authtypes.Burner)) | ||
}, | ||
func() { | ||
accountKeeper := suite.archway.GetApp().AccountKeeper | ||
fcAccount := accountKeeper.GetModuleAccount(suite.archway.GetContext(), authtypes.FeeCollectorName) | ||
suite.Require().True(fcAccount.HasPermission(authtypes.Burner)) | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
suite.Run(fmt.Sprintf("Case %s", tc.name), func() { | ||
suite.SetupTest() // reset | ||
|
||
tc.pre_upgrade() | ||
|
||
ctx := suite.archway.GetContext().WithBlockHeight(dummyUpgradeHeight - 1) | ||
plan := upgradetypes.Plan{Name: "v4.0.1", Height: dummyUpgradeHeight} | ||
upgradekeeper := suite.archway.GetApp().UpgradeKeeper | ||
err := upgradekeeper.ScheduleUpgrade(ctx, plan) | ||
suite.Require().NoError(err) | ||
_, exists := upgradekeeper.GetUpgradePlan(ctx) | ||
suite.Require().True(exists) | ||
ctx = ctx.WithBlockHeight(dummyUpgradeHeight) | ||
suite.Require().NotPanics(func() { | ||
suite.archway.GetApp().BeginBlocker(ctx, abci.RequestBeginBlock{}) | ||
}) | ||
|
||
tc.post_upgrade() | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.