Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependency-graph.png
# AI-assisted tools
.claude/
CLAUDE.md
my_doc/

# CI cache (populated during Docker builds)
.cache/
.cache/
149 changes: 149 additions & 0 deletions app/cron_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package app_test

import (
"context"
"testing"
"time"

sdkmath "cosmossdk.io/math"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/classic-terra/core/v4/app"
appparams "github.com/classic-terra/core/v4/app/params"
helpers "github.com/classic-terra/core/v4/app/testing"
coretypes "github.com/classic-terra/core/v4/types"
"github.com/classic-terra/core/v4/x/cron/types"
dyncommtypes "github.com/classic-terra/core/v4/x/dyncomm/types"
markettypes "github.com/classic-terra/core/v4/x/market/types"
oracletypes "github.com/classic-terra/core/v4/x/oracle/types"
taxtypes "github.com/classic-terra/core/v4/x/tax/types"
treasurytypes "github.com/classic-terra/core/v4/x/treasury/types"
abci "github.com/cometbft/cometbft/abci/types"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/require"
)

type appCronWasmMsgServer struct {
calls []*wasmtypes.MsgExecuteContract
}

func (s *appCronWasmMsgServer) ExecuteContract(_ context.Context, msg *wasmtypes.MsgExecuteContract) (*wasmtypes.MsgExecuteContractResponse, error) {
s.calls = append(s.calls, msg)
return &wasmtypes.MsgExecuteContractResponse{}, nil
}

func initCronAppState(t *testing.T, terraApp *app.TerraApp, ctx sdk.Context) {
t.Helper()

terraApp.ConsensusParamsKeeper.ParamsStore.Set(ctx, *helpers.DefaultConsensusParams)
terraApp.MintKeeper.Params.Set(ctx, minttypes.DefaultParams())
terraApp.MintKeeper.Minter.Set(ctx, minttypes.DefaultInitialMinter())

taxParams := taxtypes.DefaultParams()
taxParams.GasPrices = sdk.NewDecCoins(sdk.NewDecCoin(coretypes.MicroSDRDenom, sdkmath.ZeroInt()))
require.NoError(t, terraApp.TaxKeeper.SetParams(ctx, taxParams))

bankParams := banktypes.DefaultParams()
bankParams.DefaultSendEnabled = true
require.NoError(t, terraApp.BankKeeper.SetParams(ctx, bankParams))
terraApp.BankKeeper.SetSendEnabled(ctx, "uluna", true)

stakingParams := stakingtypes.DefaultParams()
stakingParams.BondDenom = appparams.BondDenom
require.NoError(t, terraApp.StakingKeeper.SetParams(ctx, stakingParams))
terraApp.DistrKeeper.Params.Set(ctx, distrtypes.DefaultParams())
terraApp.DistrKeeper.FeePool.Set(ctx, distrtypes.InitialFeePool())
terraApp.WasmKeeper.SetParams(ctx, wasmtypes.DefaultParams())
terraApp.MarketKeeper.SetParams(ctx, markettypes.DefaultParams())
terraApp.OracleKeeper.SetParams(ctx, oracletypes.DefaultParams())
terraApp.TreasuryKeeper.SetParams(ctx, treasurytypes.DefaultParams())
terraApp.DyncommKeeper.SetParams(ctx, dyncommtypes.DefaultParams())
}

type appBlockModule interface {
BeginBlock(context.Context) ([]abci.ValidatorUpdate, error)
EndBlock(context.Context) ([]abci.ValidatorUpdate, error)
}

func TestCronModuleWiredIntoApp(t *testing.T) {
terraApp := helpers.SetupApp(t, "cron-test")

require.Contains(t, terraApp.Modules(), types.ModuleName)
require.NotNil(t, terraApp.CronKeeper.WasmMsgServer)
require.True(t, terraApp.ModuleAccountAddrs()[authtypes.NewModuleAddress(types.ModuleName).String()])
}

