Skip to content
Merged
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
v12 "github.com/classic-terra/core/v4/app/upgrades/v12"
v13 "github.com/classic-terra/core/v4/app/upgrades/v13"
v13_1 "github.com/classic-terra/core/v4/app/upgrades/v13_1"
v14 "github.com/classic-terra/core/v4/app/upgrades/v14"
v14_1 "github.com/classic-terra/core/v4/app/upgrades/v14_1"
v2 "github.com/classic-terra/core/v4/app/upgrades/v2"
v3 "github.com/classic-terra/core/v4/app/upgrades/v3"
v4 "github.com/classic-terra/core/v4/app/upgrades/v4"
Expand Down Expand Up @@ -104,7 +104,7 @@ var (
v12.Upgrade,
v13.Upgrade,
v13_1.Upgrade,
v14.Upgrade,
v14_1.Upgrade,
}

// Forks defines forks to be applied to the network
Expand Down
1 change: 0 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ func initParamsKeeper(
paramsKeeper.Subspace(authtypes.ModuleName).WithKeyTable(authtypes.ParamKeyTable())
paramsKeeper.Subspace(banktypes.ModuleName).WithKeyTable(banktypes.ParamKeyTable())
paramsKeeper.Subspace(stakingtypes.ModuleName).WithKeyTable(stakingtypes.ParamKeyTable())
paramsKeeper.Subspace(minttypes.ModuleName).WithKeyTable(minttypes.ParamKeyTable())
paramsKeeper.Subspace(distrtypes.ModuleName).WithKeyTable(distrtypes.ParamKeyTable())
paramsKeeper.Subspace(slashingtypes.ModuleName).WithKeyTable(slashingtypes.ParamKeyTable())
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypesv1.ParamKeyTable())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package v14
//nolint:revive
package v14_1

import (
store "cosmossdk.io/store/types"
"github.com/classic-terra/core/v4/app/upgrades"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
)

