diff --git a/interchaintest/global/abci_utils_test.go b/interchaintest/global/abci_utils_test.go index bf2ddba0..ca7ed75c 100644 --- a/interchaintest/global/abci_utils_test.go +++ b/interchaintest/global/abci_utils_test.go @@ -7,7 +7,6 @@ import ( "cosmossdk.io/math" - "github.com/KYVENetwork/chain/app" i "github.com/KYVENetwork/chain/testutil/integration" sdk "github.com/cosmos/cosmos-sdk/types" sdktestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" @@ -28,7 +27,7 @@ const ( func encodingConfig() *sdktestutil.TestEncodingConfig { cfg := sdktestutil.TestEncodingConfig{} - a := app.Setup() + a := i.NewCleanChain().App() cfg.Codec = a.AppCodec() cfg.TxConfig = authtx.NewTxConfig(a.AppCodec(), authtx.DefaultSignModes) diff --git a/interchaintest/ibc/ibc_utils_test.go b/interchaintest/ibc/ibc_utils_test.go index 8f3ec29c..81ec80b5 100644 --- a/interchaintest/ibc/ibc_utils_test.go +++ b/interchaintest/ibc/ibc_utils_test.go @@ -4,9 +4,10 @@ import ( "encoding/json" "strconv" + i "github.com/KYVENetwork/chain/testutil/integration" + "cosmossdk.io/math" - "github.com/KYVENetwork/chain/app" sdk "github.com/cosmos/cosmos-sdk/types" sdktestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" @@ -24,7 +25,7 @@ const ( func encodingConfig() *sdktestutil.TestEncodingConfig { cfg := sdktestutil.TestEncodingConfig{} - a := app.Setup() + a := i.NewCleanChain().App() cfg.Codec = a.AppCodec() cfg.TxConfig = authtx.NewTxConfig(a.AppCodec(), authtx.DefaultSignModes) diff --git a/testutil/integration/integration.go b/testutil/integration/integration.go index 366fd8bc..4a35c2cd 100644 --- a/testutil/integration/integration.go +++ b/testutil/integration/integration.go @@ -2,22 +2,19 @@ package integration import ( mrand "math/rand" + "strconv" "time" + "github.com/cometbft/cometbft/proto/tendermint/types" + "cosmossdk.io/math" "github.com/KYVENetwork/chain/util" - "github.com/stretchr/testify/suite" - abci "github.com/cometbft/cometbft/abci/types" globalTypes "github.com/KYVENetwork/chain/x/global/types" "github.com/KYVENetwork/chain/app" - "github.com/cometbft/cometbft/crypto/tmhash" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - tmversion "github.com/cometbft/cometbft/proto/tendermint/version" - "github.com/cometbft/cometbft/version" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types" @@ -60,7 +57,7 @@ var ( ) const ( - KYVE = uint64(1_000_000_000) + KYVE = uint64(1_000_000) T_KYVE = int64(KYVE) ) @@ -104,44 +101,41 @@ func CCoins(amount int64) sdk.Coins { } func NewCleanChain() *KeeperTestSuite { - s := KeeperTestSuite{} - s.SetupTest(time.Now().Unix()) - s.initDummyAccounts() - return &s + return NewCleanChainAtTime(time.Now().Unix()) } func NewCleanChainAtTime(startTime int64) *KeeperTestSuite { s := KeeperTestSuite{} - s.SetupTest(startTime) + s.SetupApp(startTime) s.initDummyAccounts() return &s } func (suite *KeeperTestSuite) initDummyAccounts() { - _ = suite.MintCoins(ALICE, 1000*KYVE) - _ = suite.MintCoins(BOB, 1000*KYVE) - _ = suite.MintCoins(CHARLIE, 1000*KYVE) - _ = suite.MintCoins(DAVID, 1000*KYVE) - - _ = suite.MintCoins(STAKER_0, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_0_A, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_0_B, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_0_C, 1000*KYVE) - - _ = suite.MintCoins(STAKER_1, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_1_A, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_1_B, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_1_C, 1000*KYVE) - - _ = suite.MintCoins(STAKER_2, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_2_A, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_2_B, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_2_C, 1000*KYVE) - - _ = suite.MintCoins(STAKER_3, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_3_A, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_3_B, 1000*KYVE) - _ = suite.MintCoins(POOL_ADDRESS_3_C, 1000*KYVE) + _ = suite.MintBaseCoins(ALICE, 1000*KYVE) + _ = suite.MintBaseCoins(BOB, 1000*KYVE) + _ = suite.MintBaseCoins(CHARLIE, 1000*KYVE) + _ = suite.MintBaseCoins(DAVID, 1000*KYVE) + + _ = suite.MintBaseCoins(STAKER_0, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_0_A, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_0_B, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_0_C, 1000*KYVE) + + _ = suite.MintBaseCoins(STAKER_1, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_1_A, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_1_B, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_1_C, 1000*KYVE) + + _ = suite.MintBaseCoins(STAKER_2, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_2_A, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_2_B, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_2_C, 1000*KYVE) + + _ = suite.MintBaseCoins(STAKER_3, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_3_A, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_3_B, 1000*KYVE) + _ = suite.MintBaseCoins(POOL_ADDRESS_3_C, 1000*KYVE) DUMMY = make([]string, 50) @@ -153,7 +147,7 @@ func (suite *KeeperTestSuite) initDummyAccounts() { } dummy, _ := sdk.Bech32ifyAddressBytes("kyve", byteAddr) DUMMY[i] = dummy - _ = suite.MintCoins(dummy, 1000*KYVE) + _ = suite.MintBaseCoins(dummy, 1000*KYVE) } VALDUMMY = make([]string, 50) @@ -165,41 +159,22 @@ func (suite *KeeperTestSuite) initDummyAccounts() { } dummy, _ := sdk.Bech32ifyAddressBytes("kyve", byteAddr) VALDUMMY[i] = dummy - _ = suite.MintCoins(dummy, 1000*KYVE) + _ = suite.MintBaseCoins(dummy, 1000*KYVE) } } -func (suite *KeeperTestSuite) MintCoins(address string, amount uint64) error { - // mint coins ukyve, A, B, C - coins := sdk.NewCoins( +func (suite *KeeperTestSuite) MintBaseCoins(address string, amount uint64) error { + return suite.MintCoins(address, sdk.NewCoins( + // mint coins ukyve, A, B, C sdk.NewInt64Coin(KYVE_DENOM, int64(amount)), sdk.NewInt64Coin(A_DENOM, int64(amount)), sdk.NewInt64Coin(B_DENOM, int64(amount)), sdk.NewInt64Coin(C_DENOM, int64(amount)), - ) - err := suite.app.BankKeeper.MintCoins(suite.ctx, mintTypes.ModuleName, coins) - if err != nil { - return err - } - - suite.Commit() - - receiver, err := sdk.AccAddressFromBech32(address) - if err != nil { - return err - } - - err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, mintTypes.ModuleName, receiver, coins) - if err != nil { - return err - } - - return nil + )) } -func (suite *KeeperTestSuite) MintCoin(address string, coin sdk.Coin) error { +func (suite *KeeperTestSuite) MintCoins(address string, coins sdk.Coins) error { // mint coins ukyve, A, B, C - coins := sdk.NewCoins(coin) err := suite.app.BankKeeper.MintCoins(suite.ctx, mintTypes.ModuleName, coins) if err != nil { return err @@ -237,15 +212,6 @@ func (suite *KeeperTestSuite) MintDenomToModule(moduleAddress string, amount uin return nil } -type KeeperTestSuite struct { - suite.Suite - - ctx sdk.Context - - app *app.App - denom string -} - func (suite *KeeperTestSuite) App() *app.App { return suite.app } @@ -258,52 +224,37 @@ func (suite *KeeperTestSuite) SetCtx(ctx sdk.Context) { suite.ctx = ctx } -func (suite *KeeperTestSuite) SetupTest(startTime int64) { - suite.SetupApp(startTime) -} +type TestValidatorAddress struct { + Moniker string -func (suite *KeeperTestSuite) SetupApp(startTime int64) { - suite.app = app.Setup() + PrivateKey *ed25519.PrivKey - suite.denom = globalTypes.Denom + Address string + AccAddress sdk.AccAddress + ConsAccAddress sdk.ConsAddress + ConsAddress string - suite.ctx = suite.app.BaseApp.NewContextLegacy(false, tmproto.Header{ - Height: 1, - ChainID: "kyve-test", - Time: time.Unix(startTime, 0).UTC(), - ProposerAddress: sdk.ConsAddress(ed25519.GenPrivKeyFromSecret([]byte("Validator-1")).PubKey().Address()).Bytes(), + PoolAccount [10]string +} - Version: tmversion.Consensus{ - Block: version.BlockProtocol, - }, - LastBlockId: tmproto.BlockID{ - Hash: tmhash.Sum([]byte("block_id")), - PartSetHeader: tmproto.PartSetHeader{ - Total: 11, - Hash: tmhash.Sum([]byte("partset_header")), - }, - }, - AppHash: tmhash.Sum([]byte("app")), - DataHash: tmhash.Sum([]byte("data")), - EvidenceHash: tmhash.Sum([]byte("evidence")), - ValidatorsHash: tmhash.Sum([]byte("validators")), - NextValidatorsHash: tmhash.Sum([]byte("next_validators")), - ConsensusHash: tmhash.Sum([]byte("consensus")), - LastResultsHash: tmhash.Sum([]byte("last_result")), - }) +func (suite *KeeperTestSuite) CreateValidatorFromFullAddress(address TestValidatorAddress, kyveStake int64) { + valAddress := util.MustValaddressFromOperatorAddress(address.Address) - mintParams, _ := suite.app.MintKeeper.Params.Get(suite.ctx) - mintParams.MintDenom = suite.denom - _ = suite.app.MintKeeper.Params.Set(suite.ctx, mintParams) + msg, _ := stakingtypes.NewMsgCreateValidator( + valAddress, + address.PrivateKey.PubKey(), + sdk.NewInt64Coin(globalTypes.Denom, kyveStake), + stakingtypes.Description{Moniker: address.Moniker}, + stakingtypes.NewCommissionRates(math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("1"), math.LegacyMustNewDecFromStr("1")), + math.NewInt(1), + ) - stakingParams, _ := suite.app.StakingKeeper.GetParams(suite.ctx) - stakingParams.BondDenom = suite.denom - stakingParams.MaxValidators = 51 - _ = suite.app.StakingKeeper.SetParams(suite.ctx, stakingParams) + _, err := suite.RunTx(msg) + if err != nil { + panic(err) + } - govParams, _ := suite.app.GovKeeper.Params.Get(suite.ctx) - govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(KYVE_DENOM, int64(100_000_000_000))) // set min deposit to 100 KYVE - _ = suite.app.GovKeeper.Params.Set(suite.ctx, govParams) + suite.Commit() } func (suite *KeeperTestSuite) CreateValidatorWithoutCommit(address, moniker string, kyveStake int64) { @@ -322,8 +273,6 @@ func (suite *KeeperTestSuite) CreateValidatorWithoutCommit(address, moniker stri if err != nil { panic(err) } - - suite.Commit() } func (suite *KeeperTestSuite) SelfDelegateValidator(address string, amount uint64) { @@ -360,6 +309,25 @@ func (suite *KeeperTestSuite) SelfUndelegateValidator(address string, amount uin suite.Commit() } +func (suite *KeeperTestSuite) CreateNewValidator(moniker string, kyveStake uint64) TestValidatorAddress { + a := GenerateTestValidatorAddress(moniker) + _ = suite.MintBaseCoins(a.Address, 10*kyveStake) + msg, _ := stakingtypes.NewMsgCreateValidator( + util.MustValaddressFromOperatorAddress(a.Address), + a.PrivateKey.PubKey(), + sdk.NewInt64Coin(globalTypes.Denom, int64(kyveStake)), + stakingtypes.Description{Moniker: moniker}, + stakingtypes.NewCommissionRates(math.LegacyMustNewDecFromStr("0.1"), math.LegacyMustNewDecFromStr("1"), math.LegacyMustNewDecFromStr("1")), + math.NewInt(1), + ) + _, err := suite.RunTx(msg) + if err != nil { + panic(err) + } + suite.Commit() + return a +} + func (suite *KeeperTestSuite) CreateValidator(address, moniker string, kyveStake int64) { suite.CreateValidatorWithoutCommit(address, moniker, kyveStake) suite.Commit() @@ -380,6 +348,18 @@ func (suite *KeeperTestSuite) CreateZeroDelegationValidator(address, name string )) } +func (suite *KeeperTestSuite) SetDelegationToZero(address string) { + val, _ := sdk.ValAddressFromBech32(util.MustValaddressFromOperatorAddress(address)) + validator, _ := suite.App().StakingKeeper.GetValidator(suite.Ctx(), val) + validator.MinSelfDelegation = math.ZeroInt() + _ = suite.App().StakingKeeper.SetValidator(suite.Ctx(), validator) + suite.RunTxSuccess(stakingtypes.NewMsgUndelegate( + address, + util.MustValaddressFromOperatorAddress(address), + sdk.NewInt64Coin("tkyve", validator.BondedTokens().Int64()), + )) +} + func (suite *KeeperTestSuite) Commit() { suite.CommitAfter(time.Second * 0) } @@ -395,6 +375,10 @@ func (suite *KeeperTestSuite) CommitAfter(t time.Duration) { _, err := suite.app.FinalizeBlock(&abci.RequestFinalizeBlock{ Height: header.Height, Time: header.Time, + DecidedLastCommit: abci.CommitInfo{ + Round: 0, + Votes: suite.VoteInfos, + }, }) if err != nil { panic(err) @@ -419,3 +403,50 @@ func (suite *KeeperTestSuite) Wait(t time.Duration) { suite.ctx = suite.ctx.WithBlockTime(suite.ctx.BlockTime().Add(t)) } + +func GenerateTestValidatorAddress(moniker string) TestValidatorAddress { + a := TestValidatorAddress{} + a.Moniker = moniker + a.PrivateKey = ed25519.GenPrivKeyFromSecret([]byte(moniker)) + + a.AccAddress = sdk.AccAddress(a.PrivateKey.PubKey().Address()) + bech32Address, _ := sdk.Bech32ifyAddressBytes("kyve", a.AccAddress) + a.Address = bech32Address + + a.ConsAccAddress = sdk.ConsAddress(a.PrivateKey.PubKey().Address()) + bech32ConsAddress, _ := sdk.Bech32ifyAddressBytes("kyvevalcons", a.AccAddress) + a.ConsAddress = bech32ConsAddress + + for i := 0; i < 10; i++ { + poolAddress := ed25519.GenPrivKeyFromSecret([]byte("pool_address" + moniker + strconv.Itoa(i))).PubKey().Address() + address, _ := sdk.Bech32ifyAddressBytes("kyve", sdk.AccAddress(poolAddress)) + a.PoolAccount[i] = address + } + + return a +} + +func (suite *KeeperTestSuite) ResetAbciVotes() { + suite.VoteInfos = nil +} + +func (suite *KeeperTestSuite) AddAbciCommitVotes(addresses ...sdk.ConsAddress) { + suite.addAbciVotes(2, addresses...) +} + +func (suite *KeeperTestSuite) AddAbciAbsentVote(addresses ...sdk.ConsAddress) { + suite.addAbciVotes(1, addresses...) +} + +func (suite *KeeperTestSuite) addAbciVotes(blogFlagId int32, addresses ...sdk.ConsAddress) { + suite.VoteInfos = make([]abci.VoteInfo, 0) + for _, address := range addresses { + suite.VoteInfos = []abci.VoteInfo{{ + Validator: abci.Validator{ + Address: address, + Power: 1, + }, + BlockIdFlag: types.BlockIDFlag(blogFlagId), + }} + } +} diff --git a/app/test_helpers.go b/testutil/integration/setup.go similarity index 50% rename from app/test_helpers.go rename to testutil/integration/setup.go index c2f2c155..c6bbade2 100644 --- a/app/test_helpers.go +++ b/testutil/integration/setup.go @@ -1,35 +1,47 @@ -package app +package integration import ( "encoding/json" "time" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - + "cosmossdk.io/log" "cosmossdk.io/math" - "cosmossdk.io/log" + "github.com/KYVENetwork/chain/app" + globalTypes "github.com/KYVENetwork/chain/x/global/types" + teamTypes "github.com/KYVENetwork/chain/x/team/types" abci "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/crypto/tmhash" cmtProto "github.com/cometbft/cometbft/proto/tendermint/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + tmversion "github.com/cometbft/cometbft/proto/tendermint/version" cmtTypes "github.com/cometbft/cometbft/types" + "github.com/cometbft/cometbft/version" dbm "github.com/cosmos/cosmos-db" "github.com/cosmos/cosmos-sdk/baseapp" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" sdk "github.com/cosmos/cosmos-sdk/types" - - // Auth authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" - // Bank bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types" - // Global - globalTypes "github.com/KYVENetwork/chain/x/global/types" - // Staking + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" + mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types" + slashingTypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingTypes "github.com/cosmos/cosmos-sdk/x/staking/types" - // Team - teamTypes "github.com/KYVENetwork/chain/x/team/types" + "github.com/stretchr/testify/suite" ) +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + + app *app.App + denom string + privateValidatorKey *ed25519.PrivKey + VoteInfos []abci.VoteInfo +} + // DefaultConsensusParams ... var DefaultConsensusParams = &cmtProto.ConsensusParams{ Block: &cmtProto.BlockParams{ @@ -48,15 +60,77 @@ var DefaultConsensusParams = &cmtProto.ConsensusParams{ }, } -type EmptyAppOptions struct{} +func (suite *KeeperTestSuite) SetupApp(startTime int64) { + db := dbm.NewMemDB() -func (ao EmptyAppOptions) Get(_ string) interface{} { return nil } + config := sdk.GetConfig() + if config.GetBech32AccountAddrPrefix() != "kyve" || + config.GetBech32AccountPubPrefix() != "kyvepub" { + config.SetBech32PrefixForAccount("kyve", "kyve"+"pub") + config.SetBech32PrefixForValidator("kyve"+"valoper", "kyve"+"valoperpub") + config.SetBech32PrefixForConsensusNode("kyve"+"valcons", "kyve"+"valconspub") + config.Seal() + } + + logger := log.NewNopLogger() + localApp, err := app.New(logger, db, nil, true, EmptyAppOptions{}, baseapp.SetChainID("kyve-test")) + if err != nil { + panic(err) + } + suite.app = localApp + + suite.privateValidatorKey = ed25519.GenPrivKeyFromSecret([]byte("Validator-1")) + genesisState := DefaultGenesisWithValSet(suite.app, suite.privateValidatorKey) + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + if err != nil { + panic(err) + } + + // Initialize the chain + if _, err = suite.app.InitChain( + &abci.RequestInitChain{ + ChainId: "kyve-test", + Validators: []abci.ValidatorUpdate{}, + ConsensusParams: DefaultConsensusParams, + AppStateBytes: stateBytes, + }, + ); err != nil { + panic(err) + } -func DefaultGenesisWithValSet(app *App) map[string]json.RawMessage { + suite.denom = globalTypes.Denom + + suite.ctx = suite.app.BaseApp.NewContextLegacy(false, tmproto.Header{ + Height: 1, + ChainID: "kyve-test", + Time: time.Unix(startTime, 0).UTC(), + ProposerAddress: sdk.ConsAddress(suite.privateValidatorKey.PubKey().Address()).Bytes(), + + Version: tmversion.Consensus{ + Block: version.BlockProtocol, + }, + LastBlockId: tmproto.BlockID{ + Hash: tmhash.Sum([]byte("block_id")), + PartSetHeader: tmproto.PartSetHeader{ + Total: 11, + Hash: tmhash.Sum([]byte("partset_header")), + }, + }, + AppHash: tmhash.Sum([]byte("app")), + DataHash: tmhash.Sum([]byte("data")), + EvidenceHash: tmhash.Sum([]byte("evidence")), + ValidatorsHash: tmhash.Sum([]byte("validators")), + NextValidatorsHash: tmhash.Sum([]byte("next_validators")), + ConsensusHash: tmhash.Sum([]byte("consensus")), + LastResultsHash: tmhash.Sum([]byte("last_result")), + }) +} + +func DefaultGenesisWithValSet(app *app.App, validatorPrivateKey *ed25519.PrivKey) map[string]json.RawMessage { bondingDenom := globalTypes.Denom // Generate a new validator. - pubKey := ed25519.GenPrivKey().PubKey() + pubKey := validatorPrivateKey.PubKey() valAddress := sdk.ValAddress(pubKey.Address()).String() pkAny, _ := codectypes.NewAnyWithValue(pubKey) @@ -76,9 +150,8 @@ func DefaultGenesisWithValSet(app *App) map[string]json.RawMessage { }, } // Generate a new delegator. - delegatorKey := secp256k1.GenPrivKey() delegator := authTypes.NewBaseAccount( - delegatorKey.PubKey().Address().Bytes(), delegatorKey.PubKey(), 0, 0, + validatorPrivateKey.PubKey().Address().Bytes(), validatorPrivateKey.PubKey(), 0, 0, ) delegations := []stakingTypes.Delegation{ @@ -112,69 +185,42 @@ func DefaultGenesisWithValSet(app *App) map[string]json.RawMessage { // Update x/staking state. stakingParams := stakingTypes.DefaultParams() stakingParams.BondDenom = bondingDenom + stakingParams.MaxValidators = 51 stakingGenesis := stakingTypes.NewGenesisState(stakingParams, validators, delegations) genesisState[stakingTypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis) - // Return. - return genesisState -} - -// Setup initializes a new App. -func Setup() *App { - db := dbm.NewMemDB() - - setPrefixes(AccountAddressPrefix) - - // cw := zerolog.NewConsoleWriter() - // logger := log.NewCustomLogger(zerolog.New(cw).Level(zerolog.DebugLevel)) - logger := log.NewNopLogger() - app, err := New(logger, db, nil, true, EmptyAppOptions{}, baseapp.SetChainID("kyve-test")) - if err != nil { - panic(err) - } - - genesisState := DefaultGenesisWithValSet(app) - stateBytes, err := json.MarshalIndent(genesisState, "", " ") - if err != nil { - panic(err) - } - - // Initialize the chain - _, err = app.InitChain( - &abci.RequestInitChain{ - ChainId: "kyve-test", - Validators: []abci.ValidatorUpdate{}, - ConsensusParams: DefaultConsensusParams, - AppStateBytes: stateBytes, + mintParams := mintTypes.DefaultParams() + mintParams.MintDenom = bondingDenom + mintGenesis := mintTypes.NewGenesisState(mintTypes.DefaultInitialMinter(), mintParams) + genesisState[mintTypes.ModuleName] = app.AppCodec().MustMarshalJSON(mintGenesis) + + govParams := govTypes.DefaultParams() + govParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(KYVE_DENOM, int64(100*KYVE))) + govGenesis := govTypes.NewGenesisState(1, govParams) + genesisState["gov"] = app.AppCodec().MustMarshalJSON(govGenesis) + + slashingParams := slashingTypes.DefaultParams() + slashingParams.SignedBlocksWindow = 1_000_000 + // Allow always being offline + slashingParams.MinSignedPerWindow = math.LegacyMustNewDecFromStr("0.1") + slashingInfo := []slashingTypes.SigningInfo{{ + Address: sdk.MustBech32ifyAddressBytes("kyvevalcons", validatorPrivateKey.PubKey().Address()), + ValidatorSigningInfo: slashingTypes.ValidatorSigningInfo{ + Address: sdk.MustBech32ifyAddressBytes("kyvevalcons", validatorPrivateKey.PubKey().Address()), + StartHeight: 0, + IndexOffset: 0, + JailedUntil: time.Time{}, + Tombstoned: false, + MissedBlocksCounter: 0, }, - ) - if err != nil { - panic(err) - } + }} + slashingGenesis := slashingTypes.NewGenesisState(slashingParams, slashingInfo, nil) + genesisState["slashing"] = app.AppCodec().MustMarshalJSON(slashingGenesis) - return app + return genesisState } -func setPrefixes(accountAddressPrefix string) { - // Set prefixes - accountPubKeyPrefix := accountAddressPrefix + "pub" - validatorAddressPrefix := accountAddressPrefix + "valoper" - validatorPubKeyPrefix := accountAddressPrefix + "valoperpub" - consNodeAddressPrefix := accountAddressPrefix + "valcons" - consNodePubKeyPrefix := accountAddressPrefix + "valconspub" - - config := sdk.GetConfig() - - // Return if prefixes are already set - if config.GetBech32AccountAddrPrefix() == accountAddressPrefix && - config.GetBech32AccountPubPrefix() == accountPubKeyPrefix { - return - } +type EmptyAppOptions struct{} - // Set and seal config - config.SetBech32PrefixForAccount(accountAddressPrefix, accountPubKeyPrefix) - config.SetBech32PrefixForValidator(validatorAddressPrefix, validatorPubKeyPrefix) - config.SetBech32PrefixForConsensusNode(consNodeAddressPrefix, consNodePubKeyPrefix) - config.Seal() -} +func (ao EmptyAppOptions) Get(_ string) interface{} { return nil } diff --git a/testutil/integration/transactions.go b/testutil/integration/transactions.go index cf09b998..5315fabd 100644 --- a/testutil/integration/transactions.go +++ b/testutil/integration/transactions.go @@ -48,11 +48,6 @@ func (suite *KeeperTestSuite) RunTxPoolSuccess(msg sdk.Msg) { Expect(err).NotTo(HaveOccurred()) } -func (suite *KeeperTestSuite) RunTxPoolError(msg sdk.Msg) { - _, err := suite.RunTx(msg) - Expect(err).To(HaveOccurred()) -} - func (suite *KeeperTestSuite) RunTxStakersSuccess(msg sdk.Msg) { _, err := suite.RunTx(msg) Expect(err).NotTo(HaveOccurred()) @@ -63,16 +58,6 @@ func (suite *KeeperTestSuite) RunTxStakersError(msg sdk.Msg) { Expect(err).To(HaveOccurred()) } -func (suite *KeeperTestSuite) RunTxDelegatorSuccess(msg sdk.Msg) { - _, err := suite.RunTx(msg) - Expect(err).NotTo(HaveOccurred()) -} - -func (suite *KeeperTestSuite) RunTxDelegatorError(msg sdk.Msg) { - _, err := suite.RunTx(msg) - Expect(err).To(HaveOccurred()) -} - func (suite *KeeperTestSuite) RunTxBundlesSuccess(msg sdk.Msg) { _, err := suite.RunTx(msg) Expect(err).NotTo(HaveOccurred()) diff --git a/testutil/nullify/nullify.go b/testutil/nullify/nullify.go deleted file mode 100644 index 3b968c09..00000000 --- a/testutil/nullify/nullify.go +++ /dev/null @@ -1,57 +0,0 @@ -// Package nullify provides methods to init nil values structs for test assertion. -package nullify - -import ( - "reflect" - "unsafe" - - sdk "github.com/cosmos/cosmos-sdk/types" -) - -var ( - coinType = reflect.TypeOf(sdk.Coin{}) - coinsType = reflect.TypeOf(sdk.Coins{}) -) - -// Fill analyze all struct fields and slices with -// reflection and initialize the nil and empty slices, -// structs, and pointers. -func Fill(x interface{}) interface{} { - v := reflect.Indirect(reflect.ValueOf(x)) - switch v.Kind() { - case reflect.Slice: - for i := 0; i < v.Len(); i++ { - obj := v.Index(i) - objPt := reflect.NewAt(obj.Type(), unsafe.Pointer(obj.UnsafeAddr())).Interface() - objPt = Fill(objPt) - obj.Set(reflect.ValueOf(objPt)) - } - case reflect.Struct: - for i := 0; i < v.NumField(); i++ { - f := reflect.Indirect(v.Field(i)) - if !f.CanSet() { - continue - } - switch f.Kind() { - case reflect.Slice: - f.Set(reflect.MakeSlice(f.Type(), 0, 0)) - case reflect.Struct: - switch f.Type() { - case coinType: - coin := reflect.New(coinType).Interface() - s := reflect.ValueOf(coin).Elem() - f.Set(s) - case coinsType: - coins := reflect.New(coinsType).Interface() - s := reflect.ValueOf(coins).Elem() - f.Set(s) - default: - objPt := reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Interface() - s := Fill(objPt) - f.Set(reflect.ValueOf(s)) - } - } - } - } - return reflect.Indirect(v).Interface() -} diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go deleted file mode 100644 index 98f2153e..00000000 --- a/testutil/sample/sample.go +++ /dev/null @@ -1,13 +0,0 @@ -package sample - -import ( - "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// AccAddress returns a sample account address -func AccAddress() string { - pk := ed25519.GenPrivKey().PubKey() - addr := pk.Address() - return sdk.AccAddress(addr).String() -} diff --git a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go index 7a6e8d95..5df7d785 100644 --- a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go +++ b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go @@ -320,13 +320,13 @@ var _ = Describe("inflation splitting", Ordered, func() { // assert commission rewards (here we round down since the result of commission rewards gets truncated) // (total_bundle_payout - treasury_reward - storage_cost) * (1 - commission) // storage_cost = byte_size * usd_per_byte / len(coins) * coin_weight - // (2471669 - (2471669 * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(244_740).String())) + // (2470 - (2470 * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(289).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) // (total_bundle_payout - treasury_reward - storage_cost) * commission + storage_cost // storage_cost = byte_size * usd_per_byte / len(coins) * coin_weight - // (2471669 - (2471669 * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(2_202_215).String())) + // (2470 - (2470 * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(2157).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -399,20 +399,20 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 49433483tkyve + // inflation payout is 49440tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (49433483 - (49433483 * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + // (49440 - (49440 * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ // Due to cosmos rounding, the result is a little off. - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(4_893_963).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(4_939).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (49433483 - (49433483 * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + // (49440 - (49440 * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) // Due to cosmos rounding, the result is a little off. - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(44_045_220).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(44_007).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -603,18 +603,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7415009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (7_415_009 + 10_000 - ((7_415_009 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(735_121).String())) + // (7410 + 10_000 - ((7410 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(1768).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (7_415_009 + 10_000 - ((7_415_009 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6_615_642).String())) + // (7410 + 10_000 - ((7410 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(15_468).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -701,17 +701,17 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (2_471_6741 + 10_000 - ((2_471_6741 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2_447_994).String())) + // (24720 + 10_000 - ((24720 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(3482).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (2_471_6741 + 10_000 - ((2_471_6741 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_031_498).String())) + // (24720 + 10_000 - ((24720 + 10_000) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(30891).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -901,18 +901,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7_415_009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (7_415_009 + 300 - ((7_415_009 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(734_161).String())) + // (7410 + 300 - ((7410 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(808).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (7_415_009 + 300 - ((7_415_009 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6_606_999).String())) + // (7410 + 300 - ((7410 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6825).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -999,18 +999,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (24_716_741 + 300 - ((24_716_741 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2_447_033).String())) + // (24720 + 300 - ((24720 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2522).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (24_716_741 + 300 - ((24_716_741 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_022_856).String())) + // (24720 + 300 - ((24720 + 300) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_248).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1200,18 +1200,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7415009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (7_415_009 + 5_000 + 200 - ((7_415_009 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(734_646).String())) + // (7410 + 5_000 + 200 - ((7410 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(1293).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (7_415_009 + 5_000 + 200 - ((7_415_009 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(6_611_365).String())) + // (7410 + 5_000 + 200 - ((7410 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(11_191).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1298,18 +1298,18 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // (24_716_741 + 5_000 + 200 - ((24_716_741 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(2_447_519).String())) + // (24720 + 5_000 + 200 - ((24720 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * 0.1 + _((100 * 0.5) / (1 * 1))_ + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(i.KYVECoins(3007).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // (24_716_741 + 5_000 + 200 - ((24_716_741 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(22_027_221).String())) + // (24720 + 5_000 + 200 - ((24720 + 5_000 + 200) * 0.01) - _((100 * 0.5) / (1 * 1))_) * (1 - 0.1) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(i.KYVECoins(26_614).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1500,22 +1500,22 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 7415009tkyve + // inflation payout is 7410tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // for kyve coin (7_415_009 - (7_415_009 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ + // for kyve coin (7410 - (7410 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for bcoin coins (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * 0.1 + _((100 * 0.5) / (3 * 2))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(734_100), i.ACoin(1004), i.BCoin(1987)).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(748), i.ACoin(1004), i.BCoin(1987)).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // for kyve coin (7_415_009 - (7_415_009 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) + // for kyve coin (7410 - (7410 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for bcoin (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(6_606_763), i.ACoin(8896), i.BCoin(17813)).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(6588), i.ACoin(8896), i.BCoin(17813)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1610,22 +1610,22 @@ var _ = Describe("inflation splitting", Ordered, func() { b2 := s.GetBalanceFromPool(0) Expect(b1).To(BeNumerically(">", b2)) - // inflation payout is 24716741tkyve + // inflation payout is 24720tkyve payout := uint64(math.LegacyNewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) Expect(b1 - b2).To(Equal(payout)) // assert bundle reward // assert commission rewards (here we round down since the result of commission rewards gets truncated) - // for kyve coin (24_716_741 - (24_716_741 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ + // for kyve coin (24720 - (24720 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * 0.1 + _((100 * 0.5) / (3 * 1))_ // for bcoin coins (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * 0.1 + _((100 * 0.5) / (3 * 2))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(2_446_973), i.ACoin(1004), i.BCoin(1987)).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(2461), i.ACoin(1004), i.BCoin(1987)).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) - // for kyve coin (24_716_741 - (24_716_741 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) + // for kyve coin (24720 - (24720 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for acoin (10_000 - (10_000 * 0.01) - _((100 * 0.5) / (3 * 1))_) * (1 - 0.1) // for bcoin (20_000 - (20_000 * 0.01) - _((100 * 0.5) / (3 * 2))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(22_022_619), i.ACoin(8896), i.BCoin(17813)).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(22012), i.ACoin(8896), i.BCoin(17813)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1828,10 +1828,10 @@ var _ = Describe("inflation splitting", Ordered, func() { inflationAmount := postMineBalance.Sub(preMineBalance) // Reward calculation: // (inflationAmount - teamRewards) * protocolInflationShare -> Both pools equally - // (340112587966tkyve - 847940tkyve) * 0.1 -> rewards for both pools, but it is split according to the different weights + // (340112417tkyve - 800tkyve) * 0.1 -> rewards for both pools, but it is split according to the different weights // teamAuthority rewards are hard to set to zero from this test-suite without using reflection. // therefore we ignore the small amount. - Expect(inflationAmount.String()).To(Equal("340112587966tkyve")) + Expect(inflationAmount.String()).To(Equal("340112417tkyve")) // assert if bundle go finalized pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -1844,21 +1844,21 @@ var _ = Describe("inflation splitting", Ordered, func() { // First pool has weight: 0.1, second pool has weight 1 // additionally, pool-0 produced a bundle -> subtract PoolInflationPayoutRate (1 - 0.1 = 0.9) // formula: (inflation - teamRewards) * inflationShare * inflationShareWeighOfPool * (1-PoolInflationPayoutRate) - // (340112587966 - 847940) * 0.1 * 1 / 11 * 0.9 - // Evaluates to 2782732418, however due to multiple roundings to actual amount is 2782732144 + // (340112417 - 800) * 0.1 * 1 / 11 * 0.9 + // Evaluates to 2782731, however due to multiple roundings to actual amount is 2782690 // second pool - // (340112587966 - 847940) * 0.1 * 10 / 11 - // Evaluates to 30919249093 - Expect(finalBalancePool0).To(Equal(uint64(2782732144))) - Expect(finalBalancePool1).To(Equal(uint64(30919246548))) + // (340112417 - 800) * 0.1 * 10 / 11 + // Evaluates to 30919237 + Expect(finalBalancePool0).To(Equal(uint64(2782690))) + Expect(finalBalancePool1).To(Equal(uint64(30919140))) // assert bundle reward // the total payout is here just the inflation payout // (inflation - teamRewards)*inflationShare - balancePool0 - balancePool1 - // (340112344399 - 847940) * 0.1 * 1 / 11 * 0.1 - // evaluates to 309192269, due to multiple rounding (and : 309192460 - totalPayout := math.LegacyNewDec(309192460) + // (340112417 - 800) * 0.1 * 1 / 11 * 0.1 + // evaluates to 309192 + totalPayout := math.LegacyNewDec(309192) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := totalPayout.Mul(networkFee).TruncateDec() @@ -1871,9 +1871,9 @@ var _ = Describe("inflation splitting", Ordered, func() { // assert commission rewards // Due to rounding in the cosmos Allocate tokens the amount is off by one. (This does not affect the total rewards // only the commission-rewards distribution) - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).AmountOf(globalTypes.Denom).String()).To(Equal(uploaderPayoutReward.Add(storageReward).RoundInt().String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).AmountOf(globalTypes.Denom).String()).To(Equal(uploaderPayoutReward.Add(storageReward).RoundInt().SubRaw(1).String())) // assert uploader self delegation rewards - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).ToLegacyDec().String()).To(Equal(uploaderDelegationReward.String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).ToLegacyDec().String()).To(Equal(uploaderDelegationReward.Sub(math.LegacyNewDec(4)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1990,10 +1990,10 @@ var _ = Describe("inflation splitting", Ordered, func() { inflationAmount := postMineBalance.Sub(preMineBalance) // Reward calculation: // (inflationAmount - teamRewards) * protocolInflationShare -> Both pools equally - // (340112587966tkyve - 847940tkyve) * 0.1 -> (//2) -> 17005574822 for both pools + // (340112417tkyve - 800tkyve) * 0.1 -> (//2) -> 17005580 for both pools // teamAuthority rewards are hard to set to zero from this test-suite without using reflection. // therefore we ignore the small amount. - Expect(inflationAmount.String()).To(Equal("340112587966tkyve")) + Expect(inflationAmount.String()).To(Equal("340112417tkyve")) // assert if bundle go finalized pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -2005,14 +2005,14 @@ var _ = Describe("inflation splitting", Ordered, func() { finalBalancePool1 := s.GetBalanceFromPool(1) // Both pools have inflation-weight 1 // however, pool-0 produced a bundle -> subtract PoolInflationPayoutRate (1 - 0.2 = 0.8) - // 17005574822 * 0.8 - Expect(finalBalancePool0).To(Equal(uint64(13604468481))) - Expect(finalBalancePool1).To(Equal(uint64(17005585601))) + // 17005534 * 0.8 + Expect(finalBalancePool0).To(Equal(uint64(13604428))) + Expect(finalBalancePool1).To(Equal(uint64(17005534))) // assert bundle reward // the total payout is here just the inflation payout - totalPayout := math.LegacyNewDec(17005585601 - 13604468481) + totalPayout := math.LegacyNewDec(17005534 - 13604428) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) treasuryReward := totalPayout.Mul(networkFee).TruncateDec() diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index c5870acd..2240d779 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -1796,10 +1796,10 @@ var _ = Describe("valid bundles", Ordered, func() { s.App().FundersKeeper.SetParams(s.Ctx(), fundersTypes.NewParams([]*fundersTypes.WhitelistCoinEntry{ { CoinDenom: globalTypes.Denom, - CoinDecimals: 9, - MinFundingAmount: math.NewIntFromUint64(100_000_000_000), // 100 $KYVE - MinFundingAmountPerBundle: math.NewInt(100_000_000), // 0.1 $KYVE - CoinWeight: math.LegacyMustNewDecFromStr("0.055"), // 0.055 $USD + CoinDecimals: 6, + MinFundingAmount: math.NewIntFromUint64(100_000_000), // 100 $KYVE + MinFundingAmountPerBundle: math.NewInt(100_000), // 0.1 $KYVE + CoinWeight: math.LegacyMustNewDecFromStr("0.055"), // 0.055 $USD }, { CoinDenom: i.A_DENOM, @@ -1825,7 +1825,7 @@ var _ = Describe("valid bundles", Ordered, func() { }, 0)) // mint another 1,000 $ARCH to Alice - err := s.MintCoin(i.ALICE, sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("1000000000000000000000"))) + err := s.MintCoins(i.ALICE, sdk.NewCoins(sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("1000000000000000000000")))) _ = err // defund everything so we have a clean state @@ -1837,8 +1837,8 @@ var _ = Describe("valid bundles", Ordered, func() { // fund with every coin 100 units for amount and 1 for amount per bundle s.RunTxPoolSuccess(&fundersTypes.MsgFundPool{ Creator: i.ALICE, - Amounts: sdk.NewCoins(i.KYVECoin(100_000_000_000), i.ACoin(100_000_000), sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("100000000000000000000")), i.CCoin(100_000_000)), - AmountsPerBundle: sdk.NewCoins(i.KYVECoin(1_000_000_000), i.ACoin(1_000_000), sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("1000000000000000000")), i.CCoin(1_000_000)), + Amounts: sdk.NewCoins(i.KYVECoin(100_000_000), i.ACoin(100_000_000), sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("100000000000000000000")), i.CCoin(100_000_000)), + AmountsPerBundle: sdk.NewCoins(i.KYVECoin(1_000_000), i.ACoin(1_000_000), sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("1000000000000000000")), i.CCoin(1_000_000)), }) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ @@ -1957,10 +1957,10 @@ var _ = Describe("valid bundles", Ordered, func() { // (amount_per_bundle - treasury_reward - storage_cost) * uploader_commission + storage_cost // storage_cost = 1MB * storage_price / coin_length * coin_price // (amount_per_bundle - (amount_per_bundle * 0.01) - _((1048576 * 0.000000006288 * 10**coin_decimals) / (4 * coin_weight))_) * 0.1 + _((1048576 * 0.000000006288) / (4 * coin_weight))_ - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), poolAccountUploader.Staker).String()).To(Equal(sdk.NewCoins(i.KYVECoin(125_973_187), i.ACoin(99_143), i.BCoin(116_661_015_771_428_571), i.CCoin(100_765)).String())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), poolAccountUploader.Staker).String()).To(Equal(sdk.NewCoins(i.KYVECoin(125_973), i.ACoin(99_143), i.BCoin(116_661_015_771_428_571), i.CCoin(100_765)).String())) // assert uploader self delegation rewards (here we round up since the result of delegation rewards is the remainder minus the truncated commission rewards) // (amount_per_bundle - (amount_per_bundle * 0.01) - _((29970208 * 0.000000006288 * 1**coin_decimals) / (4 * coin_weight))_) * (1 - 0.1) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(864_026_813), i.ACoin(890_857), i.BCoin(873_338_984_228_571_429), i.CCoin(889_235)).String())) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).String()).To(Equal(sdk.NewCoins(i.KYVECoin(864_027), i.ACoin(890_857), i.BCoin(873_338_984_228_571_429), i.CCoin(889_235)).String())) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1971,7 +1971,7 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(c2.Sub(c1...).AmountOf(i.C_DENOM)).To(Equal(math.NewInt(10000))) // assert total pool funds - Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId).String()).To(Equal(sdk.NewCoins(i.KYVECoin(99_000_000_000), i.ACoin(99_000_000), sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("99000000000000000000")), i.CCoin(99_000_000)).String())) + Expect(s.App().FundersKeeper.GetTotalActiveFunding(s.Ctx(), fundingState.PoolId).String()).To(Equal(sdk.NewCoins(i.KYVECoin(99_000_000), i.ACoin(99_000_000), sdk.NewCoin(i.B_DENOM, s.MustNewIntFromStr("99000000000000000000")), i.CCoin(99_000_000)).String())) Expect(fundingState.ActiveFunderAddresses).To(HaveLen(1)) }) }) diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index 70714bc1..ec2ee747 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -296,11 +296,15 @@ var _ = Describe("zero delegation", Ordered, func() { It("Staker submit bundle proposal with zero delegation", func() { // ARRANGE + // create zero delegation validator - s.CreateZeroDelegationValidator(i.STAKER_0, "Staker-0") + staker0 := s.CreateNewValidator("Staker-0", 100*i.KYVE) + + validators, _ := s.App().StakingKeeper.GetValidators(s.Ctx(), 20) + _ = validators s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_0, + Creator: staker0.Address, PoolId: 0, PoolAddress: i.POOL_ADDRESS_0_A, Commission: math.LegacyMustNewDecFromStr("0.1"), @@ -308,10 +312,10 @@ var _ = Describe("zero delegation", Ordered, func() { }) // create normal validator - s.CreateValidator(i.STAKER_1, "Staker-1", int64(100*i.KYVE)) + staker1 := s.CreateNewValidator("Staker-1", 100*i.KYVE) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: staker1.Address, PoolId: 0, PoolAddress: i.POOL_ADDRESS_1_A, Commission: math.LegacyMustNewDecFromStr("0.1"), @@ -319,10 +323,10 @@ var _ = Describe("zero delegation", Ordered, func() { }) // create normal validator - s.CreateValidator(i.STAKER_2, "Staker-2", int64(100*i.KYVE)) + staker2 := s.CreateNewValidator("Staker-2", 100*i.KYVE) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_2, + Creator: staker2.Address, PoolId: 0, PoolAddress: i.POOL_ADDRESS_2_A, Commission: math.LegacyMustNewDecFromStr("0.1"), @@ -331,14 +335,14 @@ var _ = Describe("zero delegation", Ordered, func() { // manually set next uploader bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - bundleProposal.NextUploader = i.STAKER_0 + bundleProposal.NextUploader = staker0.Address s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ Creator: i.POOL_ADDRESS_0_A, - Staker: i.STAKER_0, + Staker: staker0.Address, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", DataSize: 100, @@ -352,7 +356,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ Creator: i.POOL_ADDRESS_1_A, - Staker: i.STAKER_1, + Staker: staker1.Address, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_VALID, @@ -360,7 +364,7 @@ var _ = Describe("zero delegation", Ordered, func() { s.RunTxBundlesSuccess(&bundletypes.MsgVoteBundleProposal{ Creator: i.POOL_ADDRESS_2_A, - Staker: i.STAKER_2, + Staker: staker2.Address, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", Vote: bundletypes.VOTE_TYPE_VALID, @@ -368,16 +372,17 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) - initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) + initialBalanceStaker0 = s.GetBalanceFromAddress(staker0.Address) initialBalancePoolAddress0 = s.GetBalanceFromAddress(i.POOL_ADDRESS_0_A) - initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) + initialBalanceStaker1 = s.GetBalanceFromAddress(staker1.Address) initialBalancePoolAddress1 = s.GetBalanceFromAddress(i.POOL_ADDRESS_1_A) + s.SetDelegationToZero(staker0.Address) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ Creator: i.POOL_ADDRESS_1_A, - Staker: i.STAKER_1, + Staker: staker1.Address, PoolId: 0, StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", DataSize: 100, @@ -405,7 +410,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(finalizedBundle.PoolId).To(Equal(uint64(0))) Expect(finalizedBundle.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(finalizedBundle.Uploader).To(Equal(i.STAKER_0)) + Expect(finalizedBundle.Uploader).To(Equal(staker0.Address)) Expect(finalizedBundle.FromIndex).To(Equal(uint64(0))) Expect(finalizedBundle.ToIndex).To(Equal(uint64(100))) Expect(finalizedBundle.FromKey).To(Equal("0")) @@ -420,8 +425,8 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(bundleProposal.PoolId).To(Equal(uint64(0))) Expect(bundleProposal.StorageId).To(Equal("P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_1)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_1)) + Expect(bundleProposal.Uploader).To(Equal(staker1.Address)) + Expect(bundleProposal.NextUploader).To(Equal(staker1.Address)) Expect(bundleProposal.DataSize).To(Equal(uint64(100))) Expect(bundleProposal.DataHash).To(Equal("test_hash2")) Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) @@ -429,12 +434,12 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(bundleProposal.ToKey).To(Equal("199")) Expect(bundleProposal.BundleSummary).To(Equal("test_value2")) Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_1)) + Expect(bundleProposal.VotersValid).To(ContainElement(staker1.Address)) Expect(bundleProposal.VotersInvalid).To(BeEmpty()) Expect(bundleProposal.VotersAbstain).To(BeEmpty()) // check uploader status - poolAccountUploader, _ := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), i.STAKER_0, 0) + poolAccountUploader, _ := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), staker0.Address, 0) Expect(poolAccountUploader.Points).To(BeZero()) balanceUploaderValaddress := s.GetBalanceFromAddress(poolAccountUploader.PoolAddress) @@ -443,7 +448,7 @@ var _ = Describe("zero delegation", Ordered, func() { balanceUploader := s.GetBalanceFromAddress(poolAccountUploader.Staker) // check voter status - poolAccountVoter, _ := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), i.STAKER_1, 0) + poolAccountVoter, _ := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), staker1.Address, 0) Expect(poolAccountVoter.Points).To(BeZero()) balanceVoterPoolAddress := s.GetBalanceFromAddress(poolAccountVoter.PoolAddress) @@ -461,9 +466,9 @@ var _ = Describe("zero delegation", Ordered, func() { // assert payout transfer Expect(balanceUploader).To(Equal(initialBalanceStaker0)) // assert commission rewards - Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), i.STAKER_0).AmountOf(globaltypes.Denom).Int64()).To(Equal(totalUploaderReward.Add(storageReward).TruncateInt64())) + Expect(s.App().StakersKeeper.GetOutstandingCommissionRewards(s.Ctx(), staker0.Address).AmountOf(globaltypes.Denom).Int64()).To(Equal(totalUploaderReward.Add(storageReward).TruncateInt64())) // assert uploader self delegation rewards - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), staker0.Address, staker0.Address)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -475,12 +480,12 @@ var _ = Describe("zero delegation", Ordered, func() { It("Staker receives upload slash with zero delegation", func() { // ARRANGE // create zero delegation validator - s.CreateZeroDelegationValidator(i.STAKER_0, "Staker-0") + staker0 := s.CreateNewValidator("Staker-0", 1*i.KYVE) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_0, + Creator: staker0.Address, PoolId: 0, - PoolAddress: i.POOL_ADDRESS_0_A, + PoolAddress: staker0.PoolAccount[0], Commission: math.LegacyMustNewDecFromStr("0.1"), StakeFraction: math.LegacyMustNewDecFromStr("1"), }) @@ -509,14 +514,14 @@ var _ = Describe("zero delegation", Ordered, func() { // manually set next uploader bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - bundleProposal.NextUploader = i.STAKER_0 + bundleProposal.NextUploader = staker0.Address s.App().BundlesKeeper.SetBundleProposal(s.Ctx(), bundleProposal) s.CommitAfterSeconds(60) s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.POOL_ADDRESS_0_A, - Staker: i.STAKER_0, + Creator: staker0.PoolAccount[0], + Staker: staker0.Address, PoolId: 0, StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", DataSize: 100, @@ -546,12 +551,13 @@ var _ = Describe("zero delegation", Ordered, func() { s.CommitAfterSeconds(60) - initialBalanceStaker0 = s.GetBalanceFromAddress(i.STAKER_0) - initialBalancePoolAddress0 = s.GetBalanceFromAddress(i.POOL_ADDRESS_0_A) + initialBalanceStaker0 = s.GetBalanceFromAddress(staker0.Address) + initialBalancePoolAddress0 = s.GetBalanceFromAddress(staker0.PoolAccount[0]) initialBalanceStaker1 = s.GetBalanceFromAddress(i.STAKER_1) initialBalancePoolAddress1 = s.GetBalanceFromAddress(i.POOL_ADDRESS_1_A) + s.SetDelegationToZero(staker0.Address) // ACT s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ Creator: i.POOL_ADDRESS_1_A, @@ -601,24 +607,24 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(bundleProposal.VotersAbstain).To(BeEmpty()) // check uploader status - _, uploaderActive := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), i.STAKER_0, 0) + _, uploaderActive := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), staker0.Address, 0) Expect(uploaderActive).To(BeFalse()) - balancePoolAddress := s.GetBalanceFromAddress(i.POOL_ADDRESS_0_A) + balancePoolAddress := s.GetBalanceFromAddress(staker0.PoolAccount[0]) Expect(balancePoolAddress).To(Equal(initialBalancePoolAddress0)) - balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) - _, uploaderFound := s.App().StakersKeeper.GetValidator(s.Ctx(), i.STAKER_0) + balanceUploader := s.GetBalanceFromAddress(staker0.Address) + _, uploaderFound := s.App().StakersKeeper.GetValidator(s.Ctx(), staker0.Address) Expect(uploaderFound).To(BeTrue()) Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) + Expect(s.App().StakersKeeper.GetOutstandingRewards(s.Ctx(), staker0.Address, staker0.Address)).To(BeEmpty()) // calculate uploader slashes fraction := s.App().StakersKeeper.GetUploadSlash(s.Ctx()) slashAmount := uint64(math.LegacyNewDec(int64(0 * i.KYVE)).Mul(fraction).TruncateInt64()) - Expect(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(0*i.KYVE - slashAmount)) + Expect(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), staker0.Address, staker0.Address)).To(Equal(0*i.KYVE - slashAmount)) Expect(s.App().StakersKeeper.GetTotalStakeOfPool(s.Ctx(), 0)).To(Equal(200*i.KYVE - slashAmount)) // check voter status @@ -654,10 +660,10 @@ var _ = Describe("zero delegation", Ordered, func() { }) // create zero delegation validator - s.CreateZeroDelegationValidator(i.STAKER_1, "Staker-1") + staker1 := s.CreateNewValidator("Staker-1", 100*i.KYVE) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: staker1.Address, PoolId: 0, PoolAddress: i.POOL_ADDRESS_1_A, Commission: math.LegacyMustNewDecFromStr("0.1"), @@ -705,6 +711,7 @@ var _ = Describe("zero delegation", Ordered, func() { }) s.CommitAfterSeconds(60) + s.SetDelegationToZero(staker1.Address) // ACT maxPoints := int(s.App().BundlesKeeper.GetMaxPoints(s.Ctx())) @@ -746,17 +753,17 @@ var _ = Describe("zero delegation", Ordered, func() { poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) Expect(poolStakers).To(HaveLen(2)) - _, stakerFound := s.App().StakersKeeper.GetValidator(s.Ctx(), i.STAKER_1) + _, stakerFound := s.App().StakersKeeper.GetValidator(s.Ctx(), staker1.Address) Expect(stakerFound).To(BeTrue()) - _, poolAccountActive := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), i.STAKER_1, 0) + _, poolAccountActive := s.App().StakersKeeper.GetPoolAccount(s.Ctx(), staker1.Address, 0) Expect(poolAccountActive).To(BeFalse()) // check if voter got slashed slashAmountRatio := s.App().StakersKeeper.GetTimeoutSlash(s.Ctx()) expectedBalance := 0*i.KYVE - uint64(math.LegacyNewDec(int64(0*i.KYVE)).Mul(slashAmountRatio).TruncateInt64()) - Expect(expectedBalance).To(Equal(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), i.STAKER_1, i.STAKER_1))) + Expect(expectedBalance).To(Equal(s.App().StakersKeeper.GetDelegationAmountOfDelegator(s.Ctx(), staker1.Address, staker1.Address))) }) It("Stakers try to produce valid bundle but all stakers have zero delegation", func() { diff --git a/x/bundles/keeper/logic_round_robin_test.go b/x/bundles/keeper/logic_round_robin_test.go index 470661fa..4584d92e 100644 --- a/x/bundles/keeper/logic_round_robin_test.go +++ b/x/bundles/keeper/logic_round_robin_test.go @@ -464,7 +464,7 @@ var _ = Describe("logic_round_robin.go", Ordered, func() { // ACT joinDummy(s, 3, 400) rrvs = s.App().BundlesKeeper.LoadRoundRobinValidatorSet(s.Ctx(), 0) - shift := int64(1125_000_000_000 / 4) + shift := int64(1125_000_000 / 4) // Assert Expect(rrvs.Progress[i.DUMMY[0]]).To(Equal(100*int64(i.KYVE) + shift)) diff --git a/x/funders/types/params.go b/x/funders/types/params.go index f998c086..9f5721a4 100644 --- a/x/funders/types/params.go +++ b/x/funders/types/params.go @@ -31,8 +31,8 @@ func DefaultParams() Params { { CoinDenom: globalTypes.Denom, CoinDecimals: uint32(6), - MinFundingAmount: math.NewInt(1_000_000_000), // 1,000 $KYVE - MinFundingAmountPerBundle: math.NewInt(100_000), // 0.1 $KYVE + MinFundingAmount: math.NewInt(100_000_000), // 100 $KYVE + MinFundingAmountPerBundle: math.NewInt(100_000), // 0.1 $KYVE CoinWeight: math.LegacyNewDec(1), }, }, diff --git a/x/global/ante_test.go b/x/global/ante_test.go index 919801da..873c3131 100644 --- a/x/global/ante_test.go +++ b/x/global/ante_test.go @@ -292,7 +292,7 @@ var _ = Describe("GasAdjustmentDecorator", Ordered, func() { // NOTE: This will change as implementation changes. // TODO: Why does this change as the implementation changes? - BaseCost := 63340 + BaseCost := 62944 BeforeEach(func() { s = i.NewCleanChain() diff --git a/x/pool/keeper/msg_server_disable_pool_test.go b/x/pool/keeper/msg_server_disable_pool_test.go index c2d086d4..07519fea 100644 --- a/x/pool/keeper/msg_server_disable_pool_test.go +++ b/x/pool/keeper/msg_server_disable_pool_test.go @@ -69,6 +69,10 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { Moniker: "Alice", }) + params := s.App().FundersKeeper.GetParams(s.Ctx()) + params.CoinWhitelist[0].MinFundingAmount = math.NewInt(100_000_000) + s.App().FundersKeeper.SetParams(s.Ctx(), params) + s.RunTxPoolSuccess(&funderstypes.MsgFundPool{ Creator: i.ALICE, PoolId: 0, diff --git a/x/pool/keeper/msg_server_update_pool_test.go b/x/pool/keeper/msg_server_update_pool_test.go index 6de46373..a82141b3 100644 --- a/x/pool/keeper/msg_server_update_pool_test.go +++ b/x/pool/keeper/msg_server_update_pool_test.go @@ -79,7 +79,7 @@ var _ = Describe("msg_server_update_pool.go", Ordered, func() { msg := &types.MsgUpdatePool{ Authority: gov, Id: 0, - Payload: "{\"Name\":\"TestPool\",\"Runtime\":\"@kyve/test\",\"Logo\":\"ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU\",\"Config\":\"ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0\",\"StartKey\":\"0\",\"UploadInterval\":60,\"InflationShareWeight\":\"10000\",\"MinDelegation\":100000000000,\"MaxBundleSize\":100,\"Version\":\"0.0.0\",\"Binaries\":\"{}\",\"StorageProviderId\":2,\"CompressionId\":1,\"EndKey\":\"1\"}", + Payload: "{\"Name\":\"TestPool\",\"Runtime\":\"@kyve/test\",\"Logo\":\"ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU\",\"Config\":\"ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0\",\"StartKey\":\"0\",\"UploadInterval\":60,\"InflationShareWeight\":\"10000\",\"MinDelegation\":100000000,\"MaxBundleSize\":100,\"Version\":\"0.0.0\",\"Binaries\":\"{}\",\"StorageProviderId\":2,\"CompressionId\":1,\"EndKey\":\"1\"}", } p, v := BuildGovernanceTxs(s, []sdk.Msg{msg}) @@ -200,7 +200,7 @@ var _ = Describe("msg_server_update_pool.go", Ordered, func() { msg := &types.MsgUpdatePool{ Authority: gov, Id: 1, - Payload: "{\"Name\":\"TestPool2\",\"Runtime\":\"@kyve/test\",\"Logo\":\"ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU\",\"Config\":\"ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0\",\"StartKey\":\"0\",\"UploadInterval\":60,\"InflationShareWeight\":\"10000\",\"MinDelegation\":100000000000,\"MaxBundleSize\":100,\"Version\":\"0.0.0\",\"Binaries\":\"{}\",\"StorageProviderId\":2,\"CompressionId\":1,\"EndKey\":\"1\"}", + Payload: "{\"Name\":\"TestPool2\",\"Runtime\":\"@kyve/test\",\"Logo\":\"ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU\",\"Config\":\"ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0\",\"StartKey\":\"0\",\"UploadInterval\":60,\"InflationShareWeight\":\"10000\",\"MinDelegation\":100000000,\"MaxBundleSize\":100,\"Version\":\"0.0.0\",\"Binaries\":\"{}\",\"StorageProviderId\":2,\"CompressionId\":1,\"EndKey\":\"1\"}", } p, v := BuildGovernanceTxs(s, []sdk.Msg{msg}) @@ -258,7 +258,7 @@ var _ = Describe("msg_server_update_pool.go", Ordered, func() { msg := &types.MsgUpdatePool{ Authority: gov, Id: 1, - Payload: "invalid_json_payload\",\"Runtime\":\"@kyve/test\",\"Logo\":\"ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU\",\"Config\":\"ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0\",\"StartKey\":\"0\",\"UploadInterval\":60,\"InflationShareWeight\":\"10000\",\"MinDelegation\":100000000000,\"MaxBundleSize\":100,\"Version\":\"0.0.0\",\"Binaries\":\"{}\",\"StorageProviderId\":2,\"CompressionId\":1,\"EndKey\":\"1\"}", + Payload: "invalid_json_payload\",\"Runtime\":\"@kyve/test\",\"Logo\":\"ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU\",\"Config\":\"ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0\",\"StartKey\":\"0\",\"UploadInterval\":60,\"InflationShareWeight\":\"10000\",\"MinDelegation\":100000000,\"MaxBundleSize\":100,\"Version\":\"0.0.0\",\"Binaries\":\"{}\",\"StorageProviderId\":2,\"CompressionId\":1,\"EndKey\":\"1\"}", } p, _ := BuildGovernanceTxs(s, []sdk.Msg{msg}) diff --git a/x/stakers/keeper/keeper.go b/x/stakers/keeper/keeper.go index ca73adee..1ec68567 100644 --- a/x/stakers/keeper/keeper.go +++ b/x/stakers/keeper/keeper.go @@ -86,7 +86,7 @@ func (k Keeper) AfterValidatorBonded(ctx context.Context, consAddr sdk.ConsAddre func (k Keeper) AfterValidatorBeginUnbonding(goCtx context.Context, consAddr sdk.ConsAddress, valAddr sdk.ValAddress) error { ctx := sdk.UnwrapSDKContext(goCtx) - for _, v := range k.GetPoolAccountsFromStaker(ctx, valAddr.String()) { + for _, v := range k.GetPoolAccountsFromStaker(ctx, util.MustAccountAddressFromValAddress(valAddr.String())) { k.LeavePool(ctx, v.Staker, v.PoolId) } return nil diff --git a/x/stakers/keeper/keeper_suite_effective_stake_test.go b/x/stakers/keeper/keeper_suite_effective_stake_test.go index 12ed0d0a..9cfbf7d5 100644 --- a/x/stakers/keeper/keeper_suite_effective_stake_test.go +++ b/x/stakers/keeper/keeper_suite_effective_stake_test.go @@ -271,35 +271,38 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() { It("Test effective stake with all validators having zero delegation", func() { // ARRANGE - s.CreateZeroDelegationValidator(i.STAKER_0, "Staker-0") + staker0 := s.CreateNewValidator("Staker-0", 100*i.KYVE) s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ - Creator: i.STAKER_0, + Creator: staker0.Address, PoolId: 0, - PoolAddress: i.POOL_ADDRESS_0_A, + PoolAddress: staker0.PoolAccount[0], Amount: 100 * i.KYVE, Commission: math.LegacyMustNewDecFromStr("0.1"), StakeFraction: math.LegacyMustNewDecFromStr("1"), }) - s.CreateZeroDelegationValidator(i.STAKER_1, "Staker-1") + staker1 := s.CreateNewValidator("Staker-1", 100*i.KYVE) s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ - Creator: i.STAKER_1, + Creator: staker1.Address, PoolId: 0, - PoolAddress: i.POOL_ADDRESS_1_A, + PoolAddress: staker1.PoolAccount[0], Amount: 100 * i.KYVE, Commission: math.LegacyMustNewDecFromStr("0.1"), StakeFraction: math.LegacyMustNewDecFromStr("1"), }) - s.CreateZeroDelegationValidator(i.STAKER_2, "Staker-2") + staker2 := s.CreateNewValidator("Staker-2", 100*i.KYVE) s.RunTxStakersSuccess(&stakerstypes.MsgJoinPool{ - Creator: i.STAKER_2, + Creator: staker2.Address, PoolId: 0, - PoolAddress: i.POOL_ADDRESS_2_A, + PoolAddress: staker2.PoolAccount[0], Amount: 100 * i.KYVE, Commission: math.LegacyMustNewDecFromStr("0.1"), StakeFraction: math.LegacyMustNewDecFromStr("1"), }) + s.SetDelegationToZero(staker0.Address) + s.SetDelegationToZero(staker1.Address) + s.SetDelegationToZero(staker2.Address) // ASSERT Expect(s.App().StakersKeeper.IsVotingPowerTooHigh(s.Ctx(), 0)).To(BeFalse()) @@ -492,11 +495,11 @@ var _ = Describe("keeper_suite_effective_stake_test.go", Ordered, func() { // ASSERT Expect(s.App().StakersKeeper.IsVotingPowerTooHigh(s.Ctx(), 0)).To(BeFalse()) - Expect(s.App().StakersKeeper.GetValidatorPoolStake(s.Ctx(), i.STAKER_0, 0)).To(Equal(uint64(23333333333))) - Expect(s.App().StakersKeeper.GetValidatorPoolStake(s.Ctx(), i.STAKER_1, 0)).To(Equal(uint64(23333333333))) + Expect(s.App().StakersKeeper.GetValidatorPoolStake(s.Ctx(), i.STAKER_0, 0)).To(Equal(uint64(23333333))) + Expect(s.App().StakersKeeper.GetValidatorPoolStake(s.Ctx(), i.STAKER_1, 0)).To(Equal(uint64(23333333))) Expect(s.App().StakersKeeper.GetValidatorPoolStake(s.Ctx(), i.STAKER_2, 0)).To(Equal(20 * i.KYVE)) - Expect(s.App().StakersKeeper.GetTotalStakeOfPool(s.Ctx(), 0)).To(Equal(uint64(66666666666))) + Expect(s.App().StakersKeeper.GetTotalStakeOfPool(s.Ctx(), 0)).To(Equal(uint64(66666666))) }) It("Test effective stake with some validators having zero delegation due to stake fractions", func() { diff --git a/x/stakers/keeper/keeper_suite_protocol_bridge_test.go b/x/stakers/keeper/keeper_suite_protocol_bridge_test.go new file mode 100644 index 00000000..d36e387e --- /dev/null +++ b/x/stakers/keeper/keeper_suite_protocol_bridge_test.go @@ -0,0 +1,219 @@ +package keeper_test + +import ( + "fmt" + + "cosmossdk.io/math" + + stakertypes "github.com/KYVENetwork/chain/x/stakers/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + i "github.com/KYVENetwork/chain/testutil/integration" + pooltypes "github.com/KYVENetwork/chain/x/pool/types" +) + +/* + +TEST CASES - msg_server_join_pool.go + +* Consensus slash leads to removal from pool +* Consensus slash leads to removal from all pool +* Getting pushed out of the active set leads to removal from pool +* Unbonded validator can not join a pool + +*/ + +var _ = Describe("keeper_suite_protocol_bridge.go", Ordered, func() { + s := i.NewCleanChain() + + gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String() + + validator1 := s.CreateNewValidator("Staker-0", 1000*i.KYVE) + + BeforeEach(func() { + // init new clean chain + s = i.NewCleanChain() + + // create pool + msg := &pooltypes.MsgCreatePool{ + Authority: gov, + UploadInterval: 60, + MaxBundleSize: 100, + InflationShareWeight: math.LegacyZeroDec(), + Binaries: "{}", + } + s.RunTxPoolSuccess(msg) + + s.SetMaxVotingPower("1") + + validator1 = s.CreateNewValidator("Staker-0", 1000*i.KYVE) + }) + + AfterEach(func() { + s.PerformValidityChecks() + }) + + It("Consensus slash leads to removal from pool", func() { + // Arrange + params, _ := s.App().SlashingKeeper.GetParams(s.Ctx()) + params.MinSignedPerWindow = math.LegacyMustNewDecFromStr("1") + params.SignedBlocksWindow = 1 + _ = s.App().SlashingKeeper.SetParams(s.Ctx(), params) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: 0, + PoolAddress: validator1.PoolAccount[0], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + + // Make validator not participate in block votes to have him kicked out + s.AddAbciAbsentVote(validator1.ConsAccAddress) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(2)) + + // Act + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + // Assert + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(1)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) + + It("Consensus slash leads to removal from all pool", func() { + // Arrange + params, _ := s.App().SlashingKeeper.GetParams(s.Ctx()) + params.MinSignedPerWindow = math.LegacyMustNewDecFromStr("1") + params.SignedBlocksWindow = 1 + _ = s.App().SlashingKeeper.SetParams(s.Ctx(), params) + + for k := 1; k < 10; k++ { + msg := &pooltypes.MsgCreatePool{ + Authority: gov, + UploadInterval: 60, + MaxBundleSize: 100, + InflationShareWeight: math.LegacyZeroDec(), + Binaries: "{}", + } + s.RunTxPoolSuccess(msg) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: uint64(k), + PoolAddress: validator1.PoolAccount[k], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + } + + // Make validator not participate in block votes to have him kicked out + s.AddAbciAbsentVote(validator1.ConsAccAddress) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(2)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(9)) + + // Act + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + // Assert + for k := 1; k < 10; k++ { + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), uint64(k)) + Expect(poolMembersCount).To(Equal(uint64(0))) + } + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(1)) + + poolAccounts = s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) + + It("Getting pushed out of the active set leads to removal from pool", func() { + // Arrange + + // There are 51 validator slots (1 is occupied by the default validator (1 $KYVE) and another one by validator1) + for k := 0; k < 50; k++ { + s.CreateNewValidator(fmt.Sprintf("val-%d", k), 10000*i.KYVE) + } + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: 0, + PoolAddress: validator1.PoolAccount[0], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(51)) + + // Act + + // Create one more validator to kick out validator1 + s.CreateNewValidator(fmt.Sprintf("val-%d", 51), 10000*i.KYVE) + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + // Assert + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(51)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) + + It("Unbonded validator can not join a pool", func() { + // Arrange + + // There are 51 validator slots (1 is occupied by the default validator (1 $KYVE) and another one by validator1) + // This will kick out validator1 + for k := 0; k < 51; k++ { + s.CreateNewValidator(fmt.Sprintf("val-%d", k), 10000*i.KYVE) + } + s.CommitAfterSeconds(1) + s.CommitAfterSeconds(1) + + preBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(preBonded).To(HaveLen(51)) + + // Act + _, err := s.RunTx(&stakertypes.MsgJoinPool{ + Creator: validator1.Address, + PoolId: 0, + PoolAddress: validator1.PoolAccount[0], + Commission: math.LegacyMustNewDecFromStr("0.1"), + StakeFraction: math.LegacyMustNewDecFromStr("1"), + }) + + // Assert + Expect(err.Error()).To(Equal("validator not in active set")) + + poolMembersCount := s.App().StakersKeeper.GetStakerCountOfPool(s.Ctx(), 0) + Expect(poolMembersCount).To(Equal(uint64(0))) + + postBonded, _ := s.App().StakingKeeper.GetBondedValidatorsByPower(s.Ctx()) + Expect(postBonded).To(HaveLen(51)) + + poolAccounts := s.App().StakersKeeper.GetPoolAccountsFromStaker(s.Ctx(), validator1.Address) + Expect(poolAccounts).To(HaveLen(0)) + }) +}) diff --git a/x/stakers/keeper/msg_server_join_pool.go b/x/stakers/keeper/msg_server_join_pool.go index 5870e836..359d2623 100644 --- a/x/stakers/keeper/msg_server_join_pool.go +++ b/x/stakers/keeper/msg_server_join_pool.go @@ -39,7 +39,7 @@ func (k msgServer) JoinPool(goCtx context.Context, msg *types.MsgJoinPool) (*typ // Validator must be in the active set. if !validator.IsBonded() { - return nil, errors.Wrapf(errorsTypes.ErrNotFound, types.ErrValidatorJailed.Error()) + return nil, types.ErrValidatorNotInActiveSet } // Validators are not allowed to use their own address, to prevent diff --git a/x/stakers/types/errors.go b/x/stakers/types/errors.go index ee8493d6..8269dccd 100644 --- a/x/stakers/types/errors.go +++ b/x/stakers/types/errors.go @@ -21,6 +21,6 @@ var ( ErrPoolLeaveAlreadyInProgress = errors.Register(ModuleName, 1117, "Pool leave is already in progress") ErrPoolAccountUnauthorized = errors.Register(ModuleName, 1118, "pool account unauthorized") - ErrValidatorJailed = errors.Register(ModuleName, 1119, "validator jailed") + ErrValidatorNotInActiveSet = errors.Register(ModuleName, 1119, "validator not in active set") ErrNoPoolAccount = errors.Register(ModuleName, 1120, "sender has no pool account") ) diff --git a/x/team/keeper/msg_server_clawback_test.go b/x/team/keeper/msg_server_clawback_test.go index 7111f6f9..1a51adfa 100644 --- a/x/team/keeper/msg_server_clawback_test.go +++ b/x/team/keeper/msg_server_clawback_test.go @@ -48,11 +48,11 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(tva.LastClaimedTime).To(Equal(uint64(0))) status := teamKeeper.GetVestingStatus(tva, uint64(s.Ctx().BlockTime().Unix())) - Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444_444))) - Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185_185))) - Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_555_556))) - Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259_259))) - Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185_185))) + Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444))) + Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185))) + Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_556))) + Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259))) + Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185))) // ACT s.RunTxTeamError(&types.MsgClawback{ @@ -81,11 +81,11 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(tva.LastClaimedTime).To(Equal(uint64(0))) status := teamKeeper.GetVestingStatus(tva, uint64(s.Ctx().BlockTime().Unix())) - Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444_444))) - Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185_185))) - Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_555_556))) - Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259_259))) - Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185_185))) + Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444))) + Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185))) + Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_556))) + Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259))) + Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185))) s.PerformValidityChecks() // ACT @@ -115,18 +115,18 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(acc.LastClaimedTime).To(Equal(uint64(0))) status := teamKeeper.GetVestingStatus(acc, uint64(s.Ctx().BlockTime().Unix())) - Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444_444))) - Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185_185))) - Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_555_556))) - Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259_259))) - Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185_185))) + Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444))) + Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185))) + Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_556))) + Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259))) + Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185))) s.PerformValidityChecks() // ACT s.RunTxTeamSuccess(&types.MsgClaimUnlocked{ Authority: types.FOUNDATION_ADDRESS, Id: 0, - Amount: 10_935_185_185_185, + Amount: 10_935_185_185, Recipient: i.ALICE, }) @@ -139,14 +139,14 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { // ASSERT acc, _ = s.App().TeamKeeper.GetTeamVestingAccount(s.Ctx(), 0) Expect(acc.Clawback).To(BeZero()) - Expect(acc.UnlockedClaimed).To(Equal(uint64(10_935_185_185_185))) + Expect(acc.UnlockedClaimed).To(Equal(uint64(10_935_185_185))) status = teamKeeper.GetVestingStatus(acc, uint64(s.Ctx().BlockTime().Unix())) - Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444_444))) - Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185_185))) - Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_555_556))) - Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259_259))) - Expect(status.CurrentClaimableAmount).To(Equal(uint64(18_000_000_000_000))) + Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444))) + Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185))) + Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_556))) + Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259))) + Expect(status.CurrentClaimableAmount).To(Equal(uint64(18_000_000_000))) }) It("apply_clawback", func() { @@ -164,11 +164,11 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(tva.LastClaimedTime).To(Equal(uint64(0))) status := teamKeeper.GetVestingStatus(tva, uint64(s.Ctx().BlockTime().Unix())) - Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444_444))) - Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185_185))) - Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_555_556))) - Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259_259))) - Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185_185))) + Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444))) + Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185))) + Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_556))) + Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259))) + Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185))) s.PerformValidityChecks() s.RunTxTeamSuccess(&types.MsgClaimUnlocked{ @@ -208,8 +208,8 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(info.FoundationAuthority).To(Equal(types.FOUNDATION_ADDRESS)) Expect(info.BcpAuthority).To(Equal(types.BCP_ADDRESS)) Expect(info.TotalTeamAllocation).To(Equal(types.TEAM_ALLOCATION)) - Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444_444))) - Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444_444))) + Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444))) + Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444))) Expect(info.ClaimedAuthorityRewards).To(BeZero()) Expect(info.AvailableAuthorityRewards).To(Equal(info.TotalAuthorityRewards)) @@ -234,8 +234,8 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(info.FoundationAuthority).To(Equal(types.FOUNDATION_ADDRESS)) Expect(info.BcpAuthority).To(Equal(types.BCP_ADDRESS)) Expect(info.TotalTeamAllocation).To(Equal(types.TEAM_ALLOCATION)) - Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444_444))) - Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444_444))) + Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444))) + Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444))) Expect(info.ClaimedAuthorityRewards).To(BeZero()) Expect(info.AvailableAuthorityRewards).To(Equal(info.TotalAuthorityRewards)) @@ -268,11 +268,11 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(tva.LastClaimedTime).To(Equal(uint64(0))) status := teamKeeper.GetVestingStatus(tva, uint64(s.Ctx().BlockTime().Unix())) - Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444_444))) - Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185_185))) - Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_555_556))) - Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259_259))) - Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185_185))) + Expect(status.TotalVestedAmount).To(Equal(uint64(694_444_444_444))) + Expect(status.TotalUnlockedAmount).To(Equal(uint64(28_935_185_185))) + Expect(status.RemainingUnvestedAmount).To(Equal(uint64(305_555_555_556))) + Expect(status.LockedVestedAmount).To(Equal(uint64(665_509_259_259))) + Expect(status.CurrentClaimableAmount).To(Equal(uint64(28_935_185_185))) s.PerformValidityChecks() s.RunTxTeamSuccess(&types.MsgClaimUnlocked{ @@ -312,8 +312,8 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(info.FoundationAuthority).To(Equal(types.FOUNDATION_ADDRESS)) Expect(info.BcpAuthority).To(Equal(types.BCP_ADDRESS)) Expect(info.TotalTeamAllocation).To(Equal(types.TEAM_ALLOCATION)) - Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444_444))) - Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444_444))) + Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444))) + Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444))) Expect(info.TotalAuthorityRewards).To(BeNumerically(">", uint64(0))) Expect(info.ClaimedAuthorityRewards).To(BeZero()) @@ -340,8 +340,8 @@ var _ = Describe("msg_server_clawback.go", Ordered, func() { Expect(info.FoundationAuthority).To(Equal(types.FOUNDATION_ADDRESS)) Expect(info.BcpAuthority).To(Equal(types.BCP_ADDRESS)) Expect(info.TotalTeamAllocation).To(Equal(types.TEAM_ALLOCATION)) - Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444_444))) - Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444_444))) + Expect(info.IssuedTeamAllocation).To(Equal(uint64(694_444_444_444))) + Expect(info.AvailableTeamAllocation).To(Equal(types.TEAM_ALLOCATION - uint64(694_444_444_444))) Expect(info.TotalAuthorityRewards).To(BeNumerically(">", uint64(0))) Expect(info.ClaimedAuthorityRewards).To(BeZero()) diff --git a/x/team/types/types.go b/x/team/types/types.go index 62ad3767..c5503c53 100644 --- a/x/team/types/types.go +++ b/x/team/types/types.go @@ -43,7 +43,7 @@ type VestingStatus struct { var ( TEAM_FOUNDATION_STRING = "kyve1u7ukf2nv6v5j5y2yqprm8yqruue2rlmrkx4xgq" TEAM_BCP_STRING = "kyve1ruxaec07ca3dh0amkzxjap7av3xjt5vjgnd424" - TEAM_ALLOCATION_STRING = "165000000000000000" + TEAM_ALLOCATION_STRING = "165000000000000" TGE_STRING = "2023-02-01T10:34:15" )