func TestCronExecutesInBeginBlock(t *testing.T) {
terraApp := helpers.SetupApp(t, "cron-test")
fakeServer := &appCronWasmMsgServer{}
terraApp.CronKeeper.WasmMsgServer = fakeServer

ctx := terraApp.NewUncachedContext(false, tmproto.Header{ChainID: "cron-test"})
ctx = ctx.WithBlockHeight(9).WithBlockTime(time.Now().UTC())
initCronAppState(t, terraApp, ctx)

require.NoError(t, terraApp.CronKeeper.SetParams(ctx, types.NewParams(1)))
require.NoError(t, terraApp.CronKeeper.AddSchedule(
ctx,
"begin-job",
1,
[]types.MsgExecuteContract{{Contract: "terra1contract", Msg: `{"ping":{}}`}},
9,
types.ExecutionStage_EXECUTION_STAGE_BEGIN_BLOCKER,
))

execCtx := terraApp.NewUncachedContext(false, tmproto.Header{ChainID: "cron-test"})
execCtx = execCtx.WithBlockHeight(10).WithBlockTime(time.Now().UTC())
require.Equal(t, int64(10), execCtx.BlockHeight())

// Use the app-registered cron module instance so the test exercises the module
// exactly as Terra wires it into the app.
cronModule := terraApp.Modules()[types.ModuleName].(appBlockModule)
_, err := cronModule.BeginBlock(sdk.WrapSDKContext(execCtx))
require.NoError(t, err)
require.Len(t, fakeServer.calls, 1)

schedule, found := terraApp.CronKeeper.GetSchedule(execCtx, "begin-job")
require.True(t, found)
require.Equal(t, uint64(10), schedule.LastExecuteHeight)
}

