ibc: remove GetChainID (#7219)
* ibc: remove GetChainID * update * test * Update x/ibc/09-localhost/types/client_state.go Co-authored-by: Aditya <adityasripal@gmail.com>
This commit is contained in:
parent
d7175e12c2
commit
b52131d60c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")))
|
||||
|
|
|
@ -25,6 +25,7 @@ type LocalhostTestSuite struct {
|
|||
suite.Suite
|
||||
|
||||
cdc codec.Marshaler
|
||||
ctx sdk.Context
|
||||
store sdk.KVStore
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue