Compare commits

..

66 Commits

Author SHA1 Message Date
0g-wh
932664efac prepare upgrade
Some checks are pending
Continuous Integration (Commit) / lint (push) Waiting to run
2024-08-03 15:05:14 +08:00
0g-wh
c949c06fce rebase to kava cosmos 0.47 upgrade
rename

rename

tidy

clean code
2024-08-03 15:05:14 +08:00
0g-wh
14ca626365 add Upload Release Assets workflow (#49)
* Create upload-release-assets.yml
2024-08-03 15:05:14 +08:00
Solovyov1796
008b421fd2 update gitignore 2024-08-03 15:05:14 +08:00
Solovyov1796
ac1fd4360d merge testnet script 2024-08-03 15:05:14 +08:00
0g-wh
d35b277cab add cosmovisor init script 2024-08-03 15:05:14 +08:00
Solovyov1796
2c248aff18 use 0glabs' cometbft 2024-08-03 15:05:14 +08:00
0xsatoshi
4ab0d3ee27 enable vesting msgs 2024-08-03 15:05:14 +08:00
0xsatoshi
8d761147a2 fix 2024-08-03 15:05:14 +08:00
0xsatoshi
4917eb5976 fix 2024-08-03 15:05:14 +08:00
MiniFrenchBread
f8d5f29078 refactor: epoch quorum storage 2024-08-03 15:05:14 +08:00
MiniFrenchBread
efee71e2e6 feat: getQuorumRow 2024-08-03 15:05:14 +08:00
Solovyov1796
6190839ddc keep the EthSecp256k1 from cosmos for compatible 2024-08-03 15:05:14 +08:00
Solovyov1796
c1efdaa507 recover "rename denoms" in 3 files 2024-08-03 15:05:14 +08:00
Solovyov1796
62c5eaf515 use chaincfg.MakeCoinForGasDenom 2024-08-03 15:05:14 +08:00
Solovyov1796
48c349c127 custom inflation calculation function 2024-08-03 15:05:14 +08:00
MiniFrenchBread
4b09c6cd37 chore: remove tmp output 2024-08-03 15:05:14 +08:00
MiniFrenchBread
02e96e6424 fix: decimals 2024-08-03 15:05:14 +08:00
MiniFrenchBread
b3a8343a19 refactor: delegator 2024-08-03 15:05:14 +08:00
MiniFrenchBread
c6e4563cac fix: localtestnet.sh 2024-08-03 15:05:14 +08:00
MiniFrenchBread
7d4828f415 tidy 2024-08-03 15:05:14 +08:00
MiniFrenchBread
1fbf607360 merge testnet/v0.1.x 2024-08-03 15:05:14 +08:00
Solovyov1796
154dd509ee remove the EthSecp256k1 from cosmos 2024-08-03 15:05:14 +08:00
Solovyov1796
986172d3a7 rename denoms 2024-08-03 15:05:13 +08:00
Solovyov1796
4fabd4d011 fix unit test 2024-08-03 15:05:03 +08:00
Solovyov1796
e25cc5f531 remove module's legacy code 2024-08-03 15:04:55 +08:00
Solovyov1796
6202424c27 recover go mod file 2024-08-03 15:04:55 +08:00
Solovyov1796
c7ed82b4f4 remove das module 2024-08-03 15:04:55 +08:00
MiniFrenchBread
a3f3aaaecc feat: add get functions 2024-08-03 15:04:55 +08:00
MiniFrenchBread
701a0ba97e fix: da signers begin block 2024-08-03 15:04:55 +08:00
MiniFrenchBread
1e0194262d feat: max quorum num 2024-08-03 15:04:55 +08:00
MiniFrenchBread
e3e47e5e2f fix: quorum 2024-08-03 15:04:55 +08:00
MiniFrenchBread
93cceff23c feat: quorum 2024-08-03 15:04:55 +08:00
MiniFrenchBread
1680cd6b32 fix: defaultGenesis 2024-08-03 15:04:55 +08:00
MiniFrenchBread
284181edc9 feat: update dasigners proto api 2024-08-03 15:04:55 +08:00
MiniFrenchBread
422e940c28 fix: dasigners module 2024-08-03 15:04:55 +08:00
MiniFrenchBread
bb5d5130cf chore: dependency 2024-08-03 15:04:55 +08:00
MiniFrenchBread
b53783447b feat: precompile 2024-08-03 15:04:55 +08:00
Solovyov1796
6f2b402294 rename the app name showed in usage (#10) 2024-08-03 15:04:55 +08:00
Peter Zhang
82139161be update max validator count 2024-08-03 15:04:55 +08:00
Peter Zhang
4798eea3ff update checkout branch 2024-08-03 15:04:55 +08:00
Solovyov1796
ee01ac7a7b update init-genesis.sh for devnet and testnet 2024-08-03 15:04:55 +08:00
Solovyov1796
47cee39c64 fix unit test 2024-08-03 15:04:53 +08:00
Solovyov1796
521f558f5d recv both cosmos denom and evm denom from bank keeper 2024-08-03 15:04:48 +08:00
0xsatoshi
adb09a7c82 fix 2024-08-03 15:04:48 +08:00
0xsatoshi
3da66a87e6 fix 2024-08-03 15:04:48 +08:00
Solovyov1796
19a202669a update scripts 2024-08-03 15:04:48 +08:00
Solovyov1796
eaf81e9465 update env vars 2024-08-03 15:04:48 +08:00
Peter Zhang
817a8a151a modify deploy script 2024-08-03 15:04:48 +08:00
Solovyov1796
78114aed73 update 2024-08-03 15:04:48 +08:00
Solovyov1796
34a76200f0 fix unit test for x 2024-08-03 15:04:48 +08:00
Solovyov1796
fe8c36f891 add scripts for devnet 2024-08-03 15:04:48 +08:00
Solovyov1796
8357cc2191 fix panic 2024-08-03 15:04:48 +08:00
Solovyov1796
f8e102fbd5 merge script from branch v0.1.0 2024-08-03 15:04:48 +08:00
Solovyov1796
d1c3f36bbe fix test 2024-08-03 15:04:48 +08:00
Solovyov1796
89d3829646 add 0g code 2024-08-03 15:04:48 +08:00
Solovyov1796
ffad9dbdd5 rename kava 2024-08-03 15:04:46 +08:00
Solovyov1796
0bbaeb0393 add vrf 2024-08-03 15:04:33 +08:00
Solovyov1796
cc4f72b165 revise file structure in cmd 2024-08-03 15:04:33 +08:00
Solovyov1796
6a197a5db5 add chaincfg to save all configration of chain 2024-08-03 15:04:33 +08:00
Solovyov1796
e787cd052e update build file 2024-08-03 15:04:33 +08:00
Solovyov1796
2454c94596 revise proto files 2024-08-03 15:04:33 +08:00
Solovyov1796
454733f55b remove useless modules 2024-08-03 15:04:32 +08:00
Solovyov1796
14e1e3a7d4 rename go mod path 2024-08-03 15:03:23 +08:00
Peter Zhang
ca3ab93657 add deploy scripts 2024-08-03 15:03:01 +08:00
Peter Zhang
c8bf4644c1 add deploy scripts 2024-08-03 15:03:01 +08:00
11 changed files with 6 additions and 1335 deletions

View File

@ -25,18 +25,13 @@ import (
)
const (
UpgradeName_Mainnet = "v0.26.0"
UpgradeName_Testnet = "v0.26.0-alpha.0"
UpgradeName_Testnet = "v0.3.0"
CDPLiquidationBlockInterval = int64(50)
)
// RegisterUpgradeHandlers registers the upgrade handlers for the app.
func (app App) RegisterUpgradeHandlers() {
app.upgradeKeeper.SetUpgradeHandler(
UpgradeName_Mainnet,
upgradeHandler(app, UpgradeName_Mainnet),
)
app.upgradeKeeper.SetUpgradeHandler(
UpgradeName_Testnet,
upgradeHandler(app, UpgradeName_Testnet),
@ -47,8 +42,7 @@ func (app App) RegisterUpgradeHandlers() {
panic(err)
}
doUpgrade := upgradeInfo.Name == UpgradeName_Mainnet ||
upgradeInfo.Name == UpgradeName_Testnet
doUpgrade := upgradeInfo.Name == UpgradeName_Testnet
if doUpgrade && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{

2
go.mod
View File

@ -229,7 +229,7 @@ replace (
github.com/cometbft/cometbft-db => github.com/kava-labs/cometbft-db v0.9.1-kava.1
// Use cosmos-sdk fork with backported fix for unsafe-reset-all, staking transfer events, and custom tally handler support
// github.com/cosmos/cosmos-sdk => github.com/0glabs/cosmos-sdk v0.46.11-kava.3
github.com/cosmos/cosmos-sdk => /home/wenhui/v047/cosmos-sdk
github.com/cosmos/cosmos-sdk => github.com/0glabs/cosmos-sdk v0.47.10-0glabs.3
// See https://github.com/cosmos/cosmos-sdk/pull/13093
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
// Use go-ethereum fork with precompiles

3
go.sum
View File

@ -222,6 +222,8 @@ git.sr.ht/~sircmpwn/getopt v0.0.0-20191230200459-23622cc906b3/go.mod h1:wMEGFFFN
git.sr.ht/~sircmpwn/go-bare v0.0.0-20210406120253-ab86bc2846d9/go.mod h1:BVJwbDfVjCjoFiKrhkei6NdGcZYpkDkdyCdg1ukytRA=
github.com/0g-wh/ethermint v0.21.0-0glabs-v26.3.1 h1:45iLmhD+WV3YTn87T4H70lZFu/X7/uV3TFY3IK4Uh0E=
github.com/0g-wh/ethermint v0.21.0-0glabs-v26.3.1/go.mod h1:GdFUfO60Wkr+ofAv4Kz+wDCsobHnwhhv8Gly6a9+k0Y=
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.3 h1:Wx3tVMTuFaaHDeJT/OzT7QLfAIpeaZsG9R6XoTOyKCw=
github.com/0glabs/cosmos-sdk v0.47.10-0glabs.3/go.mod h1:BWo24B8cApWcO2/widWYIdt3CPxbh+HCSypCPpjTjog=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 h1:/vQbFIOMbk2FiG/kXiLl8BRyzTWDw7gX/Hz7Dd5eDMs=
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4/go.mod h1:hN7oaIRCjzsZ2dE+yG5k+rsdt3qcwykqK6HVGcKwsw4=
github.com/Antonboom/errname v0.1.7/go.mod h1:g0ONh16msHIPgJSGsecu1G/dcF2hlYR/0SddnIAGavU=
@ -2015,6 +2017,7 @@ golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -1,80 +0,0 @@
# Kava 15 Upgrade Instructions
## Software Version and Key Dates
- The version of `kava` for Kava 15 is v0.25.0
- The Kava 14 chain will be shutdown with a `SoftwareUpgradeProposal` that
activates at approximately 15:00 UTC on December 7th, 2023.
## Dependency Changes
### For validators using RocksDB
> [!NOTE]
> If you use goleveldb or other database backends, this is not required.
If you use RocksDB as your database backend, you will need to update RocksDB
from v7 to v8. The tested and recommended RocksDB version is `v8.1.1`.
Please reference the [RocksDB repository](https://github.com/facebook/rocksdb/tree/v8.1.1)
to update your installation before building the RocksDB kava binary.
## API Changes
If you require calculating the yearly staking reward percentages, standard
calculation will no longer be accurate. [Additional Details can be found here.](./staking_rewards.md)
### On the day of the upgrade
The kava chain is expected to halt at block height **7637070**. **Do not stop your node and begin the upgrade before the upgrade height**, or you may go offline and be unable to recover until after the upgrade!
**Make sure the kava process is stopped before proceeding and that you have backed up your validator**. Failure to backup your validator could make it impossible to restart your node if the upgrade fails.
**Ensure you are using golang 1.20.x and not a different version.** Golang 1.19 and below may cause app hash mismatches!
To update to v0.25.0
```sh
# check go version - look for 1.20!
go version
# go version go1.20.5 linux/amd64
# in the `kava` folder
git fetch
git checkout v0.25.0
# Note: Golang 1.20 must be installed before this step
make install
# verify versions
kava version --long
# name: kava
# server_name: kava
# version: 0.25.0
# commit: <commit placeholder>
# build_tags: netgo ledger,
# go: go version go1.20.5 linux/amd64
# build_deps:
# ...
# cosmos_sdk_version: v0.46.11
# Restart node -
kava start
```
### Risks
As a validator, performing the upgrade procedure on your consensus nodes carries a heightened risk of double-signing and being slashed. The most important piece of this procedure is verifying your software version and genesis file hash before starting your validator and signing.
The riskiest thing a validator can do is discover that they made a mistake and repeat the upgrade procedure again during the network startup. If you discover a mistake in the process, the best thing to do is wait for the network to start before correcting it. If the network is halted and you have started with a different genesis file than the expected one, seek advice from a Kava developer before resetting your validator.
### Recovery
Prior to applying the Kava 15 upgrade, validators are encouraged to take a full data snapshot at the upgrade height before proceeding. Snap-shotting depends heavily on infrastructure, but generally this can be done by backing up the .kava directory.
It is critically important to back-up the .kava/data/priv_validator_state.json file after stopping your kava process. This file is updated every block as your validator participates in consensus rounds. It is a critical file needed to prevent double-signing, in case the upgrade fails and the previous chain needs to be restarted.
In the event that the upgrade does not succeed, validators and operators must downgrade back to v0.24.x of the Kava software and restore to their latest snapshot before restarting their nodes.
### Coordination
If the Kava 15 chain does not launch by December 8th, 2023 at 00:00 UTC, the launch should be considered a failure. In the event of launch failure, coordination will occur in the [Kava discord](https://discord.com/invite/kQzh3Uv).

View File

@ -1,80 +0,0 @@
# Migrate Staking Reward Calculation to Endpoint
Kava 15 (v0.25.x) changes the mechanism for staking rewards, which will no longer be inflationary but will be paid out of the community module. In order to continue displaying expected yields or APYs to users, wallets and explorers will need to update.
The endpoint calculates staking rewards for the current kava version and is forward compatible with future changes.
All consumers who display yearly staking reward percentages are encouraged to migrate from the standard calculation to using the endpoint, as the standard calculation will no longer be accurate.
Endpoint: `/kava/community/v1beta1/annualized_rewards`
Example Response:
```json
{
"staking_rewards": "0.203023625910000000"
}
```
## Before Kava 15
The staking APR is calculated the same way as other cosmos-sdk chains. Various parameters are fetched and then combined in this calculation:
```
staking_apr ≈ mint_inflation *
(1 - distribution_params.community_tax) *
(total_supply_ukava/pool.bonded_tokens)
```
_Note this doesnt include transaction fees paid to stakers._
Endpoints used:
* https://api.data.kava.io/cosmos/mint/v1beta1/params
* https://api.data.kava.io/cosmos/distribution/v1beta1/params
* https://api.data.kava.io/cosmos/bank/v1beta1/supply/by_denom?denom=ukava
* https://api.data.kava.io/cosmos/staking/v1beta1/pool
Informational Endpoints
* https://api.data.kava.io/cosmos/mint/v1beta1/inflation
* https://api.data.kava.io/cosmos/mint/v1beta1/annual_provisions
## After Kava 15
Kava 15 implements new staking rewards as ratified in this proposal: https://www.mintscan.io/kava/proposals/141. They will come into effect at the “switchover time” on 2024-01-01 00:00 UTC.
* All delegating and claiming transactions remain unchanged. There is no change in how rewards are claimed or how claimable balances are queried.
* After the switchover time, inflation will be set to zero (and rewards will be paid from the community module account).
* After the switchover time, rewards are paid out according to:
```
staking apy ≈ community_params.staking_rewards_per_second *
seconds_per_year / pool.bonded_tokens
```
_Note this doesnt include transaction fees paid to stakers._
* There is a new endpoint `kava/community/v1beta1/annualized_rewards`
* before the switchover time, it will return the current staking APY (calculated in the previous section)
* after the switchover time, it will return the new staking APY above
* Existing endpoints above will remain active, but the params will change such that the old apr calculation will return 0.
* https://api.data.kava.io/cosmos/mint/v1beta1/params
* no format changes
* `inflation_max` and `inflation_min` will be 0.0
* https://api.data.kava.io/cosmos/distribution/v1beta1/params
* no format changes
* `community_tax` will be 0.0
* https://api.data.kava.io/cosmos/bank/v1beta1/supply/by_denom?denom=ukava
* no changes
* https://api.data.kava.io/cosmos/staking/v1beta1/pool
* no changes
* https://api.data.kava.io/cosmos/mint/v1beta1/inflation
* no format changes
* `inflation` will be 0.0
* https://api.data.kava.io/cosmos/mint/v1beta1/annual_provisions
* no format changes
* `annual_provisions` will be 0.0

View File

@ -1,241 +0,0 @@
package e2e_test
// func (suite *IntegrationTestSuite) TestUpgradeCommunityParams() {
// suite.SkipIfUpgradeDisabled()
// beforeUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight - 1)
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
// // Before params
// kavaDistParamsBefore, err := suite.ZgChain.Kavadist.Params(beforeUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
// suite.NoError(err)
// mintParamsBefore, err := suite.ZgChain.Mint.Params(beforeUpgradeCtx, &minttypes.QueryParamsRequest{})
// suite.NoError(err)
// // Before parameters
// suite.Run("x/community and x/kavadist parameters before upgrade", func() {
// _, err = suite.ZgChain.Community.Params(beforeUpgradeCtx, &communitytypes.QueryParamsRequest{})
// 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() {
// kavaDistParamsAfter, err := suite.ZgChain.Kavadist.Params(afterUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
// suite.NoError(err)
// mintParamsAfter, err := suite.ZgChain.Mint.Params(afterUpgradeCtx, &minttypes.QueryParamsRequest{})
// suite.NoError(err)
// communityParamsAfter, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
// 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
// params, err := suite.ZgChain.Community.Params(
// 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
// _, switchoverHeight, err := suite.ZgChain.GetBeginBlockEventsFromQuery(
// 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() {
// kavaDistParamsAfter, err := suite.ZgChain.Kavadist.Params(
// afterSwitchoverCtx,
// &kavadisttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// mintParamsAfter, err := suite.ZgChain.Mint.Params(
// afterSwitchoverCtx,
// &minttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// communityParamsAfter, err := suite.ZgChain.Community.Params(
// 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
// kavaDistBalBefore, err := suite.ZgChain.Kavadist.Balance(
// beforeSwitchoverCtx,
// &kavadisttypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
// distrBalBefore, err := suite.ZgChain.Distribution.CommunityPool(
// beforeSwitchoverCtx,
// &distrtypes.QueryCommunityPoolRequest{},
// )
// suite.NoError(err)
// distrBalCoinsBefore, distrDustBefore := distrBalBefore.Pool.TruncateDecimal()
// beforeCommPoolBalance, err := suite.ZgChain.Community.Balance(
// beforeSwitchoverCtx,
// &communitytypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
// // After balances
// kavaDistBalAfter, err := suite.ZgChain.Kavadist.Balance(
// afterSwitchoverCtx,
// &kavadisttypes.QueryBalanceRequest{},
// )
// suite.NoError(err)
// distrBalAfter, err := suite.ZgChain.Distribution.CommunityPool(
// afterSwitchoverCtx,
// &distrtypes.QueryCommunityPoolRequest{},
// )
// suite.NoError(err)
// afterCommPoolBalance, err := suite.ZgChain.Community.Balance(
// 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
// blockRes, err := suite.ZgChain.TmSignClient.BlockResults(
// 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",
// )
// })
// }

View File

@ -1,292 +0,0 @@
package e2e_test
import (
"context"
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
query "github.com/cosmos/cosmos-sdk/types/query"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/tests/e2e/testutil"
"github.com/0glabs/0g-chain/tests/util"
)
const (
govModuleAcc = "0g10d07y265gmmuvt4z0w9aw880jnsr700jxh8cq5"
communityModuleAcc = "0g17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5"
zgChainDistModuleAcc = "0g1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w"
)
func (suite *IntegrationTestSuite) TestGovParamChanges() {
suite.SkipIfUpgradeDisabled()
beforeUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight - 1)
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
// fetch gov parameters before upgrade
govBeforeParams, err := suite.ZgChain.Gov.Params(beforeUpgradeCtx, &govv1.QueryParamsRequest{ParamsType: "tallying"})
suite.Require().NoError(err)
// assert expected gov quorum before upgrade
suite.NotEqual(govBeforeParams.TallyParams.Quorum, "0.200000000000000000")
govAfterParams, err := suite.ZgChain.Gov.Params(afterUpgradeCtx, &govv1.QueryParamsRequest{ParamsType: "tallying"})
suite.Require().NoError(err)
// assert expected gov quorum after upgrade
suite.Equal(govAfterParams.TallyParams.Quorum, "0.200000000000000000")
}
func (suite *IntegrationTestSuite) TestAuthzParamChanges() {
suite.SkipIfUpgradeDisabled()
beforeUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight - 1)
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
// fetch authz grants before upgrade
authzBeforeGrants, err := suite.ZgChain.Authz.Grants(beforeUpgradeCtx, &authz.QueryGrantsRequest{Granter: zgChainDistModuleAcc, Grantee: govModuleAcc, Pagination: &query.PageRequest{Limit: 1000, CountTotal: true}})
suite.Require().NoError(err)
suite.Require().Equal(authzBeforeGrants.Pagination.Total, uint64(len(authzBeforeGrants.Grants)), "expected all grants to have been requested")
// no kavadist -> gov grants
suite.Equal(0, len(authzBeforeGrants.Grants))
// fetch authz grants after upgrade
authzAfterGrants, err := suite.ZgChain.Authz.Grants(afterUpgradeCtx, &authz.QueryGrantsRequest{Granter: zgChainDistModuleAcc, Grantee: govModuleAcc, Pagination: &query.PageRequest{Limit: 1000, CountTotal: true}})
suite.Require().NoError(err)
suite.Require().Equal(authzAfterGrants.Pagination.Total, uint64(len(authzAfterGrants.Grants)), "expected all grants to have been requested")
// one kavadist -> gov grants
suite.Require().Equal(1, len(authzAfterGrants.Grants))
grant := authzAfterGrants.Grants[0]
var authorization authz.Authorization
suite.ZgChain.EncodingConfig.Marshaler.UnpackAny(grant.Authorization, &authorization)
genericAuthorization, ok := authorization.(*authz.GenericAuthorization)
suite.Require().True(ok, "expected generic authorization")
// kavadist allows gov to MsgSend it's funds
suite.Equal(sdk.MsgTypeURL(&banktypes.MsgSend{}), genericAuthorization.Msg)
// no expiration
var expectedExpiration *time.Time
suite.Equal(expectedExpiration, grant.Expiration)
}
func (suite *IntegrationTestSuite) TestModuleAccountGovTransfers() {
suite.SkipIfUpgradeDisabled()
suite.SkipIfKvtoolDisabled()
// the module account (authority) that executes the transfers
govAcc := sdk.MustAccAddressFromBech32(govModuleAcc)
// module accounts for gov transfer test cases
communityAcc := sdk.MustAccAddressFromBech32(communityModuleAcc)
zgChainDistAcc := sdk.MustAccAddressFromBech32(zgChainDistModuleAcc)
testCases := []struct {
name string
sender sdk.AccAddress
receiver sdk.AccAddress
amount sdk.Coin
}{
{
name: "transfer from community to kavadist for incentive rewards",
sender: communityAcc,
receiver: zgChainDistAcc,
amount: chaincfg.MakeCoinForGasDenom(100),
},
{
name: "transfer from kavadist to community",
sender: zgChainDistAcc,
receiver: communityAcc,
amount: chaincfg.MakeCoinForGasDenom(50),
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
// create msg exec for transfer between modules
msg := banktypes.NewMsgSend(
tc.sender,
tc.receiver,
sdk.NewCoins(tc.amount),
)
execMsg := authz.NewMsgExec(govAcc, []sdk.Msg{msg})
// ensure proposal passes
passBlock := suite.submitAndPassProposal([]sdk.Msg{&execMsg})
transfers := suite.getBankTransferAmountAtBlock(passBlock, tc.sender, tc.receiver)
suite.Require().Containsf(
transfers,
tc.amount,
"expected transfer of %s to be included in bank transfer events: %s",
tc.amount,
transfers,
)
})
}
}
func (suite *IntegrationTestSuite) submitAndPassProposal(msgs []sdk.Msg) int64 {
govParamsRes, err := suite.ZgChain.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
ParamsType: govv1.ParamDeposit,
})
suite.NoError(err)
zgChainAcc := suite.ZgChain.GetAccount(testutil.FundedAccountName)
proposalMsg, err := govv1.NewMsgSubmitProposal(
msgs,
govParamsRes.DepositParams.MinDeposit,
zgChainAcc.SdkAddress.String(),
"",
)
suite.NoError(err)
gasLimit := 1e6
fee := chaincfg.MakeCoinForEvmDenom(1e15)
req := util.ZgChainMsgRequest{
Msgs: []sdk.Msg{proposalMsg},
GasLimit: uint64(gasLimit),
FeeAmount: sdk.NewCoins(fee),
Memo: "this is a proposal please accept me",
}
res := zgChainAcc.SignAndBroadcastZgChainTx(req)
suite.Require().NoError(res.Err)
// Wait for proposal to be submitted
txRes, err := util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.Result.TxHash, 6*time.Second)
suite.Require().NoError(err)
var govRes govv1.MsgSubmitProposalResponse
suite.decodeTxMsgResponse(txRes, &govRes)
// 2. Vote for proposal from whale account
whale := suite.ZgChain.GetAccount(testutil.FundedAccountName)
voteMsg := govv1.NewMsgVote(
whale.SdkAddress,
govRes.ProposalId,
govv1.OptionYes,
"",
)
voteReq := util.ZgChainMsgRequest{
Msgs: []sdk.Msg{voteMsg},
GasLimit: uint64(gasLimit),
FeeAmount: sdk.NewCoins(fee),
Memo: "voting",
}
voteRes := whale.SignAndBroadcastZgChainTx(voteReq)
suite.Require().NoError(voteRes.Err)
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, voteRes.Result.TxHash, 6*time.Second)
suite.Require().NoError(err)
// 3. Wait until proposal passes
suite.Require().Eventually(func() bool {
proposalRes, err := suite.ZgChain.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
ProposalId: govRes.ProposalId,
})
suite.NoError(err)
switch status := proposalRes.Proposal.Status; status {
case govv1.StatusDepositPeriod, govv1.StatusVotingPeriod:
return false
case govv1.StatusPassed:
return true
case govv1.StatusFailed, govv1.StatusRejected:
suite.Failf("proposal failed", "proposal failed with status %s", status.String())
return true
}
return false
}, 60*time.Second, 1*time.Second)
page := 1
perPage := 100
// Get the block the proposal was passed in
passBlock, err := suite.ZgChain.TmSignClient.BlockSearch(
context.Background(),
fmt.Sprintf(
"active_proposal.proposal_result = 'proposal_passed' AND active_proposal.proposal_id = %d",
govRes.ProposalId,
),
&page,
&perPage,
"asc",
)
suite.Require().NoError(err)
suite.Require().Equal(1, len(passBlock.Blocks), "passed proposal should be searchable")
return passBlock.Blocks[len(passBlock.Blocks)-1].Block.Height
}
// getBankTransferAmountAtBlock returns the amount of coins transferred between
// the given accounts in the block at the given height. Note that this returns
// a slice of sdk.Coin that can contain multiple coins of the SAME denom -- ie. NOT sdk.Coins
func (suite *IntegrationTestSuite) getBankTransferAmountAtBlock(
blockHeight int64,
sender sdk.AccAddress,
receiver sdk.AccAddress,
) []sdk.Coin {
// Fetch block results for paid staking rewards in the block
blockRes, err := suite.ZgChain.TmSignClient.BlockResults(
context.Background(),
&blockHeight,
)
suite.Require().NoError(err)
transferEvents := util.FilterEventsByType(
blockRes.EndBlockEvents, // gov proposals applied in EndBlocker
banktypes.EventTypeTransfer,
)
suite.Require().NotEmpty(transferEvents, "there should be at least 1 bank transfer event")
transfers := []sdk.Coin{}
event:
for _, event := range transferEvents {
if event.Type != banktypes.EventTypeTransfer {
suite.FailNowf(
"unexpected event type %s in block results",
event.Type,
)
}
for _, attr := range event.Attributes {
suite.T().Logf("event attr: %s = %s", string(attr.Key), string(attr.Value))
if string(attr.Key) == banktypes.AttributeKeyRecipient {
if string(attr.Value) != receiver.String() {
continue event
}
}
if string(attr.Key) == banktypes.AttributeKeySender {
if string(attr.Value) != sender.String() {
continue event
}
}
if string(attr.Key) == sdk.AttributeKeyAmount {
amount, err := sdk.ParseCoinNormalized(string(attr.Value))
suite.Require().NoError(err)
transfers = append(transfers, amount)
}
}
}
return transfers
}

