Skip to content

Commit

Permalink
Merge branch 'main' into feat/wasmdir_flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs47 authored Feb 28, 2024
2 parents 8db2342 + c6c5294 commit 434a330
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
22 changes: 18 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func NewAxelarApp(
upgradeKeeper: *getKeeper[upgradekeeper.Keeper](keepers),
}

app.setUpgradeBehaviour(configurator)
app.setUpgradeBehaviour(configurator, keepers)

// initialize stores
app.MountKVStores(keys)
Expand Down Expand Up @@ -453,11 +453,25 @@ func initMessageRouter(keepers *KeeperCache) nexusTypes.MessageRouter {
return messageRouter
}

func (app *AxelarApp) setUpgradeBehaviour(configurator module.Configurator) {
func (app *AxelarApp) setUpgradeBehaviour(configurator module.Configurator, keepers *KeeperCache) {
app.upgradeKeeper.SetUpgradeHandler(
upgradeName(app.Version()),
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, configurator, fromVM)
updatedVM, err := app.mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return updatedVM, err
}

// TODO: remove after v35 upgrade
// Override wasm module default params
if upgradeName(app.Version()) == "v0.35" && IsWasmEnabled() {
getKeeper[wasm.Keeper](keepers).SetParams(ctx, wasmtypes.Params{
CodeUploadAccess: wasmtypes.AllowNobody,
InstantiateDefaultPermission: wasmtypes.AccessTypeNobody,
})
}

return updatedVM, err
},
)

Expand Down Expand Up @@ -1041,7 +1055,7 @@ func GetModuleBasics() module.BasicManager {
}

if IsWasmEnabled() {
managers = append(managers, NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{}, authtypes.NewModuleAddress(govtypes.ModuleName)))
managers = append(managers, NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{}))
}

if IsIBCWasmHooksEnabled() {
Expand Down
8 changes: 3 additions & 5 deletions app/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,11 @@ func isIBCSendPacketMsg(msg wasmvmtypes.CosmosMsg) bool {

type WasmAppModuleBasicOverride struct {
wasm.AppModuleBasic
uploader sdk.AccAddress
}

func NewWasmAppModuleBasicOverride(wasmModule wasm.AppModuleBasic, uploader sdk.AccAddress) WasmAppModuleBasicOverride {
func NewWasmAppModuleBasicOverride(wasmModule wasm.AppModuleBasic) WasmAppModuleBasicOverride {
return WasmAppModuleBasicOverride{
AppModuleBasic: wasmModule,
uploader: uploader,
}
}

Expand All @@ -134,8 +132,8 @@ func NewWasmAppModuleBasicOverride(wasmModule wasm.AppModuleBasic, uploader sdk.
func (m WasmAppModuleBasicOverride) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(&wasm.GenesisState{
Params: wasmtypes.Params{
CodeUploadAccess: wasmtypes.AccessTypeAnyOfAddresses.With(m.uploader),
InstantiateDefaultPermission: wasmtypes.AccessTypeAnyOfAddresses,
CodeUploadAccess: wasmtypes.AllowNobody,
InstantiateDefaultPermission: wasmtypes.AccessTypeNobody,
},
})
}
9 changes: 3 additions & 6 deletions app/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -242,8 +241,7 @@ func TestMsgTypeBlacklistMessenger_DispatchMsg(t *testing.T) {
}

func TestNewWasmAppModuleBasicOverride(t *testing.T) {
uploader := authtypes.NewModuleAddress("allowed to upload")
wasmModule := app.NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{}, uploader)
wasmModule := app.NewWasmAppModuleBasicOverride(wasm.AppModuleBasic{})
cdc := app.MakeEncodingConfig().Codec

genesis := wasmModule.DefaultGenesis(cdc)
Expand All @@ -252,9 +250,8 @@ func TestNewWasmAppModuleBasicOverride(t *testing.T) {
var state wasm.GenesisState
assert.NoError(t, cdc.UnmarshalJSON(genesis, &state))

assert.Equal(t, state.Params.InstantiateDefaultPermission, wasmtypes.AccessTypeAnyOfAddresses)
assert.True(t, state.Params.CodeUploadAccess.Allowed(uploader))
assert.Len(t, state.Params.CodeUploadAccess.AllAuthorizedAddresses(), 1)
assert.Equal(t, state.Params.InstantiateDefaultPermission, wasmtypes.AccessTypeNobody)
assert.True(t, state.Params.CodeUploadAccess.Equals(wasmtypes.AllowNobody))
}

func TestICSMiddleWare(t *testing.T) {
Expand Down

0 comments on commit 434a330

Please sign in to comment.