Skip to content

Commit

Permalink
ibc: remove GetChainID (cosmos#7219)
Browse files Browse the repository at this point in the history
* ibc: remove GetChainID

* update

* test

* Update x/ibc/09-localhost/types/client_state.go

Co-authored-by: Aditya <adityasripal@gmail.com>
  • Loading branch information
fedekunze and AdityaSripal authored Sep 1, 2020
1 parent d7175e1 commit b52131d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
1 change: 0 additions & 1 deletion x/ibc/02-client/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

// ClientState defines the required common functions for light clients.
type ClientState interface {
GetChainID() string
ClientType() ClientType
GetLatestHeight() uint64
IsFrozen() bool
Expand Down
10 changes: 5 additions & 5 deletions x/ibc/09-localhost/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func (cs ClientState) GetProofSpecs() []*ics23.ProofSpec {
}

// CheckHeaderAndUpdateState updates the localhost client. It only needs access to the context
func (cs ClientState) CheckHeaderAndUpdateState(
func (cs *ClientState) CheckHeaderAndUpdateState(
ctx sdk.Context, _ codec.BinaryMarshaler, _ sdk.KVStore, _ clientexported.Header,
) (clientexported.ClientState, clientexported.ConsensusState, error) {
// use the chain ID from context since the localhost client is from the running chain (i.e self).
cs.ChainId = ctx.ChainID()
// Hardcode 0 for epoch number for now
// TODO: Retrieve epoch number from chain-id
return NewClientState(
ctx.ChainID(), // use the chain ID from context since the client is from the running chain (i.e self).
clienttypes.NewHeight(0, uint64(ctx.BlockHeight())),
), nil, nil
cs.Height = clienttypes.NewHeight(0, uint64(ctx.BlockHeight()))
return cs, nil, nil
}

// CheckMisbehaviourAndUpdateState implements ClientState
Expand Down
7 changes: 7 additions & 0 deletions x/ibc/09-localhost/types/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
)
suite.Require().NoError(err)
}
func (suite *LocalhostTestSuite) TestCheckHeaderAndUpdateState() {
clientState := types.NewClientState("chainID", clientHeight)
cs, _, err := clientState.CheckHeaderAndUpdateState(suite.ctx, nil, nil, nil)
suite.Require().NoError(err)
suite.Require().Equal(suite.ctx.BlockHeight(), int64(cs.GetLatestHeight()))
suite.Require().Equal(suite.ctx.BlockHeader().ChainID, clientState.ChainId)
}

func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
counterparty := connectiontypes.NewCounterparty("clientB", testConnectionID, commitmenttypes.NewMerklePrefix([]byte("ibc")))
Expand Down
5 changes: 3 additions & 2 deletions x/ibc/09-localhost/types/localhost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type LocalhostTestSuite struct {
suite.Suite

cdc codec.Marshaler
ctx sdk.Context
store sdk.KVStore
}

Expand All @@ -33,8 +34,8 @@ func (suite *LocalhostTestSuite) SetupTest() {
app := simapp.Setup(isCheckTx)

suite.cdc = app.AppCodec()
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: 1})
suite.store = app.IBCKeeper.ClientKeeper.ClientStore(ctx, clientexported.ClientTypeLocalHost)
suite.ctx = app.BaseApp.NewContext(isCheckTx, tmproto.Header{Height: 1, ChainID: "ibc-chain"})
suite.store = app.IBCKeeper.ClientKeeper.ClientStore(suite.ctx, clientexported.ClientTypeLocalHost)
}

func TestLocalhostTestSuite(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions x/ibc/light-clients/solomachine/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ func NewClientState(consensusState *ConsensusState) *ClientState {
}
}

// GetChainID returns an empty string.
func (cs ClientState) GetChainID() string {
return ""
}

// ClientType is Solo Machine.
func (cs ClientState) ClientType() clientexported.ClientType {
return clientexported.SoloMachine
Expand Down

0 comments on commit b52131d

Please sign in to comment.