Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cosmos-50 #39

Merged
merged 11 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
steps:
- uses: actions/[email protected]
with:
go-version: 1.19
go-version: 1.21
- uses: technote-space/get-diff-action@v5
id: git_diff
with:
Expand Down Expand Up @@ -60,7 +60,7 @@ jobs:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
# for private repo access
- run: git config --global url.https://${GITHUB_ACCESS_TOKEN}:[email protected]/.insteadOf https://github.com/
- run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
- name: Install openssl
run: sudo apt-get install libssl-dev
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ante

import (
"cosmossdk.io/errors"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
582 changes: 221 additions & 361 deletions app/app.go

Large diffs are not rendered by default.

47 changes: 21 additions & 26 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,32 @@ import (
"os"
"testing"

dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"

"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/cosmos-sdk/testutil/mock"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/ibc-go/modules/capability"

feegrantmodule "cosmossdk.io/x/feegrant/module"
"cosmossdk.io/x/upgrade"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/params"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/upgrade"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
"github.com/strangelove-ventures/packet-forward-middleware/v7/router"
ica "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts"
ibctransfer "github.com/cosmos/ibc-go/v8/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v8/modules/core"

"github.com/initia-labs/initia/x/bank"
"github.com/initia-labs/initia/x/distribution"
Expand Down Expand Up @@ -77,10 +74,10 @@ func TestGetMaccPerms(t *testing.T) {

func TestInitGenesisOnMigration(t *testing.T) {
db := dbm.NewMemDB()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
logger := log.NewLogger(os.Stdout)
app := NewInitiaApp(
logger, db, nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()})

// Create a mock module. This module will serve as the new module we're
// adding during a migration.
Expand All @@ -89,14 +86,14 @@ func TestInitGenesisOnMigration(t *testing.T) {
mockModule := mock.NewMockAppModuleWithAllExtensions(mockCtrl)
mockDefaultGenesis := json.RawMessage(`{"key": "value"}`)
mockModule.EXPECT().DefaultGenesis(gomock.Eq(app.appCodec)).Times(1).Return(mockDefaultGenesis)
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1).Return(nil)
mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(app.appCodec), gomock.Eq(mockDefaultGenesis)).Times(1)
mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0))

app.mm.Modules["mock"] = mockModule
app.ModuleManager.Modules["mock"] = mockModule

// Run migrations only for "mock" module. We exclude it from
// the VersionMap to simulate upgrading with a new module.
_, err := app.mm.RunMigrations(ctx, app.configurator,
_, err := app.ModuleManager.RunMigrations(ctx, app.configurator,
module.VersionMap{
"bank": bank.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
Expand All @@ -106,7 +103,6 @@ func TestInitGenesisOnMigration(t *testing.T) {
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
"gov": gov.AppModule{}.ConsensusVersion(),
"params": params.AppModule{}.ConsensusVersion(),
"upgrade": upgrade.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
Expand All @@ -119,7 +115,6 @@ func TestInitGenesisOnMigration(t *testing.T) {
"transfer": ibctransfer.AppModule{}.ConsensusVersion(),
"nonfungibletokentransfer": nfttransfer.AppModule{}.ConsensusVersion(),
"interchainaccounts": ica.AppModule{}.ConsensusVersion(),
"packetfowardmiddleware": router.AppModule{}.ConsensusVersion(),
"permissionedchannelrelayer": ibcperm.AppModule{}.ConsensusVersion(),
"move": move.AppModule{}.ConsensusVersion(),
},
Expand All @@ -131,9 +126,11 @@ func TestUpgradeStateOnGenesis(t *testing.T) {
app := SetupWithGenesisAccounts(nil, nil)

// make sure the upgrade keeper has version map in state
ctx := app.NewContext(false, tmproto.Header{})
vm := app.UpgradeKeeper.GetModuleVersionMap(ctx)
for v, i := range app.mm.Modules {
ctx := app.NewContext(true)
vm, err := app.UpgradeKeeper.GetModuleVersionMap(ctx)
require.NoError(t, err)

for v, i := range app.ModuleManager.Modules {
if i, ok := i.(module.HasConsensusVersion); ok {
require.Equal(t, vm[v], i.ConsensusVersion())
}
Expand All @@ -143,10 +140,8 @@ func TestUpgradeStateOnGenesis(t *testing.T) {
func TestGetKey(t *testing.T) {
db := dbm.NewMemDB()
app := NewInitiaApp(
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
log.NewLogger(os.Stdout),
db, nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})

require.NotEmpty(t, app.GetKey(banktypes.StoreKey))
require.NotEmpty(t, app.GetTKey(paramstypes.TStoreKey))
require.NotEmpty(t, app.GetMemKey(capabilitytypes.MemStoreKey))
}
60 changes: 42 additions & 18 deletions app/encoding.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
package app

import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/std"

"cosmossdk.io/client/v2/autocli"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
dbm "github.com/cosmos/cosmos-db"
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
"github.com/initia-labs/initia/app/params"
moveconfig "github.com/initia-labs/initia/x/move/config"
)

var legacyCodecRegistered = false

// MakeEncodingConfig creates an EncodingConfig for testing
func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)

if !legacyCodecRegistered {
// authz module use this codec to get signbytes.
// authz MsgExec can execute all message types,
// so legacy.Cdc need to register all amino messages to get proper signature
ModuleBasics.RegisterLegacyAminoCodec(legacy.Cdc)
legacyCodecRegistered = true
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApp.InterfaceRegistry(),
Codec: tempApp.AppCodec(),
TxConfig: tempApp.TxConfig(),
Amino: tempApp.LegacyAmino(),

Check warning on line 23 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L18-L23

Added lines #L18 - L23 were not covered by tests
}

return encodingConfig
}

func AutoCliOpts() autocli.AppOptions {
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
modules := make(map[string]appmodule.AppModule, 0)
for _, m := range tempApp.ModuleManager.Modules {
if moduleWithName, ok := m.(module.HasName); ok {
moduleName := moduleWithName.Name()
if appModule, ok := moduleWithName.(appmodule.AppModule); ok {
modules[moduleName] = appModule
}

Check warning on line 37 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L29-L37

Added lines #L29 - L37 were not covered by tests
}
}

return autocli.AppOptions{
Modules: modules,
ModuleOptions: runtimeservices.ExtractAutoCLIOptions(tempApp.ModuleManager.Modules),
AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()),
ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
}

Check warning on line 47 in app/encoding.go

View check run for this annotation

Codecov / codecov/patch

app/encoding.go#L41-L47

Added lines #L41 - L47 were not covered by tests
}

func BasicManager() module.BasicManager {
tempApp := NewInitiaApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), simtestutil.EmptyAppOptions{})
return tempApp.BasicModuleManager
}
Loading
Loading