0g-chain/tests/e2e/e2e_upgrade_community_test.go

242 lines
8.5 KiB
Go
Raw Permalink Normal View History

package e2e_test
2024-05-01 03:46:33 +00:00
// func (suite *IntegrationTestSuite) TestUpgradeCommunityParams() {
// suite.SkipIfUpgradeDisabled()
// beforeUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight - 1)
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
// // Before params
2024-05-01 05:53:58 +00:00
// kavaDistParamsBefore, err := suite.ZgChain.Kavadist.Params(beforeUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
2024-05-01 03:46:33 +00:00
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// mintParamsBefore, err := suite.ZgChain.Mint.Params(beforeUpgradeCtx, &minttypes.QueryParamsRequest{})
2024-05-01 03:46:33 +00:00
// suite.NoError(err)
// // Before parameters
// suite.Run("x/community and x/kavadist parameters before upgrade", func() {
2024-05-01 05:53:58 +00:00
// _, err = suite.ZgChain.Community.Params(beforeUpgradeCtx, &communitytypes.QueryParamsRequest{})
2024-05-01 03:46:33 +00:00
// suite.Error(err, "x/community should not have params before upgrade")
// suite.Require().True(
// kavaDistParamsBefore.Params.Active,
// "x/kavadist should be active before upgrade",
// )
// suite.Require().True(
// mintParamsBefore.Params.InflationMax.IsPositive(),
// "x/mint inflation max should be positive before upgrade",
// )
// suite.Require().True(
// mintParamsBefore.Params.InflationMin.IsPositive(),
// "x/mint inflation min should be positive before upgrade",
// )
// })
// // After upgrade, Before switchover - parameters
// suite.Run("x/kavadist, x/mint, x/community parameters after upgrade, before switchover", func() {
2024-05-01 05:53:58 +00:00
// kavaDistParamsAfter, err := suite.ZgChain.Kavadist.Params(afterUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
2024-05-01 03:46:33 +00:00
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// mintParamsAfter, err := suite.ZgChain.Mint.Params(afterUpgradeCtx, &minttypes.QueryParamsRequest{})
2024-05-01 03:46:33 +00:00
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// communityParamsAfter, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
2024-05-01 03:46:33 +00:00
// suite.NoError(err)
// suite.Equal(
// kavaDistParamsBefore.Params,
// kavaDistParamsAfter.Params,
// "x/kavadist should be unaffected after upgrade",
// )
// suite.Equal(
// mintParamsBefore.Params,
// mintParamsAfter.Params,
// "x/mint params should be unaffected after upgrade",
// )
// expectedParams := app.CommunityParams_E2E
// // Make UpgradeTimeDisableInflation match so that we ignore it, because
// // referencing app.CommunityParams_E2E in this test files is different
// // from the one set in the upgrade handler. At least check that it is
// // set to a non-zero value in the assertion below
// expectedParams.UpgradeTimeDisableInflation = communityParamsAfter.Params.UpgradeTimeDisableInflation
// suite.False(
// communityParamsAfter.Params.UpgradeTimeDisableInflation.IsZero(),
// "x/community switchover time should be set after upgrade",
// )
// suite.Equal(
// expectedParams,
// communityParamsAfter.Params,
// "x/community params should be set to E2E params after upgrade",
// )
// })
// suite.Require().Eventually(
// func() bool {
// // Get x/community for switchover time
2024-05-01 05:53:58 +00:00
// params, err := suite.ZgChain.Community.Params(
2024-05-01 03:46:33 +00:00
// context.Background(),
// &communitytypes.QueryParamsRequest{},
// )
// suite.Require().NoError(err)
// // Check that switchover time is set to zero, e.g. switchover happened
// return params.Params.UpgradeTimeDisableInflation.Equal(time.Time{})
// },
// 20*time.Second, 1*time.Second,
// "switchover should happen and x/community params should be updated",
// )
// // Fetch exact block when inflation stop event emitted
2024-05-01 05:53:58 +00:00
// _, switchoverHeight, err := suite.ZgChain.GetBeginBlockEventsFromQuery(
2024-05-01 03:46:33 +00:00
// context.Background(),
// fmt.Sprintf(
// "%s.%s EXISTS",
// communitytypes.EventTypeInflationStop,
// communitytypes.AttributeKeyInflationDisableTime,
// ),
// )
// suite.Require().NoError(err)
// suite.Require().NotZero(switchoverHeight)
// beforeSwitchoverCtx := util.CtxAtHeight(switchoverHeight - 1)
// afterSwitchoverCtx := util.CtxAtHeight(switchoverHeight)
// suite.Run("x/kavadist, x/mint, x/community parameters after upgrade, after switchover", func() {
2024-05-01 05:53:58 +00:00
// kavaDistParamsAfter, err := suite.ZgChain.Kavadist.Params(
2024-05-01 03:46:33 +00:00
// afterSwitchoverCtx,
// &kavadisttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// mintParamsAfter, err := suite.ZgChain.Mint.Params(
2024-05-01 03:46:33 +00:00
// afterSwitchoverCtx,
// &minttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// communityParamsAfter, err := suite.ZgChain.Community.Params(
2024-05-01 03:46:33 +00:00
// afterSwitchoverCtx,
// &communitytypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// suite.False(
// kavaDistParamsAfter.Params.Active,
// "x/kavadist should be disabled after upgrade",
// )
// suite.True(
// mintParamsAfter.Params.InflationMax.IsZero(),
// "x/mint inflation max should be zero after switchover",
// )
// suite.True(
// mintParamsAfter.Params.InflationMin.IsZero(),
// "x/mint inflation min should be zero after switchover",
// )
// suite.Equal(
// time.Time{},
// communityParamsAfter.Params.UpgradeTimeDisableInflation,
// "x/community switchover time should be reset",
// )
// suite.Equal(
// communityParamsAfter.Params.UpgradeTimeSetStakingRewardsPerSecond,
// communityParamsAfter.Params.StakingRewardsPerSecond,
// "x/community staking rewards per second should match upgrade time staking rewards per second",
// )
// })
// suite.Run("x/kavadist, x/distribution, x/community balances after switchover", func() {
// // Before balances - community pool fund consolidation
2024-05-01 05:53:58 +00:00
// kavaDistBalBefore, err := suite.ZgChain.Kavadist.Balance(
2024-05-01 03:46:33 +00:00
// beforeSwitchoverCtx,
// &kavadisttypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// distrBalBefore, err := suite.ZgChain.Distribution.CommunityPool(
2024-05-01 03:46:33 +00:00
// beforeSwitchoverCtx,
// &distrtypes.QueryCommunityPoolRequest{},
// )
// suite.NoError(err)
// distrBalCoinsBefore, distrDustBefore := distrBalBefore.Pool.TruncateDecimal()
2024-05-01 05:53:58 +00:00
// beforeCommPoolBalance, err := suite.ZgChain.Community.Balance(
2024-05-01 03:46:33 +00:00
// beforeSwitchoverCtx,
// &communitytypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
// // After balances
2024-05-01 05:53:58 +00:00
// kavaDistBalAfter, err := suite.ZgChain.Kavadist.Balance(
2024-05-01 03:46:33 +00:00
// afterSwitchoverCtx,
// &kavadisttypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// distrBalAfter, err := suite.ZgChain.Distribution.CommunityPool(
2024-05-01 03:46:33 +00:00
// afterSwitchoverCtx,
// &distrtypes.QueryCommunityPoolRequest{},
// )
// suite.NoError(err)
2024-05-01 05:53:58 +00:00
// afterCommPoolBalance, err := suite.ZgChain.Community.Balance(
2024-05-01 03:46:33 +00:00
// afterSwitchoverCtx,
// &communitytypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
// expectedKavadistBal := sdk.NewCoins(sdk.NewCoin(
// "ukava",
// kavaDistBalBefore.Coins.AmountOf("ukava"),
// ))
// suite.Equal(
// expectedKavadistBal,
// kavaDistBalAfter.Coins,
// "x/kavadist balance should persist the ukava amount and move all other funds",
// )
// expectedKavadistTransferred := kavaDistBalBefore.Coins.Sub(expectedKavadistBal...)
// // very low ukava balance after (ignoring dust in x/distribution)
// // a small amount of tx fees can still end up here.
// // dust should stay in x/distribution, but may not be the same so it's unchecked
// distrCoinsAfter, distrDustAfter := distrBalAfter.Pool.TruncateDecimal()
// suite.Empty(distrCoinsAfter, "expected no coins in x/distribution community pool")
// // Fetch block results for paid staking rewards in the block
2024-05-01 05:53:58 +00:00
// blockRes, err := suite.ZgChain.TmSignClient.BlockResults(
2024-05-01 03:46:33 +00:00
// context.Background(),
// &switchoverHeight,
// )
// suite.Require().NoError(err)
// stakingRewardPaidEvents := util.FilterEventsByType(
// blockRes.BeginBlockEvents,
// communitytypes.EventTypeStakingRewardsPaid,
// )
// suite.Require().Len(stakingRewardPaidEvents, 1, "there should be only 1 staking reward paid event")
// stakingRewardAmount := sdk.NewCoins()
// for _, attr := range stakingRewardPaidEvents[0].Attributes {
// if string(attr.Key) == communitytypes.AttributeKeyStakingRewardAmount {
// stakingRewardAmount, err = sdk.ParseCoinsNormalized(string(attr.Value))
// suite.Require().NoError(err)
// break
// }
// }
// expectedCommunityBal := beforeCommPoolBalance.Coins.
// Add(distrBalCoinsBefore...).
// Add(expectedKavadistTransferred...).
// Sub(stakingRewardAmount...) // Remove staking rewards paid in the block
// // x/kavadist and x/distribution community pools should be moved to x/community
// suite.Equal(
// expectedCommunityBal,
// afterCommPoolBalance.Coins,
// )
// suite.Equal(
// distrDustBefore,
// distrDustAfter,
// "x/distribution community pool dust should be unchanged",
// )
// })
// }