func TestCronExecutesInEndBlock(t *testing.T) {
terraApp := helpers.SetupApp(t, "cron-test")
fakeServer := &appCronWasmMsgServer{}
terraApp.CronKeeper.WasmMsgServer = fakeServer

ctx := terraApp.NewUncachedContext(false, tmproto.Header{ChainID: "cron-test"})
ctx = ctx.WithBlockHeight(10).WithBlockTime(time.Now().UTC())
initCronAppState(t, terraApp, ctx)

require.NoError(t, terraApp.CronKeeper.SetParams(ctx, types.NewParams(1)))
require.NoError(t, terraApp.CronKeeper.AddSchedule(
ctx,
"end-job",
1,
[]types.MsgExecuteContract{{Contract: "terra1contract", Msg: `{"pong":{}}`}},
10,
types.ExecutionStage_EXECUTION_STAGE_END_BLOCKER,
))

execCtx := terraApp.NewUncachedContext(false, tmproto.Header{ChainID: "cron-test"})
execCtx = execCtx.WithBlockHeight(11).WithBlockTime(time.Now().UTC())
require.Equal(t, int64(11), execCtx.BlockHeight())

// Use the app-registered cron module instance so the test exercises the module
// exactly as Terra wires it into the app.
cronModule := terraApp.Modules()[types.ModuleName].(appBlockModule)
_, err := cronModule.EndBlock(sdk.WrapSDKContext(execCtx))
require.NoError(t, err)
require.Len(t, fakeServer.calls, 1)

schedule, found := terraApp.CronKeeper.GetSchedule(execCtx, "end-job")
require.True(t, found)
require.Equal(t, uint64(11), schedule.LastExecuteHeight)
}
13 changes: 13 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
customstaking "github.com/classic-terra/core/v4/custom/staking"
customwasmkeeper "github.com/classic-terra/core/v4/custom/wasm/keeper"
terrawasm "github.com/classic-terra/core/v4/wasmbinding"
cronkeeper "github.com/classic-terra/core/v4/x/cron/keeper"
crontypes "github.com/classic-terra/core/v4/x/cron/types"
dyncommkeeper "github.com/classic-terra/core/v4/x/dyncomm/keeper"
dyncommtypes "github.com/classic-terra/core/v4/x/dyncomm/types"
marketkeeper "github.com/classic-terra/core/v4/x/market/keeper"
Expand Down Expand Up @@ -101,6 +103,7 @@ type AppKeepers struct {
TreasuryKeeper treasurykeeper.Keeper
TaxExemptionKeeper taxexemptionkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
CronKeeper cronkeeper.Keeper
DyncommKeeper dyncommkeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
Expand Down Expand Up @@ -147,6 +150,7 @@ func NewAppKeepers(
treasurytypes.StoreKey: storetypes.NewKVStoreKey(treasurytypes.StoreKey),
taxexemptiontypes.StoreKey: storetypes.NewKVStoreKey(taxexemptiontypes.StoreKey),
wasmtypes.StoreKey: storetypes.NewKVStoreKey(wasmtypes.StoreKey),
crontypes.StoreKey: storetypes.NewKVStoreKey(crontypes.StoreKey),
dyncommtypes.StoreKey: storetypes.NewKVStoreKey(dyncommtypes.StoreKey),
taxtypes.StoreKey: storetypes.NewKVStoreKey(taxtypes.StoreKey),
}
Expand Down Expand Up @@ -343,6 +347,13 @@ func NewAppKeepers(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.CronKeeper = cronkeeper.NewKeeper(
appCodec,
appKeepers.keys[crontypes.StoreKey],
appKeepers.AccountKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

hooksKeeper := ibchookskeeper.NewKeeper(
appKeepers.keys[ibchookstypes.StoreKey],
)
Expand Down Expand Up @@ -435,6 +446,8 @@ func NewAppKeepers(
wasmOpts..., // Options
)

appKeepers.CronKeeper.WasmMsgServer = wasmkeeper.NewMsgServerImpl(&appKeepers.WasmKeeper)

// AFTER wasm set contractKeeper for ics20 wasm hook
appKeepers.Ics20WasmHooks.ContractKeeper = &appKeepers.WasmKeeper

Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
customstaking "github.com/classic-terra/core/v4/custom/staking"
customupgrade "github.com/classic-terra/core/v4/custom/upgrade"
customwasm "github.com/classic-terra/core/v4/custom/wasm"
"github.com/classic-terra/core/v4/x/cron"
crontypes "github.com/classic-terra/core/v4/x/cron/types"
"github.com/classic-terra/core/v4/x/dyncomm"
dyncommtypes "github.com/classic-terra/core/v4/x/dyncomm/types"
"github.com/classic-terra/core/v4/x/market"
Expand Down Expand Up @@ -111,6 +113,7 @@ var (
treasury.AppModuleBasic{},
taxexemption.AppModuleBasic{},
customwasm.AppModuleBasic{},
cron.AppModuleBasic{},
dyncomm.AppModuleBasic{},
ibchooks.AppModuleBasic{},
consensus.AppModuleBasic{},
Expand All @@ -131,6 +134,7 @@ var (
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
icatypes.ModuleName: nil,
wasmtypes.ModuleName: {authtypes.Burner},
crontypes.ModuleName: nil,
}
// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{
Expand Down Expand Up @@ -169,6 +173,7 @@ func appModules(
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
taxexemption.NewAppModule(appCodec, app.TaxExemptionKeeper),
customwasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName), app.GetKey(wasmtypes.StoreKey)),
cron.NewAppModule(appCodec, &app.CronKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
Expand Down Expand Up @@ -232,6 +237,7 @@ func orderBeginBlockers() []string {
taxexemptiontypes.ModuleName,
markettypes.ModuleName,
wasmtypes.ModuleName,
crontypes.ModuleName,
dyncommtypes.ModuleName,
taxtypes.ModuleName,
// consensus module
Expand Down Expand Up @@ -266,6 +272,7 @@ func orderEndBlockers() []string {
taxexemptiontypes.ModuleName,
markettypes.ModuleName,
wasmtypes.ModuleName,
crontypes.ModuleName,
dyncommtypes.ModuleName,
taxtypes.ModuleName,
// consensus module
Expand Down Expand Up @@ -300,6 +307,7 @@ func orderInitGenesis() []string {
treasurytypes.ModuleName,
taxexemptiontypes.ModuleName,
wasmtypes.ModuleName,
crontypes.ModuleName,
dyncommtypes.ModuleName,
taxtypes.ModuleName,
// consensus module
Expand Down
13 changes: 13 additions & 0 deletions app/sim_flags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package app_test

import (
"flag"

simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"
)

func init() {
if flag.Lookup("Enabled") == nil {
simcli.GetSimulatorFlags()
}
}
6 changes: 4 additions & 2 deletions custom/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ func WeightedOperations(
appParams simtypes.AppParams, cdc codec.JSONCodec, ak banktypes.AccountKeeper, bk keeper.Keeper,
) simulation.WeightedOperations {
var weightMsgSend, weightMsgMultiSend int
appParams.GetOrGenerate(OpWeightMsgSend, &weightMsgSend, nil,
appParams.GetOrGenerate(
OpWeightMsgSend, &weightMsgSend, nil,
func(*rand.Rand) {
weightMsgSend = banksim.DefaultWeightMsgSend
},
)

appParams.GetOrGenerate(OpWeightMsgMultiSend, &weightMsgMultiSend, nil,
appParams.GetOrGenerate(
OpWeightMsgMultiSend, &weightMsgMultiSend, nil,
func(*rand.Rand) {
weightMsgMultiSend = banksim.DefaultWeightMsgMultiSend
},
Expand Down
9 changes: 6 additions & 3 deletions custom/staking/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func (q *LegacyQueryServer) ensureLegacyParams(ctx context.Context) context.Cont

// Only set legacy params for pre-upgrade heights
legacyMode := legacyupgrade.GetLegacyHandling(sdkCtx.ChainID(), sdkCtx.BlockHeight())
sdkCtx.Logger().Debug("Setting legacy params for pre-upgrade height queries",
sdkCtx.Logger().Debug(
"Setting legacy params for pre-upgrade height queries",
"block_height", sdkCtx.BlockHeight(),
"legacy_mode", legacyMode,
"chain_id", sdkCtx.ChainID(),
Expand All @@ -88,7 +89,8 @@ func (q *LegacyQueryServer) ensureLegacyParams(ctx context.Context) context.Cont
})

// Return updated context
sdkCtx.Logger().Debug("Legacy params set for pre-upgrade height queries",
sdkCtx.Logger().Debug(
"Legacy params set for pre-upgrade height queries",
"block_height", sdkCtx.BlockHeight(),
"chain_id", sdkCtx.ChainID(),
"params", params,
Expand All @@ -110,7 +112,8 @@ func (q *LegacyQueryServer) ensureLegacyParams(ctx context.Context) context.Cont
q.keeper.SetParams(sdkCtx, params)

// Return updated context
sdkCtx.Logger().Debug("Legacy params set for pre-upgrade height queries",
sdkCtx.Logger().Debug(
"Legacy params set for pre-upgrade height queries",
"block_height", sdkCtx.BlockHeight(),
"chain_id", sdkCtx.ChainID(),
"params", params,
Expand Down
13 changes: 13 additions & 0 deletions proto/terra/cron/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package terra.cron.v1;

import "gogoproto/gogo.proto";
import "terra/cron/v1/params.proto";
import "terra/cron/v1/schedule.proto";

option go_package = "github.com/classic-terra/core/v4/x/cron/types";

message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated Schedule schedule_list = 2 [(gogoproto.nullable) = false];
}
13 changes: 13 additions & 0 deletions proto/terra/cron/v1/params.proto
Comment thread
ZuluSpl0it marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package terra.cron.v1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/classic-terra/core/v4/x/cron/types";

message Params {
uint64 limit = 1;
uint64 max_execution_gas = 2;
}
Loading
Loading