-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rate limits in upgrade (#4340)
* added rate limits in upgrade * added upgrade test * refactor rate limiting tests and added rate limits pre-upgrade * lint * goimports * experiments for E2E * post merge lints * added RL before upgrade * just get the latest contract * experiments * updated wasm file * remove unnecessary prints * bad check * experiments without e2e * removed unnecessary fmt * param space initialization for rate limiting (#4360) * param space initialization for rate limiting * lint * better test * properly initialize empty params * fix typo * adding RL to E2E * removing RL again from E2E * debug * genesis * genesis 2 * add genesis and solve params bug * uncomment setup rate limiting * added configurable gov module * clean up * clean up and genesis test * upgrade handler * genesis clean up * clean up e2e * wire querier * route fix * fix router * debug things * fix init genesis bug * push fix * lint * fix * clean up upgrades * testing propper params after upgrade in E2E * "properly" unmarshaling the parm * goimports * allowing for types other than objects in cosmwasm queries * fix check for param reset * remove unnecessary prints * compiled with the proper vesion of workspace optimizer * Revert "compiled with the proper vesion of workspace optimizer" This reverts commit ab5cf6c. * added length check * params experiment for test with state-export --------- Co-authored-by: Roman <[email protected]> Co-authored-by: Roman <[email protected]> (cherry picked from commit a1e2b3d) # Conflicts: # app/keepers/modules.go # app/modules.go # app/upgrades/v15/export_test.go # app/upgrades/v15/upgrade_test.go # app/upgrades/v15/upgrades.go # tests/e2e/configurer/chain/commands.go # tests/e2e/e2e_test.go
- Loading branch information
1 parent
19e3b25
commit 67f633e
Showing
29 changed files
with
1,521 additions
and
245 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package v15 | ||
|
||
import ( | ||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
ibcratelimit "github.com/osmosis-labs/osmosis/v14/x/ibc-rate-limit" | ||
icqkeeper "github.com/strangelove-ventures/async-icq/v4/keeper" | ||
|
||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
|
||
gammkeeper "github.com/osmosis-labs/osmosis/v14/x/gamm/keeper" | ||
poolmanagerkeeper "github.com/osmosis-labs/osmosis/v14/x/poolmanager" | ||
) | ||
|
||
func MigrateNextPoolId(ctx sdk.Context, gammKeeper *gammkeeper.Keeper, poolmanagerKeeper *poolmanagerkeeper.Keeper) { | ||
migrateNextPoolId(ctx, gammKeeper, poolmanagerKeeper) | ||
} | ||
|
||
func RegisterOsmoIonMetadata(ctx sdk.Context, bankKeeper bankkeeper.Keeper) { | ||
registerOsmoIonMetadata(ctx, bankKeeper) | ||
} | ||
|
||
func SetICQParams(ctx sdk.Context, icqKeeper *icqkeeper.Keeper) { | ||
setICQParams(ctx, icqKeeper) | ||
} | ||
|
||
func SetRateLimits(ctx sdk.Context, accountKeeper *authkeeper.AccountKeeper, rateLimitingICS4Wrapper *ibcratelimit.ICS4Wrapper, wasmKeeper *wasmkeeper.Keeper) { | ||
setRateLimits(ctx, accountKeeper, rateLimitingICS4Wrapper, wasmKeeper) | ||
} |
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,161 @@ | ||
package v15_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"reflect" | ||
"testing" | ||
|
||
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" | ||
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types" | ||
|
||
ibcratelimittypes "github.com/osmosis-labs/osmosis/v14/x/ibc-rate-limit/types" | ||
|
||
gamm "github.com/osmosis-labs/osmosis/v14/x/gamm/keeper" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/osmosis-labs/osmosis/v14/app/apptesting" | ||
v15 "github.com/osmosis-labs/osmosis/v14/app/upgrades/v15" | ||
) | ||
|
||
type UpgradeTestSuite struct { | ||
apptesting.KeeperTestHelper | ||
} | ||
|
||
func (suite *UpgradeTestSuite) SetupTest() { | ||
suite.Setup() | ||
} | ||
|
||
func TestUpgradeTestSuite(t *testing.T) { | ||
suite.Run(t, new(UpgradeTestSuite)) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestMigrateNextPoolIdAndCreatePool() { | ||
suite.SetupTest() // reset | ||
|
||
const ( | ||
expectedNextPoolId uint64 = 1 | ||
) | ||
|
||
var ( | ||
gammKeeperType = reflect.TypeOf(&gamm.Keeper{}) | ||
) | ||
|
||
ctx := suite.Ctx | ||
gammKeeper := suite.App.GAMMKeeper | ||
poolmanagerKeeper := suite.App.PoolManagerKeeper | ||
|
||
nextPoolId := gammKeeper.GetNextPoolId(ctx) | ||
suite.Require().Equal(expectedNextPoolId, nextPoolId) | ||
|
||
// system under test. | ||
v15.MigrateNextPoolId(ctx, gammKeeper, poolmanagerKeeper) | ||
|
||
// validate poolmanager's next pool id. | ||
actualNextPoolId := poolmanagerKeeper.GetNextPoolId(ctx) | ||
suite.Require().Equal(expectedNextPoolId, actualNextPoolId) | ||
|
||
// create a pool after migration. | ||
actualCreatedPoolId := suite.PrepareBalancerPool() | ||
suite.Require().Equal(expectedNextPoolId, actualCreatedPoolId) | ||
|
||
// validate that module route mapping has been created for each pool id. | ||
for poolId := uint64(1); poolId < expectedNextPoolId; poolId++ { | ||
swapModule, err := poolmanagerKeeper.GetPoolModule(ctx, poolId) | ||
suite.Require().NoError(err) | ||
|
||
suite.Require().Equal(gammKeeperType, reflect.TypeOf(swapModule)) | ||
} | ||
|
||
// validate params | ||
gammPoolCreationFee := gammKeeper.GetParams(ctx).PoolCreationFee | ||
poolmanagerPoolCreationFee := poolmanagerKeeper.GetParams(ctx).PoolCreationFee | ||
suite.Require().Equal(gammPoolCreationFee, poolmanagerPoolCreationFee) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestRegisterOsmoIonMetadata() { | ||
suite.SetupTest() // reset | ||
|
||
expectedUosmodenom := "uosmo" | ||
expectedUiondenom := "uion" | ||
|
||
ctx := suite.Ctx | ||
bankKeeper := suite.App.BankKeeper | ||
|
||
// meta data should not be found pre-registration of meta data | ||
uosmoMetadata, found := suite.App.BankKeeper.GetDenomMetaData(ctx, "uosmo") | ||
suite.Require().False(found) | ||
|
||
uionMetadata, found := suite.App.BankKeeper.GetDenomMetaData(ctx, "uion") | ||
suite.Require().False(found) | ||
|
||
// system under test. | ||
v15.RegisterOsmoIonMetadata(ctx, *bankKeeper) | ||
|
||
uosmoMetadata, found = suite.App.BankKeeper.GetDenomMetaData(ctx, "uosmo") | ||
suite.Require().True(found) | ||
|
||
uionMetadata, found = suite.App.BankKeeper.GetDenomMetaData(ctx, "uion") | ||
suite.Require().True(found) | ||
|
||
suite.Require().Equal(expectedUosmodenom, uosmoMetadata.Base) | ||
suite.Require().Equal(expectedUiondenom, uionMetadata.Base) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestSetICQParams() { | ||
suite.SetupTest() // reset | ||
|
||
// system under test. | ||
v15.SetICQParams(suite.Ctx, suite.App.ICQKeeper) | ||
|
||
suite.Require().True(suite.App.ICQKeeper.IsHostEnabled(suite.Ctx)) | ||
suite.Require().Len(suite.App.ICQKeeper.GetAllowQueries(suite.Ctx), 63) | ||
} | ||
|
||
func (suite *UpgradeTestSuite) TestSetRateLimits() { | ||
suite.SetupTest() // reset | ||
accountKeeper := suite.App.AccountKeeper | ||
govModule := accountKeeper.GetModuleAddress(govtypes.ModuleName) | ||
|
||
code, err := os.ReadFile("../v13/rate_limiter.wasm") | ||
suite.Require().NoError(err) | ||
contractKeeper := wasmkeeper.NewGovPermissionKeeper(suite.App.WasmKeeper) | ||
instantiateConfig := wasmtypes.AccessConfig{Permission: wasmtypes.AccessTypeOnlyAddress, Address: govModule.String()} | ||
codeID, _, err := contractKeeper.Create(suite.Ctx, govModule, code, &instantiateConfig) | ||
suite.Require().NoError(err) | ||
transferModule := accountKeeper.GetModuleAddress(transfertypes.ModuleName) | ||
initMsgBz := []byte(fmt.Sprintf(`{ | ||
"gov_module": "%s", | ||
"ibc_module":"%s", | ||
"paths": [] | ||
}`, | ||
govModule, transferModule)) | ||
|
||
addr, _, err := contractKeeper.Instantiate(suite.Ctx, codeID, govModule, govModule, initMsgBz, "rate limiting contract", nil) | ||
suite.Require().NoError(err) | ||
addrStr, err := sdk.Bech32ifyAddressBytes("osmo", addr) | ||
suite.Require().NoError(err) | ||
params, err := ibcratelimittypes.NewParams(addrStr) | ||
suite.Require().NoError(err) | ||
paramSpace, ok := suite.App.ParamsKeeper.GetSubspace(ibcratelimittypes.ModuleName) | ||
suite.Require().True(ok) | ||
paramSpace.SetParamSet(suite.Ctx, ¶ms) | ||
|
||
// system under test. | ||
v15.SetRateLimits(suite.Ctx, accountKeeper, suite.App.RateLimitingICS4Wrapper, suite.App.WasmKeeper) | ||
|
||
state, err := suite.App.WasmKeeper.QuerySmart(suite.Ctx, addr, []byte(`{"get_quotas": {"channel_id": "any", "denom": "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2"}}`)) | ||
suite.Require().Greaterf(len(state), 0, "state should not be empty") | ||
|
||
state, err = suite.App.WasmKeeper.QuerySmart(suite.Ctx, addr, []byte(`{"get_quotas": {"channel_id": "any", "denom": "ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858"}}`)) | ||
suite.Require().Greaterf(len(state), 0, "state should not be empty") | ||
|
||
// This is the last one. If the others failed the upgrade would've panicked before adding this one | ||
state, err = suite.App.WasmKeeper.QuerySmart(suite.Ctx, addr, []byte(`{"get_quotas": {"channel_id": "any", "denom": "ibc/E6931F78057F7CC5DA0FD6CEF82FF39373A6E0452BF1FD76910B93292CF356C1"}}`)) | ||
suite.Require().Greaterf(len(state), 0, "state should not be empty") | ||
|
||
} |
Oops, something went wrong.