const UpgradeName = "v14"
const UpgradeName = "v14_1"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV14UpgradeHandler,
CreateUpgradeHandler: CreateV141UpgradeHandler,
// Add new stores introduced since the last upgrade here. If there are
// no new stores for this upgrade, leave this empty.
StoreUpgrades: store.StoreUpgrades{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package v14
//nolint:revive
package v14_1

import (
"context"
Expand All @@ -11,9 +12,9 @@ import (
clienttypes "github.com/cosmos/ibc-go/v10/modules/core/02-client/types"
)

// CreateV14UpgradeHandler wires module migrations for v14.
// CreateV141UpgradeHandler wires module migrations for v14_1.
// Add any one-off migration logic here before/after RunMigrations if needed.
func CreateV14UpgradeHandler(
func CreateV141UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
Expand Down
3 changes: 0 additions & 3 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -45,8 +44,6 @@ func CreateV8UpgradeHandler(
keyTable = banktypes.ParamKeyTable()
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable()
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable()
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable()
case slashingtypes.ModuleName:
Expand Down
56 changes: 54 additions & 2 deletions custom/wasm/legacy_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"

storetypes "cosmossdk.io/store/types"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
legacytypes "github.com/classic-terra/core/v4/custom/wasm/types/legacy"
coretypes "github.com/classic-terra/core/v4/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -206,10 +208,60 @@ func stripLegacyLenPrefix(b []byte) []byte {
return b
}

func translateLegacyValueForKey(newKey, value []byte) []byte {
if len(newKey) == 0 || value == nil {
return value
}

switch newKey[0] {
case 0x01:
return translateLegacyCodeInfoValue(value)
case 0x02:
return translateLegacyContractInfoValue(value)
default:
return value
}
}

func translateLegacyCodeInfoValue(value []byte) []byte {
var legacyInfo legacytypes.LegacyCodeInfo
if err := legacyInfo.Unmarshal(value); err != nil {
return value
}

translated := wasmtypes.CodeInfo{
CodeHash: append([]byte(nil), legacyInfo.CodeHash...),
Creator: legacyInfo.Creator,
}
marshaled, err := translated.Marshal()
if err != nil {
return value
}
return marshaled
}

func translateLegacyContractInfoValue(value []byte) []byte {
var legacyInfo legacytypes.LegacyContractInfo
if err := legacyInfo.Unmarshal(value); err != nil {
return value
}

translated := wasmtypes.ContractInfo{
CodeID: legacyInfo.CodeID,
Creator: legacyInfo.Creator,
Admin: legacyInfo.Admin,
}
marshaled, err := translated.Marshal()
if err != nil {
return value
}
return marshaled
}

func (s *legacyWasmStore) Get(key []byte) []byte {
for _, cand := range translateNewToOld(key) {
if bz := s.parent.Get(cand); bz != nil {
return bz
return translateLegacyValueForKey(key, bz)
}
}
return nil
Expand Down Expand Up @@ -351,7 +403,7 @@ func (it *legacyIterator) advance() {
continue
}
it.key = newKey
it.val = it.under.Value()
it.val = translateLegacyValueForKey(newKey, it.under.Value())
it.valid = true
it.under.Next() // Advance before returning, since post-statement won't run
return
Expand Down
86 changes: 86 additions & 0 deletions custom/wasm/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
wasmvmtypes "github.com/CosmWasm/wasmvm/v3/types"
legacytypes "github.com/classic-terra/core/v4/custom/wasm/types/legacy"
coretypes "github.com/classic-terra/core/v4/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -451,6 +452,91 @@ func (suite *LegacyQueryHandlerTestSuite) TestHandleQuery_LegacyStoreIntegration
})
}

func (suite *LegacyQueryHandlerTestSuite) TestLegacyStore_TranslatesLegacyMetadataValues() {
ctx := suite.ctx.WithChainID(coretypes.ColumbusChainID).WithBlockHeight(25619229)
parent := ctx.KVStore(suite.storeKey)
legacyStore := &legacyWasmStore{parent: parent}

contractAddr := make([]byte, 20)
for i := range contractAddr {
contractAddr[i] = byte(i + 1)
}
codeID := uint64(77)

oldContractKey := append([]byte{0x04, 0x14}, contractAddr...)
oldContractValue, err := (&legacytypes.LegacyContractInfo{
Address: "terra1legacycontract",
Creator: "terra1creator",
Admin: "terra1admin",
CodeID: codeID,
InitMsg: []byte(`{"count":1}`),
}).Marshal()
require.NoError(suite.T(), err)
parent.Set(oldContractKey, oldContractValue)

oldCodeKey := append([]byte{0x03}, sdk.Uint64ToBigEndian(codeID)...)
oldCodeValue, err := (&legacytypes.LegacyCodeInfo{
CodeID: codeID,
CodeHash: []byte("legacy-hash"),
Creator: "terra1creator",
}).Marshal()
require.NoError(suite.T(), err)
parent.Set(oldCodeKey, oldCodeValue)

newContractKey := append([]byte{0x02}, contractAddr...)
contractBz := legacyStore.Get(newContractKey)
require.NotNil(suite.T(), contractBz)

var contractInfo wasmtypes.ContractInfo
require.NoError(suite.T(), contractInfo.Unmarshal(contractBz))
require.Equal(suite.T(), codeID, contractInfo.CodeID)
require.Equal(suite.T(), "terra1creator", contractInfo.Creator)
require.Equal(suite.T(), "terra1admin", contractInfo.Admin)
require.Empty(suite.T(), contractInfo.Label)

newCodeKey := append([]byte{0x01}, sdk.Uint64ToBigEndian(codeID)...)
codeBz := legacyStore.Get(newCodeKey)
require.NotNil(suite.T(), codeBz)

var codeInfo wasmtypes.CodeInfo
require.NoError(suite.T(), codeInfo.Unmarshal(codeBz))
require.Equal(suite.T(), []byte("legacy-hash"), codeInfo.CodeHash)
require.Equal(suite.T(), "terra1creator", codeInfo.Creator)
}

func (suite *LegacyQueryHandlerTestSuite) TestLegacyStore_IteratorTranslatesLegacyMetadataValues() {
ctx := suite.ctx.WithChainID(coretypes.ColumbusChainID).WithBlockHeight(25619229)
parent := ctx.KVStore(suite.storeKey)
legacyStore := &legacyWasmStore{parent: parent}

contractAddr := make([]byte, 20)
for i := range contractAddr {
contractAddr[i] = byte(20 - i)
}

oldContractKey := append([]byte{0x04, 0x14}, contractAddr...)
oldContractValue, err := (&legacytypes.LegacyContractInfo{
Address: "terra1legacycontract",
Creator: "terra1creator",
CodeID: 9,
}).Marshal()
require.NoError(suite.T(), err)
parent.Set(oldContractKey, oldContractValue)

iter := legacyStore.Iterator([]byte{0x02}, []byte{0x03})
defer iter.Close()

require.True(suite.T(), iter.Valid())
require.Equal(suite.T(), append([]byte{0x02}, contractAddr...), iter.Key())

var contractInfo wasmtypes.ContractInfo
require.NoError(suite.T(), contractInfo.Unmarshal(iter.Value()))
require.Equal(suite.T(), uint64(9), contractInfo.CodeID)
require.Equal(suite.T(), "terra1creator", contractInfo.Creator)
iter.Next()
require.False(suite.T(), iter.Valid())
}

// Test the isPreWasmKeyMigration function directly
func (suite *LegacyQueryHandlerTestSuite) TestIsPreWasmKeyMigration() {
testCases := []struct {
Expand Down
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ require (
cosmossdk.io/x/feegrant v0.2.0
cosmossdk.io/x/tx v1.1.0
cosmossdk.io/x/upgrade v0.2.0
github.com/CosmWasm/wasmd v0.61.5
github.com/CosmWasm/wasmvm/v3 v3.0.2
github.com/CosmWasm/wasmd v0.61.8
github.com/CosmWasm/wasmvm/v3 v3.0.3
github.com/cometbft/cometbft v0.38.21
github.com/cosmos/cosmos-db v1.1.3
github.com/cosmos/cosmos-sdk v0.53.4
github.com/cosmos/cosmos-sdk v0.53.6
github.com/cosmos/gogoproto v1.7.2
github.com/cosmos/ibc-apps/modules/ibc-hooks/v10 v10.0.0-20250826214904-d53749a559f6
github.com/cosmos/ibc-go/v10 v10.3.0
github.com/cosmos/ibc-go/v10 v10.5.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.4
github.com/google/gofuzz v1.2.0
Expand All @@ -33,7 +33,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.10.0
github.com/spf13/cobra v1.10.1
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
google.golang.org/genproto/googleapis/api v0.0.0-20250908214217-97024824d090
Expand All @@ -58,6 +58,7 @@ require (
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.51.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect
github.com/bits-and-blooms/bitset v1.24.3 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.14.2 // indirect
Expand All @@ -84,7 +85,7 @@ require (
github.com/emicklei/dot v1.8.0 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
github.com/ethereum/go-ethereum v1.15.11 // indirect
github.com/ethereum/go-ethereum v1.16.8 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/getsentry/sentry-go v0.35.0 // indirect
github.com/go-jose/go-jose/v4 v4.1.1 // indirect
Expand Down Expand Up @@ -171,7 +172,7 @@ require (
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v1.2.6 // indirect
github.com/cosmos/ledger-cosmos-go v0.16.0 // indirect
github.com/cosmos/ledger-cosmos-go v1.0.0 // indirect
github.com/danieljoos/wincred v1.2.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
Expand Down Expand Up @@ -236,14 +237,14 @@ require (
github.com/ulikunitz/xz v0.5.14 // indirect
github.com/zondax/hid v0.9.2 // indirect
go.etcd.io/bbolt v1.4.0 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/crypto v0.45.0 // indirect
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sync v0.17.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/term v0.34.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.37.0 // indirect
golang.org/x/text v0.31.0 // indirect
google.golang.org/api v0.247.0 // indirect
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
google.golang.org/protobuf v1.36.10
Expand Down
Loading
Loading