Skip to content

Commit

Permalink
fix: supply offsets for osmo token
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddyMc committed Oct 2, 2024
1 parent 002d10b commit 4c4dca1
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/upgrades/v27/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
)

// UpgradeName defines the on-chain upgrade name for the Osmosis v27 upgrade.
const UpgradeName = "v27"
const (
UpgradeName = "v27"
OsmoToken = "uosmo"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
Expand Down
10 changes: 10 additions & 0 deletions app/upgrades/v27/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ func CreateUpgradeHandler(
if err != nil {
return nil, err
}
bk := keepers.BankKeeper

// Get the old offset from the old key: []byte{0x88}
offsetOld := bk.GetSupplyOffsetOld(ctx, OsmoToken)

// Add the old offset to the new key: collection.NewPrefix(88)
bk.AddSupplyOffset(ctx, OsmoToken, offsetOld)

// Remove the old key: []byte{0x88}
bk.RemoveOldSupplyOffset(ctx, OsmoToken)

return migrations, nil
}
Expand Down
77 changes: 77 additions & 0 deletions app/upgrades/v27/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package v27_test

import (
"testing"
"time"

"github.com/stretchr/testify/suite"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/header"
upgradetypes "cosmossdk.io/x/upgrade/types"

"github.com/osmosis-labs/osmosis/v26/app/apptesting"
v27 "github.com/osmosis-labs/osmosis/v26/app/upgrades/v27"

"cosmossdk.io/x/upgrade"

addresscodec "github.com/cosmos/cosmos-sdk/codec/address"

"github.com/osmosis-labs/osmosis/osmomath"
)

const (
v27UpgradeHeight = int64(10)
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
preModule appmodule.HasPreBlocker
}

func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()
s.preModule = upgrade.NewAppModule(s.App.UpgradeKeeper, addresscodec.NewBech32Codec("osmo"))

s.PrepareSupplyOffsetTest()

// Run the upgrade
dummyUpgrade(s)
s.Require().NotPanics(func() {
_, err := s.preModule.PreBlock(s.Ctx)
s.Require().NoError(err)
})

s.ExecuteSupplyOffsetTest()
}

func dummyUpgrade(s *UpgradeTestSuite) {
s.Ctx = s.Ctx.WithBlockHeight(v27UpgradeHeight - 1)
plan := upgradetypes.Plan{Name: v27.Upgrade.UpgradeName, Height: v27UpgradeHeight}
err := s.App.UpgradeKeeper.ScheduleUpgrade(s.Ctx, plan)
s.Require().NoError(err)
_, err = s.App.UpgradeKeeper.GetUpgradePlan(s.Ctx)
s.Require().NoError(err)

s.Ctx = s.Ctx.WithHeaderInfo(header.Info{Height: v27UpgradeHeight, Time: s.Ctx.BlockTime().Add(time.Second)}).WithBlockHeight(v27UpgradeHeight)
}

func (s *UpgradeTestSuite) PrepareSupplyOffsetTest() {
// Set some supply offsets
s.App.BankKeeper.AddSupplyOffset(s.Ctx, v27.OsmoToken, osmomath.NewInt(1000))
s.App.BankKeeper.AddSupplyOffsetOld(s.Ctx, v27.OsmoToken, osmomath.NewInt(-500))
}

func (s *UpgradeTestSuite) ExecuteSupplyOffsetTest() {
coin := s.App.BankKeeper.GetSupplyWithOffset(s.Ctx, v27.OsmoToken)
offset := s.App.BankKeeper.GetSupplyOffset(s.Ctx, v27.OsmoToken)
oldOffset := s.App.BankKeeper.GetSupplyOffsetOld(s.Ctx, v27.OsmoToken)

s.Require().Equal("500uosmo", coin.String())
s.Require().Equal("500", offset.String())
s.Require().Equal("0", oldOffset.String())
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ replace (
// Direct cosmos-sdk branch link: https://github.com/osmosis-labs/cosmos-sdk/tree/osmo-v26/v0.50.10, current branch: osmo-v26/v0.50.10
// Direct commit link: https://github.com/osmosis-labs/cosmos-sdk/commit/5a045895704de7fdc69d144895dcd9f162481502
// Direct tag link: https://github.com/osmosis-labs/cosmos-sdk/releases/tag/v0.50.10-v26-osmo-2
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.50.10-v26-osmo-2
// NOTE: TEMP TAG, will be replaced after review and tagging
github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.50.10-v26-osmo-1.0.20241002161840-d2ff8f7253c7

// replace as directed by sdk upgrading.md https://github.com/cosmos/cosmos-sdk/blob/393de266c8675dc16cc037c1a15011b1e990975f/UPGRADING.md?plain=1#L713
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -912,8 +912,6 @@ github.com/ory/dockertest/v3 v3.11.0 h1:OiHcxKAvSDUwsEVh2BjxQQc/5EHz9n0va9awCtNG
github.com/ory/dockertest/v3 v3.11.0/go.mod h1:VIPxS1gwT9NpPOrfD3rACs8Y9Z7yhzO4SB194iUDnUI=
github.com/osmosis-labs/cometbft v0.38.12-v26-osmo-2 h1:9X9qTF0nXgn/U/jb6BV1kgRg5t/CdTHHOmx9cwsiDdw=
github.com/osmosis-labs/cometbft v0.38.12-v26-osmo-2/go.mod h1:a8NBI2IdO283RZdpH0MuXlze3j+lv6PXuzOtTCq4YGE=
github.com/osmosis-labs/cosmos-sdk v0.50.10-v26-osmo-2 h1:R0ahhobLCJ+GIA/RxC6NzNapQcwAilT7779Mep0Uu4o=
github.com/osmosis-labs/cosmos-sdk v0.50.10-v26-osmo-2/go.mod h1:sYSfC78jZEx6m0WOprklQJG4PMGSmNJ0Y8lYrsv/MfU=
github.com/osmosis-labs/cosmos-sdk/store v0.1.0-alpha.1.0.20240509221435-b8feb2ffb728 h1:AMz4HWC+WA/MwBQdsb11yIF9ForIvSLYYVy/jyhJ3/I=
github.com/osmosis-labs/cosmos-sdk/store v0.1.0-alpha.1.0.20240509221435-b8feb2ffb728/go.mod h1:gjE3DZe4t/+VeIk6CmrouyqiuDbZ7QOVDDq3nLqBTpg=
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 h1:YlmchqTmlwdWSmrRmXKR+PcU96ntOd8u10vTaTZdcNY=
Expand Down
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ use ./x/ibc-hooks
use ./x/epochs

replace github.com/onsi/ginkgo => github.com/onsi/ginkgo v1.16.5
replace github.com/cosmos/cosmos-sdk => github.com/osmosis-labs/cosmos-sdk v0.50.10-v26-osmo-1.0.20241002161840-d2ff8f7253c7

0 comments on commit 4c4dca1

Please sign in to comment.