Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: require light clients to set initial client and consensus state #2936

Merged
merged 11 commits into from
Dec 15, 2022
Prev Previous commit
Next Next commit
adding tests to lightclients
damiannolan committed Dec 15, 2022
commit 5e896eb171e57ab6ed70e8c0d70f27f19248070f
9 changes: 7 additions & 2 deletions modules/light-clients/06-solomachine/client_state_test.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v6/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
"github.com/cosmos/ibc-go/v6/modules/core/exported"
solomachine "github.com/cosmos/ibc-go/v6/modules/light-clients/06-solomachine"
ibctm "github.com/cosmos/ibc-go/v6/modules/light-clients/07-tendermint"
@@ -125,16 +126,20 @@ func (suite *SoloMachineTestSuite) TestInitialize() {
}

for _, tc := range testCases {
suite.SetupTest()

store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "solomachine")
err := sm.ClientState().Initialize(
suite.chainA.GetContext(), suite.chainA.Codec,
suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "solomachine"),
tc.consState,
store, tc.consState,
)

if tc.expPass {
suite.Require().NoError(err, "valid testcase: %s failed", tc.name)
suite.Require().True(store.Has(host.ClientStateKey()))
} else {
suite.Require().Error(err, "invalid testcase: %s passed", tc.name)
suite.Require().False(store.Has(host.ClientStateKey()))
}
}
}
23 changes: 17 additions & 6 deletions modules/light-clients/07-tendermint/client_state_test.go
Original file line number Diff line number Diff line change
@@ -192,19 +192,30 @@ func (suite *TendermintTestSuite) TestInitialize() {
},
}

path := ibctesting.NewPath(suite.chainA, suite.chainB)
err := path.EndpointA.CreateClient()
suite.Require().NoError(err)
for _, tc := range testCases {
suite.SetupTest()
path := ibctesting.NewPath(suite.chainA, suite.chainB)

clientState := suite.chainA.GetClientState(path.EndpointA.ClientID)
store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)
tmConfig, ok := path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig)
suite.Require().True(ok)

for _, tc := range testCases {
clientState := ibctm.NewClientState(
path.EndpointB.Chain.ChainID,
tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift,
suite.chainB.LastHeader.GetTrustedHeight(), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath,
)

store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)
err := clientState.Initialize(suite.chainA.GetContext(), suite.chainA.Codec, store, tc.consensusState)

if tc.expPass {
suite.Require().NoError(err, "valid case returned an error")
suite.Require().True(store.Has(host.ClientStateKey()))
suite.Require().True(store.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetTrustedHeight())))
} else {
suite.Require().Error(err, "invalid case didn't return an error")
suite.Require().False(store.Has(host.ClientStateKey()))
suite.Require().False(store.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetTrustedHeight())))
}
}
}