parent
20f7cd7aac
commit
b2feec158f
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/api/cometbft/types/v1"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"cosmossdk.io/x/staking"
|
||||
stakingtypes "cosmossdk.io/x/staking/types"
|
||||
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -41,9 +43,25 @@ func (app *SimApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAd
|
||||
}
|
||||
|
||||
validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
|
||||
cmtValidators := []cmttypes.GenesisValidator{}
|
||||
for _, val := range validators {
|
||||
cmtPk, err := cryptocodec.ToCmtPubKeyInterface(val.PubKey)
|
||||
if err != nil {
|
||||
return servertypes.ExportedApp{}, err
|
||||
}
|
||||
cmtVal := cmttypes.GenesisValidator{
|
||||
Address: val.Address.Bytes(),
|
||||
PubKey: cmtPk,
|
||||
Power: val.Power,
|
||||
Name: val.Name,
|
||||
}
|
||||
|
||||
cmtValidators = append(cmtValidators, cmtVal)
|
||||
}
|
||||
|
||||
return servertypes.ExportedApp{
|
||||
AppState: appState,
|
||||
Validators: validators,
|
||||
Validators: cmtValidators,
|
||||
Height: height,
|
||||
ConsensusParams: app.BaseApp.GetConsensusParams(ctx),
|
||||
}, err
|
||||
|
||||
@ -27,9 +27,9 @@ func NewMockCometRPC(respQuery abci.QueryResponse) MockCometRPC {
|
||||
return MockCometRPC{responseQuery: respQuery}
|
||||
}
|
||||
|
||||
// NewMockCometRPCWithValue returns a mock CometBFT RPC implementation with value only.
|
||||
// NewMockCometRPCWithResponseQueryValue returns a mock CometBFT RPC implementation with value only.
|
||||
// It is used for CLI testing.
|
||||
func NewMockCometRPCWithValue(bz []byte) MockCometRPC {
|
||||
func NewMockCometRPCWithResponseQueryValue(bz []byte) MockCometRPC {
|
||||
return MockCometRPC{responseQuery: abci.QueryResponse{
|
||||
Value: bz,
|
||||
}}
|
||||
@ -47,3 +47,80 @@ func (m MockCometRPC) ABCIQueryWithOptions(
|
||||
) (*coretypes.ResultABCIQuery, error) {
|
||||
return &coretypes.ResultABCIQuery{Response: m.responseQuery}, nil
|
||||
}
|
||||
|
||||
type FilterTxsFn = func(query string, start, end int) ([][]byte, error)
|
||||
|
||||
type MockCometTxSearchRPC struct {
|
||||
rpcclientmock.Client
|
||||
|
||||
txConfig client.TxConfig
|
||||
txs []cmttypes.Tx
|
||||
filterTxsFn FilterTxsFn
|
||||
}
|
||||
|
||||
func (m MockCometTxSearchRPC) Txs() []cmttypes.Tx {
|
||||
return m.txs
|
||||
}
|
||||
|
||||
// accept [][]byte so that module that use this for testing dont have to import comet directly
|
||||
func (m *MockCometTxSearchRPC) WithTxs(txs [][]byte) {
|
||||
cmtTxs := make([]cmttypes.Tx, len(txs))
|
||||
for i, tx := range txs {
|
||||
cmtTxs[i] = tx
|
||||
}
|
||||
m.txs = cmtTxs
|
||||
}
|
||||
|
||||
func (m *MockCometTxSearchRPC) WithTxConfig(cfg client.TxConfig) {
|
||||
m.txConfig = cfg
|
||||
}
|
||||
|
||||
func (m *MockCometTxSearchRPC) WithFilterTxsFn(fn FilterTxsFn) {
|
||||
m.filterTxsFn = fn
|
||||
}
|
||||
|
||||
func (MockCometTxSearchRPC) BroadcastTxSync(context.Context, cmttypes.Tx) (*coretypes.ResultBroadcastTx, error) {
|
||||
return &coretypes.ResultBroadcastTx{Code: 0}, nil
|
||||
}
|
||||
|
||||
func (mock MockCometTxSearchRPC) TxSearch(ctx context.Context, query string, prove bool, page, perPage *int, orderBy string) (*coretypes.ResultTxSearch, error) {
|
||||
if page == nil {
|
||||
*page = 0
|
||||
}
|
||||
|
||||
if perPage == nil {
|
||||
*perPage = 0
|
||||
}
|
||||
|
||||
start, end := client.Paginate(len(mock.txs), *page, *perPage, 100)
|
||||
if start < 0 || end < 0 {
|
||||
// nil result with nil error crashes utils.QueryTxsByEvents
|
||||
return &coretypes.ResultTxSearch{}, nil
|
||||
}
|
||||
|
||||
var txs []cmttypes.Tx
|
||||
if mock.filterTxsFn != nil {
|
||||
filterTxs, err := mock.filterTxsFn(query, start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmtTxs := make([]cmttypes.Tx, len(filterTxs))
|
||||
for i, tx := range filterTxs {
|
||||
cmtTxs[i] = tx
|
||||
}
|
||||
txs = append(txs, cmtTxs...)
|
||||
} else {
|
||||
txs = mock.txs[start:end]
|
||||
}
|
||||
|
||||
rst := &coretypes.ResultTxSearch{Txs: make([]*coretypes.ResultTx, len(txs)), TotalCount: len(txs)}
|
||||
for i := range txs {
|
||||
rst.Txs[i] = &coretypes.ResultTx{Tx: txs[i]}
|
||||
}
|
||||
return rst, nil
|
||||
}
|
||||
|
||||
func (mock MockCometTxSearchRPC) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
|
||||
return &coretypes.ResultBlock{Block: &cmttypes.Block{}}, nil
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ func (s *CLITestSuite) TestTxInitCmd() {
|
||||
Response: sdk.MsgTypeURL(&types.Empty{})[1:],
|
||||
},
|
||||
})
|
||||
c := clitestutil.NewMockCometRPCWithValue(bz)
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
s.clientCtx = ctxGen()
|
||||
|
||||
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@ -117,7 +116,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
|
||||
|
||||
suite.clientCtx = client.Context{}.
|
||||
WithTxConfig(suite.encCfg.TxConfig).
|
||||
WithClient(clitestutil.NewMockCometRPC(abci.QueryResponse{}))
|
||||
WithClient(clitestutil.NewMockCometRPCWithResponseQueryValue(nil))
|
||||
|
||||
anteHandler, err := ante.NewAnteHandler(
|
||||
ante.HandlerOptions{
|
||||
|
||||
@ -68,7 +68,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPCWithValue(bz)
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
s.clientCtx = ctxGen()
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@ -44,7 +43,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithClient(clitestutil.MockCometRPC{}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithAddressCodec(addresscodec.NewBech32Codec("cosmos")).
|
||||
|
||||
@ -13,7 +13,7 @@ require (
|
||||
cosmossdk.io/math v1.3.0
|
||||
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6 // main
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f // indirect
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||
github.com/cosmos/cosmos-sdk v0.52.0
|
||||
github.com/cosmos/gogoproto v1.7.0
|
||||
|
||||
@ -7,8 +7,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@ -69,7 +67,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithClient(clitestutil.MockCometRPC{}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain").
|
||||
@ -79,9 +77,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPC(abci.QueryResponse{
|
||||
Value: bz,
|
||||
})
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ require (
|
||||
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6
|
||||
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91
|
||||
cosmossdk.io/x/gov v0.0.0-20230925135524-a1bc045b3190
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f // indirect
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||
github.com/cosmos/cosmos-sdk v0.52.0
|
||||
github.com/cosmos/gogoproto v1.7.0
|
||||
@ -58,7 +58,7 @@ require (
|
||||
github.com/cockroachdb/redact v1.1.5 // indirect
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/cometbft/cometbft-db v0.15.0 // indirect
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1 // indirect
|
||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||
github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect
|
||||
github.com/cosmos/crypto v0.1.2 // indirect
|
||||
|
||||
@ -7,8 +7,6 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@ -48,16 +46,14 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithClient(clitestutil.MockCometRPC{}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain")
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPC(abci.QueryResponse{
|
||||
Value: bz,
|
||||
})
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
s.clientCtx = ctxGen()
|
||||
|
||||
@ -6,8 +6,6 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@ -50,7 +48,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithClient(clitestutil.MockCometRPC{}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain").
|
||||
@ -60,9 +58,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPC(abci.QueryResponse{
|
||||
Value: bz,
|
||||
})
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
s.clientCtx = ctxGen()
|
||||
|
||||
@ -1,15 +1,11 @@
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cometbft/cometbft/rpc/client/mock"
|
||||
coretypes "github.com/cometbft/cometbft/rpc/core/types"
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
@ -20,100 +16,73 @@ import (
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
|
||||
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
)
|
||||
|
||||
type TxSearchMock struct {
|
||||
txConfig client.TxConfig
|
||||
mock.Client
|
||||
txs []cmttypes.Tx
|
||||
clitestutil.MockCometTxSearchRPC
|
||||
|
||||
// use for filter tx with query conditions
|
||||
msgsSet [][]sdk.Msg
|
||||
}
|
||||
|
||||
func (mock TxSearchMock) TxSearch(ctx context.Context, query string, _ bool, page, perPage *int, _ string) (*coretypes.ResultTxSearch, error) {
|
||||
if page == nil {
|
||||
*page = 0
|
||||
}
|
||||
|
||||
if perPage == nil {
|
||||
*perPage = 0
|
||||
}
|
||||
|
||||
start, end := client.Paginate(len(mock.txs), *page, *perPage, 100)
|
||||
if start < 0 || end < 0 {
|
||||
// nil result with nil error crashes utils.QueryTxsByEvents
|
||||
return &coretypes.ResultTxSearch{}, nil
|
||||
}
|
||||
txs, err := mock.filterTxs(query, start, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rst := &coretypes.ResultTxSearch{Txs: make([]*coretypes.ResultTx, len(txs)), TotalCount: len(txs)}
|
||||
for i := range txs {
|
||||
rst.Txs[i] = &coretypes.ResultTx{Tx: txs[i]}
|
||||
}
|
||||
return rst, nil
|
||||
}
|
||||
|
||||
func (mock TxSearchMock) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) {
|
||||
// any non nil Block needs to be returned. used to get time value
|
||||
return &coretypes.ResultBlock{Block: &cmttypes.Block{}}, nil
|
||||
}
|
||||
|
||||
// mock applying the query string in TxSearch
|
||||
func (mock TxSearchMock) filterTxs(query string, start, end int) ([]cmttypes.Tx, error) {
|
||||
filterTxs := []cmttypes.Tx{}
|
||||
proposalIdStr, senderAddr := getQueryAttributes(query)
|
||||
if senderAddr != "" {
|
||||
proposalId, err := strconv.ParseUint(proposalIdStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func filterTxs(mock *TxSearchMock) clitestutil.FilterTxsFn {
|
||||
return func(query string, start, end int) ([][]byte, error) {
|
||||
filterTxs := [][]byte{}
|
||||
proposalIdStr, senderAddr := getQueryAttributes(query)
|
||||
txs := mock.Txs()
|
||||
if senderAddr != "" {
|
||||
proposalId, err := strconv.ParseUint(proposalIdStr, 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i, msgs := range mock.msgsSet {
|
||||
for _, msg := range msgs {
|
||||
if voteMsg, ok := msg.(*v1beta1.MsgVote); ok {
|
||||
if voteMsg.Voter == senderAddr && voteMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, mock.txs[i])
|
||||
continue
|
||||
for i, msgs := range mock.msgsSet {
|
||||
for _, msg := range msgs {
|
||||
if voteMsg, ok := msg.(*v1beta1.MsgVote); ok {
|
||||
if voteMsg.Voter == senderAddr && voteMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, txs[i])
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if voteMsg, ok := msg.(*v1.MsgVote); ok {
|
||||
if voteMsg.Voter == senderAddr && voteMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, mock.txs[i])
|
||||
continue
|
||||
if voteMsg, ok := msg.(*v1.MsgVote); ok {
|
||||
if voteMsg.Voter == senderAddr && voteMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, txs[i])
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if voteWeightedMsg, ok := msg.(*v1beta1.MsgVoteWeighted); ok {
|
||||
if voteWeightedMsg.Voter == senderAddr && voteWeightedMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, mock.txs[i])
|
||||
continue
|
||||
if voteWeightedMsg, ok := msg.(*v1beta1.MsgVoteWeighted); ok {
|
||||
if voteWeightedMsg.Voter == senderAddr && voteWeightedMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, txs[i])
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if voteWeightedMsg, ok := msg.(*v1.MsgVoteWeighted); ok {
|
||||
if voteWeightedMsg.Voter == senderAddr && voteWeightedMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, mock.txs[i])
|
||||
continue
|
||||
if voteWeightedMsg, ok := msg.(*v1.MsgVoteWeighted); ok {
|
||||
if voteWeightedMsg.Voter == senderAddr && voteWeightedMsg.ProposalId == proposalId {
|
||||
filterTxs = append(filterTxs, txs[i])
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, tx := range txs {
|
||||
filterTxs = append(filterTxs, tx)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filterTxs = append(filterTxs, mock.txs...)
|
||||
}
|
||||
|
||||
if len(filterTxs) < end {
|
||||
return filterTxs, nil
|
||||
}
|
||||
if len(filterTxs) < end {
|
||||
return filterTxs, nil
|
||||
}
|
||||
|
||||
return filterTxs[start:end], nil
|
||||
return filterTxs[start:end], nil
|
||||
}
|
||||
}
|
||||
|
||||
// getQueryAttributes extracts value from query string
|
||||
@ -227,11 +196,9 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
marshaled := make([]cmttypes.Tx, len(tc.msgs))
|
||||
cli := TxSearchMock{txs: marshaled, txConfig: encCfg.TxConfig}
|
||||
marshaled := make([][]byte, len(tc.msgs))
|
||||
clientCtx := client.Context{}.
|
||||
WithLegacyAmino(encCfg.Amino).
|
||||
WithClient(cli).
|
||||
WithTxConfig(encCfg.TxConfig)
|
||||
|
||||
for i := range tc.msgs {
|
||||
@ -244,6 +211,12 @@ func TestGetPaginatedVotes(t *testing.T) {
|
||||
marshaled[i] = tx
|
||||
}
|
||||
|
||||
cli := &TxSearchMock{msgsSet: tc.msgs}
|
||||
cli.WithTxs(marshaled)
|
||||
cli.WithTxConfig(encCfg.TxConfig)
|
||||
cli.WithFilterTxsFn(filterTxs(cli))
|
||||
clientCtx = clientCtx.WithClient(cli)
|
||||
|
||||
params := utils.QueryProposalVotesParams{0, tc.page, tc.limit}
|
||||
votesData, err := utils.QueryVotesByTxQuery(clientCtx, params)
|
||||
require.NoError(t, err)
|
||||
@ -328,11 +301,9 @@ func TestGetSingleVote(t *testing.T) {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
marshaled := make([]cmttypes.Tx, len(tc.msgs))
|
||||
cli := TxSearchMock{txs: marshaled, txConfig: encCfg.TxConfig, msgsSet: tc.msgs}
|
||||
marshaled := make([][]byte, len(tc.msgs))
|
||||
clientCtx := client.Context{}.
|
||||
WithLegacyAmino(encCfg.Amino).
|
||||
WithClient(cli).
|
||||
WithTxConfig(encCfg.TxConfig).
|
||||
WithAddressCodec(cdcOpts.GetAddressCodec()).
|
||||
WithCodec(encCfg.Codec)
|
||||
@ -347,6 +318,12 @@ func TestGetSingleVote(t *testing.T) {
|
||||
marshaled[i] = tx
|
||||
}
|
||||
|
||||
cli := &TxSearchMock{msgsSet: tc.msgs}
|
||||
cli.WithTxs(marshaled)
|
||||
cli.WithTxConfig(encCfg.TxConfig)
|
||||
cli.WithFilterTxsFn(filterTxs(cli))
|
||||
clientCtx = clientCtx.WithClient(cli)
|
||||
|
||||
// testing query single vote
|
||||
for i, v := range tc.votes {
|
||||
accAddr, err := clientCtx.AddressCodec.StringToBytes(v.Voter)
|
||||
|
||||
@ -16,7 +16,7 @@ require (
|
||||
cosmossdk.io/x/protocolpool v0.0.0-20230925135524-a1bc045b3190
|
||||
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000
|
||||
github.com/chzyer/readline v1.5.1
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f // indirect
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||
github.com/cosmos/cosmos-sdk v0.52.0
|
||||
github.com/cosmos/gogoproto v1.7.0
|
||||
|
||||
@ -7,8 +7,6 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
// without this import amino json encoding will fail when resolving any types
|
||||
@ -56,7 +54,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithClient(clitestutil.MockCometRPC{}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain").
|
||||
@ -77,9 +75,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPC(abci.QueryResponse{
|
||||
Value: bz,
|
||||
})
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
s.clientCtx = ctxGen()
|
||||
|
||||
@ -18,8 +18,6 @@ require (
|
||||
cosmossdk.io/x/mint v0.0.0-00010101000000-000000000000
|
||||
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000
|
||||
github.com/cockroachdb/apd/v2 v2.0.2
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1
|
||||
github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||
github.com/cosmos/cosmos-sdk v0.52.0
|
||||
@ -64,7 +62,9 @@ require (
|
||||
github.com/cockroachdb/pebble v1.1.2 // indirect
|
||||
github.com/cockroachdb/redact v1.1.5 // indirect
|
||||
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f // indirect
|
||||
github.com/cometbft/cometbft-db v0.15.0 // indirect
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1 // indirect
|
||||
github.com/cosmos/btcutil v1.0.5 // indirect
|
||||
github.com/cosmos/crypto v0.1.2 // indirect
|
||||
github.com/cosmos/go-bip39 v1.0.0 // indirect
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
"github.com/golang/mock/gomock"
|
||||
|
||||
"cosmossdk.io/core/header"
|
||||
@ -1852,7 +1851,7 @@ func (s *TestSuite) TestSubmitProposal() {
|
||||
s.Require().Contains(fromBalances, sdk.NewInt64Coin("test", 9900))
|
||||
toBalances := s.bankKeeper.GetAllBalances(sdkCtx, addr2)
|
||||
s.Require().Contains(toBalances, sdk.NewInt64Coin("test", 100))
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().True(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
},
|
||||
@ -1996,7 +1995,7 @@ func (s *TestSuite) TestWithdrawProposal() {
|
||||
timeDiff := vpe.Sub(s.sdkCtx.HeaderInfo().Time)
|
||||
ctxVPE := sdkCtx.WithHeaderInfo(header.Info{Time: s.sdkCtx.HeaderInfo().Time.Add(timeDiff).Add(time.Second * 1)})
|
||||
s.Require().NoError(s.groupKeeper.TallyProposalsAtVPEnd(ctxVPE))
|
||||
events := ctxVPE.EventManager().ABCIEvents()
|
||||
events := ctxVPE.EventManager().Events()
|
||||
|
||||
s.Require().True(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
@ -2576,7 +2575,7 @@ func (s *TestSuite) TestExecProposal() {
|
||||
expFromBalances: sdk.NewInt64Coin("test", 9900),
|
||||
expToBalances: sdk.NewInt64Coin("test", 100),
|
||||
postRun: func(sdkCtx sdk.Context) {
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().True(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
},
|
||||
@ -2594,7 +2593,7 @@ func (s *TestSuite) TestExecProposal() {
|
||||
expFromBalances: sdk.NewInt64Coin("test", 9800),
|
||||
expToBalances: sdk.NewInt64Coin("test", 200),
|
||||
postRun: func(sdkCtx sdk.Context) {
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().True(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
},
|
||||
@ -2607,7 +2606,7 @@ func (s *TestSuite) TestExecProposal() {
|
||||
expProposalStatus: group.PROPOSAL_STATUS_REJECTED,
|
||||
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_NOT_RUN,
|
||||
postRun: func(sdkCtx sdk.Context) {
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().False(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
},
|
||||
@ -2618,7 +2617,7 @@ func (s *TestSuite) TestExecProposal() {
|
||||
expProposalStatus: group.PROPOSAL_STATUS_SUBMITTED,
|
||||
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_NOT_RUN,
|
||||
postRun: func(sdkCtx sdk.Context) {
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().False(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
},
|
||||
@ -2676,7 +2675,7 @@ func (s *TestSuite) TestExecProposal() {
|
||||
expProposalStatus: group.PROPOSAL_STATUS_ACCEPTED,
|
||||
expExecutorResult: group.PROPOSAL_EXECUTOR_RESULT_SUCCESS,
|
||||
postRun: func(sdkCtx sdk.Context) {
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().True(eventTypeFound(events, EventProposalPruned))
|
||||
},
|
||||
},
|
||||
@ -2962,7 +2961,7 @@ func (s *TestSuite) TestExecPrunedProposalsAndVotes() {
|
||||
res, err := s.groupKeeper.VotesByProposal(sdkCtx, &group.QueryVotesByProposalRequest{ProposalId: proposalID})
|
||||
s.Require().NoError(err)
|
||||
s.Require().Empty(res.GetVotes())
|
||||
events := sdkCtx.EventManager().ABCIEvents()
|
||||
events := sdkCtx.EventManager().Events()
|
||||
s.Require().True(eventTypeFound(events, EventProposalPruned))
|
||||
|
||||
} else {
|
||||
@ -3398,7 +3397,7 @@ func (s *TestSuite) TestExecProposalsWhenMemberLeavesOrIsUpdated() {
|
||||
}
|
||||
}
|
||||
|
||||
func eventTypeFound(events []abci.Event, eventType string) bool {
|
||||
func eventTypeFound(events []sdk.Event, eventType string) bool {
|
||||
eventTypeFound := false
|
||||
for _, e := range events {
|
||||
if e.Type == eventType {
|
||||
|
||||
@ -5,8 +5,6 @@ import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
|
||||
rpcclientmock "github.com/cometbft/cometbft/rpc/client/mock"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
@ -51,7 +49,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
WithKeyring(s.kr).
|
||||
WithTxConfig(s.encCfg.TxConfig).
|
||||
WithCodec(s.encCfg.Codec).
|
||||
WithClient(clitestutil.MockCometRPC{Client: rpcclientmock.Client{}}).
|
||||
WithClient(clitestutil.MockCometRPC{}).
|
||||
WithAccountRetriever(client.MockAccountRetriever{}).
|
||||
WithOutput(io.Discard).
|
||||
WithChainID("test-chain").
|
||||
@ -61,9 +59,7 @@ func (s *CLITestSuite) SetupSuite() {
|
||||
|
||||
ctxGen := func() client.Context {
|
||||
bz, _ := s.encCfg.Codec.Marshal(&sdk.TxResponse{})
|
||||
c := clitestutil.NewMockCometRPC(abci.QueryResponse{
|
||||
Value: bz,
|
||||
})
|
||||
c := clitestutil.NewMockCometRPCWithResponseQueryValue(bz)
|
||||
return s.baseCtx.WithClient(c)
|
||||
}
|
||||
s.clientCtx = ctxGen()
|
||||
|
||||
@ -4,18 +4,28 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
cmttypes "github.com/cometbft/cometbft/types"
|
||||
gogotypes "github.com/cosmos/gogoproto/types"
|
||||
|
||||
"cosmossdk.io/x/staking/keeper"
|
||||
"cosmossdk.io/x/staking/types"
|
||||
|
||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// TODO: move this to sdk types and use this instead of comet types GenesisValidator
|
||||
// then we can do pubkey conversion in ToGenesisDoc
|
||||
//
|
||||
// this is a temporary work around to avoid import comet directly in staking
|
||||
type GenesisValidator struct {
|
||||
Address sdk.ConsAddress
|
||||
PubKey cryptotypes.PubKey
|
||||
Power int64
|
||||
Name string
|
||||
}
|
||||
|
||||
// WriteValidators returns a slice of bonded genesis validators.
|
||||
func WriteValidators(ctx context.Context, keeper *keeper.Keeper) (vals []cmttypes.GenesisValidator, returnErr error) {
|
||||
func WriteValidators(ctx context.Context, keeper *keeper.Keeper) (vals []GenesisValidator, returnErr error) {
|
||||
err := keeper.LastValidatorPower.Walk(ctx, nil, func(key []byte, _ gogotypes.Int64Value) (bool, error) {
|
||||
validator, err := keeper.GetValidator(ctx, key)
|
||||
if err != nil {
|
||||
@ -27,15 +37,10 @@ func WriteValidators(ctx context.Context, keeper *keeper.Keeper) (vals []cmttype
|
||||
returnErr = err
|
||||
return true, err
|
||||
}
|
||||
cmtPk, err := cryptocodec.ToCmtPubKeyInterface(pk)
|
||||
if err != nil {
|
||||
returnErr = err
|
||||
return true, err
|
||||
}
|
||||
|
||||
vals = append(vals, cmttypes.GenesisValidator{
|
||||
Address: sdk.ConsAddress(cmtPk.Address()).Bytes(),
|
||||
PubKey: cmtPk,
|
||||
vals = append(vals, GenesisValidator{
|
||||
Address: sdk.ConsAddress(pk.Address()),
|
||||
PubKey: pk,
|
||||
Power: validator.GetConsensusPower(keeper.PowerReduction(ctx)),
|
||||
Name: validator.GetMoniker(),
|
||||
})
|
||||
|
||||
@ -11,7 +11,7 @@ require (
|
||||
cosmossdk.io/errors v1.0.1
|
||||
cosmossdk.io/math v1.3.0
|
||||
cosmossdk.io/store v1.1.1-0.20240909133312-50288938d1b6
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f
|
||||
github.com/cometbft/cometbft v1.0.0-rc1.0.20240908111210-ab0be101882f // indirect
|
||||
github.com/cometbft/cometbft/api v1.0.0-rc.1
|
||||
github.com/cosmos/cosmos-proto v1.0.0-beta.5
|
||||
github.com/cosmos/cosmos-sdk v0.52.0
|
||||
|
||||
@ -33,8 +33,7 @@ func TestHistoricalKeysMigration(t *testing.T) {
|
||||
logger := coretesting.NewNopLogger()
|
||||
|
||||
type testCase struct {
|
||||
oldKey, newKey []byte
|
||||
historicalInfo []byte
|
||||
oldKey, newKey, historicalInfo []byte
|
||||
}
|
||||
|
||||
testCases := make(map[int64]testCase)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user