add Increment method to Height interface (#8157)

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
This commit is contained in:
Jun Kimura 2020-12-15 21:26:43 +09:00 committed by GitHub
parent 7c1da3d998
commit 039036f1cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 8 additions and 7 deletions

View File

@ -73,7 +73,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
clientID, err = suite.keeper.CreateClient(suite.ctx, clientState, suite.consensusState)
// store intermediate consensus state to check that trustedHeight does not need to be highest consensus state before header height
incrementedClientHeight := testClientHeight.Increment()
incrementedClientHeight := testClientHeight.Increment().(types.Height)
intermediateConsState := &ibctmtypes.ConsensusState{
Timestamp: suite.now.Add(time.Minute),
NextValidatorsHash: suite.valSetHash,

View File

@ -321,7 +321,7 @@ func (suite *KeeperTestSuite) TestQueryConsensusStates() {
// order is swapped because the res is sorted by client id
expConsensusStates = []types.ConsensusStateWithHeight{
types.NewConsensusStateWithHeight(testClientHeight, cs),
types.NewConsensusStateWithHeight(testClientHeight.Increment(), cs2),
types.NewConsensusStateWithHeight(testClientHeight.Increment().(types.Height), cs2),
}
req = &types.QueryConsensusStatesRequest{
ClientId: testClientID,

View File

@ -109,7 +109,7 @@ func (h Height) Decrement() (decremented exported.Height, success bool) {
// Increment will return a height with the same revision number but an
// incremented revision height
func (h Height) Increment() Height {
func (h Height) Increment() exported.Height {
return NewHeight(h.RevisionNumber, h.RevisionHeight+1)
}

View File

@ -210,7 +210,7 @@ func (suite *KeeperTestSuite) TestConnOpenTry() {
// modify counterparty client without setting in store so it still passes validate but fails proof verification
tmClient, ok := counterpartyClient.(*ibctmtypes.ClientState)
suite.Require().True(ok)
tmClient.LatestHeight = tmClient.LatestHeight.Increment()
tmClient.LatestHeight = tmClient.LatestHeight.Increment().(clienttypes.Height)
}, false},
{"consensus state verification failed", func() {
clientA, clientB = suite.coordinator.SetupClients(suite.chainA, suite.chainB, exported.Tendermint)
@ -562,7 +562,7 @@ func (suite *KeeperTestSuite) TestConnOpenAck() {
// modify counterparty client without setting in store so it still passes validate but fails proof verification
tmClient, ok := counterpartyClient.(*ibctmtypes.ClientState)
suite.Require().True(ok)
tmClient.LatestHeight = tmClient.LatestHeight.Increment()
tmClient.LatestHeight = tmClient.LatestHeight.Increment().(clienttypes.Height)
err = suite.coordinator.ConnOpenTry(suite.chainB, suite.chainA, connB, connA)
suite.Require().NoError(err)

View File

@ -204,6 +204,7 @@ type Height interface {
GTE(Height) bool
GetRevisionNumber() uint64
GetRevisionHeight() uint64
Increment() Height
Decrement() (Height, bool)
String() string
}

View File

@ -44,7 +44,7 @@ func (suite *TendermintTestSuite) TestHeaderValidateBasic() {
header.SignedHeader.Commit = nil
}, false},
{"trusted height is greater than header height", func() {
header.TrustedHeight = header.GetHeight().(clienttypes.Height).Increment()
header.TrustedHeight = header.GetHeight().(clienttypes.Height).Increment().(clienttypes.Height)
}, false},
{"validator set nil", func() {
header.ValidatorSet = nil

View File

@ -23,7 +23,7 @@ func (suite *TendermintTestSuite) TestCheckProposedHeaderAndUpdateStateBasic() {
suite.Require().Nil(cs)
suite.Require().Nil(consState)
clientState.LatestHeight = clientState.LatestHeight.Increment()
clientState.LatestHeight = clientState.LatestHeight.Increment().(clienttypes.Height)
// consensus state for latest height does not exist
cs, consState, err = clientState.CheckProposedHeaderAndUpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, suite.chainA.LastHeader)