Skip to content

Commit

Permalink
auto: code-gen upgrade handler v18 (osmosis-labs#6107)
Browse files Browse the repository at this point in the history
* [create-pull-request] automated change

* Update config.go

* remove v17 specific tests from e2e

* change config.go

* use alpine image

* small improvement to e2e

---------

Co-authored-by: czarcas7ic <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
  • Loading branch information
4 people authored Aug 18, 2023
1 parent ae2f485 commit 1f7426c
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"OSMOSIS_E2E_SKIP_UPGRADE": "true",
"OSMOSIS_E2E_SKIP_CLEANUP": "true",
"OSMOSIS_E2E_SKIP_STATE_SYNC": "true",
"OSMOSIS_E2E_UPGRADE_VERSION": "v17",
"OSMOSIS_E2E_UPGRADE_VERSION": "v18",
"OSMOSIS_E2E_DEBUG_LOG": "false",
},
"preLaunchTask": "e2e-setup"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
E2E_UPGRADE_VERSION := "v17"
E2E_UPGRADE_VERSION := "v18"
#SHELL := /bin/bash

GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
Expand Down
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
v15 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v15"
v16 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v16"
v17 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v17"
v18 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v18"
v3 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v3"
v4 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v4"
v5 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v5"
Expand Down Expand Up @@ -103,7 +104,7 @@ var (

// _ sdksimapp.App = (*OsmosisApp)(nil)

Upgrades = []upgrades.Upgrade{v4.Upgrade, v5.Upgrade, v7.Upgrade, v9.Upgrade, v11.Upgrade, v12.Upgrade, v13.Upgrade, v14.Upgrade, v15.Upgrade, v16.Upgrade, v17.Upgrade}
Upgrades = []upgrades.Upgrade{v4.Upgrade, v5.Upgrade, v7.Upgrade, v9.Upgrade, v11.Upgrade, v12.Upgrade, v13.Upgrade, v14.Upgrade, v15.Upgrade, v16.Upgrade, v17.Upgrade, v18.Upgrade}
Forks = []upgrades.Fork{v3.Fork, v6.Fork, v8.Fork, v10.Fork}
)

Expand Down
19 changes: 19 additions & 0 deletions app/upgrades/v18/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v18

import (
"github.com/osmosis-labs/osmosis/v17/app/upgrades"

store "github.com/cosmos/cosmos-sdk/store/types"
)

// UpgradeName defines the on-chain upgrade name for the Osmosis v18 upgrade.
const UpgradeName = "v18"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
28 changes: 28 additions & 0 deletions app/upgrades/v18/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package v18

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/osmosis-labs/osmosis/v17/app/keepers"
"github.com/osmosis-labs/osmosis/v17/app/upgrades"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Run migrations before applying any other state changes.
// NOTE: DO NOT PUT ANY STATE CHANGES BEFORE RunMigrations().
migrations, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return nil, err
}

return migrations, nil
}
}
57 changes: 0 additions & 57 deletions tests/e2e/configurer/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

