Skip to content

Commit cca717d

Browse files
committed
use typed string for status
1 parent 90c9f29 commit cca717d

File tree

7 files changed

+26
-20
lines changed

7 files changed

+26
-20
lines changed

modules/core/02-client/keeper/grpc_query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (q Keeper) ClientStatus(c context.Context, req *types.QueryClientStatusRequ
211211
status := clientState.Status(ctx, clientStore, q.cdc)
212212

213213
return &types.QueryClientStatusResponse{
214-
Status: status,
214+
Status: status.String(),
215215
}, nil
216216
}
217217

modules/core/02-client/keeper/grpc_query_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() {
436436
ClientId: path.EndpointA.ClientID,
437437
}
438438
},
439-
true, exported.Active,
439+
true, exported.Active.String(),
440440
},
441441
{
442442
"Unknown client status",
@@ -453,7 +453,7 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() {
453453
ClientId: path.EndpointA.ClientID,
454454
}
455455
},
456-
true, exported.Unknown,
456+
true, exported.Unknown.String(),
457457
},
458458
{
459459
"Frozen client status",
@@ -469,7 +469,7 @@ func (suite *KeeperTestSuite) TestQueryClientStatus() {
469469
ClientId: path.EndpointA.ClientID,
470470
}
471471
},
472-
true, exported.Frozen,
472+
true, exported.Frozen.String(),
473473
},
474474
}
475475

modules/core/exported/client.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import (
88
sdk "github.com/cosmos/cosmos-sdk/types"
99
)
1010

11+
// Status represents the status of a client
12+
type Status string
13+
1114
const (
1215
// TypeClientMisbehaviour is the shared evidence misbehaviour type
1316
TypeClientMisbehaviour string = "client_misbehaviour"
@@ -23,13 +26,16 @@ const (
2326
Localhost string = "09-localhost"
2427

2528
// Active is a status type of a client. An active client is allowed to be used.
26-
Active string = "Active"
29+
Active Status = "Active"
2730

2831
// Frozen is a status type of a client. A frozen client is not allowed to be used.
29-
Frozen string = "Frozen"
32+
Frozen Status = "Frozen"
33+
34+
// Expired is a status type of a client. An expired client is not allowed to be used.
35+
Expired Status = "Expired"
3036

31-
// Unknown indicates there was an error in determining the status of a client
32-
Unknown string = "Unknown"
37+
// Unknown indicates there was an error in determining the status of a client.
38+
Unknown Status = "Unknown"
3339
)
3440

3541
// ClientState defines the required common functions for light clients.
@@ -49,7 +55,7 @@ type ClientState interface {
4955

5056
// Status function
5157
// Clients must return their status. Only Active clients are allowed to process packets.
52-
Status(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryMarshaler) string
58+
Status(ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryMarshaler) Status
5359

5460
// Genesis function
5561
ExportMetadata(sdk.KVStore) []GenesisMetadata
@@ -233,3 +239,8 @@ type GenesisMetadata interface {
233239
// returns metadata value
234240
GetValue() []byte
235241
}
242+
243+
// String returns the string representation of a client status.
244+
func (s Status) String() string {
245+
return string(s)
246+
}

modules/light-clients/06-solomachine/types/client_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (cs ClientState) GetLatestHeight() exported.Height {
4444
// The client may be:
4545
// - Active: if frozen sequence is 0
4646
// - Frozen: otherwise solo machine is frozen
47-
func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryMarshaler) string {
47+
func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryMarshaler) exported.Status {
4848
if cs.FrozenSequence != 0 {
4949
return exported.Frozen
5050
}

modules/light-clients/07-tendermint/types/client_state.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ import (
1919
"github.com/cosmos/ibc-go/modules/core/exported"
2020
)
2121

22-
// Expired is a potential status of a client. A client is expired
23-
// if its latest consensus state timestamp added to its trusting period
24-
// is before or equal to the current time.
25-
const Expired = "Expired"
26-
2722
var _ exported.ClientState = (*ClientState)(nil)
2823

2924
// NewClientState creates a new ClientState instance
@@ -75,7 +70,7 @@ func (cs ClientState) Status(
7570
ctx sdk.Context,
7671
clientStore sdk.KVStore,
7772
cdc codec.BinaryMarshaler,
78-
) string {
73+
) exported.Status {
7974
if !cs.FrozenHeight.IsZero() {
8075
return exported.Frozen
8176
}
@@ -87,7 +82,7 @@ func (cs ClientState) Status(
8782
}
8883

8984
if cs.IsExpired(consState.Timestamp, ctx.BlockTime()) {
90-
return Expired
85+
return exported.Expired
9186
}
9287

9388
return exported.Active

modules/light-clients/07-tendermint/types/client_state_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (suite *TendermintTestSuite) TestStatus() {
3737
testCases := []struct {
3838
name string
3939
malleate func()
40-
expStatus string
40+
expStatus exported.Status
4141
}{
4242
{"client is active", func() {}, exported.Active},
4343
{"client is frozen", func() {
@@ -50,7 +50,7 @@ func (suite *TendermintTestSuite) TestStatus() {
5050
}, exported.Unknown},
5151
{"client status is expired", func() {
5252
suite.coordinator.IncrementTimeBy(clientState.TrustingPeriod)
53-
}, types.Expired},
53+
}, exported.Expired},
5454
}
5555

5656
for _, tc := range testCases {

modules/light-clients/09-localhost/types/client_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (cs ClientState) GetLatestHeight() exported.Height {
4545

4646
// Status always returns Active. The localhost status cannot be changed.
4747
func (cs ClientState) Status(_ sdk.Context, _ sdk.KVStore, _ codec.BinaryMarshaler,
48-
) string {
48+
) exported.Status {
4949
return exported.Active
5050
}
5151

0 commit comments

Comments
 (0)