-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix genesis exporting of tendermint metadata (#210)
* fix genesis exporting of metadata * changelog * Update CHANGELOG.md
- Loading branch information
1 parent
8320447
commit 7a44bf7
Showing
4 changed files
with
95 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 72 additions & 21 deletions
93
modules/light-clients/07-tendermint/types/genesis_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,89 @@ | ||
package types_test | ||
|
||
import ( | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
clienttypes "github.com/cosmos/ibc-go/modules/core/02-client/types" | ||
commitmenttypes "github.com/cosmos/ibc-go/modules/core/23-commitment/types" | ||
"github.com/cosmos/ibc-go/modules/light-clients/07-tendermint/types" | ||
ibctesting "github.com/cosmos/ibc-go/testing" | ||
) | ||
|
||
// expected export ordering: | ||
// processed height and processed time per height | ||
// then all iteration keys | ||
func (suite *TendermintTestSuite) TestExportMetadata() { | ||
clientState := types.NewClientState(chainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false) | ||
suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), "clientA", clientState) | ||
// test intializing client and exporting metadata | ||
path := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupClients(path) | ||
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) | ||
clientState := path.EndpointA.GetClientState() | ||
height := clientState.GetLatestHeight() | ||
|
||
initIteration := types.GetIterationKey(clientStore, height) | ||
suite.Require().NotEqual(0, len(initIteration)) | ||
initProcessedTime, found := types.GetProcessedTime(clientStore, height) | ||
suite.Require().True(found) | ||
initProcessedHeight, found := types.GetProcessedHeight(clientStore, height) | ||
suite.Require().True(found) | ||
|
||
gm := clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)) | ||
suite.Require().NotNil(gm, "client with metadata returned nil exported metadata") | ||
suite.Require().Len(gm, 3, "exported metadata has unexpected length") | ||
|
||
suite.Require().Equal(types.ProcessedHeightKey(height), gm[0].GetKey(), "metadata has unexpected key") | ||
actualProcessedHeight, err := clienttypes.ParseHeight(string(gm[0].GetValue())) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(initProcessedHeight, actualProcessedHeight, "metadata has unexpected value") | ||
|
||
suite.Require().Equal(types.ProcessedTimeKey(height), gm[1].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(initProcessedTime, sdk.BigEndianToUint64(gm[1].GetValue()), "metadata has unexpected value") | ||
|
||
gm := clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "clientA")) | ||
suite.Require().Nil(gm, "client with no metadata returned non-nil exported metadata") | ||
suite.Require().Equal(types.IterationKey(height), gm[2].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(initIteration, gm[2].GetValue(), "metadata has unexpected value") | ||
|
||
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "clientA") | ||
// test updating client and exporting metadata | ||
err = path.EndpointA.UpdateClient() | ||
suite.Require().NoError(err) | ||
|
||
// set some processed times | ||
timestamp1 := uint64(time.Now().UnixNano()) | ||
timestamp2 := uint64(time.Now().Add(time.Minute).UnixNano()) | ||
timestampBz1 := sdk.Uint64ToBigEndian(timestamp1) | ||
timestampBz2 := sdk.Uint64ToBigEndian(timestamp2) | ||
types.SetProcessedTime(clientStore, clienttypes.NewHeight(0, 1), timestamp1) | ||
types.SetProcessedTime(clientStore, clienttypes.NewHeight(0, 2), timestamp2) | ||
clientState = path.EndpointA.GetClientState() | ||
updateHeight := clientState.GetLatestHeight() | ||
|
||
gm = clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), "clientA")) | ||
iteration := types.GetIterationKey(clientStore, updateHeight) | ||
suite.Require().NotEqual(0, len(initIteration)) | ||
processedTime, found := types.GetProcessedTime(clientStore, updateHeight) | ||
suite.Require().True(found) | ||
processedHeight, found := types.GetProcessedHeight(clientStore, updateHeight) | ||
suite.Require().True(found) | ||
|
||
gm = clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)) | ||
suite.Require().NotNil(gm, "client with metadata returned nil exported metadata") | ||
suite.Require().Len(gm, 2, "exported metadata has unexpected length") | ||
suite.Require().Len(gm, 6, "exported metadata has unexpected length") | ||
|
||
// expected ordering: | ||
// initProcessedHeight, initProcessedTime, processedHeight, processedTime, initIteration, iteration | ||
|
||
// check init processed height and time | ||
suite.Require().Equal(types.ProcessedHeightKey(height), gm[0].GetKey(), "metadata has unexpected key") | ||
actualProcessedHeight, err = clienttypes.ParseHeight(string(gm[0].GetValue())) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(initProcessedHeight, actualProcessedHeight, "metadata has unexpected value") | ||
|
||
suite.Require().Equal(types.ProcessedTimeKey(height), gm[1].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(initProcessedTime, sdk.BigEndianToUint64(gm[1].GetValue()), "metadata has unexpected value") | ||
|
||
// check processed height and time after update | ||
suite.Require().Equal(types.ProcessedHeightKey(updateHeight), gm[2].GetKey(), "metadata has unexpected key") | ||
actualProcessedHeight, err = clienttypes.ParseHeight(string(gm[2].GetValue())) | ||
suite.Require().NoError(err) | ||
suite.Require().Equal(processedHeight, actualProcessedHeight, "metadata has unexpected value") | ||
|
||
suite.Require().Equal(types.ProcessedTimeKey(updateHeight), gm[3].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(processedTime, sdk.BigEndianToUint64(gm[3].GetValue()), "metadata has unexpected value") | ||
|
||
suite.Require().Equal(types.ProcessedTimeKey(clienttypes.NewHeight(0, 1)), gm[0].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(timestampBz1, gm[0].GetValue(), "metadata has unexpected value") | ||
// check iteration keys | ||
suite.Require().Equal(types.IterationKey(height), gm[4].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(initIteration, gm[4].GetValue(), "metadata has unexpected value") | ||
|
||
suite.Require().Equal(types.ProcessedTimeKey(clienttypes.NewHeight(0, 2)), gm[1].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(timestampBz2, gm[1].GetValue(), "metadata has unexpected value") | ||
suite.Require().Equal(types.IterationKey(updateHeight), gm[5].GetKey(), "metadata has unexpected key") | ||
suite.Require().Equal(iteration, gm[5].GetValue(), "metadata has unexpected value") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters