Skip to content

Commit

Permalink
fix golangci comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chengwenxi committed Nov 5, 2019
1 parent dc099af commit 17e4230
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
2 changes: 1 addition & 1 deletion x/ibc/02-client/types/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package types
// Any actor holding the Stage can access on and modify that client information.
type State struct {
// Client ID
Id string
Id string `json:"id" yaml:"id"`
// Boolean that states if the client is frozen when a misbehaviour proof is
// submitted in the event of an equivocation.
Frozen bool `json:"frozen" yaml:"frozen"`
Expand Down
120 changes: 60 additions & 60 deletions x/ibc/03-connection/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
)

func (suite *KeeperTestSuite) getConsensusState(chainId string) tendermint.ConsensusState {
app := suite.apps[chainId]
commitId := app.store.Commit()
func (suite *KeeperTestSuite) getConsensusState(chainID string) tendermint.ConsensusState {
app := suite.apps[chainID]
commitID := app.store.Commit()
state := tendermint.ConsensusState{
ChainID: app.chainId,
Height: uint64(commitId.Version),
Root: commitment.NewRoot(commitId.Hash),
ChainID: app.chainID,
Height: uint64(commitID.Version),
Root: commitment.NewRoot(commitID.Hash),
}
app.ctx.WithBlockHeight(commitId.Version)
app.ctx.WithBlockHeight(commitID.Version)
return state
}

func (suite *KeeperTestSuite) queryProof(chainId string, key string) (proof commitment.Proof, height int64) {
app := suite.apps[chainId]
func (suite *KeeperTestSuite) queryProof(chainID string, key string) (proof commitment.Proof, height int64) {
app := suite.apps[chainID]
store := app.store.(*rootmulti.Store)
res := store.Query(abci.RequestQuery{
Path: fmt.Sprintf("/%s/key", storeKey),
Expand All @@ -39,34 +39,34 @@ func (suite *KeeperTestSuite) queryProof(chainId string, key string) (proof comm
return
}

func (suite *KeeperTestSuite) createClient(chainId string, clientID string,
func (suite *KeeperTestSuite) createClient(chainID string, clientID string,
clientType exported.ClientType, state tendermint.ConsensusState) {
app := suite.apps[chainId]
app := suite.apps[chainID]
_, err := app.clientKeeper.CreateClient(app.ctx, clientID, clientType, state)
if err != nil {
panic(err)
}
commitId := app.store.Commit()
app.ctx.WithBlockHeight(commitId.Version)
commitID := app.store.Commit()
app.ctx.WithBlockHeight(commitID.Version)
}

func (suite *KeeperTestSuite) updateClient(chainId string, clientID string) {
otherChainId := ChainIdGaia1
if chainId == ChainIdGaia1 {
otherChainId = ChainIdGaia2
func (suite *KeeperTestSuite) updateClient(chainID string, clientID string) {
otherChainID := ChainIDGaia1
if chainID == ChainIDGaia1 {
otherChainID = ChainIDGaia2
}
consensusState := suite.getConsensusState(otherChainId)
consensusState := suite.getConsensusState(otherChainID)

//update client consensus state
app := suite.apps[chainId]
app := suite.apps[chainID]
app.clientKeeper.SetConsensusState(app.ctx, clientID, consensusState)
app.clientKeeper.SetVerifiedRoot(app.ctx, clientID, consensusState.GetHeight(), consensusState.GetRoot())
commitId := app.store.Commit()
app.ctx.WithBlockHeight(commitId.Version)
commitID := app.store.Commit()
app.ctx.WithBlockHeight(commitID.Version)
}

func (suite *KeeperTestSuite) connOpenInit(chainId string, connectionID, clientID, counterpartyClientID, counterpartyConnID string) {
app := suite.apps[chainId]
func (suite *KeeperTestSuite) connOpenInit(chainID string, connectionID, clientID, counterpartyClientID, counterpartyConnID string) {
app := suite.apps[chainID]
counterparty := types.NewCounterparty(counterpartyClientID, counterpartyConnID, app.connKeeper.GetCommitmentPrefix())

err := app.connKeeper.ConnOpenInit(app.ctx, connectionID, clientID, counterparty)
Expand All @@ -82,68 +82,68 @@ func (suite *KeeperTestSuite) connOpenInit(chainId string, connectionID, clientI
Versions: types.GetCompatibleVersions(),
}
suite.EqualValues(expectConn, conn)
commitId := app.store.Commit()
app.ctx.WithBlockHeight(commitId.Version)
commitID := app.store.Commit()
app.ctx.WithBlockHeight(commitID.Version)
}

func (suite *KeeperTestSuite) connOpenTry(chainId string, connectionID, clientID, counterpartyClientID, counterpartyConnID string) {
app := suite.apps[chainId]
func (suite *KeeperTestSuite) connOpenTry(chainID string, connectionID, clientID, counterpartyClientID, counterpartyConnID string) {
app := suite.apps[chainID]
counterparty := types.NewCounterparty(counterpartyClientID, counterpartyConnID, app.connKeeper.GetCommitmentPrefix())

connKey := fmt.Sprintf("%s/%s", types.SubModuleName, types.ConnectionPath(counterpartyConnID))
otherChainId := ChainIdGaia1
if chainId == ChainIdGaia1 {
otherChainId = ChainIdGaia2
otherChainID := ChainIDGaia1
if chainID == ChainIDGaia1 {
otherChainID = ChainIDGaia2
}
proof, h := suite.queryProof(otherChainId, connKey)
proof, h := suite.queryProof(otherChainID, connKey)

err := app.connKeeper.ConnOpenTry(app.ctx, connectionID, counterparty, clientID, types.GetCompatibleVersions(), proof, uint64(h), 0)
suite.Nil(err)

commitId := app.store.Commit()
app.ctx.WithBlockHeight(commitId.Version)
commitID := app.store.Commit()
app.ctx.WithBlockHeight(commitID.Version)

//check connection state
conn, existed := app.connKeeper.GetConnection(app.ctx, connectionID)
suite.True(existed)
suite.Equal(types.TRYOPEN, conn.State)
}

func (suite *KeeperTestSuite) connOpenAck(chainId string, connectionID, counterpartyConnID string) {
app := suite.apps[chainId]
func (suite *KeeperTestSuite) connOpenAck(chainID string, connectionID, counterpartyConnID string) {
app := suite.apps[chainID]
connKey := fmt.Sprintf("%s/%s", types.SubModuleName, types.ConnectionPath(counterpartyConnID))
otherChainId := ChainIdGaia1
if chainId == ChainIdGaia1 {
otherChainId = ChainIdGaia2
otherChainID := ChainIDGaia1
if chainID == ChainIDGaia1 {
otherChainID = ChainIDGaia2
}
proof, h := suite.queryProof(otherChainId, connKey)
proof, h := suite.queryProof(otherChainID, connKey)

err := app.connKeeper.ConnOpenAck(app.ctx, connectionID, types.GetCompatibleVersions()[0], proof, uint64(h), 0)
suite.Nil(err)

commitId := app.store.Commit()
app.ctx.WithBlockHeight(commitId.Version)
commitID := app.store.Commit()
app.ctx.WithBlockHeight(commitID.Version)

//check connection state
conn, existed := app.connKeeper.GetConnection(app.ctx, connectionID)
suite.True(existed)
suite.Equal(types.OPEN, conn.State)
}

func (suite *KeeperTestSuite) connOpenConfirm(chainId string, connectionID, counterpartyConnID string) {
app := suite.apps[chainId]
func (suite *KeeperTestSuite) connOpenConfirm(chainID string, connectionID, counterpartyConnID string) {
app := suite.apps[chainID]
connKey := fmt.Sprintf("%s/%s", types.SubModuleName, types.ConnectionPath(counterpartyConnID))
otherChainId := ChainIdGaia1
if chainId == ChainIdGaia1 {
otherChainId = ChainIdGaia2
otherChainID := ChainIDGaia1
if chainID == ChainIDGaia1 {
otherChainID = ChainIDGaia2
}
proof, h := suite.queryProof(otherChainId, connKey)
proof, h := suite.queryProof(otherChainID, connKey)

err := app.connKeeper.ConnOpenConfirm(app.ctx, connectionID, proof, uint64(h))
suite.Nil(err)

commitId := app.store.Commit()
app.ctx.WithBlockHeight(commitId.Version)
commitID := app.store.Commit()
app.ctx.WithBlockHeight(commitID.Version)

//check connection state
conn, existed := app.connKeeper.GetConnection(app.ctx, connectionID)
Expand All @@ -153,32 +153,32 @@ func (suite *KeeperTestSuite) connOpenConfirm(chainId string, connectionID, coun

func (suite *KeeperTestSuite) TestHandshake() {
//get gaia1 consensusState
state1 := suite.getConsensusState(ChainIdGaia1)
state1 := suite.getConsensusState(ChainIDGaia1)
//create gaia1's client on gaia2
suite.createClient(ChainIdGaia2, ClientToGaia2, clientType, state1)
suite.createClient(ChainIDGaia2, ClientToGaia2, clientType, state1)

//get gaia2 consensusState
state2 := suite.getConsensusState(ChainIdGaia2)
state2 := suite.getConsensusState(ChainIDGaia2)
// create gaia2's client on gaia1
suite.createClient(ChainIdGaia1, ClientToGaia1, clientType, state2)
suite.createClient(ChainIDGaia1, ClientToGaia1, clientType, state2)

//===========OpenInit on gaia2===========
suite.connOpenInit(ChainIdGaia2, ConnectionToGaia1, ClientToGaia2, ClientToGaia1, ConnectionToGaia2)
suite.connOpenInit(ChainIDGaia2, ConnectionToGaia1, ClientToGaia2, ClientToGaia1, ConnectionToGaia2)

//===========OpenTry on gaia1===========
// update gaia1 consensusState(should be UpdateClient)
suite.updateClient(ChainIdGaia1, ClientToGaia1)
suite.updateClient(ChainIDGaia1, ClientToGaia1)
// open-try on gaia1
suite.connOpenTry(ChainIdGaia1, ConnectionToGaia2, ClientToGaia1, ClientToGaia2, ConnectionToGaia1)
suite.connOpenTry(ChainIDGaia1, ConnectionToGaia2, ClientToGaia1, ClientToGaia2, ConnectionToGaia1)

//===========ConnOpenAck on gaia2===========
// update gaia2 consensusState(should be UpdateClient)
suite.updateClient(ChainIdGaia2, ClientToGaia2)
suite.connOpenAck(ChainIdGaia2, ConnectionToGaia1, ConnectionToGaia2)
suite.updateClient(ChainIDGaia2, ClientToGaia2)
suite.connOpenAck(ChainIDGaia2, ConnectionToGaia1, ConnectionToGaia2)

//===========ConnOpenConfirm on gaia1===========
// update gaia1 consensusState(should be UpdateClient)
suite.updateClient(ChainIdGaia1, ClientToGaia1)
suite.connOpenConfirm(ChainIdGaia1, ConnectionToGaia2, ConnectionToGaia1)
suite.updateClient(ChainIDGaia1, ClientToGaia1)
suite.connOpenConfirm(ChainIDGaia1, ConnectionToGaia2, ConnectionToGaia1)

}
30 changes: 15 additions & 15 deletions x/ibc/03-connection/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const (
clientType = clientexported.Tendermint
storeKey = "ibc"

ChainIdGaia1 = "gaia-1"
ChainIdGaia2 = "gaia-2"
ChainIDGaia1 = "gaia-1"
ChainIDGaia2 = "gaia-2"

ClientToGaia2 = "clienttogaia2"
ClientToGaia1 = "clienttogaia1"
Expand All @@ -37,8 +37,8 @@ type KeeperTestSuite struct {

func (suite *KeeperTestSuite) SetupTest() {
suite.apps = map[string]App{
ChainIdGaia1: NewApp(ChainIdGaia1),
ChainIdGaia2: NewApp(ChainIdGaia2),
ChainIDGaia1: NewApp(ChainIDGaia1),
ChainIDGaia2: NewApp(ChainIDGaia2),
}
}

Expand All @@ -47,9 +47,9 @@ func TestKeeperTestSuite(t *testing.T) {
}

func (suite *KeeperTestSuite) TestSetAndGetConnection() {
gaia := suite.apps[ChainIdGaia1]
gaia := suite.apps[ChainIDGaia1]

conn, existed := gaia.connKeeper.GetConnection(gaia.ctx, ConnectionToGaia2)
_, existed := gaia.connKeeper.GetConnection(gaia.ctx, ConnectionToGaia2)
suite.False(existed)

counterparty := types.NewCounterparty(ClientToGaia2, ConnectionToGaia1, gaia.connKeeper.GetCommitmentPrefix())
Expand All @@ -60,25 +60,25 @@ func (suite *KeeperTestSuite) TestSetAndGetConnection() {
Versions: types.GetCompatibleVersions(),
}
gaia.connKeeper.SetConnection(gaia.ctx, ConnectionToGaia2, expConn)
conn, existed = gaia.connKeeper.GetConnection(gaia.ctx, ConnectionToGaia2)
conn, existed := gaia.connKeeper.GetConnection(gaia.ctx, ConnectionToGaia2)
suite.True(existed)
suite.EqualValues(expConn, conn)
}

func (suite *KeeperTestSuite) TestSetAndGetClientConnectionPaths() {
gaia := suite.apps[ChainIdGaia1]
gaia := suite.apps[ChainIDGaia1]

paths, existed := gaia.connKeeper.GetClientConnectionPaths(gaia.ctx, ClientToGaia2)
_, existed := gaia.connKeeper.GetClientConnectionPaths(gaia.ctx, ClientToGaia2)
suite.False(existed)

gaia.connKeeper.SetClientConnectionPaths(gaia.ctx, ClientToGaia2, types.GetCompatibleVersions())
paths, existed = gaia.connKeeper.GetClientConnectionPaths(gaia.ctx, ClientToGaia2)
paths, existed := gaia.connKeeper.GetClientConnectionPaths(gaia.ctx, ClientToGaia2)
suite.True(existed)
suite.EqualValues(types.GetCompatibleVersions(), paths)
}

func (suite *KeeperTestSuite) TestAddAndRemoveConnectionToClient() {
gaia := suite.apps[ChainIdGaia1]
gaia := suite.apps[ChainIDGaia1]

//add connection to client
err := gaia.connKeeper.addConnectionToClient(gaia.ctx, ClientToGaia2, ConnectionToGaia1)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (suite *KeeperTestSuite) TestAddAndRemoveConnectionToClient() {
}

type App struct {
chainId string
chainID string
ctx sdk.Context
cdc *codec.Codec
store sdk.CommitMultiStore
Expand All @@ -129,7 +129,7 @@ type IBCKeeper struct {
clientKeeper client.Keeper
}

func NewApp(chainId string) App {
func NewApp(chainID string) App {
var codespaceType sdk.CodespaceType = storeKey
storeKey := sdk.NewKVStoreKey(storeKey)

Expand All @@ -144,10 +144,10 @@ func NewApp(chainId string) App {

clientKeeper := client.NewKeeper(cdc, storeKey, codespaceType)
connKeeper := NewKeeper(cdc, storeKey, codespaceType, clientKeeper)
ctx := sdk.NewContext(ms, abci.Header{ChainID: chainId, Height: 0}, false, log.NewNopLogger())
ctx := sdk.NewContext(ms, abci.Header{ChainID: chainID, Height: 0}, false, log.NewNopLogger())

return App{
chainId: chainId,
chainID: chainID,
ctx: ctx,
cdc: cdc,
store: ms,
Expand Down

0 comments on commit 17e4230

Please sign in to comment.