|
| 1 | +package client_test |
| 2 | + |
| 3 | +import ( |
| 4 | + sdkmath "cosmossdk.io/math" |
| 5 | + |
| 6 | + sdk "github.com/cosmos/cosmos-sdk/types" |
| 7 | + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" |
| 8 | + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" |
| 9 | + |
| 10 | + client "github.com/cosmos/ibc-go/v8/modules/core/02-client" |
| 11 | + clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" |
| 12 | + ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" |
| 13 | + ibctesting "github.com/cosmos/ibc-go/v8/testing" |
| 14 | +) |
| 15 | + |
| 16 | +func (suite *ClientTestSuite) TestNewClientUpdateProposalHandler() { |
| 17 | + var ( |
| 18 | + content govtypes.Content |
| 19 | + err error |
| 20 | + ) |
| 21 | + |
| 22 | + testCases := []struct { |
| 23 | + name string |
| 24 | + malleate func() |
| 25 | + expPass bool |
| 26 | + }{ |
| 27 | + { |
| 28 | + "valid update client proposal", func() { |
| 29 | + subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) |
| 30 | + suite.coordinator.SetupClients(subjectPath) |
| 31 | + subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID) |
| 32 | + |
| 33 | + substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB) |
| 34 | + suite.coordinator.SetupClients(substitutePath) |
| 35 | + |
| 36 | + // update substitute twice |
| 37 | + err = substitutePath.EndpointA.UpdateClient() |
| 38 | + suite.Require().NoError(err) |
| 39 | + err = substitutePath.EndpointA.UpdateClient() |
| 40 | + suite.Require().NoError(err) |
| 41 | + substituteClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID) |
| 42 | + |
| 43 | + tmClientState, ok := subjectClientState.(*ibctm.ClientState) |
| 44 | + suite.Require().True(ok) |
| 45 | + tmClientState.AllowUpdateAfterMisbehaviour = true |
| 46 | + tmClientState.FrozenHeight = tmClientState.LatestHeight |
| 47 | + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID, tmClientState) |
| 48 | + |
| 49 | + // replicate changes to substitute (they must match) |
| 50 | + tmClientState, ok = substituteClientState.(*ibctm.ClientState) |
| 51 | + suite.Require().True(ok) |
| 52 | + tmClientState.AllowUpdateAfterMisbehaviour = true |
| 53 | + suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID, tmClientState) |
| 54 | + |
| 55 | + content = clienttypes.NewClientUpdateProposal(ibctesting.Title, ibctesting.Description, subjectPath.EndpointA.ClientID, substitutePath.EndpointA.ClientID) |
| 56 | + }, true, |
| 57 | + }, |
| 58 | + { |
| 59 | + "nil proposal", func() { |
| 60 | + content = nil |
| 61 | + }, false, |
| 62 | + }, |
| 63 | + { |
| 64 | + "unsupported proposal type", func() { |
| 65 | + content = &distributiontypes.CommunityPoolSpendProposal{ //nolint:staticcheck |
| 66 | + Title: ibctesting.Title, |
| 67 | + Description: ibctesting.Description, |
| 68 | + Recipient: suite.chainA.SenderAccount.GetAddress().String(), |
| 69 | + Amount: sdk.NewCoins(sdk.NewCoin("communityfunds", sdkmath.NewInt(10))), |
| 70 | + } |
| 71 | + }, false, |
| 72 | + }, |
| 73 | + } |
| 74 | + |
| 75 | + for _, tc := range testCases { |
| 76 | + tc := tc |
| 77 | + |
| 78 | + suite.Run(tc.name, func() { |
| 79 | + suite.SetupTest() // reset |
| 80 | + |
| 81 | + tc.malleate() |
| 82 | + |
| 83 | + proposalHandler := client.NewClientProposalHandler(suite.chainA.App.GetIBCKeeper().ClientKeeper) |
| 84 | + |
| 85 | + err = proposalHandler(suite.chainA.GetContext(), content) |
| 86 | + |
| 87 | + if tc.expPass { |
| 88 | + suite.Require().NoError(err) |
| 89 | + } else { |
| 90 | + suite.Require().Error(err) |
| 91 | + } |
| 92 | + }) |
| 93 | + } |
| 94 | +} |
0 commit comments