View File

@ -1,57 +0,0 @@
package e2e_test
// func (suite *IntegrationTestSuite) TestUpgradeIncentiveParams() {
// suite.SkipIfUpgradeDisabled()
// beforeUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight - 1)
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
// // Before params
// incentiveParamsBefore, err := suite.ZgChain.Incentive.Params(
// beforeUpgradeCtx,
// &incentivetypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// incentiveParamsAfter, err := suite.ZgChain.Incentive.Params(
// afterUpgradeCtx,
// &incentivetypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// suite.Run("x/incentive parameters before upgrade", func() {
// suite.Require().Len(
// incentiveParamsBefore.Params.EarnRewardPeriods,
// 1,
// "x/incentive should have 1 earn reward period before upgrade",
// )
// suite.Require().Equal(
// sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(159_459))),
// incentiveParamsBefore.Params.EarnRewardPeriods[0].RewardsPerSecond,
// )
// })
// suite.Run("x/incentive parameters after upgrade", func() {
// suite.Require().Len(
// incentiveParamsAfter.Params.EarnRewardPeriods,
// 1,
// "x/incentive should have 1 earn reward period before upgrade",
// )
// suite.Require().Equal(
// // Manual calculation of
// // 600,000 * 1000,000 / (365 * 24 * 60 * 60)
// sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(19025))),
// incentiveParamsAfter.Params.EarnRewardPeriods[0].RewardsPerSecond,
// )
// // No other changes
// incentiveParamsAfter.Params.EarnRewardPeriods[0].RewardsPerSecond = incentiveParamsBefore.Params.EarnRewardPeriods[0].RewardsPerSecond
// suite.Require().Equal(
// incentiveParamsBefore,
// incentiveParamsAfter,
// "other param values should not be changed",
// )
// })
// }

