diff --git a/tests/e2e/chain.go b/tests/e2e/chain.go index eea8e46b35d..9a978903f45 100644 --- a/tests/e2e/chain.go +++ b/tests/e2e/chain.go @@ -10,10 +10,12 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + tmrand "github.com/tendermint/tendermint/libs/rand" + gaia "github.com/cosmos/gaia/v8/app" "github.com/cosmos/gaia/v8/app/params" - tmrand "github.com/tendermint/tendermint/libs/rand" ) const ( @@ -40,6 +42,7 @@ func init() { ) authvesting.RegisterInterfaces(encodingConfig.InterfaceRegistry) + evidencetypes.RegisterInterfaces(encodingConfig.InterfaceRegistry) cdc = encodingConfig.Codec } diff --git a/tests/e2e/e2e_evidence_test.go b/tests/e2e/e2e_evidence_test.go new file mode 100644 index 00000000000..7dbf3f8ced0 --- /dev/null +++ b/tests/e2e/e2e_evidence_test.go @@ -0,0 +1,29 @@ +package e2e + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/x/evidence/exported" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" +) + +func (s *IntegrationTestSuite) TestEvidence() { + s.Run("test evidence queries", func() { + var ( + valIdx = 0 + chain = s.chainA + chainAPI = fmt.Sprintf("http://%s", s.valResources[chain.id][valIdx].GetHostPort("1317/tcp")) + ) + res, err := queryAllEvidence(chainAPI) + s.Require().NoError(err) + s.Require().Equal(numberOfEvidences, len(res.Evidence)) + for _, evidence := range res.Evidence { + var exportedEvidence exported.Evidence + err := cdc.UnpackAny(evidence, &exportedEvidence) + s.Require().NoError(err) + eq, ok := exportedEvidence.(*evidencetypes.Equivocation) + s.Require().True(ok) + s.execQueryEvidence(chain, valIdx, eq.Hash().String()) + } + }) +} diff --git a/tests/e2e/e2e_exec_test.go b/tests/e2e/e2e_exec_test.go index d71ceda677b..28b6903972c 100644 --- a/tests/e2e/e2e_exec_test.go +++ b/tests/e2e/e2e_exec_test.go @@ -13,13 +13,15 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" grouptypes "github.com/cosmos/cosmos-sdk/x/group" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - icamauth "github.com/cosmos/gaia/v8/x/icamauth/types" "github.com/ory/dockertest/v3/docker" + + icamauth "github.com/cosmos/gaia/v8/x/icamauth/types" ) const ( @@ -72,8 +74,8 @@ func (s *IntegrationTestSuite) execVestingTx( s.T().Logf("%s - Executing gaiad %s with %v", c.id, method, args) gaiaCommand := []string{ gaiadBinary, - "tx", - "vesting", + txCommand, + vestingtypes.ModuleName, method, "-y", } @@ -732,7 +734,7 @@ func (s *IntegrationTestSuite) registerICA(owner, connectionID string) { s.executeGaiaTxCommand(ctx, s.chainA, registerICAcmd, 0, s.defaultExecValidation(s.chainA, 0)) - s.T().Logf("%s reigstered an interchain account on chain %s from chain %s", owner, s.chainB.id, s.chainA.id) + s.T().Logf("%s registered an interchain account on chain %s from chain %s", owner, s.chainB.id, s.chainA.id) } func (s *IntegrationTestSuite) executeGaiaTxCommand(ctx context.Context, c *chain, gaiaCommand []string, valIdx int, validation func([]byte, []byte) bool) { diff --git a/tests/e2e/e2e_query_test.go b/tests/e2e/e2e_query_test.go new file mode 100644 index 00000000000..fc16ba84c3e --- /dev/null +++ b/tests/e2e/e2e_query_test.go @@ -0,0 +1,30 @@ +package e2e + +import ( + "context" + "time" + + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" +) + +func (s *IntegrationTestSuite) execQueryEvidence(c *chain, valIdx int, hash string) (res evidencetypes.Equivocation) { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + s.T().Logf("querying evidence %s on chain %s", hash, c.id) + + gaiaCommand := []string{ + gaiadBinary, + queryCommand, + evidencetypes.ModuleName, + hash, + } + + s.executeGaiaTxCommand(ctx, c, gaiaCommand, valIdx, func(stdOut []byte, stdErr []byte) bool { + // TODO parse evidence after fix the SDK + // https://github.com/cosmos/cosmos-sdk/issues/13444 + // s.Require().NoError(yaml.Unmarshal(stdOut, &res)) + return true + }) + return res +} diff --git a/tests/e2e/e2e_setup_test.go b/tests/e2e/e2e_setup_test.go index efb691fd373..7ced75ce4d9 100644 --- a/tests/e2e/e2e_setup_test.go +++ b/tests/e2e/e2e_setup_test.go @@ -15,8 +15,10 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client/flags" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/server" srvconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,12 +27,12 @@ import ( authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" gov "github.com/cosmos/cosmos-sdk/x/gov/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/group" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/cosmos/gaia/v8/app/params" ibcclienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" ibcchanneltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" "github.com/ory/dockertest/v3" @@ -41,11 +43,14 @@ import ( tmjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/rand" rpchttp "github.com/tendermint/tendermint/rpc/client/http" + + "github.com/cosmos/gaia/v8/app/params" ) const ( gaiadBinary = "gaiad" txCommand = "tx" + queryCommand = "query" keysCommand = "keys" gaiaHomePath = "/home/nonroot/.gaia" photonDenom = "photon" @@ -61,6 +66,7 @@ const ( govProposalBlockBuffer = 35 relayerAccountIndex = 0 icaOwnerAccountIndex = 1 + numberOfEvidences = 10 ) var ( @@ -75,30 +81,12 @@ var ( proposalCounter = 0 govSendMsgRecipientAddress = Address() sendGovAmount = sdk.NewInt64Coin(uatomDenom, 10) - fundGovAmount = sdk.NewInt64Coin(uatomDenom, 1000) proposalSendMsg = &govtypes.MsgSubmitProposal{ InitialDeposit: sdk.Coins{depositAmount}, Metadata: b64.StdEncoding.EncodeToString([]byte("Testing 1, 2, 3!")), } ) -type UpgradePlan struct { - Name string `json:"name"` - Height int `json:"height"` - Info string `json:"info"` -} - -type SoftwareUpgrade struct { - Type string `json:"@type"` - Authority string `json:"authority"` - Plan UpgradePlan `json:"plan"` -} - -type CancelSoftwareUpgrade struct { - Type string `json:"@type"` - Authority string `json:"authority"` -} - type IntegrationTestSuite struct { suite.Suite @@ -352,6 +340,25 @@ func (s *IntegrationTestSuite) initGenesis(c *chain, vestingMnemonic string) { appGenState[authtypes.ModuleName] = authGenState appGenState[banktypes.ModuleName] = bankGenState + var evidenceGenState evidencetypes.GenesisState + s.Require().NoError(cdc.UnmarshalJSON(appGenState[evidencetypes.ModuleName], &evidenceGenState)) + + evidenceGenState.Evidence = make([]*codectypes.Any, numberOfEvidences) + for i := range evidenceGenState.Evidence { + pk := ed25519.GenPrivKey() + evidence := &evidencetypes.Equivocation{ + Height: 1, + Power: 100, + Time: time.Now().UTC(), + ConsensusAddress: sdk.ConsAddress(pk.PubKey().Address().Bytes()).String(), + } + evidenceGenState.Evidence[i], err = codectypes.NewAnyWithValue(evidence) + s.Require().NoError(err) + } + + appGenState[evidencetypes.ModuleName], err = cdc.MarshalJSON(&evidenceGenState) + s.Require().NoError(err) + var genUtilGenState genutiltypes.GenesisState s.Require().NoError(cdc.UnmarshalJSON(appGenState[genutiltypes.ModuleName], &genUtilGenState)) diff --git a/tests/e2e/query.go b/tests/e2e/query.go index 2ec8ea82c21..a875dc85087 100644 --- a/tests/e2e/query.go +++ b/tests/e2e/query.go @@ -12,9 +12,11 @@ import ( authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/group" staketypes "github.com/cosmos/cosmos-sdk/x/staking/types" + globalfee "github.com/cosmos/gaia/v8/x/globalfee/types" icamauth "github.com/cosmos/gaia/v8/x/icamauth/types" ) @@ -312,3 +314,29 @@ func queryPeriodicVestingAccount(endpoint, address string) (authvesting.Periodic } return *acc, nil } + +func queryEvidence(endpoint, hash string) (evidencetypes.QueryEvidenceResponse, error) { + var res evidencetypes.QueryEvidenceResponse + body, err := httpGet(fmt.Sprintf("%s/cosmos/evidence/v1beta1/evidence/%s", endpoint, hash)) + if err != nil { + return res, err + } + + if err = cdc.UnmarshalJSON(body, &res); err != nil { + return res, err + } + return res, nil +} + +func queryAllEvidence(endpoint string) (evidencetypes.QueryAllEvidenceResponse, error) { + var res evidencetypes.QueryAllEvidenceResponse + body, err := httpGet(fmt.Sprintf("%s/cosmos/evidence/v1beta1/evidence", endpoint)) + if err != nil { + return res, err + } + + if err = cdc.UnmarshalJSON(body, &res); err != nil { + return res, err + } + return res, nil +}