diff --git a/x/arkeo/keeper/keeper.go b/x/arkeo/keeper/keeper.go index 0dfe860e..fa3e5389 100644 --- a/x/arkeo/keeper/keeper.go +++ b/x/arkeo/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "strings" "cosmossdk.io/errors" + "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -15,7 +16,6 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/libs/log" "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" @@ -55,7 +55,7 @@ type Keeper interface { // passthrough funcs SendCoins(ctx cosmos.Context, from, to cosmos.AccAddress, coins cosmos.Coins) error AddCoins(ctx cosmos.Context, addr cosmos.AccAddress, coins cosmos.Coins) error - GetActiveValidators(ctx cosmos.Context) []stakingtypes.Validator + GetActiveValidators(ctx cosmos.Context) ([]stakingtypes.Validator, error) GetAccount(ctx cosmos.Context, addr cosmos.AccAddress) cosmos.Account StakingSetParams(ctx cosmos.Context, params stakingtypes.Params) @@ -168,9 +168,13 @@ func (k KVStore) SetParams(ctx sdk.Context, params types.Params) { k.paramstore.SetParamSet(ctx, ¶ms) } +// TODO: Check Thi Again func (k KVStore) GetComputedVersion(ctx cosmos.Context) int64 { versions := make(map[int64]int64) // maps are safe in blockchains, but should be okay in this case - validators := k.stakingKeeper.GetBondedValidatorsByPower(ctx) + validators, err := k.stakingKeeper.GetBondedValidatorsByPower(ctx) + if err != nil { + k.Logger(ctx).Error(err.Error()) + } // if there is only one validator, no need for consensus. Just return the // validator's current version. This also helps makes @@ -187,7 +191,12 @@ func (k KVStore) GetComputedVersion(ctx cosmos.Context) int64 { if !val.IsBonded() { continue } - ver := k.GetVersionForAddress(ctx, val.GetOperator()) + + valBz, err := k.stakingKeeper.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + k.Logger(ctx).Error(err.Error()) + } + ver := k.GetVersionForAddress(ctx, valBz) if _, ok := versions[ver]; !ok { versions[ver] = 0 } @@ -334,7 +343,7 @@ func (k KVStore) GetAccount(ctx cosmos.Context, addr cosmos.AccAddress) cosmos.A return k.accountKeeper.GetAccount(ctx, addr) } -func (k KVStore) GetActiveValidators(ctx cosmos.Context) []stakingtypes.Validator { +func (k KVStore) GetActiveValidators(ctx cosmos.Context) ([]stakingtypes.Validator, error) { return k.stakingKeeper.GetBondedValidatorsByPower(ctx) } diff --git a/x/arkeo/keeper/keeper_dummy.go b/x/arkeo/keeper/keeper_dummy.go index a4928092..750ed2e5 100644 --- a/x/arkeo/keeper/keeper_dummy.go +++ b/x/arkeo/keeper/keeper_dummy.go @@ -9,12 +9,12 @@ import ( "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/x/arkeo/types" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/libs/log" ) var kaboom = errors.New("Kaboom!!!") diff --git a/x/arkeo/keeper/keeper_test.go b/x/arkeo/keeper/keeper_test.go index fed4ec3c..e13d2ccd 100644 --- a/x/arkeo/keeper/keeper_test.go +++ b/x/arkeo/keeper/keeper_test.go @@ -3,39 +3,43 @@ package keeper import ( "testing" + arekoappParams "github.com/arkeonetwork/arkeo/app/params" "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" "github.com/arkeonetwork/arkeo/testutil/utils" "github.com/arkeonetwork/arkeo/x/arkeo/types" + "github.com/cosmos/cosmos-sdk/runtime" "github.com/stretchr/testify/require" + "cosmossdk.io/log" "cosmossdk.io/store" storetypes "cosmossdk.io/store/types" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + tmdb "github.com/cosmos/cosmos-db" sdk "github.com/cosmos/cosmos-sdk/types" + authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" 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" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmdb "github.com/tendermint/tm-db" ) func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { - storeKey := sdk.NewKVStoreKey(types.StoreKey) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) keyAcc := cosmos.NewKVStoreKey(authtypes.StoreKey) keyBank := cosmos.NewKVStoreKey(banktypes.StoreKey) keyStake := cosmos.NewKVStoreKey(stakingtypes.StoreKey) keyParams := cosmos.NewKVStoreKey(typesparams.StoreKey) tkeyParams := cosmos.NewTransientStoreKey(typesparams.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) - + logger := log.NewNopLogger() db := tmdb.NewMemDB() - stateStore := store.NewCommitMultiStore(db) + stateStore := store.NewCommitMultiStore(db, logger, nil) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(keyAcc, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(keyBank, storetypes.StoreTypeIAVL, db) @@ -44,7 +48,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) require.NoError(t, stateStore.LoadLatestVersion()) - encodingConfig := MakeTestEncodingConfig() + encodingConfig := arekoappParams.MakeEncodingConfig() types.RegisterInterfaces(encodingConfig.InterfaceRegistry) cdc := utils.MakeTestMarshaler() amino := encodingConfig.Amino @@ -58,21 +62,45 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - pk := paramskeeper.NewKeeper(cdc, amino, keyParams, tkeyParams) - ak := authkeeper.NewAccountKeeper(cdc, keyAcc, pk.Subspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, map[string][]string{ - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - types.ModuleName: {authtypes.Minter, authtypes.Burner}, - types.ReserveName: {}, - types.ProviderName: {}, - types.ContractName: {}, - }, sdk.Bech32PrefixAccAddr) - ak.SetParams(ctx, authtypes.DefaultParams()) - - bk := bankkeeper.NewBaseKeeper(cdc, keyBank, ak, pk.Subspace(banktypes.ModuleName), nil) + _ = paramskeeper.NewKeeper(cdc, amino, keyParams, tkeyParams) + govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String() + ak := authkeeper.NewAccountKeeper( + cdc, + runtime.NewKVStoreService(keyAcc), + authtypes.ProtoBaseAccount, + map[string][]string{ + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + types.ModuleName: {authtypes.Minter, authtypes.Burner}, + types.ReserveName: {}, + types.ProviderName: {}, + types.ContractName: {}, + }, + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + sdk.Bech32PrefixAccAddr, + govModuleAddr, + ) + + bk := bankkeeper.NewBaseKeeper( + cdc, + runtime.NewKVStoreService(keyBank), + ak, + nil, + govModuleAddr, + logger, + ) bk.SetParams(ctx, banktypes.DefaultParams()) - sk := stakingkeeper.NewKeeper(cdc, keyStake, ak, bk, pk.Subspace(stakingtypes.ModuleName)) + sk := stakingkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keyStake), + ak, + bk, + govModuleAddr, + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + ) + k := NewKVStore( cdc, storeKey, @@ -80,7 +108,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { paramsSubspace, bk, ak, - sk, + *sk, ) k.SetVersion(ctx, common.GetCurrentVersion()) @@ -91,7 +119,7 @@ func SetupKeeper(t testing.TB) (cosmos.Context, Keeper) { } func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper.Keeper) { - storeKey := sdk.NewKVStoreKey(types.StoreKey) + storeKey := storetypes.NewKVStoreKey(types.StoreKey) keyAcc := cosmos.NewKVStoreKey(authtypes.StoreKey) keyBank := cosmos.NewKVStoreKey(banktypes.StoreKey) keyStake := cosmos.NewKVStoreKey(stakingtypes.StoreKey) @@ -99,8 +127,9 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper tkeyParams := cosmos.NewTransientStoreKey(typesparams.TStoreKey) memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey) + logger := log.NewNopLogger() db := tmdb.NewMemDB() - stateStore := store.NewCommitMultiStore(db) + stateStore := store.NewCommitMultiStore(db, logger, nil) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(keyAcc, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(keyBank, storetypes.StoreTypeIAVL, db) @@ -110,7 +139,7 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) require.NoError(t, stateStore.LoadLatestVersion()) - encodingConfig := MakeTestEncodingConfig() + encodingConfig := arekoappParams.MakeEncodingConfig() types.RegisterInterfaces(encodingConfig.InterfaceRegistry) cdc := utils.MakeTestMarshaler() amino := encodingConfig.Amino @@ -124,22 +153,44 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) - pk := paramskeeper.NewKeeper(cdc, amino, keyParams, tkeyParams) - ak := authkeeper.NewAccountKeeper(cdc, keyAcc, pk.Subspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, map[string][]string{ - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - types.ModuleName: {authtypes.Minter, authtypes.Burner}, - types.ReserveName: {}, - types.ProviderName: {}, - types.ContractName: {}, - }, sdk.Bech32PrefixAccAddr) - ak.SetParams(ctx, authtypes.DefaultParams()) - - bk := bankkeeper.NewBaseKeeper(cdc, keyBank, ak, pk.Subspace(banktypes.ModuleName), nil) + govModuleAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String() + _ = paramskeeper.NewKeeper(cdc, amino, keyParams, tkeyParams) + ak := authkeeper.NewAccountKeeper( + cdc, + runtime.NewKVStoreService(keyAcc), + authtypes.ProtoBaseAccount, + map[string][]string{ + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + types.ModuleName: {authtypes.Minter, authtypes.Burner}, + types.ReserveName: {}, + types.ProviderName: {}, + types.ContractName: {}, + }, + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + sdk.Bech32PrefixAccAddr, + govModuleAddr, + ) + + bk := bankkeeper.NewBaseKeeper( + cdc, + runtime.NewKVStoreService(keyBank), + ak, + nil, + govModuleAddr, + logger, + ) bk.SetParams(ctx, banktypes.DefaultParams()) - sk := stakingkeeper.NewKeeper(cdc, keyStake, ak, bk, pk.Subspace(stakingtypes.ModuleName)) - sk.SetParams(ctx, stakingtypes.DefaultParams()) + sk := stakingkeeper.NewKeeper( + cdc, + runtime.NewKVStoreService(keyStake), + ak, + bk, + govModuleAddr, + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), + authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + ) k := NewKVStore( cdc, @@ -148,12 +199,12 @@ func SetupKeeperWithStaking(t testing.TB) (cosmos.Context, Keeper, stakingkeeper paramsSubspace, bk, ak, - sk, + *sk, ) k.SetVersion(ctx, common.GetCurrentVersion()) // Initialize params k.SetParams(ctx, types.DefaultParams()) - return ctx, *k, sk + return ctx, *k, *sk } diff --git a/x/arkeo/keeper/manager.go b/x/arkeo/keeper/manager.go index 0a955c3a..39cd9deb 100644 --- a/x/arkeo/keeper/manager.go +++ b/x/arkeo/keeper/manager.go @@ -4,8 +4,9 @@ import ( "fmt" "cosmossdk.io/errors" + abci "github.com/cometbft/cometbft/abci/types" + cmptm "github.com/cometbft/cometbft/proto/tendermint/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - abci "github.com/tendermint/tendermint/abci/types" "github.com/arkeonetwork/arkeo/common" "github.com/arkeonetwork/arkeo/common/cosmos" @@ -25,7 +26,7 @@ func NewManager(k Keeper, sk stakingkeeper.Keeper) Manager { } } -func (mgr *Manager) BeginBlock(ctx cosmos.Context, req abci.RequestBeginBlock) error { +func (mgr *Manager) BeginBlock(ctx cosmos.Context) error { // if local version is behind the consensus version, panic and don't try to // create a new block ver := mgr.keeper.GetComputedVersion(ctx) @@ -39,7 +40,20 @@ func (mgr *Manager) BeginBlock(ctx cosmos.Context, req abci.RequestBeginBlock) e } mgr.keeper.SetVersion(ctx, ver) // update stored version - if err := mgr.ValidatorPayout(ctx, req.LastCommitInfo.GetVotes()); err != nil { + var votes = []abci.VoteInfo{} + for i := 0; i <= ctx.CometInfo().GetLastCommit().Votes().Len(); i++ { + vote := ctx.CometInfo().GetLastCommit().Votes().Get(0) + abciVote := abci.VoteInfo{ + Validator: abci.Validator{ + Address: vote.Validator().Address(), + Power: vote.Validator().Power(), + }, + BlockIdFlag: cmptm.BlockIDFlag(vote.GetBlockIDFlag()), + } + votes = append(votes, abciVote) + + } + if err := mgr.ValidatorPayout(ctx, votes); err != nil { ctx.Logger().Error("unable to settle contracts", "error", err) } return nil @@ -193,8 +207,8 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er // sum tokens total := cosmos.ZeroInt() for _, vote := range votes { - val := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) - if val == nil { + val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) + if err != nil { ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) continue } @@ -208,22 +222,28 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er } for _, vote := range votes { - if !vote.SignedLastBlock { - ctx.Logger().Info("validator rewards skipped due to lack of signature", "validator", string(vote.Validator.Address)) - continue - } - val := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) - if val == nil { + // if !vote.SignedLastBlock { + // ctx.Logger().Info("validator rewards skipped due to lack of signature", "validator", string(vote.Validator.Address)) + // continue + // } + + val, err := mgr.sk.ValidatorByConsAddr(ctx, vote.Validator.Address) + if err != nil { ctx.Logger().Info("unable to find validator", "validator", string(vote.Validator.Address)) continue } if !val.IsBonded() || val.IsJailed() { - ctx.Logger().Info("validator rewards skipped due to status or jailed", "validator", val.GetOperator().String()) + ctx.Logger().Info("validator rewards skipped due to status or jailed", "validator", val.GetOperator()) continue } - valVersion := mgr.keeper.GetVersionForAddress(ctx, val.GetOperator()) + valBz, err := mgr.sk.ValidatorAddressCodec().StringToBytes(val.GetOperator()) + if err != nil { + panic(err) + } + + valVersion := mgr.keeper.GetVersionForAddress(ctx, valBz) curVersion := mgr.keeper.GetVersion(ctx) if valVersion < curVersion { continue @@ -234,7 +254,11 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er validatorReward := cosmos.ZeroInt() rateBasisPts := val.GetCommission().MulInt64(100).RoundInt() - delegates := mgr.sk.GetValidatorDelegations(ctx, val.GetOperator()) + delegates, err := mgr.sk.GetValidatorDelegations(ctx, valBz) + if err != nil { + panic(err) + } + for _, delegate := range delegates { delegateAcc, err := cosmos.AccAddressFromBech32(delegate.DelegatorAddress) if err != nil { @@ -255,7 +279,7 @@ func (mgr Manager) ValidatorPayout(ctx cosmos.Context, votes []abci.VoteInfo) er if !validatorReward.IsZero() { if err := mgr.keeper.SendFromModuleToAccount(ctx, types.ReserveName, acc, cosmos.NewCoins(cosmos.NewCoin(bal.Denom, validatorReward))); err != nil { - ctx.Logger().Error("unable to pay rewards to validator", "validator", val.GetOperator().String(), "error", err) + ctx.Logger().Error("unable to pay rewards to validator", "validator", val.GetOperator(), "error", err) continue } ctx.Logger().Info("validator additional rewards", "validator", acc.String(), "amount", validatorReward) diff --git a/x/arkeo/keeper/manager_test.go b/x/arkeo/keeper/manager_test.go index ac8a99ff..4a415040 100644 --- a/x/arkeo/keeper/manager_test.go +++ b/x/arkeo/keeper/manager_test.go @@ -9,14 +9,15 @@ import ( "github.com/arkeonetwork/arkeo/x/arkeo/types" "github.com/stretchr/testify/require" + abci "github.com/cometbft/cometbft/abci/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - abci "github.com/tendermint/tendermint/abci/types" ) func TestValidatorPayout(t *testing.T) { ctx, k, sk := SetupKeeperWithStaking(t) - pks := CreateTestPubKeys(3) + pks := simtestutil.CreateTestPubKeys(3) pk1, err := common.NewPubKeyFromCrypto(pks[0]) require.NoError(t, err) acc1, err := pk1.GetMyAddress() @@ -30,23 +31,23 @@ func TestValidatorPayout(t *testing.T) { acc3, err := pk3.GetMyAddress() require.NoError(t, err) - valAddrs := ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) + valAddrs := simtestutil.ConvertAddrsToValAddrs([]cosmos.AccAddress{acc1, acc2, acc3}) - val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{}) + val1, err := stakingtypes.NewValidator(valAddrs[0].String(), pks[0], stakingtypes.Description{}) require.NoError(t, err) val1.Tokens = cosmos.NewInt(100) val1.DelegatorShares = cosmos.NewDec(100 + 10 + 20) val1.Status = stakingtypes.Bonded val1.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(1, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - val2, err := stakingtypes.NewValidator(valAddrs[1], pks[1], stakingtypes.Description{}) + val2, err := stakingtypes.NewValidator(valAddrs[1].String(), pks[1], stakingtypes.Description{}) require.NoError(t, err) val2.Tokens = cosmos.NewInt(200) val2.DelegatorShares = cosmos.NewDec(200 + 20) val2.Status = stakingtypes.Bonded val2.Commission = stakingtypes.NewCommission(cosmos.NewDecWithPrec(2, 1), cosmos.ZeroDec(), cosmos.ZeroDec()) - val3, err := stakingtypes.NewValidator(valAddrs[2], pks[2], stakingtypes.Description{}) + val3, err := stakingtypes.NewValidator(valAddrs[2].String(), pks[2], stakingtypes.Description{}) require.NoError(t, err) val3.Tokens = cosmos.NewInt(500) val3.DelegatorShares = cosmos.NewDec(500) @@ -64,13 +65,13 @@ func TestValidatorPayout(t *testing.T) { delAcc2 := types.GetRandomBech32Addr() delAcc3 := types.GetRandomBech32Addr() - sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1, valAddrs[0], cosmos.NewDec(100))) - sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2, valAddrs[1], cosmos.NewDec(200))) - sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3, valAddrs[2], cosmos.NewDec(500))) + sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc1.String(), valAddrs[0].String(), cosmos.NewDec(100))) + sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc2.String(), valAddrs[1].String(), cosmos.NewDec(200))) + sk.SetDelegation(ctx, stakingtypes.NewDelegation(acc3.String(), valAddrs[2].String(), cosmos.NewDec(500))) - del1 := stakingtypes.NewDelegation(delAcc1, valAddrs[0], cosmos.NewDec(10)) - del2 := stakingtypes.NewDelegation(delAcc2, valAddrs[1], cosmos.NewDec(20)) - del3 := stakingtypes.NewDelegation(delAcc3, valAddrs[2], cosmos.NewDec(20)) + del1 := stakingtypes.NewDelegation(delAcc1.String(), valAddrs[0].String(), cosmos.NewDec(10)) + del2 := stakingtypes.NewDelegation(delAcc2.String(), valAddrs[1].String(), cosmos.NewDec(20)) + del3 := stakingtypes.NewDelegation(delAcc3.String(), valAddrs[2].String(), cosmos.NewDec(20)) sk.SetDelegation(ctx, del1) sk.SetDelegation(ctx, del2) sk.SetDelegation(ctx, del3) @@ -92,10 +93,9 @@ func TestValidatorPayout(t *testing.T) { require.NoError(t, err) votes[i] = abci.VoteInfo{ Validator: abci.Validator{ - Address: consAddr.Bytes(), + Address: consAddr, Power: val.Tokens.Int64(), }, - SignedLastBlock: true, } } diff --git a/x/arkeo/keeper/msg_server_claim_contract_income_test.go b/x/arkeo/keeper/msg_server_claim_contract_income_test.go index aaf7a77e..0e218571 100644 --- a/x/arkeo/keeper/msg_server_claim_contract_income_test.go +++ b/x/arkeo/keeper/msg_server_claim_contract_income_test.go @@ -13,6 +13,7 @@ import ( cKeys "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/stretchr/testify/require" ) @@ -64,7 +65,7 @@ func TestValidate(t *testing.T) { } message := msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) require.NoError(t, s.HandlerClaimContractIncome(ctx, &msg)) @@ -125,7 +126,7 @@ func TestHandlePayAsYouGo(t *testing.T) { } message := msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) require.NoError(t, s.HandlerClaimContractIncome(ctx, &msg)) @@ -141,7 +142,7 @@ func TestHandlePayAsYouGo(t *testing.T) { } message = msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) // repeat the same thing and ensure we don't pay providers twice @@ -155,7 +156,7 @@ func TestHandlePayAsYouGo(t *testing.T) { // update signature for message message = msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) require.NoError(t, s.HandlerClaimContractIncome(ctx, &msg)) @@ -172,7 +173,7 @@ func TestHandlePayAsYouGo(t *testing.T) { // update signature for message message = msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) require.NoError(t, s.HandlerClaimContractIncome(ctx, &msg)) @@ -307,7 +308,7 @@ func TestClaimContractIncomeHandler(t *testing.T) { } message := msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) require.NoError(t, s.HandlerClaimContractIncome(ctx, &msg)) @@ -320,7 +321,7 @@ func TestClaimContractIncomeHandler(t *testing.T) { msg.Nonce = 0 message = msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) // handle claim with bad nonce diff --git a/x/arkeo/keeper/msg_server_open_contract_test.go b/x/arkeo/keeper/msg_server_open_contract_test.go index 3013e4f5..f5a3db7f 100644 --- a/x/arkeo/keeper/msg_server_open_contract_test.go +++ b/x/arkeo/keeper/msg_server_open_contract_test.go @@ -13,6 +13,7 @@ import ( cKeys "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/stretchr/testify/require" ) @@ -339,7 +340,7 @@ func TestOpenContractWithSettlementPeriod(t *testing.T) { Nonce: 20, } message := claimMsg.GetBytesToSign() - claimMsg.Signature, _, err = kb.Sign("whatever", message) + claimMsg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) _, err = s.ClaimContractIncome(ctx, &claimMsg) require.NoError(t, err) diff --git a/x/arkeo/types/message_claim_contract_income_test.go b/x/arkeo/types/message_claim_contract_income_test.go index f0028954..56592c48 100644 --- a/x/arkeo/types/message_claim_contract_income_test.go +++ b/x/arkeo/types/message_claim_contract_income_test.go @@ -16,6 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/types/tx/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -41,7 +42,7 @@ func TestClaimContractIncomeValidateBasic(t *testing.T) { } message := msg.GetBytesToSign() - msg.Signature, _, err = kb.Sign("whatever", message) + msg.Signature, _, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) err = msg.ValidateBasic() require.NoError(t, err) @@ -75,7 +76,7 @@ func TestValidateSignature(t *testing.T) { require.NoError(t, err) message := []byte(fmt.Sprintf("%d:%d", msg.ContractId, msg.Nonce)) - msg.Signature, pub, err = kb.Sign("whatever", message) + msg.Signature, pub, err = kb.Sign("whatever", message, signing.SignMode_SIGN_MODE_DIRECT) require.NoError(t, err) require.True(t, pub.VerifySignature(message, msg.Signature))