View File

@ -1,457 +0,0 @@
package e2e_test
import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// func (suite *IntegrationTestSuite) TestUpgradeInflation_Disable() {
// suite.SkipIfUpgradeDisabled()
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
// // Get x/community for switchover time
// params, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
// suite.Require().NoError(err)
// // Sleep until switchover time + 6 seconds for extra block
// sleepDuration := time.Until(params.Params.UpgradeTimeDisableInflation.Add(6 * time.Second))
// time.Sleep(sleepDuration)
// suite.Require().Eventually(func() bool {
// communityParams, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
// suite.Require().NoError(err)
// // After params are set in x/community -- non-zero switchover time
// return !communityParams.Params.UpgradeTimeDisableInflation.Equal(time.Time{})
// }, 20*time.Second, 3*time.Second)
// // Fetch exact block when inflation stop event emitted
// // This is run after the switchover, so we don't need to poll
// _, switchoverHeight, err := suite.ZgChain.GetBeginBlockEventsFromQuery(
// context.Background(),
// fmt.Sprintf(
// "%s.%s EXISTS",
// communitytypes.EventTypeInflationStop,
// communitytypes.AttributeKeyInflationDisableTime,
// ),
// )
// suite.Require().NoError(err)
// suite.Require().NotZero(switchoverHeight)
// // 1 block before switchover
// beforeSwitchoverCtx := util.CtxAtHeight(switchoverHeight - 1)
// afterSwitchoverCtx := util.CtxAtHeight(switchoverHeight)
// suite.Run("x/mint, x/kavadist inflation before switchover", func() {
// mintParams, err := suite.ZgChain.Mint.Params(
// beforeSwitchoverCtx,
// &minttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// kavaDistParams, err := suite.ZgChain.Kavadist.Params(
// beforeSwitchoverCtx,
// &kavadisttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// // Use .String() to compare Decs since x/mint uses the deprecated one,
// // mismatch of types but same value.
// suite.Equal(
// sdkmath.LegacyMustNewDecFromStr("0.595000000000000000").String(),
// mintParams.Params.InflationMin.String(),
// "x/mint inflation min should be 59.5%% before switchover",
// )
// suite.Equal(
// sdkmath.LegacyMustNewDecFromStr("0.595000000000000000").String(),
// mintParams.Params.InflationMax.String(),
// "x/mint inflation max should be 59.5%% before switchover",
// )
// suite.True(
// kavaDistParams.Params.Active,
// "x/kavadist should be active before switchover",
// )
// })
// suite.Run("x/distribution community tax before switchover", func() {
// distrParams, err := suite.ZgChain.Distribution.Params(
// beforeSwitchoverCtx,
// &distributiontypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// suite.Equal(
// sdkmath.LegacyMustNewDecFromStr("0.949500000000000000").String(),
// distrParams.Params.CommunityTax.String(),
// "x/distribution community tax should be 94.95%% before switchover",
// )
// })
// suite.Run("x/mint, x/kavadist inflation after switchover", func() {
// mintParams, err := suite.ZgChain.Mint.Params(
// afterSwitchoverCtx,
// &minttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// kavaDistParams, err := suite.ZgChain.Kavadist.Params(
// afterSwitchoverCtx,
// &kavadisttypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// suite.Equal(
// sdkmath.LegacyZeroDec().String(),
// mintParams.Params.InflationMin.String(),
// "x/mint inflation min should be 0% after switchover",
// )
// suite.Equal(
// sdkmath.LegacyZeroDec().String(),
// mintParams.Params.InflationMax.String(),
// "x/mint inflation max should be 0% after switchover",
// )
// suite.False(
// kavaDistParams.Params.Active,
// "x/kavadist should be inactive after switchover",
// )
// })
// suite.Run("x/distribution community tax after switchover", func() {
// distrParams, err := suite.ZgChain.Distribution.Params(
// afterSwitchoverCtx,
// &distributiontypes.QueryParamsRequest{},
// )
// suite.NoError(err)
// suite.Equal(
// sdkmath.LegacyZeroDec().String(),
// distrParams.Params.CommunityTax.String(),
// "x/distribution community tax should be 0%% before switchover",
// )
// })
// // Ensure inflation was still active before switchover
// suite.Run("positive mint events before switchover", func() {
// // 1 block before switchover
// queryHeight := switchoverHeight - 1
// block, err := suite.ZgChain.TmSignClient.BlockResults(
// context.Background(),
// &queryHeight,
// )
// suite.Require().NoError(err)
// // Mint events should only occur in begin block
// mintEvents := util.FilterEventsByType(block.BeginBlockEvents, minttypes.EventTypeMint)
// suite.Require().NotEmpty(mintEvents, "mint events should be emitted")
// // Ensure mint amounts are non-zero
// found := false
// for _, event := range mintEvents {
// for _, attribute := range event.Attributes {
// // Bonded ratio and annual provisions unchecked
// if string(attribute.Key) == minttypes.AttributeKeyInflation {
// suite.Equal(
// sdkmath.LegacyMustNewDecFromStr("0.595000000000000000").String(),
// string(attribute.Value),
// "inflation should be 59.5%% before switchover",
// )
// }
// if string(attribute.Key) == sdk.AttributeKeyAmount {
// found = true
// // Parse as native go int, not necessary to use sdk.Int
// value, err := strconv.Atoi(string(attribute.Value))
// suite.Require().NoError(err)
// suite.NotZero(value, "mint amount should be non-zero")
// suite.Positive(value, "mint amount should be positive")
// }
// }
// }
// suite.True(found, "mint amount should be found")
// })
// suite.Run("staking denom supply increases before switchover", func() {
// queryHeight := switchoverHeight - 2
// supply1, err := suite.ZgChain.Bank.SupplyOf(
// util.CtxAtHeight(queryHeight),
// &types.QuerySupplyOfRequest{
// Denom: suite.ZgChain.StakingDenom,
// },
// )
// suite.Require().NoError(err)
// suite.NotZero(supply1.Amount, "ukava supply should be non-zero")
// // Next block
// queryHeight += 1
// supply2, err := suite.ZgChain.Bank.SupplyOf(
// util.CtxAtHeight(queryHeight),
// &types.QuerySupplyOfRequest{
// Denom: suite.ZgChain.StakingDenom,
// },
// )
// suite.Require().NoError(err)
// suite.NotZero(supply2.Amount, "ukava supply should be non-zero")
// suite.Truef(
// supply2.Amount.Amount.GT(supply1.Amount.Amount),
// "ukava supply before switchover should increase between blocks, %s > %s",
// supply2.Amount.Amount.String(),
// )
// })
// // Check if inflation is ACTUALLY disabled... check if any coins are being
// // minted in the blocks after switchover
// suite.Run("no minting after switchover", func() {
// kavaSupply := sdk.NewCoin(suite.ZgChain.StakingDenom, sdkmath.ZeroInt())
// // Next 5 blocks after switchover, ensure there's actually no more inflation
// for i := 0; i < 5; i++ {
// queryHeight := switchoverHeight + int64(i)
// suite.Run(
// fmt.Sprintf("x/mint events with 0 amount @ height=%d", queryHeight),
// func() {
// var block *coretypes.ResultBlockResults
// suite.Require().Eventually(func() bool {
// // Check begin block events
// block, err = suite.ZgChain.TmSignClient.BlockResults(
// context.Background(),
// &queryHeight,
// )
// return err == nil
// }, 20*time.Second, 3*time.Second)
// var mintEvents []abci.Event
// // Mint events should only occur in begin block, but we just include
// // everything else just in case anything changes in x/mint
// mintEventsBegin := util.FilterEventsByType(block.BeginBlockEvents, minttypes.EventTypeMint)
// mintEventsEnd := util.FilterEventsByType(block.EndBlockEvents, minttypes.EventTypeMint)
// mintEventsTx := util.FilterTxEventsByType(block.TxsResults, minttypes.EventTypeMint)
// mintEvents = append(mintEvents, mintEventsBegin...)
// mintEvents = append(mintEvents, mintEventsEnd...)
// mintEvents = append(mintEvents, mintEventsTx...)
// suite.Require().NotEmpty(mintEvents, "mint events should still be emitted")
// // Ensure mint amounts are 0
// found := false
// for _, event := range mintEvents {
// for _, attribute := range event.Attributes {
// // Bonded ratio and annual provisions unchecked
// if string(attribute.Key) == minttypes.AttributeKeyInflation {
// suite.Equal(sdkmath.LegacyZeroDec().String(), string(attribute.Value))
// }
// if string(attribute.Key) == sdk.AttributeKeyAmount {
// found = true
// suite.Equal(sdkmath.ZeroInt().String(), string(attribute.Value))
// }
// }
// }
// suite.True(found, "mint amount should be found")
// },
// )
// // Run this after the events check, since that one waits for the
// // new block if necessary
// suite.Run(
// fmt.Sprintf("total staking denom supply should not change @ height=%d", queryHeight),
// func() {
// supplyRes, err := suite.ZgChain.Bank.SupplyOf(
// util.CtxAtHeight(queryHeight),
// &types.QuerySupplyOfRequest{
// Denom: suite.ZgChain.StakingDenom,
// },
// )
// suite.Require().NoError(err)
// if kavaSupply.IsZero() {
// // First iteration, set supply
// kavaSupply = supplyRes.Amount
// } else {
// suite.Require().Equal(
// kavaSupply,
// supplyRes.Amount,
// "ukava supply should not change",
// )
// }
// },
// )
// }
// })
// suite.Run("no staking rewards from x/community before switchover", func() {
// // 1 block before switchover
// queryHeight := switchoverHeight - 1
// block, err := suite.ZgChain.TmSignClient.BlockResults(
// context.Background(),
// &queryHeight,
// )
// suite.Require().NoError(err)
// // Events are not emitted if amount is 0
// stakingRewardEvents := util.FilterEventsByType(block.BeginBlockEvents, communitytypes.EventTypeStakingRewardsPaid)
// suite.Require().Empty(stakingRewardEvents, "staking reward events should not be emitted")
// })
// suite.Run("staking rewards pay out from x/community after switchover", func() {
// for i := 0; i < 5; i++ {
// // after switchover
// queryHeight := switchoverHeight + int64(i)
// block, err := suite.ZgChain.TmSignClient.BlockResults(
// context.Background(),
// &queryHeight,
// )
// suite.Require().NoError(err)
// stakingRewardEvents := util.FilterEventsByType(
// block.BeginBlockEvents,
// communitytypes.EventTypeStakingRewardsPaid,
// )
// suite.Require().NotEmptyf(
// stakingRewardEvents,
// "staking reward events should be emitted at height=%d",
// queryHeight,
// )
// // Ensure amounts are non-zero
// found := false
// for _, attr := range stakingRewardEvents[0].Attributes {
// if string(attr.Key) == communitytypes.AttributeKeyStakingRewardAmount {
// coins, err := sdk.ParseCoinNormalized(string(attr.Value))
// suite.Require().NoError(err, "staking reward amount should be parsable coins")
// suite.Truef(
// coins.Amount.IsPositive(),
// "staking reward amount should be a positive amount at height=%d",
// queryHeight,
// )
// found = true
// }
// }
// suite.Truef(
// found,
// "staking reward amount should be found in events at height=%d",
// queryHeight,
// )
// }
// })
// // Staking rewards can still be claimed
// suite.Run("staking rewards claimable after switchover", func() {
// suite.SkipIfKvtoolDisabled()
// // Get the delegator of the only validator
// validators, err := suite.ZgChain.Staking.Validators(
// context.Background(),
// &stakingtypes.QueryValidatorsRequest{},
// )
// suite.Require().NoError(err)
// suite.Require().Positive(len(validators.Validators), "should only be at least 1 validator")
// valAddr, err := sdk.ValAddressFromBech32(validators.Validators[0].OperatorAddress)
// suite.Require().NoError(err)
// accAddr := sdk.AccAddress(valAddr.Bytes())
// balBefore, err := suite.ZgChain.Bank.Balance(
// context.Background(),
// &types.QueryBalanceRequest{
// Address: accAddr.String(),
// Denom: suite.ZgChain.StakingDenom,
// },
// )
// suite.Require().NoError(err)
// suite.Require().False(balBefore.Balance.IsZero(), "val staking denom balance should be non-zero")
// delegationRewards, err := suite.ZgChain.Distribution.DelegationRewards(
// context.Background(),
// &distributiontypes.QueryDelegationRewardsRequest{
// ValidatorAddress: valAddr.String(),
// DelegatorAddress: accAddr.String(),
// },
// )
// suite.Require().NoError(err)
// suite.False(delegationRewards.Rewards.Empty())
// suite.True(delegationRewards.Rewards.IsAllPositive(), "queried rewards should be positive")
// withdrawRewardsMsg := distributiontypes.NewMsgWithdrawDelegatorReward(
// accAddr,
// valAddr,
// )
// // Get the validator private key from kava keyring
// key, err := suite.ZgChain.Keyring.(unsafeExporter).ExportPrivateKeyObject(
// "validator",
// )
// suite.Require().NoError(err)
// acc := suite.ZgChain.AddNewSigningAccountFromPrivKey(
// "validator",
// key,
// "",
// suite.ZgChain.ChainID,
// )
// gasLimit := int64(2e5)
// fee := ukava(200)
// req := util.KavaMsgRequest{
// Msgs: []sdk.Msg{withdrawRewardsMsg},
// GasLimit: uint64(gasLimit),
// FeeAmount: sdk.NewCoins(fee),
// Memo: "give me my money",
// }
// res := acc.SignAndBroadcastKavaTx(req)
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.Result.TxHash, 6*time.Second)
// suite.Require().NoError(err)
// balAfter, err := suite.ZgChain.Bank.Balance(
// context.Background(),
// &types.QueryBalanceRequest{
// Address: accAddr.String(),
// Denom: suite.ZgChain.StakingDenom,
// },
// )
// suite.Require().NoError(err)
// suite.Require().False(balAfter.Balance.IsZero(), "val staking denom balance should be non-zero")
// balIncrease := balAfter.Balance.
// Sub(*balBefore.Balance).
// Add(res.Tx.GetFee()[0]) // Add the fee back to balance to compare actual balances
// queriedRewardsCoins, _ := delegationRewards.Rewards.TruncateDecimal()
// suite.Require().Truef(
// queriedRewardsCoins.AmountOf(suite.ZgChain.StakingDenom).
// LTE(balIncrease.Amount),
// "claimed rewards should be >= queried delegation rewards, got claimed %s vs queried %s",
// balIncrease.Amount.String(),
// queriedRewardsCoins.AmountOf(suite.ZgChain.StakingDenom).String(),
// )
// })
// }
// unsafeExporter is implemented by key stores that support unsafe export
// of private keys' material.
type unsafeExporter interface {
// ExportPrivateKeyObject returns a private key in unarmored format.
ExportPrivateKeyObject(uid string) (cryptotypes.PrivKey, error)
}

