From d337f40e36c372b83db1a24be3165d7a55f0858b Mon Sep 17 00:00:00 2001 From: sampocs Date: Mon, 4 Mar 2024 14:29:46 -0600 Subject: [PATCH 1/4] moved wasm permissions to own function --- app/upgrades/v19/upgrades.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/app/upgrades/v19/upgrades.go b/app/upgrades/v19/upgrades.go index 21fd793a54..b9ee0535af 100644 --- a/app/upgrades/v19/upgrades.go +++ b/app/upgrades/v19/upgrades.go @@ -1,6 +1,7 @@ package v19 import ( + errorsmod "cosmossdk.io/errors" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/cosmos/cosmos-sdk/codec" @@ -30,17 +31,24 @@ func CreateUpgradeHandler( return newVm, err } - // Update wasm params so that contracts can only be uploaded through governance - wasmParams := wasmKeeper.GetParams(ctx) - wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{ - Permission: wasmtypes.AccessTypeNobody, - Addresses: []string{}, - } - wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody - if err := wasmKeeper.SetParams(ctx, wasmParams); err != nil { - return newVm, err + if err := SetWasmPermissions(ctx, wasmKeeper); err != nil { + return newVm, errorsmod.Wrapf(err, "unable to set wasm permissions") } return newVm, nil } } + +// Update wasm params so that contracts can only be uploaded through governance +func SetWasmPermissions(ctx sdk.Context, wk wasmkeeper.Keeper) error { + wasmParams := wk.GetParams(ctx) + wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{ + Permission: wasmtypes.AccessTypeNobody, + Addresses: []string{}, + } + wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody + if err := wk.SetParams(ctx, wasmParams); err != nil { + return err + } + return nil +} From 3a92cb14538d7972643986da6c3570d8b6651d7c Mon Sep 17 00:00:00 2001 From: sampocs Date: Mon, 4 Mar 2024 14:30:40 -0600 Subject: [PATCH 2/4] changed perms to have an admin address --- app/upgrades/v19/upgrades.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/upgrades/v19/upgrades.go b/app/upgrades/v19/upgrades.go index b9ee0535af..897ea02b5f 100644 --- a/app/upgrades/v19/upgrades.go +++ b/app/upgrades/v19/upgrades.go @@ -12,6 +12,8 @@ import ( const ( UpgradeName = "v19" + + WasmAdmin = "TODO" ) // CreateUpgradeHandler creates an SDK upgrade handler for v19 @@ -43,8 +45,8 @@ func CreateUpgradeHandler( func SetWasmPermissions(ctx sdk.Context, wk wasmkeeper.Keeper) error { wasmParams := wk.GetParams(ctx) wasmParams.CodeUploadAccess = wasmtypes.AccessConfig{ - Permission: wasmtypes.AccessTypeNobody, - Addresses: []string{}, + Permission: wasmtypes.AccessTypeAnyOfAddresses, + Addresses: []string{WasmAdmin}, } wasmParams.InstantiateDefaultPermission = wasmtypes.AccessTypeNobody if err := wk.SetParams(ctx, wasmParams); err != nil { From f9a8e02f7b16ae7c5a2bdbc22b583cbb5673f071 Mon Sep 17 00:00:00 2001 From: sampocs Date: Mon, 4 Mar 2024 16:12:21 -0600 Subject: [PATCH 3/4] added unit test --- app/upgrades/v19/upgrades_test.go | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 app/upgrades/v19/upgrades_test.go diff --git a/app/upgrades/v19/upgrades_test.go b/app/upgrades/v19/upgrades_test.go new file mode 100644 index 0000000000..04616fce4a --- /dev/null +++ b/app/upgrades/v19/upgrades_test.go @@ -0,0 +1,40 @@ +package v19_test + +import ( + "testing" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/stretchr/testify/suite" + + "github.com/Stride-Labs/stride/v18/app/apptesting" + v19 "github.com/Stride-Labs/stride/v18/app/upgrades/v19" +) + +type UpgradeTestSuite struct { + apptesting.AppTestHelper +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(UpgradeTestSuite)) +} + +func (s *UpgradeTestSuite) SetupTest() { + s.Setup() +} + +func (s *UpgradeTestSuite) TestUpgrade() { + dummyUpgradeHeight := int64(5) + + // Run through upgrade + s.ConfirmUpgradeSucceededs("v19", dummyUpgradeHeight) + + // Check state after upgrade + s.CheckWasmPerms() +} + +func (s *UpgradeTestSuite) CheckWasmPerms() { + wasmParams := s.App.WasmKeeper.GetParams(s.Ctx) + s.Require().Equal(wasmtypes.AccessTypeAnyOfAddresses, wasmParams.CodeUploadAccess.Permission, "upload permission") + s.Require().Equal(v19.WasmAdmin, wasmParams.CodeUploadAccess.Addresses[0], "upload address") + s.Require().Equal(wasmtypes.AccessTypeNobody, wasmParams.InstantiateDefaultPermission, "instantiate permission") +} From 8aa492776a14fad016ff385b6959f023df2179cd Mon Sep 17 00:00:00 2001 From: sampocs Date: Mon, 4 Mar 2024 21:25:34 -0600 Subject: [PATCH 4/4] set address --- app/upgrades/v19/upgrades.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/upgrades/v19/upgrades.go b/app/upgrades/v19/upgrades.go index 897ea02b5f..7a2a3e7370 100644 --- a/app/upgrades/v19/upgrades.go +++ b/app/upgrades/v19/upgrades.go @@ -13,7 +13,7 @@ import ( const ( UpgradeName = "v19" - WasmAdmin = "TODO" + WasmAdmin = "stride159smvptpq6evq0x6jmca6t8y7j8xmwj6kxapyh" ) // CreateUpgradeHandler creates an SDK upgrade handler for v19