diff --git a/app/app_test.go b/app/app_test.go index 0cd24d5e..84a4b9f1 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -78,7 +78,7 @@ func TestInitGenesisOnMigration(t *testing.T) { logger := log.NewLogger(os.Stdout) app := NewInitiaApp( logger, db, nil, true, moveconfig.DefaultMoveConfig(), apporacle.DefaultConfig(), EmptyAppOptions{}) - ctx := app.NewContextLegacy(true, cmtproto.Header{Height: app.LastBlockHeight()}) + ctx := app.NewUncachedContext(false, cmtproto.Header{Height: app.LastBlockHeight()}) // Create a mock module. This module will serve as the new module we're // adding during a migration. @@ -127,7 +127,7 @@ func TestUpgradeStateOnGenesis(t *testing.T) { app := SetupWithGenesisAccounts(nil, nil) // make sure the upgrade keeper has version map in state - ctx := app.NewContext(true) + ctx := app.NewUncachedContext(false, cmtproto.Header{}) vm, err := app.UpgradeKeeper.GetModuleVersionMap(ctx) require.NoError(t, err) diff --git a/go.mod b/go.mod index 349b55c0..e1f64259 100644 --- a/go.mod +++ b/go.mod @@ -221,7 +221,7 @@ replace ( // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 - github.com/cosmos/cosmos-sdk => github.com/initia-labs/cosmos-sdk v0.0.0-20240425031032-6bc18cf6e67d + github.com/cosmos/cosmos-sdk => github.com/initia-labs/cosmos-sdk v0.0.0-20240617100523-e47019ce8c64 github.com/cosmos/iavl => github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e // dgrijalva/jwt-go is deprecated and doesn't receive security updates. diff --git a/go.sum b/go.sum index b42d8fd1..9d2e816d 100644 --- a/go.sum +++ b/go.sum @@ -727,8 +727,8 @@ github.com/initia-labs/OPinit v0.3.1 h1:uffngNx8a7hQl3ENhVbdSAJ8j5MYksiaiCLVI6xu github.com/initia-labs/OPinit v0.3.1/go.mod h1:pHU2472uQZpiKXBOa/D7/aDYn0gtTiddKvhloyliOQU= github.com/initia-labs/OPinit/api v0.3.0 h1:OY8ijwmgZLoYwtw9LI1mSY3VC8PY+gtxJFitB6ZNFl4= github.com/initia-labs/OPinit/api v0.3.0/go.mod h1:Xy/Nt3ubXLQ4zKn0m7RuQOM1sj8TVdlNNyek21TGYR0= -github.com/initia-labs/cosmos-sdk v0.0.0-20240425031032-6bc18cf6e67d h1:8OCL+PBoWydjxP07wE567ySQfY8gbu+rjE04OCNx/9U= -github.com/initia-labs/cosmos-sdk v0.0.0-20240425031032-6bc18cf6e67d/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40= +github.com/initia-labs/cosmos-sdk v0.0.0-20240617100523-e47019ce8c64 h1:4eODaWXthTX2yCpSCXTZ4QgrkXoHnJqhKjKhRJMrg5k= +github.com/initia-labs/cosmos-sdk v0.0.0-20240617100523-e47019ce8c64/go.mod h1:lVkRY6cdMJ0fG3gp8y4hFrsKZqF4z7y0M2UXFb9Yt40= github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e h1:1gkMWkAgVhYFhEv7K4tX+8uJJLdiTKlQhl5+wGaxdMg= github.com/initia-labs/iavl v0.0.0-20240415085037-7e81233cdd9e/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM= github.com/initia-labs/movevm v0.3.1 h1:vydw0mdqsLyPN9W2DVq1/gDXDR3snbr6c4Wy/sTYVxY= diff --git a/x/move/abci_test.go b/x/move/abci_test.go index dc6dd981..051db766 100644 --- a/x/move/abci_test.go +++ b/x/move/abci_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/require" 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" @@ -22,14 +23,14 @@ func Test_BeginBlocker(t *testing.T) { require.NoError(t, err) // initialize staking for secondBondDenom - ctx := app.BaseApp.NewContext(false) + ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{}) err = app.MoveKeeper.InitializeStaking(ctx, secondBondDenom) require.NoError(t, err) // fund addr2 app.BankKeeper.SendCoins(ctx, types.StdAddr, addr2, sdk.NewCoins(secondBondCoin)) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) + _, err = app.Commit() require.NoError(t, err) // delegate coins via move staking module @@ -61,7 +62,7 @@ func Test_BeginBlocker(t *testing.T) { require.NoError(t, err) // generate rewards - ctx = app.BaseApp.NewContext(false) + ctx = app.BaseApp.NewUncachedContext(false, tmproto.Header{}) validator, err := app.StakingKeeper.Validator(ctx, sdk.ValAddress(addr1)) require.NoError(t, err) @@ -78,10 +79,16 @@ func Test_BeginBlocker(t *testing.T) { secondBondDenom, sdk.NewDecCoinsFromCoins(rewardCoins...)) + _, err = app.Commit() + require.NoError(t, err) + // rewards distributed _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + // withdraw rewards to move module _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) require.NoError(t, err) diff --git a/x/move/ante/ante_test.go b/x/move/ante/ante_test.go index 0f3e3d14..2c904c45 100644 --- a/x/move/ante/ante_test.go +++ b/x/move/ante/ante_test.go @@ -6,6 +6,8 @@ import ( "github.com/stretchr/testify/suite" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "cosmossdk.io/log" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/client" @@ -38,7 +40,7 @@ type AnteTestSuite struct { } // returns context and app with params set on account keeper -func (suite *AnteTestSuite) createTestApp(isCheckTx bool, tempDir string) (*initiaapp.InitiaApp, sdk.Context) { +func (suite *AnteTestSuite) createTestApp(tempDir string) (*initiaapp.InitiaApp, sdk.Context) { appOptions := make(simtestutil.AppOptionsMap, 0) appOptions[flags.FlagHome] = tempDir appOptions[server.FlagInvCheckPeriod] = simcli.FlagPeriodValue @@ -46,7 +48,7 @@ func (suite *AnteTestSuite) createTestApp(isCheckTx bool, tempDir string) (*init app := initiaapp.NewInitiaApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, moveconfig.DefaultMoveConfig(), initiaapporacle.DefaultConfig(), appOptions, ) - ctx := app.BaseApp.NewContext(isCheckTx) + ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{}) err := app.AccountKeeper.Params.Set(ctx, authtypes.DefaultParams()) suite.NoError(err) @@ -56,9 +58,9 @@ func (suite *AnteTestSuite) createTestApp(isCheckTx bool, tempDir string) (*init } // SetupTest setups a new test, with new app, context, and anteHandler. -func (suite *AnteTestSuite) SetupTest(isCheckTx bool) { +func (suite *AnteTestSuite) SetupTest() { tempDir := suite.T().TempDir() - suite.app, suite.ctx = suite.createTestApp(isCheckTx, tempDir) + suite.app, suite.ctx = suite.createTestApp(tempDir) suite.ctx = suite.ctx.WithBlockHeight(1) // Set up TxConfig. diff --git a/x/move/ante/fee_test.go b/x/move/ante/fee_test.go index e3a80382..a9d01af1 100644 --- a/x/move/ante/fee_test.go +++ b/x/move/ante/fee_test.go @@ -61,7 +61,7 @@ func (k TestAnteKeeper) BaseMinGasPrice(ctx context.Context) (math.LegacyDec, er } func (suite *AnteTestSuite) TestEnsureMempoolFees() { - suite.SetupTest(true) // setup + suite.SetupTest() // setup suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() dexPools := make(map[string][]math.Int) diff --git a/x/move/ante/gas_prices_test.go b/x/move/ante/gas_prices_test.go index d47f37dd..06806496 100644 --- a/x/move/ante/gas_prices_test.go +++ b/x/move/ante/gas_prices_test.go @@ -10,7 +10,7 @@ import ( ) func (suite *AnteTestSuite) TestGasPricesDecorator() { - suite.SetupTest(true) // setup + suite.SetupTest() // setup suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() // keys and addresses diff --git a/x/move/common_test.go b/x/move/common_test.go index 731a0a51..e71c8652 100644 --- a/x/move/common_test.go +++ b/x/move/common_test.go @@ -73,7 +73,7 @@ func createApp(t *testing.T) *initiaapp.InitiaApp { _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) require.NoError(t, err) - ctx := app.BaseApp.NewContext(false) + ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{}) createDexPool(t, ctx, app, baseCoin, quoteCoin, math.LegacyNewDecWithPrec(8, 1), math.LegacyNewDecWithPrec(2, 1)) // set reward weight @@ -87,7 +87,7 @@ func createApp(t *testing.T) *initiaapp.InitiaApp { // fund second bond coin app.BankKeeper.SendCoins(ctx, types.StdAddr, addr1, sdk.NewCoins(secondBondCoin)) - _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) + _, err = app.Commit() require.NoError(t, err) // create validator diff --git a/x/reward/abci_test.go b/x/reward/abci_test.go index 703b0fb5..0ce78528 100644 --- a/x/reward/abci_test.go +++ b/x/reward/abci_test.go @@ -11,6 +11,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" abci "github.com/cometbft/cometbft/abci/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/initia-labs/initia/x/reward/types" ) @@ -22,7 +23,7 @@ func Test_BeginBlocker(t *testing.T) { _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) require.NoError(t, err) - ctx := app.BaseApp.NewContext(false) + ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{}) // update params & mint coins for reward distribution params, err := app.RewardKeeper.GetParams(ctx) @@ -46,19 +47,34 @@ func Test_BeginBlocker(t *testing.T) { lastReleaseTimestamp, err := app.RewardKeeper.GetLastReleaseTimestamp(ctx) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + + ctx = app.BaseApp.NewContext(true) + paramsAfter, err := app.RewardKeeper.GetParams(ctx) + require.NoError(t, err) + require.Equal(t, paramsAfter, params) + // new block after _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1, Time: lastReleaseTimestamp}) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + // new block after 24 hours _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1, Time: lastReleaseTimestamp.Add(time.Hour * 24).Add(time.Second)}) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + // check supply expectedReleasedAmount := math.LegacyNewDec(7).QuoInt64(100).MulInt(supply.Amount).QuoInt64(365).TruncateInt() checkBalance(t, app, authtypes.NewModuleAddress(types.ModuleName), rewardCoins.Sub(sdk.NewCoin(rewardDenom, expectedReleasedAmount))) // release rate should be half + ctx = app.BaseApp.NewContext(true) releaseRate, err := app.RewardKeeper.GetReleaseRate(ctx) require.NoError(t, err) require.Equal(t, math.LegacyNewDecWithPrec(35, 3), releaseRate) @@ -78,7 +94,7 @@ func Test_BeginBlockerNotEnabled(t *testing.T) { _, err := app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1}) require.NoError(t, err) - ctx := app.BaseApp.NewContext(false) + ctx := app.BaseApp.NewUncachedContext(false, tmproto.Header{}) // update params & mint coins for reward distribution params, err := app.RewardKeeper.GetParams(ctx) @@ -100,14 +116,25 @@ func Test_BeginBlockerNotEnabled(t *testing.T) { lastReleaseTimestamp, err := app.RewardKeeper.GetLastReleaseTimestamp(ctx) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + // new block after _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1, Time: lastReleaseTimestamp}) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + // new block after 24 hours _, err = app.FinalizeBlock(&abci.RequestFinalizeBlock{Height: app.LastBlockHeight() + 1, Time: lastReleaseTimestamp.Add(time.Hour * 24).Add(time.Second)}) require.NoError(t, err) + _, err = app.Commit() + require.NoError(t, err) + + ctx = app.BaseApp.NewContext(true) + // check supply expectedReleasedAmount := math.ZeroInt() checkBalance(t, app, authtypes.NewModuleAddress(types.ModuleName), rewardCoins.Sub(sdk.NewCoin(rewardDenom, expectedReleasedAmount)))