View File

@ -1,103 +0,0 @@
package e2e_test
import (
"context"
sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/0glabs/0g-chain/tests/util"
)
func (suite *IntegrationTestSuite) TestValMinCommission() {
suite.SkipIfUpgradeDisabled()
beforeUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight - 1)
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
suite.Run("before upgrade", func() {
// Before params
beforeParams, err := suite.ZgChain.Staking.Params(beforeUpgradeCtx, &types.QueryParamsRequest{})
suite.Require().NoError(err)
suite.Require().Equal(
sdkmath.LegacyZeroDec().String(),
beforeParams.Params.MinCommissionRate.String(),
"min commission rate should be 0%% before upgrade",
)
// Before validators
beforeValidators, err := suite.ZgChain.Staking.Validators(beforeUpgradeCtx, &types.QueryValidatorsRequest{})
suite.Require().NoError(err)
for _, val := range beforeValidators.Validators {
// In kvtool gentx, the commission rate is set to 0, with max of 0.01
expectedRate := sdkmath.LegacyZeroDec()
expectedRateMax := sdkmath.LegacyMustNewDecFromStr("0.01")
suite.Require().Equalf(
expectedRate.String(),
val.Commission.CommissionRates.Rate.String(),
"validator %s should have commission rate of %s before upgrade",
val.OperatorAddress,
expectedRate,
)
suite.Require().Equalf(
expectedRateMax.String(),
val.Commission.CommissionRates.MaxRate.String(),
"validator %s should have max commission rate of %s before upgrade",
val.OperatorAddress,
expectedRateMax,
)
}
})
suite.Run("after upgrade", func() {
block, err := suite.ZgChain.Tm.GetBlockByHeight(context.Background(), &tmservice.GetBlockByHeightRequest{
Height: suite.UpgradeHeight,
})
suite.Require().NoError(err)
// After params
afterParams, err := suite.ZgChain.Staking.Params(afterUpgradeCtx, &types.QueryParamsRequest{})
suite.Require().NoError(err)
expectedMinRate := sdk.MustNewDecFromStr("0.05")
suite.Require().Equal(
expectedMinRate.String(),
afterParams.Params.MinCommissionRate.String(),
"min commission rate should be 5%% after upgrade",
)
// After validators
afterValidators, err := suite.ZgChain.Staking.Validators(afterUpgradeCtx, &types.QueryValidatorsRequest{})
suite.Require().NoError(err)
for _, val := range afterValidators.Validators {
suite.Require().Truef(
val.Commission.CommissionRates.Rate.GTE(expectedMinRate),
"validator %s should have commission rate of at least 5%%",
val.OperatorAddress,
)
suite.Require().Truef(
val.Commission.CommissionRates.MaxRate.GTE(expectedMinRate),
"validator %s should have max commission rate of at least 5%%",
val.OperatorAddress,
)
suite.Require().Truef(
val.Commission.UpdateTime.Equal(block.SdkBlock.Header.Time),
"validator %s should have commission update time set to block time, expected %s, got %s",
val.OperatorAddress,
block.SdkBlock.Header.Time,
val.Commission.UpdateTime,
)
}
})
}

View File

@ -14,7 +14,6 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authz "github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
evmhd "github.com/evmos/ethermint/crypto/hd"
@ -212,21 +211,6 @@ func (chain *Chain) QuerySdkForBalances(addr sdk.AccAddress) sdk.Coins {
return res.Balances
}
// QuerySdkForBalancesAtHeight gets the balance of a particular address on this Chain, at the specified height.
func (chain *Chain) QuerySdkForBalancesAtHeight(
height int64,
addr sdk.AccAddress,
) sdk.Coins {
res, err := chain.Bank.AllBalances(
util.CtxAtHeight(height),
&banktypes.QueryAllBalancesRequest{
Address: addr.String(),
},
)
require.NoError(chain.t, err)
return res.Balances
}
// GetModuleBalances returns the balance of a requested module account
func (chain *Chain) GetModuleBalances(moduleName string) sdk.Coins {
addr := authtypes.NewModuleAddress(moduleName)