Skip to content

Commit

Permalink
Add v20 Upgrade Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Jan 29, 2024
1 parent f029efe commit 87c5ad1
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 105 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import (
v17 "github.com/CosmosContracts/juno/v19/app/upgrades/v17"
v18 "github.com/CosmosContracts/juno/v19/app/upgrades/v18"
v19 "github.com/CosmosContracts/juno/v19/app/upgrades/v19"
v20 "github.com/CosmosContracts/juno/v19/app/upgrades/v20"
"github.com/CosmosContracts/juno/v19/docs"
)

Expand Down Expand Up @@ -117,6 +118,7 @@ var (
v17.Upgrade,
v18.Upgrade,
v19.Upgrade,
v20.Upgrade,
}
)

Expand Down
35 changes: 0 additions & 35 deletions app/upgrades/v19/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,6 @@ func TestKeeperTestSuite(t *testing.T) {
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

// Setup mainnet account
_, err := v19.CreateMainnetVestingAccount(s.Ctx, s.App.AppKeepers)
s.Require().NoError(err)

// Create 3 generic validators
val1 := s.SetupValidator(stakingtypes.Bonded)
val2 := s.SetupValidator(stakingtypes.Bonded)
val3 := s.SetupValidator(stakingtypes.Bonded)

// Get last validator, set as mock jack validator
val, found := s.App.AppKeepers.StakingKeeper.GetValidator(s.Ctx, val3)
s.Require().True(found)
v19.JackValidatorAddress = val.OperatorAddress

validators := []sdk.ValAddress{val1, val2, val3}

// Should equal 4, including default validator
s.Require().Equal(4, len(s.App.AppKeepers.StakingKeeper.GetAllValidators(s.Ctx)))

// Create delegations to each validator 2x, ensuring multiple delegations
// are created for each validator and combined in state.
for i := 0; i < 2; i++ {
for _, delegator := range v19.Core1VestingAccounts {
delegatorAddr := sdk.MustAccAddressFromBech32(delegator.Address)

for _, validator := range validators {

fmt.Println("Delegator: ", delegatorAddr.String())
fmt.Println("Delegating to validator: ", validator.String())

s.StakingHelper.Delegate(delegatorAddr, validator, sdk.NewInt(1_000_000))
}
}
}

preUpgradeChecks(s)

upgradeHeight := int64(5)
Expand Down
68 changes: 0 additions & 68 deletions app/upgrades/v19/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,6 @@ import (
"github.com/CosmosContracts/juno/v19/app/upgrades"
)

const (
// Charter Council's SubDAO Address
CharterCouncil = "juno1nmezpepv3lx45mndyctz2lzqxa6d9xzd2xumkxf7a6r4nxt0y95qypm6c0"
JackKey = "jack"
)

// JackValidatorAddress must be mutable for testing
var JackValidatorAddress = "junovaloper130mdu9a0etmeuw52qfxk73pn0ga6gawk2tz77l"

type IndividualAccount struct {
Owner string
Address string
}

// Core1VestingAccounts https://daodao.zone/dao/juno1j6glql3xmrcnga0gytecsucq3kd88jexxamxg3yn2xnqhunyvflqr7lxx3/members
var Core1VestingAccounts = []IndividualAccount{
{
Owner: "block",
Address: "juno17py8gfneaam64vt9kaec0fseqwxvkq0flmsmhg",
},
{
Owner: "dimi",
Address: "juno1s33zct2zhhaf60x4a90cpe9yquw99jj0zen8pt",
},
{
Owner: JackKey,
Address: "juno130mdu9a0etmeuw52qfxk73pn0ga6gawk4k539x",
},
{
Owner: "jake",
Address: "juno18qw9ydpewh405w4lvmuhlg9gtaep79vy2gmtr2",
},
{
Owner: "multisig",
Address: "juno190g5j8aszqhvtg7cprmev8xcxs6csra7xnk3n3",
},
{
Owner: "wolf",
Address: "juno1a8u47ggy964tv9trjxfjcldutau5ls705djqyu",
},
}

func CreateV19UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
Expand Down Expand Up @@ -92,32 +50,6 @@ func CreateV19UpgradeHandler(
params.AllowedClients = append(params.AllowedClients, wasmlctypes.Wasm)
k.IBCKeeper.ClientKeeper.SetParams(ctx, params)

// Migrate Core-1 vesting account remaining funds -> Council SubDAO
// if ctx.ChainID() == "juno-1" {

if err := migrateCore1VestingAccounts(ctx, k, nativeDenom); err != nil {
return nil, err
}
// }

return versionMap, err
}
}

func migrateCore1VestingAccounts(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string) error {
for _, account := range Core1VestingAccounts {
// A new vesting contract will not be created if the account name is 'wolf'.
if err := MoveVestingCoinFromVestingAccount(ctx,
keepers,
bondDenom,
account.Owner,
sdk.MustAccAddressFromBech32(account.Address),
sdk.MustAccAddressFromBech32(CharterCouncil),
); err != nil {
return err
}
}

// return fmt.Errorf("DEBUGGING; not finished yet. (migrateCore1VestingAccounts)")
return nil
}
22 changes: 22 additions & 0 deletions app/upgrades/v20/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v20

import (
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"

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

"github.com/CosmosContracts/juno/v19/app/upgrades"
)

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

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV20UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
wasmlctypes.ModuleName,
},
},
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v19
package v20

import (
"encoding/json"
Expand Down
73 changes: 73 additions & 0 deletions app/upgrades/v20/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package v20_test

import (
"testing"

"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/CosmosContracts/juno/v19/app/apptesting"
v20 "github.com/CosmosContracts/juno/v19/app/upgrades/v20"
)

type UpgradeTestSuite struct {
apptesting.KeeperTestHelper
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

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

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

preUpgradeChecks(s)

upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v20.UpgradeName, upgradeHeight)

postUpgradeChecks(s)
}

func preUpgradeChecks(s *UpgradeTestSuite) {
// Setup mainnet account
_, err := v20.CreateMainnetVestingAccount(s.Ctx, s.App.AppKeepers)
s.Require().NoError(err)

// Create 3 generic validators
val1 := s.SetupValidator(stakingtypes.Bonded)
val2 := s.SetupValidator(stakingtypes.Bonded)
val3 := s.SetupValidator(stakingtypes.Bonded)

// Get last validator, set as mock jack validator
val, found := s.App.AppKeepers.StakingKeeper.GetValidator(s.Ctx, val3)
s.Require().True(found)
v20.JackValidatorAddress = val.OperatorAddress

validators := []sdk.ValAddress{val1, val2, val3}

// Should equal 4, including default validator
s.Require().Equal(4, len(s.App.AppKeepers.StakingKeeper.GetAllValidators(s.Ctx)))

// Create delegations to each validator 2x, ensuring multiple delegations
// are created for each validator and combined in state.
for i := 0; i < 2; i++ {
for _, delegator := range v20.Core1VestingAccounts {
delegatorAddr := sdk.MustAccAddressFromBech32(delegator.Address)

for _, validator := range validators {
s.StakingHelper.Delegate(delegatorAddr, validator, sdk.NewInt(1_000_000))
}
}
}
}

func postUpgradeChecks(_ *UpgradeTestSuite) {
}
101 changes: 101 additions & 0 deletions app/upgrades/v20/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package v20

import (
"fmt"

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/CosmosContracts/juno/v19/app/keepers"
"github.com/CosmosContracts/juno/v19/app/upgrades"
)

const (
// Charter Council's SubDAO Address
CharterCouncil = "juno1nmezpepv3lx45mndyctz2lzqxa6d9xzd2xumkxf7a6r4nxt0y95qypm6c0"
JackKey = "jack"
)

// JackValidatorAddress must be mutable for testing
var JackValidatorAddress = "junovaloper130mdu9a0etmeuw52qfxk73pn0ga6gawk2tz77l"

type IndividualAccount struct {
Owner string
Address string
}

// Core1VestingAccounts https://daodao.zone/dao/juno1j6glql3xmrcnga0gytecsucq3kd88jexxamxg3yn2xnqhunyvflqr7lxx3/members
var Core1VestingAccounts = []IndividualAccount{
{
Owner: "block",
Address: "juno17py8gfneaam64vt9kaec0fseqwxvkq0flmsmhg",
},
{
Owner: "dimi",
Address: "juno1s33zct2zhhaf60x4a90cpe9yquw99jj0zen8pt",
},
{
Owner: JackKey,
Address: "juno130mdu9a0etmeuw52qfxk73pn0ga6gawk4k539x",
},
{
Owner: "jake",
Address: "juno18qw9ydpewh405w4lvmuhlg9gtaep79vy2gmtr2",
},
{
Owner: "multisig",
Address: "juno190g5j8aszqhvtg7cprmev8xcxs6csra7xnk3n3",
},
{
Owner: "wolf",
Address: "juno1a8u47ggy964tv9trjxfjcldutau5ls705djqyu",
},
}

func CreateV20UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
k *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

nativeDenom := upgrades.GetChainsDenomToken(ctx.ChainID())
logger.Info(fmt.Sprintf("With native denom %s", nativeDenom))

// Run migrations
logger.Info(fmt.Sprintf("pre migrate version map: %v", vm))
versionMap, err := mm.RunMigrations(ctx, cfg, vm)
if err != nil {
return nil, err
}
logger.Info(fmt.Sprintf("post migrate version map: %v", versionMap))

// Migrate Core-1 vesting account remaining funds -> Council SubDAO
if ctx.ChainID() == "juno-1" {
if err := migrateCore1VestingAccounts(ctx, k, nativeDenom); err != nil {
return nil, err
}
}

return versionMap, err
}
}

// Migrate balances from the Core-1 vesting accounts to the Council SubDAO.
func migrateCore1VestingAccounts(ctx sdk.Context, keepers *keepers.AppKeepers, bondDenom string) error {
for _, account := range Core1VestingAccounts {
// A new vesting contract will not be created if the account name is 'wolf'.
if err := MoveVestingCoinFromVestingAccount(ctx,
keepers,
bondDenom,
account.Owner,
sdk.MustAccAddressFromBech32(account.Address),
sdk.MustAccAddressFromBech32(CharterCouncil),
); err != nil {
return err
}
}
return nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v19
package v20

import (
"fmt"
Expand Down

0 comments on commit 87c5ad1

Please sign in to comment.