diff --git a/client/x/evmengine/keeper/upgrades_internal_test.go b/client/x/evmengine/keeper/upgrades_internal_test.go index 9e0e0947..3162f302 100644 --- a/client/x/evmengine/keeper/upgrades_internal_test.go +++ b/client/x/evmengine/keeper/upgrades_internal_test.go @@ -30,7 +30,6 @@ var ( ) func TestKeeper_ProcessSoftwareUpgrade(t *testing.T) { - t.Parallel() keeper, ctx, ctrl, uk := setupTestEnvironment(t) t.Cleanup(ctrl.Finish) @@ -88,7 +87,6 @@ func TestKeeper_ProcessSoftwareUpgrade(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - t.Parallel() tc.setupMock() err := keeper.ProcessSoftwareUpgrade(ctx, tc.ev()) if tc.expectedErr != "" { @@ -102,7 +100,6 @@ func TestKeeper_ProcessSoftwareUpgrade(t *testing.T) { } func TestKeeper_ProcessUpgradeEvents(t *testing.T) { - t.Parallel() keeper, ctx, ctrl, uk := setupTestEnvironment(t) t.Cleanup(ctrl.Finish) @@ -241,7 +238,6 @@ func TestKeeper_ProcessUpgradeEvents(t *testing.T) { for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - t.Parallel() if tc.setupMock != nil { tc.setupMock() } diff --git a/client/x/evmstaking/keeper/deposit_test.go b/client/x/evmstaking/keeper/deposit_test.go index 3cba9cb6..4dbbd3e0 100644 --- a/client/x/evmstaking/keeper/deposit_test.go +++ b/client/x/evmstaking/keeper/deposit_test.go @@ -1,12 +1,9 @@ package keeper_test -/* import ( "context" "math/big" - "time" - "cosmossdk.io/math" sdkmath "cosmossdk.io/math" "github.com/cometbft/cometbft/crypto" @@ -19,17 +16,14 @@ import ( "github.com/piplabs/story/client/x/evmstaking/types" "github.com/piplabs/story/contracts/bindings" - "github.com/piplabs/story/lib/errors" "github.com/piplabs/story/lib/k1util" - - "go.uber.org/mock/gomock" ) // createValidator creates a validator. func (s *TestSuite) createValidator(ctx context.Context, valPubKey crypto.PubKey, valAddr sdk.ValAddress) { sdkCtx := sdk.UnwrapSDKContext(ctx) require := s.Require() - bankKeeper, stakingKeeper := s.BankKeeper, s.StakingKeeper + stakingKeeper := s.StakingKeeper // Convert public key to cosmos format valCosmosPubKey, err := k1util.PubKeyToCosmos(valPubKey) @@ -39,13 +33,15 @@ func (s *TestSuite) createValidator(ctx context.Context, valPubKey crypto.PubKey val := testutil.NewValidator(s.T(), valAddr, valCosmosPubKey) valTokens := stakingKeeper.TokensFromConsensusPower(ctx, 10) validator, _, _ := val.AddTokensFromDel(valTokens, sdkmath.LegacyOneDec()) - bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) + // bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) + require.NoError(s.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, valTokens)))) + require.NoError(s.BankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, stypes.NotBondedPoolName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, valTokens)))) _ = skeeper.TestingUpdateValidator(stakingKeeper, sdkCtx, validator, true) } func (s *TestSuite) TestProcessDeposit() { require := s.Require() - ctx, keeper, accountKeeper, bankKeeper, stakingKeeper := s.Ctx, s.EVMStakingKeeper, s.AccountKeeper, s.BankKeeper, s.StakingKeeper + ctx, keeper, stakingKeeper := s.Ctx, s.EVMStakingKeeper, s.StakingKeeper pubKeys, accAddrs, valAddrs := createAddresses(2) // delegator @@ -66,15 +62,6 @@ func (s *TestSuite) TestProcessDeposit() { OperatorAddress: cmpToEVM(delPubKey), } } - expectAccountMock := func(isNewAccount bool) { - if isNewAccount { - accountKeeper.EXPECT().HasAccount(gomock.Any(), delAddr).Return(false) - accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), delAddr).Return(nil) - accountKeeper.EXPECT().SetAccount(gomock.Any(), gomock.Any()) - } else { - accountKeeper.EXPECT().HasAccount(gomock.Any(), delAddr).Return(true) - } - } tcs := []struct { name string @@ -107,129 +94,25 @@ func (s *TestSuite) TestProcessDeposit() { }, expectedErr: "invalid uncompressed public key length or format", }, + // TODO: corrupted delegator and validator pubkey { - name: "fail: corrupted delegator pubkey", - deposit: &bindings.IPTokenStakingDeposit{ - DelegatorUncmpPubkey: createCorruptedPubKey(cmpToUncmp(delPubKey.Bytes())), - ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()), - StakeAmount: new(big.Int).SetUint64(1), - StakingPeriod: big.NewInt(0), - DelegationId: big.NewInt(0), - OperatorAddress: cmpToEVM(delPubKey.Bytes()), - }, - expectedErr: "invalid uncompressed public key length or format", - }, - // { - // name: "fail: corrupted validator pubkey", - // deposit: createDeposit(delPubKey.Bytes(), createCorruptedPubKey(valPubKey.Bytes()), new(big.Int).SetUint64(1)), - // expectedErr: "validator pubkey to evm address", - // }, - { - name: "fail: mint coins to existing delegator", - settingMock: func() { - accountKeeper.EXPECT().HasAccount(gomock.Any(), delAddr).Return(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(errors.New("")) - }, - deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), - expectedErr: "create stake coin for depositor: mint coins", - }, - { - name: "fail: mint coins to new delegator", - settingMock: func() { - expectAccountMock(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(errors.New("")) - }, - deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), - expectedErr: "create stake coin for depositor: mint coins", - }, - { - name: "fail: send coins from module to existing delegator", - settingMock: func() { - expectAccountMock(false) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, delAddr, gomock.Any()).Return(errors.New("")) - }, - deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), - expectedErr: "create stake coin for depositor: send coins", - }, - { - name: "fail: send coins from module to new delegator", - settingMock: func() { - expectAccountMock(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, delAddr, gomock.Any()).Return(errors.New("")) - }, - deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), - expectedErr: "create stake coin for depositor: send coins", - }, - { - name: "fail: delegate to existing delegator", - settingMock: func() { - expectAccountMock(false) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, delAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), delAddr, stypes.BondedPoolName, gomock.Any()).Return(errors.New("failed to delegate")) - }, - deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), - expectedErr: "failed to delegate", - }, - { - name: "fail: delegate to new delegator", - settingMock: func() { - expectAccountMock(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, delAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), delAddr, stypes.BondedPoolName, gomock.Any()).Return(errors.New("failed to delegate")) - }, - deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), - expectedErr: "failed to delegate", - }, - { - name: "pass: existing delegator", - settingMock: func() { - expectAccountMock(false) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, delAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), delAddr, stypes.BondedPoolName, gomock.Any()).Return(nil) - }, + name: "pass: existing delegator", deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), expectedResult: stypes.Delegation{ DelegatorAddress: delAddr.String(), ValidatorAddress: valAddr.String(), - Shares: math.LegacyNewDecFromInt(math.NewInt(1)), - RewardsShares: math.LegacyNewDecFromInt(math.NewInt(1)), - PeriodDelegations: map[string]*stypes.PeriodDelegation{ - stypes.FlexibleDelegationID: { - PeriodDelegationId: stypes.FlexibleDelegationID, - Shares: math.LegacyNewDecFromInt(math.NewInt(1)), - RewardsShares: math.LegacyNewDecFromInt(math.NewInt(1)), - EndTime: time.Time{}, - }, - }, + Shares: sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(1)), + RewardsShares: sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(1)).Quo(sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(2))), }, }, { - name: "pass: new delegator", - settingMock: func() { - expectAccountMock(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, delAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), delAddr, stypes.BondedPoolName, gomock.Any()).Return(nil) - }, + name: "pass: new delegator", deposit: createDeposit(delPubKey.Bytes(), valPubKey.Bytes(), new(big.Int).SetUint64(1)), expectedResult: stypes.Delegation{ DelegatorAddress: delAddr.String(), ValidatorAddress: valAddr.String(), - Shares: math.LegacyNewDecFromInt(math.NewInt(1)), - RewardsShares: math.LegacyNewDecFromInt(math.NewInt(1)), - PeriodDelegations: map[string]*stypes.PeriodDelegation{ - stypes.FlexibleDelegationID: { - PeriodDelegationId: stypes.FlexibleDelegationID, - Shares: math.LegacyNewDecFromInt(math.NewInt(1)), - RewardsShares: math.LegacyNewDecFromInt(math.NewInt(1)), - EndTime: time.Time{}, - }, - }, + Shares: sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(1)), + RewardsShares: sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(1)).Quo(sdkmath.LegacyNewDecFromInt(sdkmath.NewInt(2))), }, }, } @@ -248,7 +131,6 @@ func (s *TestSuite) TestProcessDeposit() { // check delegation delegation, err := stakingKeeper.GetDelegation(cachedCtx, delAddr, valAddr) require.NoError(err) - delegation.PeriodDelegations[stypes.FlexibleDelegationID].EndTime = time.Time{} require.Equal(tc.expectedResult, delegation) } }) @@ -291,4 +173,3 @@ func (s *TestSuite) TestParseDepositLog() { }) } } -*/ diff --git a/client/x/evmstaking/keeper/keeper.go b/client/x/evmstaking/keeper/keeper.go index 0c47384c..696304dd 100644 --- a/client/x/evmstaking/keeper/keeper.go +++ b/client/x/evmstaking/keeper/keeper.go @@ -109,7 +109,7 @@ func (k Keeper) ValidatorAddressCodec() addresscodec.Codec { return k.validatorAddressCodec } -//nolint:gocyclo // TODO +//nolint:gocyclo // a lot of switch cases, could be refactored func (k Keeper) ProcessStakingEvents(ctx context.Context, height uint64, logs []*evmenginetypes.EVMEvent) error { gwei, exp := big.NewInt(10), big.NewInt(9) gwei.Exp(gwei, exp, nil) @@ -123,11 +123,6 @@ func (k Keeper) ProcessStakingEvents(ctx context.Context, height uint64, logs [] return err } - // TODO: handle when each event processing fails. - - // Convert the amount from wei to gwei (Eth2 spec withdrawal is specified in gwei) by dividing by 10^9. - // TODO: consider rounding and decimal precision when dividing bigint. - switch ethlog.Topics[0] { case types.UpdateValidatorCommission.ID: ev, err := k.ipTokenStakingContract.ParseUpdateValidatorCommssion(ethlog) diff --git a/client/x/evmstaking/keeper/keeper_test.go b/client/x/evmstaking/keeper/keeper_test.go index 3995e5dc..ac53a1a2 100644 --- a/client/x/evmstaking/keeper/keeper_test.go +++ b/client/x/evmstaking/keeper/keeper_test.go @@ -25,8 +25,14 @@ import ( simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" skeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + "github.com/cosmos/cosmos-sdk/x/staking/testutil" stypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/decred/dcrd/dcrec/secp256k1" "github.com/ethereum/go-ethereum/common" @@ -38,9 +44,11 @@ import ( "github.com/piplabs/story/client/x/evmstaking/module" estestutil "github.com/piplabs/story/client/x/evmstaking/testutil" "github.com/piplabs/story/client/x/evmstaking/types" + minttypes "github.com/piplabs/story/client/x/mint/types" "github.com/piplabs/story/contracts/bindings" "github.com/piplabs/story/lib/errors" "github.com/piplabs/story/lib/ethclient" + "github.com/piplabs/story/lib/k1util" "go.uber.org/mock/gomock" ) @@ -79,8 +87,9 @@ type TestSuite struct { Ctx sdk.Context - AccountKeeper *estestutil.MockAccountKeeper - BankKeeper *estestutil.MockBankKeeper + AccountKeeper authkeeper.AccountKeeper + // AccountKeeper *estestutil.MockAccountKeeper + BankKeeper bankkeeper.BaseKeeper DistrKeeper *estestutil.MockDistributionKeeper StakingKeeper *skeeper.Keeper SlashingKeeper *estestutil.MockSlashingKeeper @@ -92,13 +101,20 @@ type TestSuite struct { func (s *TestSuite) SetupTest() { s.encCfg = moduletestutil.MakeTestEncodingConfig(module.AppModuleBasic{}) + authKey := storetypes.NewKVStoreKey(authtypes.StoreKey) + bankKey := storetypes.NewKVStoreKey(banktypes.StoreKey) evmstakingKey := storetypes.NewKVStoreKey(types.StoreKey) stakingKey := storetypes.NewKVStoreKey(stypes.StoreKey) + + authStoreService := runtime.NewKVStoreService(authKey) + bankStoreService := runtime.NewKVStoreService(bankKey) storeService := runtime.NewKVStoreService(evmstakingKey) stakingStoreService := runtime.NewKVStoreService(stakingKey) db := dbm.NewMemDB() cms := store.NewCommitMultiStore(db, log.NewNopLogger(), metrics.NewNoOpMetrics()) + cms.MountStoreWithDB(authKey, storetypes.StoreTypeIAVL, db) + cms.MountStoreWithDB(bankKey, storetypes.StoreTypeIAVL, db) cms.MountStoreWithDB(evmstakingKey, storetypes.StoreTypeIAVL, db) cms.MountStoreWithDB(stakingKey, storetypes.StoreTypeIAVL, db) err := cms.LoadLatestVersion() @@ -109,6 +125,10 @@ func (s *TestSuite) SetupTest() { interfaceRegistry := codectypes.NewInterfaceRegistry() cryptocodec.RegisterInterfaces(interfaceRegistry) legacyAmino := codec.NewLegacyAmino() + authtypes.RegisterLegacyAminoCodec(legacyAmino) + authtypes.RegisterInterfaces(interfaceRegistry) + banktypes.RegisterLegacyAminoCodec(legacyAmino) + banktypes.RegisterInterfaces(interfaceRegistry) stypes.RegisterLegacyAminoCodec(legacyAmino) stypes.RegisterInterfaces(interfaceRegistry) marshaler := codec.NewProtoCodec(interfaceRegistry) @@ -121,16 +141,45 @@ func (s *TestSuite) SetupTest() { // gomock initializations ctrl := gomock.NewController(s.T()) - // mock keepers - accountKeeper := estestutil.NewMockAccountKeeper(ctrl) - accountKeeper.EXPECT().GetModuleAddress(types.ModuleName).Return(authtypes.NewModuleAddress(types.ModuleName)).AnyTimes() - accountKeeper.EXPECT().GetModuleAddress(stypes.ModuleName).Return(authtypes.NewModuleAddress(stypes.ModuleName)).AnyTimes() - accountKeeper.EXPECT().GetModuleAddress(stypes.BondedPoolName).Return(authtypes.NewModuleAddress(stypes.BondedPoolName)).AnyTimes() - accountKeeper.EXPECT().GetModuleAddress(stypes.NotBondedPoolName).Return(authtypes.NewModuleAddress(stypes.NotBondedPoolName)).AnyTimes() - accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("story")).AnyTimes() + maccPerms := map[string][]string{ + authtypes.FeeCollectorName: nil, + minttypes.ModuleName: {authtypes.Minter}, + distrtypes.ModuleName: nil, + stypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + types.ModuleName: {authtypes.Burner, authtypes.Minter}, + govtypes.ModuleName: {authtypes.Burner}, + } + + accountKeeper := authkeeper.NewAccountKeeper( + marshaler, + authStoreService, + authtypes.ProtoBaseAccount, + maccPerms, + address.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + "story", + authtypes.NewModuleAddress(authtypes.ModuleName).String(), + ) s.AccountKeeper = accountKeeper - bankKeeper := estestutil.NewMockBankKeeper(ctrl) + + blockedAddrs := make(map[string]bool) + blockedAddrs[authtypes.NewModuleAddress(authtypes.FeeCollectorName).String()] = true + blockedAddrs[authtypes.NewModuleAddress(authtypes.ModuleName).String()] = true + blockedAddrs[authtypes.NewModuleAddress(distrtypes.ModuleName).String()] = true + blockedAddrs[authtypes.NewModuleAddress(stypes.BondedPoolName).String()] = true + blockedAddrs[authtypes.NewModuleAddress(stypes.NotBondedPoolName).String()] = true + blockedAddrs[authtypes.NewModuleAddress(types.ModuleName).String()] = true + + bankKeeper := bankkeeper.NewBaseKeeper( + marshaler, + bankStoreService, + accountKeeper, + blockedAddrs, + authtypes.NewModuleAddress(banktypes.ModuleName).String(), + log.NewNopLogger(), + ) s.BankKeeper = bankKeeper + distrKeeper := estestutil.NewMockDistributionKeeper(ctrl) s.DistrKeeper = distrKeeper slashingKeeper := estestutil.NewMockSlashingKeeper(ctrl) @@ -201,7 +250,7 @@ func cmpToEVM(cmpPubKey []byte) common.Address { func (s *TestSuite) TestProcessStakingEvents() { require := s.Require() - ctx, evmstakingKeeper := s.Ctx, s.EVMStakingKeeper + ctx, evmstakingKeeper, stakingKeeper := s.Ctx, s.EVMStakingKeeper, s.StakingKeeper // slashingKeeper := s.SlashingKeeper // create addresses pubKeys, addrs, _ := createAddresses(3) @@ -486,6 +535,50 @@ func (s *TestSuite) TestProcessStakingEvents() { require.Equal(delEvmAddr.String(), evmDelAddr) }, }, + { + name: "pass: process CreateValidatorEvent", + evmEvents: func() ([]*evmenginetypes.EVMEvent, error) { + data, err := stakingAbi.Events["CreateValidator"].Inputs.NonIndexed().Pack( + uncompressedDelPubKeyBytes, + "moniker", + delAmtGwei, + uint32(1000), + uint32(5000), + uint32(500), + uint8(0), + cmpToEVM(delPubKey.Bytes()), + []byte{}, + ) + require.NoError(err) + logs := []ethtypes.Log{{Topics: []common.Hash{types.CreateValidatorEvent.ID}, Data: data}} + evmEvents, err := ethLogsToEvmEvents(logs) + if err != nil { + return nil, err + } + + return evmEvents, nil + }, + setup: func(c context.Context) { + // accountKeeper.EXPECT().HasAccount(c, delAddr).Return(true) + // bankKeeper.EXPECT().MintCoins(c, types.ModuleName, sdk.NewCoins(delCoin)) + // bankKeeper.EXPECT().SendCoinsFromModuleToAccount(c, types.ModuleName, delAddr, sdk.NewCoins(delCoin)) + // bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(c, delAddr, stypes.NotBondedPoolName, sdk.NewCoins(delCoin)) + }, + stateCheck: func(c context.Context) { + _, err := stakingKeeper.GetValidator(c, sdk.ValAddress(delAddr)) + require.ErrorContains(err, "validator does not exist") + }, + postStateCheck: func(c context.Context) { + newVal, err := stakingKeeper.GetValidator(c, sdk.ValAddress(delAddr)) + require.NoError(err) + require.Equal(sdk.ValAddress(delAddr).String(), newVal.OperatorAddress) + require.Equal("moniker", newVal.Description.GetMoniker()) + require.Equal(sdkmath.NewInt(100), newVal.Tokens) + require.Equal("0.100000000000000000", newVal.Commission.Rate.String()) + require.Equal("0.500000000000000000", newVal.Commission.MaxRate.String()) + require.Equal("0.050000000000000000", newVal.Commission.MaxChangeRate.String()) + }, + }, /* { name: "pass: process CreateValidatorEvent", @@ -692,12 +785,20 @@ func TestTestSuite(t *testing.T) { suite.Run(t, new(TestSuite)) } -/* // setupValidatorAndDelegation creates a validator and delegation for testing. func (s *TestSuite) setupValidatorAndDelegation(ctx context.Context, valPubKey, delPubKey crypto.PubKey, valAddr sdk.ValAddress, delAddr sdk.AccAddress, valTokens sdkmath.Int) { sdkCtx := sdk.UnwrapSDKContext(ctx) require := s.Require() - bankKeeper, stakingKeeper, keeper := s.BankKeeper, s.StakingKeeper, s.EVMStakingKeeper + accountKeeper, bankKeeper, stakingKeeper, evmstakingKeeper := s.AccountKeeper, s.BankKeeper, s.StakingKeeper, s.EVMStakingKeeper + + notBondedPool := stakingKeeper.GetNotBondedPool(ctx) + accountKeeper.SetModuleAccount(ctx, notBondedPool) + + initCoins := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, valTokens)) + require.NoError(bankKeeper.MintCoins(ctx, types.ModuleName, initCoins)) + require.NoError(bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, delAddr, initCoins)) + require.NoError(bankKeeper.MintCoins(ctx, types.ModuleName, initCoins)) + require.NoError(bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, notBondedPool.GetName(), initCoins)) // Convert public key to cosmos format valCosmosPubKey, err := k1util.PubKeyToCosmos(valPubKey) @@ -705,55 +806,62 @@ func (s *TestSuite) setupValidatorAndDelegation(ctx context.Context, valPubKey, // Create and update validator val := testutil.NewValidator(s.T(), valAddr, valCosmosPubKey) - validator, _, _ := val.AddTokensFromDel(valTokens, sdkmath.LegacyOneDec()) - bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) - _ = skeeper.TestingUpdateValidator(stakingKeeper, sdkCtx, validator, true) + validator, issuedShares, _ := val.AddTokensFromDel(valTokens, sdkmath.LegacyOneDec()) + require.Equal(valTokens, issuedShares.RoundInt()) + + // bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()).Times(2) + // _ = skeeper.TestingUpdateValidator(stakingKeeper, sdkCtx, validator, true) + + // Create/Get period delegation + periodDelegation, err := stakingKeeper.GetOrCreatePeriodDelegation(ctx, delAddr, valAddr, stypes.FlexiblePeriodDelegationID, stypes.DefaultFlexiblePeriodType, time.Now()) + require.NoError(err) // Create and set delegation delAmt := stakingKeeper.TokensFromConsensusPower(ctx, 100).ToLegacyDec() - delegation := stypes.NewDelegation( - delAddr.String(), valAddr.String(), - delAmt, stypes.FlexibleDelegationID, stypes.PeriodType_FLEXIBLE, time.Time{}, + _, _, err = stakingKeeper.Delegate( + ctx, delAddr, delAmt.RoundInt(), stypes.Unbonded, val, false, + periodDelegation.PeriodDelegationId, periodDelegation.PeriodType, periodDelegation.EndTime, ) - require.NoError(stakingKeeper.SetDelegation(ctx, delegation)) + require.NoError(err) validator.DelegatorShares = validator.DelegatorShares.Add(delAmt) validator.DelegatorRewardsShares = validator.DelegatorRewardsShares.Add(delAmt) + require.NoError(bankKeeper.MintCoins(ctx, types.ModuleName, initCoins)) + require.NoError(bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, notBondedPool.GetName(), initCoins)) _ = skeeper.TestingUpdateValidator(stakingKeeper, sdkCtx, validator, true) // Map delegator to EVM address delEvmAddr, err := k1util.CosmosPubkeyToEVMAddress(delPubKey.Bytes()) require.NoError(err) - require.NoError(keeper.DelegatorMap.Set(ctx, delAddr.String(), delEvmAddr.String())) + require.NoError(evmstakingKeeper.DelegatorWithdrawAddress.Set(ctx, delAddr.String(), delEvmAddr.String())) + require.NoError(evmstakingKeeper.DelegatorRewardAddress.Set(ctx, delAddr.String(), delEvmAddr.String())) + // require.NoError(evmstakingKeeper.DelegatorOperatorAddress.Set(ctx, delAddr.String(), delEvmAddr.String())) // Ensure delegation is set correctly - delegation, err = stakingKeeper.GetDelegation(ctx, delAddr, valAddr) + delegation, err := stakingKeeper.GetDelegation(ctx, delAddr, valAddr) require.NoError(err) require.Equal(delAmt, delegation.GetShares()) } -*/ func createCorruptedPubKey(pubKey []byte) []byte { corruptedPubKey := append([]byte(nil), pubKey...) - corruptedPubKey[0] = 0x03 + // corruptedPubKey[0] = 0x03 corruptedPubKey[1] = 0xFF return corruptedPubKey } -/* // setupUnbonding creates unbondings for testing. func (s *TestSuite) setupUnbonding(ctx context.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount string) { require := s.Require() - bankKeeper, stakingKeeper := s.BankKeeper, s.StakingKeeper + stakingKeeper := s.StakingKeeper - bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.BondedPoolName, stypes.NotBondedPoolName, gomock.Any()) + // bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.BondedPoolName, stypes.NotBondedPoolName, gomock.Any()) _, _, err := stakingKeeper.Undelegate( - ctx, delAddr, valAddr, stypes.FlexibleDelegationID, sdkmath.LegacyMustNewDecFromStr(amount), + ctx, delAddr, valAddr, stypes.FlexiblePeriodDelegationID, sdkmath.LegacyMustNewDecFromStr(amount), ) require.NoError(err) } -*/ // ethLogsToEvmEvents converts Ethereum logs to a slice of EVM events. func ethLogsToEvmEvents(logs []ethtypes.Log) ([]*evmenginetypes.EVMEvent, error) { diff --git a/client/x/evmstaking/keeper/redelegation_test.go b/client/x/evmstaking/keeper/redelegation_test.go deleted file mode 100644 index dfef78e6..00000000 --- a/client/x/evmstaking/keeper/redelegation_test.go +++ /dev/null @@ -1,219 +0,0 @@ -package keeper_test - -/* -import ( - "context" - "math/big" - - "github.com/cometbft/cometbft/crypto" - k1 "github.com/cometbft/cometbft/crypto/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" - gethtypes "github.com/ethereum/go-ethereum/core/types" - - "github.com/piplabs/story/client/x/evmstaking/keeper" - "github.com/piplabs/story/client/x/evmstaking/types" - "github.com/piplabs/story/contracts/bindings" -) - -func (s *TestSuite) TestRedelegation() { - ctx, keeper, stakingKeeper := s.Ctx, s.EVMStakingKeeper, s.StakingKeeper - require := s.Require() - - // create addresses - pubKeys, accAddrs, valAddrs := createAddresses(3) - delAddr := accAddrs[0] - delPubKey := pubKeys[0] - valSrcPubKey := pubKeys[1] - valSrcAddr := valAddrs[1] - valDstPubKey := pubKeys[2] - valDstAddr := valAddrs[2] - - valTokens := stakingKeeper.TokensFromConsensusPower(ctx, 10) - s.setupValidatorAndDelegation(ctx, valSrcPubKey, delPubKey, valSrcAddr, delAddr, valTokens) - s.setupValidatorAndDelegation(ctx, valDstPubKey, delPubKey, valDstAddr, delAddr, valTokens) - - // check the amount of delegated tokens - delSrc, err := stakingKeeper.GetDelegatorValidator(ctx, delAddr, valSrcAddr) - require.NoError(err) - require.True(delSrc.Tokens.Equal(valTokens)) - - delDst, err := stakingKeeper.GetDelegatorValidator(ctx, delAddr, valDstAddr) - require.NoError(err) - require.True(delDst.Tokens.Equal(valTokens)) - - // test shouldn't have and redelegations - has, err := stakingKeeper.HasReceivingRedelegation(ctx, delAddr, valDstAddr) - require.NoError(err) - require.False(has) - - redelTokens := stakingKeeper.TokensFromConsensusPower(ctx, 5) // multiply power reduction of 1000000 - validInput := &bindings.IPTokenStakingRedelegate{ - DelegatorUncmpPubkey: cmpToUncmp(delPubKey.Bytes()), - ValidatorUncmpSrcPubkey: cmpToUncmp(valSrcPubKey.Bytes()), - ValidatorUncmpDstPubkey: cmpToUncmp(valDstPubKey.Bytes()), - DelegationId: big.NewInt(0), - Amount: big.NewInt(redelTokens.Int64()), - } - checkStateAfterRedelegation := func(c context.Context) { - // check the amount of delegated tokens after redelegation - delSrc, err = stakingKeeper.GetDelegatorValidator(c, delAddr, valSrcAddr) - require.NoError(err) - require.True(delSrc.Tokens.Equal(valTokens.Sub(redelTokens))) - - delDst, err = stakingKeeper.GetDelegatorValidator(c, delAddr, valDstAddr) - require.NoError(err) - require.True(delDst.Tokens.Equal(valTokens.Add(redelTokens))) - - // params - params, err := s.StakingKeeper.GetParams(c) - require.NoError(err) - - redelegation, err := stakingKeeper.GetRedelegation(c, delAddr, valSrcAddr, valDstAddr) - require.NoError(err) - require.Equal(delAddr.String(), redelegation.DelegatorAddress) - require.Equal(valSrcAddr.String(), redelegation.ValidatorSrcAddress) - require.Equal(valDstAddr.String(), redelegation.ValidatorDstAddress) - require.Equal(redelTokens, redelegation.Entries[0].InitialBalance) - sdkCtx := sdk.UnwrapSDKContext(c) - require.Equal(sdkCtx.BlockTime().Add(params.UnbondingTime), redelegation.Entries[0].CompletionTime) - } - - tcs := []struct { - name string - input func() bindings.IPTokenStakingRedelegate - expectedError string - // postCheck checks the state is changed after the successful operation - postCheck func(c context.Context) - }{ - { - name: "pass: valid redelegation", - input: func() bindings.IPTokenStakingRedelegate { - return *validInput - }, - postCheck: checkStateAfterRedelegation, - }, - { - name: "fail: zero amount", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.Amount = big.NewInt(0) - - return inputCpy - }, - expectedError: "invalid shares amount", - }, - { - name: "fail: invalid delegator pubkey", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.DelegatorUncmpPubkey = cmpToUncmp(delPubKey.Bytes())[1:] - - return inputCpy - }, - expectedError: "invalid uncompressed public key length or format", - }, - { - name: "fail: invalid src validator pubkey", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.ValidatorUncmpSrcPubkey = cmpToUncmp(valSrcPubKey.Bytes())[1:] - - return inputCpy - }, - expectedError: "invalid uncompressed public key length or format", - }, - { - name: "fail: invalid dst validator pubkey", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.ValidatorUncmpDstPubkey = cmpToUncmp(valDstPubKey.Bytes())[1:] - - return inputCpy - }, - expectedError: "invalid uncompressed public key length or format", - }, - { - name: "fail: corrupted delegator pubkey", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.DelegatorUncmpPubkey = createCorruptedPubKey(cmpToUncmp(delPubKey.Bytes())) - - return inputCpy - }, - expectedError: "invalid uncompressed public key length or format", - }, - { - name: "fail: corrupted src validator pubkey", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.ValidatorUncmpSrcPubkey = createCorruptedPubKey(cmpToUncmp(valSrcPubKey.Bytes())) - - return inputCpy - }, - expectedError: "invalid uncompressed public key length or format", - }, - { - name: "fail: corrupted dst validator pubkey", - input: func() bindings.IPTokenStakingRedelegate { - inputCpy := *validInput - inputCpy.ValidatorUncmpDstPubkey = createCorruptedPubKey(cmpToUncmp(valDstPubKey.Bytes())) - - return inputCpy - }, - expectedError: "invalid uncompressed public key length or format", - }, - } - - for _, tc := range tcs { - s.Run(tc.name, func() { - cachedCtx, _ := ctx.CacheContext() - input := tc.input() - err := keeper.ProcessRedelegate(cachedCtx, &input) - if tc.expectedError != "" { - require.ErrorContains(err, tc.expectedError) - } else { - require.NoError(err, tc.expectedError) - tc.postCheck(cachedCtx) - } - }) - } -} - -func (s *TestSuite) TestParseRedelegationLog() { - require := s.Require() - keeper := s.EVMStakingKeeper - - testCases := []struct { - name string - log gethtypes.Log - expectErr bool - }{ - { - name: "Unknown Topic", - log: gethtypes.Log{ - Topics: []common.Hash{common.HexToHash("0x1111111111111111111111111111111111111111111111111111111111111111")}, - }, - expectErr: true, - }, - { - name: "Valid Topic", - log: gethtypes.Log{ - Topics: []common.Hash{types.RedelegateEvent.ID}, - }, - expectErr: false, - }, - } - - for _, tc := range testCases { - s.Run(tc.name, func() { - _, err := keeper.ParseRedelegateLog(tc.log) - if tc.expectErr { - require.Error(err, "should return error for %s", tc.name) - } else { - require.NoError(err, "should not return error for %s", tc.name) - } - }) - } -} -*/ diff --git a/client/x/evmstaking/keeper/reward_queue.go b/client/x/evmstaking/keeper/reward_queue.go index 16ec7c81..540d4253 100644 --- a/client/x/evmstaking/keeper/reward_queue.go +++ b/client/x/evmstaking/keeper/reward_queue.go @@ -88,3 +88,42 @@ func (k Keeper) PeekEligibleRewardWithdrawals(ctx context.Context, maxPeek uint3 return withdrawals, nil } + +// GetAllRewardWithdrawals gets the set of all reward withdrawals with no limits. +func (k Keeper) GetAllRewardWithdrawals(ctx context.Context) (withdrawals []types.Withdrawal, err error) { + iterator, err := k.RewardWithdrawalQueue.Iterate(ctx) + if err != nil { + return nil, err + } + + wdrKvs, err := iterator.KeyValues() + if err != nil { + return nil, err + } + + for _, withdrawal := range wdrKvs { + withdrawals = append(withdrawals, withdrawal.Value) + } + + return withdrawals, nil +} + +// GetRewardWithdrawals returns at max the requested amount of reward withdrawals. +func (k Keeper) GetRewardWithdrawals(ctx context.Context, maxRetrieve uint32) (withdrawals []types.Withdrawal, err error) { + iterator, err := k.RewardWithdrawalQueue.Iterate(ctx) + if err != nil { + return nil, err + } + + i := 0 + for ; iterator.Valid() && i < int(maxRetrieve); iterator.Next() { + withdrawal, err := iterator.Value() + if err != nil { + return nil, err + } + withdrawals = append(withdrawals, withdrawal) + i++ + } + + return withdrawals[:i], nil // trim if the array length < maxRetrieve +} diff --git a/client/x/evmstaking/keeper/staking_queue_test.go b/client/x/evmstaking/keeper/staking_queue_test.go index 923a5e44..a9db79f1 100644 --- a/client/x/evmstaking/keeper/staking_queue_test.go +++ b/client/x/evmstaking/keeper/staking_queue_test.go @@ -1,6 +1,5 @@ package keeper_test -/* import ( "context" "time" @@ -53,12 +52,16 @@ func (s *TestSuite) TestGetMatureUnbondedDelegations() { tcs := []struct { name string + preRun func(c context.Context) setUnbondings func(c context.Context) expectedResult []stypes.DVPair expectedError string }{ { name: "pass: no matured unbondings", + preRun: func(c context.Context) { + // s.BankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) + }, setUnbondings: func(c context.Context) { s.setupUnbonding(c, delAddr, valAddr1, "100") s.setupUnbonding(c, delAddr, valAddr2, "100") @@ -67,6 +70,9 @@ func (s *TestSuite) TestGetMatureUnbondedDelegations() { }, { name: "pass: one matured and one not matured unbonding", + preRun: func(c context.Context) { + // s.BankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) + }, setUnbondings: func(c context.Context) { s.setupMatureUnbonding(c, delAddr, valAddr1, "100", ubdTime) s.setupUnbonding(c, delAddr, valAddr2, "100") @@ -77,6 +83,9 @@ func (s *TestSuite) TestGetMatureUnbondedDelegations() { }, { name: "pass: two matured unbondings", + preRun: func(c context.Context) { + // s.BankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) + }, setUnbondings: func(c context.Context) { s.setupMatureUnbonding(c, delAddr, valAddr1, "100", ubdTime) s.setupMatureUnbonding(c, delAddr, valAddr2, "100", ubdTime) @@ -91,6 +100,9 @@ func (s *TestSuite) TestGetMatureUnbondedDelegations() { for _, tc := range tcs { s.Run(tc.name, func() { cachedCtx, _ := ctx.CacheContext() + if tc.preRun != nil { + tc.preRun(cachedCtx) + } if tc.setUnbondings != nil { tc.setUnbondings(cachedCtx) } @@ -107,4 +119,3 @@ func (s *TestSuite) TestGetMatureUnbondedDelegations() { }) } } -*/ diff --git a/client/x/evmstaking/keeper/validator_test.go b/client/x/evmstaking/keeper/validator_test.go index f5baca59..69e02a68 100644 --- a/client/x/evmstaking/keeper/validator_test.go +++ b/client/x/evmstaking/keeper/validator_test.go @@ -1,65 +1,33 @@ package keeper_test -/* import ( "math/big" "testing" "cosmossdk.io/math" - sdkmath "cosmossdk.io/math" "github.com/cometbft/cometbft/crypto" sdk "github.com/cosmos/cosmos-sdk/types" - skeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/testutil" - stypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/common" gethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/piplabs/story/client/x/evmstaking/types" "github.com/piplabs/story/contracts/bindings" - "github.com/piplabs/story/lib/errors" "github.com/piplabs/story/lib/k1util" - - "go.uber.org/mock/gomock" ) func (s *TestSuite) TestProcessCreateValidator() { require := s.Require() - ctx, eskeeper, stakingKeeper, accountKeeper, bankKeeper := s.Ctx, s.EVMStakingKeeper, s.StakingKeeper, s.AccountKeeper, s.BankKeeper + ctx, eskeeper := s.Ctx, s.EVMStakingKeeper - pubKeys, addrs, valAddrs := createAddresses(3) + pubKeys, _, _ := createAddresses(3) uncmpPubKey0 := cmpToUncmp(pubKeys[0].Bytes()) - uncmpPubKey1 := cmpToUncmp(pubKeys[1].Bytes()) - uncmpPubKey2 := cmpToUncmp(pubKeys[2].Bytes()) corruptedPubKey := append([]byte{}, uncmpPubKey0...) - corruptedPubKey[0] = 0x04 + corruptedPubKey[0] = 0x09 corruptedPubKey[1] = 0xFF - tokens10 := stakingKeeper.TokensFromConsensusPower(ctx, 10) - - // checkDelegatorMapAndValidator checks if the delegator map and validator are created - checkDelegatorMapAndValidator := func(c sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, delEvmAddr common.Address, _ math.Int) { - val, err := eskeeper.DelegatorMap.Get(c, delAddr.String()) - require.NoError(err) - require.Equal(delEvmAddr.String(), val) - // check validator is created - _, err = stakingKeeper.GetValidator(c, valAddr) - require.NoError(err) - } - // checkDelegatorMapAndValTokens checks if the delegator map and validator tokens are added - checkDelegatorMapAndValTokens := func(c sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress, delEvmAddr common.Address, previousValTokens math.Int) { - val, err := eskeeper.DelegatorMap.Get(c, delAddr.String()) - require.NoError(err) - require.Equal(delEvmAddr.String(), val) - // check validator tokens are added - validator, err := stakingKeeper.GetValidator(c, valAddr) - require.NoError(err) - require.True(validator.Tokens.GT(previousValTokens)) - } - tcs := []struct { name string valDelAddr sdk.AccAddress @@ -76,135 +44,17 @@ func (s *TestSuite) TestProcessCreateValidator() { { name: "fail: nil validator pubkey", valUncmpPubKey: nil, - expectedError: "validator pubkey to cosmos", + expectedError: "compress validator pubkey: invalid uncompressed public key length or format", }, { name: "fail: invalid validator pubkey", valUncmpPubKey: uncmpPubKey0[1:], - expectedError: "validator pubkey to cosmos", - }, - // { - // name: "fail: corrupted validator pubkey", - // valUncmpPubKey: corruptedPubKey, - // expectedError: "validator pubkey to evm address", - // }, - { - name: "fail: mint coins", - valDelAddr: addrs[0], - valUncmpPubKey: uncmpPubKey0, - preRun: func(_ *testing.T, _ sdk.Context, valDelAddr sdk.AccAddress, _ crypto.PubKey, _ math.Int) { - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(errors.New("mint coins")) - }, - expectedError: "create stake coin for depositor: mint coins", - }, - { - name: "fail: send coins from module to account", - valDelAddr: addrs[0], - valUncmpPubKey: uncmpPubKey0, - preRun: func(_ *testing.T, _ sdk.Context, valDelAddr sdk.AccAddress, _ crypto.PubKey, _ math.Int) { - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, valDelAddr, gomock.Any()).Return(errors.New("send coins")) - }, - expectedError: "create stake coin for depositor: mint coins", - }, - { - name: "pass: new validator & existing delegator", - valDelAddr: addrs[2], - valAddr: valAddrs[2], - valUncmpPubKey: uncmpPubKey2, - valPubKey: pubKeys[2], - preRun: func(_ *testing.T, _ sdk.Context, valDelAddr sdk.AccAddress, _ crypto.PubKey, _ math.Int) { - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, valDelAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), valDelAddr, gomock.Any(), gomock.Any()).Return(nil) - }, - postCheck: checkDelegatorMapAndValidator, + expectedError: "compress validator pubkey: invalid uncompressed public key length or format", }, { - name: "pass: new validator & existing delegator & default moniker", - valDelAddr: addrs[2], - valAddr: valAddrs[2], - valUncmpPubKey: uncmpPubKey2, - valPubKey: pubKeys[2], - moniker: "validator", - preRun: func(_ *testing.T, _ sdk.Context, valDelAddr sdk.AccAddress, _ crypto.PubKey, _ math.Int) { - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, valDelAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), valDelAddr, gomock.Any(), gomock.Any()).Return(nil) - }, - postCheck: checkDelegatorMapAndValidator, - }, - { - name: "pass: new validator & new delegator", - valDelAddr: addrs[1], - valAddr: valAddrs[1], - valUncmpPubKey: uncmpPubKey1, - valPubKey: pubKeys[1], - preRun: func(_ *testing.T, _ sdk.Context, valDelAddr sdk.AccAddress, _ crypto.PubKey, _ math.Int) { - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(false) - accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), valDelAddr).Return(nil) - accountKeeper.EXPECT().SetAccount(gomock.Any(), gomock.Any()) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, valDelAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), valDelAddr, gomock.Any(), gomock.Any()).Return(nil) - }, - postCheck: checkDelegatorMapAndValidator, - }, - { - name: "pass: existing validator & delegator", - valDelAddr: addrs[1], - valAddr: valAddrs[1], - valUncmpPubKey: uncmpPubKey1, - valPubKey: pubKeys[1], - valTokens: tokens10, - preRun: func(t *testing.T, c sdk.Context, valDelAddr sdk.AccAddress, valPubKey crypto.PubKey, _ math.Int) { - t.Helper() - // create a validator with valTokens - valAddr := sdk.ValAddress(valPubKey.Address().Bytes()) - pubKey, err := k1util.PubKeyToCosmos(valPubKey) - require.NoError(err) - val := testutil.NewValidator(t, valAddr, pubKey) - validator, _, _ := val.AddTokensFromDel(tokens10, sdkmath.LegacyOneDec()) - s.BankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) - _ = skeeper.TestingUpdateValidator(stakingKeeper, c, validator, true) - - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(true) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, valDelAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), valDelAddr, gomock.Any(), gomock.Any()).Return(nil) - }, - postCheck: checkDelegatorMapAndValTokens, - }, - { - name: "pass: existing validator & new delegator", - valDelAddr: addrs[1], - valAddr: valAddrs[1], - valUncmpPubKey: uncmpPubKey1, - valPubKey: pubKeys[1], - valTokens: tokens10, - preRun: func(t *testing.T, c sdk.Context, valDelAddr sdk.AccAddress, valPubKey crypto.PubKey, valTokens math.Int) { - t.Helper() - // create a validator - valAddr := sdk.ValAddress(valPubKey.Address().Bytes()) - pubKey, err := k1util.PubKeyToCosmos(valPubKey) - require.NoError(err) - val := testutil.NewValidator(t, valAddr, pubKey) - validator, _, _ := val.AddTokensFromDel(valTokens, sdkmath.LegacyOneDec()) - s.BankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.NotBondedPoolName, stypes.BondedPoolName, gomock.Any()) - _ = skeeper.TestingUpdateValidator(stakingKeeper, c, validator, true) - - accountKeeper.EXPECT().HasAccount(gomock.Any(), valDelAddr).Return(false) - accountKeeper.EXPECT().NewAccountWithAddress(gomock.Any(), valDelAddr).Return(nil) - accountKeeper.EXPECT().SetAccount(gomock.Any(), gomock.Any()) - bankKeeper.EXPECT().MintCoins(gomock.Any(), types.ModuleName, gomock.Any()).Return(nil) - bankKeeper.EXPECT().SendCoinsFromModuleToAccount(gomock.Any(), types.ModuleName, valDelAddr, gomock.Any()).Return(nil) - bankKeeper.EXPECT().DelegateCoinsFromAccountToModule(gomock.Any(), valDelAddr, gomock.Any(), gomock.Any()).Return(nil) - }, - postCheck: checkDelegatorMapAndValTokens, + name: "fail: corrupted validator pubkey", + valUncmpPubKey: corruptedPubKey, + expectedError: "validator pubkey to evm address: invalid public key", }, } @@ -277,4 +127,3 @@ func (s *TestSuite) TestParseCreateValidatorLog() { }) } } -*/ diff --git a/client/x/evmstaking/keeper/withdraw_test.go b/client/x/evmstaking/keeper/withdraw_test.go index c12621e7..178d1b23 100644 --- a/client/x/evmstaking/keeper/withdraw_test.go +++ b/client/x/evmstaking/keeper/withdraw_test.go @@ -1,264 +1,26 @@ package keeper_test -/* -func (s *TestSuite) TestExpectedPartialWithdrawals() { - require := s.Require() - ctx, keeper, stakingKeeper, distrKeeper := s.Ctx, s.EVMStakingKeeper, s.StakingKeeper, s.DistrKeeper - - pubKeys, accAddrs, valAddrs := createAddresses(3) - delAddr := accAddrs[0] - delPubKey := pubKeys[0] - evmDelAddr, err := k1util.CosmosPubkeyToEVMAddress(delPubKey.Bytes()) - require.NoError(err) - valPubKey := pubKeys[1] - valAddr := valAddrs[1] - valPubKey2 := pubKeys[2] - valAddr2 := valAddrs[2] - - valTokens := stakingKeeper.TokensFromConsensusPower(ctx, 10) - s.setupValidatorAndDelegation(ctx, valPubKey, delPubKey, valAddr, delAddr, valTokens) - // set params as default - params := types.DefaultParams() - require.NoError(keeper.SetParams(ctx, params)) - delRewardsAmt := params.MinPartialWithdrawalAmount + 100 - delRewards := sdk.NewDecCoinsFromCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, int64(delRewardsAmt))) - - // Test cases for ExpectedPartialWithdrawals - tcs := []struct { - name string - preRun func(ctx sdk.Context) - expectedResult []types.Withdrawal - expectedError string - }{ - { - name: "pass", - preRun: func(_ sdk.Context) { - distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil) - distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), nil) - distrKeeper.EXPECT().CalculateDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, nil) - }, - expectedResult: []types.Withdrawal{ - { - DelegatorAddress: delAddr.String(), - ValidatorAddress: valAddr.String(), - ExecutionAddress: evmDelAddr.String(), - Amount: delRewardsAmt, - }, - { - name: "pass: val sweep index is out of bounds, so it should be reset to 0 which is the index of the first validator", - preRun: func(_ sdk.Context) { - require.NoError(keeper.SetValidatorSweepIndex(ctx, uint64(100), uint64(0))) - distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil) - distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), nil) - distrKeeper.EXPECT().CalculateDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, nil) - }, - expectedResult: []types.Withdrawal{ - { - DelegatorAddress: delAddr.String(), - ValidatorAddress: valAddr.String(), - ExecutionAddress: evmDelAddr.String(), - Amount: delRewardsAmt, - }, - { - name: "fail: increment validator period", - preRun: func(_ sdk.Context) { - distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil) - distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), errors.New("failed to increment validator period")) - }, - expectedError: "failed to increment validator period", - }, - { - name: "fail: calculate delegation rewards", - preRun: func(_ sdk.Context) { - distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil) - distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), nil) - distrKeeper.EXPECT().CalculateDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, errors.New("failed to calculate delegation rewards")) - }, - expectedError: "failed to calculate delegation rewards", - }, - { - name: "pass: multiple validators", - preRun: func(c sdk.Context) { - s.setupValidatorAndDelegation(c, valPubKey2, delPubKey, valAddr2, delAddr, valTokens) - distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil).Times(2) - distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), nil).Times(2) - distrKeeper.EXPECT().CalculateDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, nil).Times(2) - }, - expectedResult: []types.Withdrawal{ - { - DelegatorAddress: delAddr.String(), - ValidatorAddress: valAddr.String(), - ExecutionAddress: evmDelAddr.String(), - Amount: delRewardsAmt, - }, - { - DelegatorAddress: delAddr.String(), - ValidatorAddress: valAddr2.String(), - ExecutionAddress: evmDelAddr.String(), - Amount: delRewardsAmt, - }, - { - name: "pass: skip jailed validator", - preRun: func(c sdk.Context) { - s.setupValidatorAndDelegation(c, valPubKey2, delPubKey, valAddr2, delAddr, valTokens) - val, err := stakingKeeper.GetValidator(c, valAddr2) - require.NoError(err) - val.Jailed = true - require.NoError(stakingKeeper.SetValidator(c, val)) - - distrKeeper.EXPECT().GetValidatorAccumulatedCommission(gomock.Any(), gomock.Any()).Return(dtypes.ValidatorAccumulatedCommission{}, nil) - distrKeeper.EXPECT().IncrementValidatorPeriod(gomock.Any(), gomock.Any()).Return(uint64(0), nil) - distrKeeper.EXPECT().CalculateDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, nil) - }, - expectedResult: []types.Withdrawal{ - { - DelegatorAddress: delAddr.String(), - ValidatorAddress: valAddr.String(), - ExecutionAddress: evmDelAddr.String(), - Amount: delRewardsAmt, - }, - } - - for _, tc := range tcs { - s.Run(tc.name, func() { - cached, _ := ctx.CacheContext() - if tc.preRun != nil { - tc.preRun(cached) - } - result, err := keeper.ExpectedPartialWithdrawals(cached) - if tc.expectedError != "" { - require.ErrorContains(err, tc.expectedError) - } else { - require.NoError(err) - isEqualWithdrawals(s.T(), tc.expectedResult, result) - } - }) - } - -func (s *TestSuite) TestEnqueueEligiblePartialWithdrawal() { - require := s.Require() - ctx, keeper, bankKeeper, distrKeeper := s.Ctx, s.EVMStakingKeeper, s.BankKeeper, s.DistrKeeper +import ( + "math" + "math/big" - pubKeys, accAddrs, valAddrs := createAddresses(2) - // delegator - delPubKey := pubKeys[0] - delAddr := accAddrs[0] - delValAddr := valAddrs[0] // delegator and validator are the same - delEvmAddr, err := k1util.CosmosPubkeyToEVMAddress(delPubKey.Bytes()) - require.NoError(err) - // validator - valAddr := valAddrs[1] + stypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" - // Test cases for EnqueueEligiblePartialWithdrawal - tcs := []struct { - name string - settingMock func(delRewards sdk.Coins) - input func() []types.Withdrawal - expectedError string - }{ - { - name: "fail: empty validator address", - input: func() []types.Withdrawal { return []types.Withdrawal{{ValidatorAddress: ""}} }, - expectedError: "validator address from bech32", - }, - { - name: "fail: invalid validator address", - settingMock: func(_ sdk.Coins) { - distrKeeper.EXPECT().WithdrawDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil, dtypes.ErrEmptyDelegationDistInfo) - }, - input: func() []types.Withdrawal { - return []types.Withdrawal{ - {ValidatorAddress: valAddr.String(), DelegatorAddress: delAddr.String(), Amount: 100}, - } - }, - expectedError: dtypes.ErrEmptyDelegationDistInfo.Error(), - }, - { - name: "fail: validator and delegator are the same, but failed to withdraw commission", - settingMock: func(delRewards sdk.Coins) { - distrKeeper.EXPECT().WithdrawDelegationRewards(gomock.Any(), gomock.Any(), gomock.Any()).Return(delRewards, nil) - distrKeeper.EXPECT().WithdrawValidatorCommission(gomock.Any(), gomock.Any()).Return(sdk.NewCoins(), errors.New("failed to withdraw commission")) - }, - input: func() []types.Withdrawal { - return []types.Withdrawal{ - { - CreationHeight: 0, - DelegatorAddress: delAddr.String(), - ValidatorAddress: delValAddr.String(), - ExecutionAddress: delEvmAddr.String(), - Amount: 100, - }, - } - }, - expectedError: "failed to withdraw commission", - }, - { - name: "pass: valid input", - settingMock: func(delRewards sdk.Coins) { - distrKeeper.EXPECT().WithdrawDelegationRewards(gomock.Any(), delAddr, valAddr).Return(delRewards, nil) - bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), delAddr, types.ModuleName, delRewards).Return(nil) - bankKeeper.EXPECT().BurnCoins(gomock.Any(), types.ModuleName, delRewards).Return(nil) - }, - input: func() []types.Withdrawal { - return []types.Withdrawal{ - { - CreationHeight: 0, - DelegatorAddress: delAddr.String(), - ValidatorAddress: valAddr.String(), - ExecutionAddress: delEvmAddr.String(), - Amount: 100, - }, - } - }, - { - name: "pass: validator and delegator are the same", - settingMock: func(delRewards sdk.Coins) { - distrKeeper.EXPECT().WithdrawDelegationRewards(gomock.Any(), delAddr, delValAddr).Return(delRewards, nil) - distrKeeper.EXPECT().WithdrawValidatorCommission(gomock.Any(), delValAddr).Return(sdk.NewCoins(), nil) - bankKeeper.EXPECT().SendCoinsFromAccountToModule(gomock.Any(), delAddr, types.ModuleName, delRewards).Return(nil) - bankKeeper.EXPECT().BurnCoins(gomock.Any(), types.ModuleName, delRewards).Return(nil) - }, - input: func() []types.Withdrawal { - return []types.Withdrawal{ - { - CreationHeight: 0, - DelegatorAddress: delAddr.String(), - ValidatorAddress: delValAddr.String(), - ExecutionAddress: delEvmAddr.String(), - Amount: 100, - }, - } - }, - } + "github.com/piplabs/story/client/x/evmstaking/types" + "github.com/piplabs/story/contracts/bindings" +) - for _, tc := range tcs { - s.Run(tc.name, func() { - input := tc.input() - coinsExpectedToWithdraw := sdk.NewCoins( - sdk.NewCoin( - sdk.DefaultBondDenom, - sdkmath.NewInt(int64(input[0].Amount)), - ), - ) - if tc.settingMock != nil { - tc.settingMock(coinsExpectedToWithdraw) - } - cachedCtx, _ := ctx.CacheContext() - err := keeper.EnqueueEligiblePartialWithdrawal(cachedCtx, tc.input()) - if tc.expectedError != "" { - require.ErrorContains(err, tc.expectedError) - } else { - require.NoError(err) - withdrawals, err := keeper.GetAllWithdrawals(cachedCtx) - require.NoError(err) - isEqualWithdrawals(s.T(), tc.input(), withdrawals) - } - }) - } +// TODO: Test for ExpectedUnbondingWithdrawals +// TODO: Test for ProcessUnbondingWithdrawals +// TODO: Test for ProcessRewardWithdrawals +// TODO: Test for ProcessEligibleRewardWithdrawal +// TODO: Test for EnqueueRewardWithdrawal func (s *TestSuite) TestProcessWithdraw() { require := s.Require() - ctx, keeper, accountKeeper, bankKeeper, stakingKeeper := s.Ctx, s.EVMStakingKeeper, s.AccountKeeper, s.BankKeeper, s.StakingKeeper + ctx, keeper, stakingKeeper := s.Ctx, s.EVMStakingKeeper, s.StakingKeeper pubKeys, accAddrs, valAddrs := createAddresses(4) // delegator-1 @@ -273,18 +35,17 @@ func (s *TestSuite) TestProcessWithdraw() { valTokens := stakingKeeper.TokensFromConsensusPower(ctx, 10) s.setupValidatorAndDelegation(ctx, valPubKey, delPubKey1, valAddr, delAddr1, valTokens) + singularityHeight, err := stakingKeeper.GetSingularityHeight(ctx) + require.NoError(err) + tcs := []struct { name string - settingMock func() withdraw *bindings.IPTokenStakingWithdraw expectedErr string }{ + // TODO: test cases before and after singularity height { name: "pass: valid input", - settingMock: func() { - accountKeeper.EXPECT().HasAccount(gomock.Any(), delAddr1).Return(true) - bankKeeper.EXPECT().SendCoinsFromModuleToModule(gomock.Any(), stypes.BondedPoolName, stypes.NotBondedPoolName, gomock.Any()) - }, withdraw: &bindings.IPTokenStakingWithdraw{ DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()), ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()), @@ -292,6 +53,7 @@ func (s *TestSuite) TestProcessWithdraw() { DelegationId: big.NewInt(0), OperatorAddress: cmpToEVM(delPubKey1.Bytes()), }, + }, { name: "fail: invalid delegator pubkey", withdraw: &bindings.IPTokenStakingWithdraw{ @@ -314,33 +76,9 @@ func (s *TestSuite) TestProcessWithdraw() { }, expectedErr: "invalid uncompressed public key length or format", }, - { - name: "fail: corrupted delegator pubkey", - withdraw: &bindings.IPTokenStakingWithdraw{ - DelegatorUncmpPubkey: createCorruptedPubKey(cmpToUncmp(delPubKey1.Bytes())), - ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()), - StakeAmount: new(big.Int).SetUint64(1), - DelegationId: big.NewInt(0), - OperatorAddress: cmpToEVM(delPubKey1.Bytes()), - }, - expectedErr: "invalid uncompressed public key length or format", - }, - { - name: "fail: corrupted validator pubkey", - withdraw: &bindings.IPTokenStakingWithdraw{ - DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()), - ValidatorUncmpPubkey: createCorruptedPubKey(cmpToUncmp(valPubKey.Bytes())), - StakeAmount: new(big.Int).SetUint64(1), - DelegationId: big.NewInt(0), - OperatorAddress: cmpToEVM(delPubKey1.Bytes()), - }, - expectedErr: "invalid uncompressed public key length or format", - }, + // TODO corrupted delegator and validator pubkey { name: "fail: unknown depositor", - settingMock: func() { - accountKeeper.EXPECT().HasAccount(gomock.Any(), sdk.AccAddress(unknownPubKey.Address().Bytes())).Return(false).Times(1) - }, withdraw: &bindings.IPTokenStakingWithdraw{ DelegatorUncmpPubkey: cmpToUncmp(unknownPubKey.Bytes()), ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()), @@ -350,11 +88,9 @@ func (s *TestSuite) TestProcessWithdraw() { }, expectedErr: "depositor account not found", }, + // Intuitive behavior is to fail but instead, max share is withdrawn (100% of delegator's stake amount) { - name: "fail: amount to withdraw is greater than the delegation amount", - settingMock: func() { - accountKeeper.EXPECT().HasAccount(gomock.Any(), sdk.AccAddress(delPubKey1.Address().Bytes())).Return(true).Times(1) - }, + name: "pass: withdraw amount exceeds the delegation amount, results in max share withdrawal", withdraw: &bindings.IPTokenStakingWithdraw{ DelegatorUncmpPubkey: cmpToUncmp(delPubKey1.Bytes()), ValidatorUncmpPubkey: cmpToUncmp(valPubKey.Bytes()), @@ -362,19 +98,18 @@ func (s *TestSuite) TestProcessWithdraw() { DelegationId: big.NewInt(0), OperatorAddress: cmpToEVM(delPubKey1.Bytes()), }, - expectedErr: "invalid shares amount", }, } for _, tc := range tcs { s.Run(tc.name, func() { - if tc.settingMock != nil { - tc.settingMock() - } cachedCtx, _ := ctx.CacheContext() + cachedCtx = cachedCtx.WithBlockHeight(int64(singularityHeight) + 1) + require.Equal(singularityHeight+1, uint64(cachedCtx.BlockHeight())) + // check undelegation does not exist _, err := s.StakingKeeper.GetUnbondingDelegation(cachedCtx, delAddr1, valAddr) - require.ErrorContains(err, "no unbonding delegation found") + require.ErrorContains(err, stypes.ErrNoUnbondingDelegation.Error()) err = keeper.ProcessWithdraw(cachedCtx, tc.withdraw) if tc.expectedErr != "" { @@ -388,6 +123,7 @@ func (s *TestSuite) TestProcessWithdraw() { } }) } +} func (s *TestSuite) TestParseWithdraw() { require := s.Require() @@ -424,23 +160,4 @@ func (s *TestSuite) TestParseWithdraw() { } }) } - -// isEqualWithdrawals compares two slices of Withdrawal without considering order. -func isEqualWithdrawals(t *testing.T, expected, actual []types.Withdrawal) { - t.Helper() - require.Len(t, actual, len(expected)) - // compare it without considering order - for _, e := range expected { - found := false - for _, a := range actual { - if e.DelegatorAddress == a.DelegatorAddress && - e.ValidatorAddress == a.ValidatorAddress && - e.ExecutionAddress == a.ExecutionAddress && - e.Amount == a.Amount { - found = true - break - } - if !found { - t.Errorf("expected %+v not found in %+v", e, actual) - } -*/ +} diff --git a/client/x/evmstaking/keeper/withdrawal_queue.go b/client/x/evmstaking/keeper/withdrawal_queue.go index a8300fb2..ddfdce43 100644 --- a/client/x/evmstaking/keeper/withdrawal_queue.go +++ b/client/x/evmstaking/keeper/withdrawal_queue.go @@ -89,7 +89,7 @@ func (k Keeper) PeekEligibleWithdrawals(ctx context.Context, maxPeek uint32) (wi return withdrawals, nil } -// GetAllWithdrawals gets the set of all withdrawals with no limits. +// GetAllWithdrawals gets the set of all stake withdrawals with no limits. func (k Keeper) GetAllWithdrawals(ctx context.Context) (withdrawals []types.Withdrawal, err error) { iterator, err := k.WithdrawalQueue.Iterate(ctx) if err != nil { diff --git a/client/x/evmstaking/testutil/expected_keepers_mocks.go b/client/x/evmstaking/testutil/expected_keepers_mocks.go index 6a62dd4e..7a66b57e 100644 --- a/client/x/evmstaking/testutil/expected_keepers_mocks.go +++ b/client/x/evmstaking/testutil/expected_keepers_mocks.go @@ -11,6 +11,7 @@ package testutil import ( context "context" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" reflect "reflect" time "time" @@ -31,6 +32,36 @@ type MockAccountKeeper struct { isgomock struct{} } +func (m *MockAccountKeeper) NewAccount(ctx context.Context, i types0.AccountI) types0.AccountI { + //TODO implement me + panic("implement me") +} + +func (m *MockAccountKeeper) GetAllAccounts(ctx context.Context) []types0.AccountI { + //TODO implement me + panic("implement me") +} + +func (m *MockAccountKeeper) ValidatePermissions(macc types0.ModuleAccountI) error { + //TODO implement me + panic("implement me") +} + +func (m *MockAccountKeeper) GetModuleAddressAndPermissions(moduleName string) (addr types0.AccAddress, permissions []string) { + //TODO implement me + panic("implement me") +} + +func (m *MockAccountKeeper) GetModuleAccountAndPermissions(ctx context.Context, moduleName string) (types0.ModuleAccountI, []string) { + //TODO implement me + panic("implement me") +} + +func (m *MockAccountKeeper) GetModulePermissions() map[string]authtypes.PermissionsForAddress { + //TODO implement me + panic("implement me") +} + // MockAccountKeeperMockRecorder is the mock recorder for MockAccountKeeper. type MockAccountKeeperMockRecorder struct { mock *MockAccountKeeper