appparams "github.com/osmosis-labs/osmosis/v17/app/params"
v17 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v17"
"github.com/osmosis-labs/osmosis/v17/tests/e2e/configurer/chain"
"github.com/osmosis-labs/osmosis/v17/tests/e2e/configurer/config"
"github.com/osmosis-labs/osmosis/v17/tests/e2e/containers"
Expand Down Expand Up @@ -139,45 +138,6 @@ func (uc *UpgradeConfigurer) CreatePreUpgradeState() error {
// Wait for all goroutines to complete
wg.Wait()

// START: CAN REMOVE POST v17 UPGRADE

v17SuperfluidAssets := v17GetSuperfluidAssets()

wg.Add(2)

// START: CAN REMOVE POST v17 UPGRADE
authorizedQuoteDenoms := "[\"uosmo\",\"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2\",\"ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7\",\"ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858\",\"ibc/4ABBEF4C8926DDDB320AE5188CFD63267ABBCEFC0583E4AE05D6E5AA2401DDAB\",\"ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5\",\"ibc/D1542AA8762DB13087D8364F3EA6509FD6F009A34F00426AF9E4F9FA85CBBF1F\"]"
// END: CAN REMOVE POST v17 UPGRADE

// Chain A
go func() {
defer wg.Done()
chainANode.EnableSuperfluidAsset(chainA, v17SuperfluidAssets)
// START: CAN REMOVE POST v17 UPGRADE
err := chainANode.ParamChangeProposal("concentratedliquidity", "AuthorizedQuoteDenoms", []byte(authorizedQuoteDenoms), chainA)
if err != nil {
uc.t.Logf("error during param change proposal: %v", err)
}
// END: CAN REMOVE POST v17 UPGRADE
}()

// Chain B

go func() {
defer wg.Done()
chainBNode.EnableSuperfluidAsset(chainB, v17SuperfluidAssets)
// START: CAN REMOVE POST v17 UPGRADE
err := chainBNode.ParamChangeProposal("concentratedliquidity", "AuthorizedQuoteDenoms", []byte(authorizedQuoteDenoms), chainB)
if err != nil {
uc.t.Logf("error during param change proposal: %v", err)
}
// END: CAN REMOVE POST v17 UPGRADE
}()

wg.Wait()

// END: CAN REMOVE POST v17 UPGRADE

var (
poolShareDenom = make([]string, 2)
preUpgradePoolId = make([]uint64, 2)
Expand Down Expand Up @@ -453,20 +413,3 @@ func (uc *UpgradeConfigurer) upgradeContainers(chainConfig *chain.Config, propHe
uc.t.Logf("upgrade successful on chain %s", chainConfig.Id)
return nil
}

// START: CAN REMOVE POST v17 UPGRADE

func v17GetSuperfluidAssets() string {
assets := ""
for _, assetPair := range v17.AssetPairsForTestsOnly {
if assetPair.Superfluid {
assets += fmt.Sprintf("gamm/pool/%d,", assetPair.LinkedClassicPool)
}
}
if len(assets) > 0 {
assets = assets[:len(assets)-1]
}
return assets
}

// END: CAN REMOVE POST v17 UPGRADE
4 changes: 2 additions & 2 deletions tests/e2e/containers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const (
// It should be uploaded to Docker Hub. OSMOSIS_E2E_SKIP_UPGRADE should be unset
// for this functionality to be used.
previousVersionOsmoRepository = "osmolabs/osmosis-dev"
previousVersionOsmoTag = "16.0-alpine"
previousVersionOsmoTag = "17.0-alpine"
// Pre-upgrade repo/tag for osmosis initialization (this should be one version below upgradeVersion)
previousVersionInitRepository = "osmolabs/osmosis-e2e-init-chain"
previousVersionInitTag = "v16-faster-epoch"
previousVersionInitTag = "17.0.0-rc0"
// Hermes repo/version for relayer
relayerRepository = "informalsystems/hermes"
relayerTag = "1.5.1"
Expand Down
81 changes: 5 additions & 76 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/osmosis-labs/osmosis/osmoutils/osmoassert"
appparams "github.com/osmosis-labs/osmosis/v17/app/params"
v17 "github.com/osmosis-labs/osmosis/v17/app/upgrades/v17"
"github.com/osmosis-labs/osmosis/v17/tests/e2e/configurer/chain"
"github.com/osmosis-labs/osmosis/v17/tests/e2e/configurer/config"
"github.com/osmosis-labs/osmosis/v17/tests/e2e/initialization"
Expand Down Expand Up @@ -132,15 +131,6 @@ func (s *IntegrationTestSuite) TestAllE2E() {
})
}

if s.skipUpgrade {
s.T().Skip("Skipping ConcentratedLiquidity_CanonicalPools test")
} else {
s.T().Run("ConcentratedLiquidity_CanonicalPools", func(t *testing.T) {
t.Parallel()
s.ConcentratedLiquidity_CanonicalPools()
})
}

// IBC Dependent Tests

if s.skipIBC {
Expand Down Expand Up @@ -1220,11 +1210,10 @@ func (s *IntegrationTestSuite) IBCTokenTransferRateLimiting() {
}

func (s *IntegrationTestSuite) LargeWasmUpload() {
chainA := s.configurer.GetChainConfig(0)
chainANode, err := chainA.GetDefaultNode()
_, chainNode, err := s.getChainCfgs()
s.Require().NoError(err)
validatorAddr := chainANode.GetWallet(initialization.ValidatorWalletName)
chainANode.StoreWasmCode("bytecode/large.wasm", validatorAddr)
validatorAddr := chainNode.GetWallet(initialization.ValidatorWalletName)
chainNode.StoreWasmCode("bytecode/large.wasm", validatorAddr)
}

func (s *IntegrationTestSuite) IBCWasmHooks() {
Expand Down Expand Up @@ -1297,7 +1286,8 @@ func (s *IntegrationTestSuite) PacketForwarding() {
}
chainA, chainANode, err := s.getChainACfgs()
s.Require().NoError(err)
chainB := s.configurer.GetChainConfig(1)
chainB, _, err := s.getChainBCfgs()
s.Require().NoError(err)

// Instantiate the counter contract on chain A
contractAddr := s.UploadAndInstantiateCounter(chainA)
Expand Down Expand Up @@ -1799,64 +1789,3 @@ func (s *IntegrationTestSuite) GeometricTWAP() {
// quote assset supply / base asset supply = 1_000_000 / 2_000_000 = 0.5
osmoassert.DecApproxEq(s.T(), sdk.NewDecWithPrec(5, 1), afterSwapTwapBOverA, sdk.NewDecWithPrec(1, 2))
}

// START: CAN REMOVE POST v17 UPGRADE

// Tests that v17 upgrade correctly creates the canonical pools in the upgrade handler.
func (s *IntegrationTestSuite) ConcentratedLiquidity_CanonicalPools() {
if s.skipUpgrade {
s.T().Skip("Skipping v17 canonical pools creation test because upgrade is not enabled")
}

_, chainABNode, err := s.getChainCfgs()
s.Require().NoError(err)

for _, assetPair := range v17.AssetPairsForTestsOnly {
expectedSpreadFactor := assetPair.SpreadFactor
concentratedPoolId := chainABNode.QueryConcentratedPooIdLinkFromCFMM(assetPair.LinkedClassicPool)
concentratedPool := s.updatedConcentratedPool(chainABNode, concentratedPoolId)

s.Require().Equal(poolmanagertypes.Concentrated, concentratedPool.GetType())
s.Require().Equal(assetPair.BaseAsset, concentratedPool.GetToken0())
s.Require().Equal(assetPair.QuoteAsset, concentratedPool.GetToken1())
s.Require().Equal(uint64(v17.TickSpacing), concentratedPool.GetTickSpacing())
s.Require().Equal(expectedSpreadFactor.String(), concentratedPool.GetSpreadFactor(sdk.Context{}).String())

superfluidAssets := chainABNode.QueryAllSuperfluidAssets()

found := false
for _, superfluidAsset := range superfluidAssets {
if superfluidAsset.Denom == cltypes.GetConcentratedLockupDenomFromPoolId(concentratedPoolId) {
found = true
break
}
}

if assetPair.Superfluid {
s.Require().True(found, "concentrated liquidity pool denom not found in superfluid assets")
} else {
s.Require().False(found, "concentrated liquidity pool denom found in superfluid assets")
}

// This spot price is taken from the balancer pool that was initiated pre upgrade.
balancerPool := s.updatedCFMMPool(chainABNode, assetPair.LinkedClassicPool)
expectedSpotPrice, err := balancerPool.SpotPrice(sdk.Context{}, assetPair.QuoteAsset, assetPair.BaseAsset)
s.Require().NoError(err)

// Margin of error should be slightly larger than the gamm pool's spread factor, as the gamm pool is used to
// swap through when creating the initial position. The below implies a 0.1% margin of error.
tollerance := expectedSpreadFactor.Add(sdk.MustNewDecFromStr("0.0001"))
multiplicativeTolerance := osmomath.ErrTolerance{
MultiplicativeTolerance: tollerance,
}

s.Require().Equal(0, multiplicativeTolerance.CompareBigDec(osmomath.BigDecFromSDKDec(expectedSpotPrice), concentratedPool.GetCurrentSqrtPrice().PowerInteger(2)))
}

// Check that the community pool module account possesses positions for all the canonical pools.
communityPoolAddress := chainABNode.QueryCommunityPoolModuleAccount()
positions := chainABNode.QueryConcentratedPositions(communityPoolAddress)
s.Require().Len(positions, len(v17.AssetPairsForTestsOnly))
}

// END: CAN REMOVE POST v17 UPGRADE

0 comments on commit 1f7426c

Please sign in to comment.