forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chg: pos-2695: replace stake module and skip some tests due to pos-2540
- Loading branch information
1 parent
f6cae67
commit 8f50359
Showing
13 changed files
with
191 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,30 @@ package sims | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/rand" | ||
"strconv" | ||
"time" | ||
|
||
"cosmossdk.io/depinject" | ||
sdkmath "cosmossdk.io/math" | ||
abci "github.com/cometbft/cometbft/abci/types" | ||
cmtjson "github.com/cometbft/cometbft/libs/json" | ||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
cmttypes "github.com/cometbft/cometbft/types" | ||
dbm "github.com/cosmos/cosmos-db" | ||
|
||
"cosmossdk.io/depinject" | ||
sdkmath "cosmossdk.io/math" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
"github.com/cosmos/cosmos-sdk/runtime" | ||
servertypes "github.com/cosmos/cosmos-sdk/server/types" | ||
"github.com/cosmos/cosmos-sdk/testutil/mock" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/simulation" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
stakeTypes "github.com/0xPolygon/heimdall-v2/x/stake/types" | ||
Check failure on line 29 in testutil/sims/app_helpers.go GitHub Actions / dependency-review
Check failure on line 29 in testutil/sims/app_helpers.go GitHub Actions / dependency-review
Check failure on line 29 in testutil/sims/app_helpers.go GitHub Actions / dependency-review
Check failure on line 29 in testutil/sims/app_helpers.go GitHub Actions / dependency-review
Check failure on line 29 in testutil/sims/app_helpers.go GitHub Actions / dependency-review
|
||
) | ||
|
||
const DefaultGenTxGas = 10000000 | ||
|
@@ -197,61 +198,48 @@ func GenesisStateWithValSet( | |
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs) | ||
genesisState[authtypes.ModuleName] = codec.MustMarshalJSON(authGenesis) | ||
|
||
validators := make([]stakingtypes.Validator, 0, len(valSet.Validators)) | ||
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators)) | ||
stakingSequence := make([]string, len(valSet.Validators)) | ||
|
||
bondAmt := sdk.DefaultPowerReduction | ||
validators := make([]*stakeTypes.Validator, 0, len(valSet.Validators)) | ||
|
||
for _, val := range valSet.Validators { | ||
r := rand.New(rand.NewSource(time.Now().UnixNano())) | ||
|
||
for i, val := range valSet.Validators { | ||
pk, err := cryptocodec.FromCmtPubKeyInterface(val.PubKey) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to convert pubkey: %w", err) | ||
} | ||
|
||
pkAny, err := codectypes.NewAnyWithValue(pk) | ||
validator, err := stakeTypes.NewValidator( | ||
uint64(i), | ||
0, | ||
0, | ||
uint64(i), | ||
int64(simulation.RandIntBetween(r, 10, 100)), | ||
pk, | ||
val.Address.String(), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create new any: %w", err) | ||
return nil, fmt.Errorf("failed to create a new validator: %w", err) | ||
} | ||
|
||
validator := stakingtypes.Validator{ | ||
OperatorAddress: sdk.ValAddress(val.Address).String(), | ||
ConsensusPubkey: pkAny, | ||
Jailed: false, | ||
Status: stakingtypes.Bonded, | ||
Tokens: bondAmt, | ||
DelegatorShares: sdkmath.LegacyOneDec(), | ||
Description: stakingtypes.Description{}, | ||
UnbondingHeight: int64(0), | ||
UnbondingTime: time.Unix(0, 0).UTC(), | ||
Commission: stakingtypes.NewCommission(sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec()), | ||
MinSelfDelegation: sdkmath.ZeroInt(), | ||
} | ||
validators = append(validators, validator) | ||
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress().String(), sdk.ValAddress(val.Address).String(), sdkmath.LegacyOneDec())) | ||
|
||
stakingSequence[i] = strconv.Itoa(simulation.RandIntBetween(r, 1000, 100000)) | ||
} | ||
|
||
validatorSet := stakeTypes.NewValidatorSet(validators) | ||
|
||
// set validators and delegations | ||
stakingGenesis := stakingtypes.NewGenesisState(stakingtypes.DefaultParams(), validators, delegations) | ||
genesisState[stakingtypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis) | ||
stakingGenesis := stakeTypes.NewGenesisState(validators, *validatorSet, stakingSequence) | ||
genesisState[stakeTypes.ModuleName] = codec.MustMarshalJSON(stakingGenesis) | ||
|
||
totalSupply := sdk.NewCoins() | ||
for _, b := range balances { | ||
// add genesis acc tokens to total supply | ||
totalSupply = totalSupply.Add(b.Coins...) | ||
} | ||
|
||
for range delegations { | ||
// add delegated tokens to total supply | ||
totalSupply = totalSupply.Add(sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)) | ||
} | ||
|
||
// add bonded amount to bonded pool module account | ||
balances = append(balances, banktypes.Balance{ | ||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(), | ||
Coins: sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, bondAmt)}, | ||
}) | ||
|
||
// update total supply | ||
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{}, []banktypes.SendEnabled{}) | ||
genesisState[banktypes.ModuleName] = codec.MustMarshalJSON(bankGenesis) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.