Skip to content

Commit

Permalink
Add a test for 07-tendermint's GetTimestampAtHeight (cosmos#4972)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
  • Loading branch information
DimitrisJim and crodriguezvega committed Oct 30, 2023
1 parent f6594f6 commit fc764dc
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions modules/light-clients/07-tendermint/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,71 @@ func (suite *TendermintTestSuite) TestStatus() {
}
}

func (suite *TendermintTestSuite) TestGetTimestampAtHeight() {
var (
path *ibctesting.Path
height exported.Height
)
expectedTimestamp := time.Unix(1, 0)

testCases := []struct {
name string
malleate func()
expErr error
}{
{
"success",
func() {},
nil,
},
{
"failure: consensus state not found for height",
func() {
clientState := path.EndpointA.GetClientState()
height = clientState.GetLatestHeight().Increment()
},
clienttypes.ErrConsensusStateNotFound,
},
}

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

path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupClients(path)

clientState := path.EndpointA.GetClientState()
height = clientState.GetLatestHeight()

store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)

// grab consensusState from store and update with a predefined timestamp
consensusState := path.EndpointA.GetConsensusState(height)
tmConsensusState, ok := consensusState.(*ibctm.ConsensusState)
suite.Require().True(ok)

tmConsensusState.Timestamp = expectedTimestamp
path.EndpointA.SetConsensusState(tmConsensusState, height)

tc.malleate()

timestamp, err := clientState.GetTimestampAtHeight(suite.chainA.GetContext(), store, suite.chainA.Codec, height)

expPass := tc.expErr == nil
if expPass {
suite.Require().NoError(err)

expectedTimestamp := uint64(expectedTimestamp.UnixNano())
suite.Require().Equal(expectedTimestamp, timestamp)
} else {
suite.Require().ErrorIs(err, tc.expErr)
}
})
}
}

func (suite *TendermintTestSuite) TestValidate() {
testCases := []struct {
name string
Expand Down

0 comments on commit fc764dc

Please sign in to comment.