@@ -18,9 +18,7 @@ use crate::testapp::ibc::clients::mock::client_state::client_type as mock_client
18
18
use crate :: testapp:: ibc:: clients:: mock:: consensus_state:: MockConsensusState ;
19
19
use crate :: testapp:: ibc:: clients:: mock:: header:: { MockHeader , MOCK_HEADER_TYPE_URL } ;
20
20
use crate :: testapp:: ibc:: clients:: mock:: misbehaviour:: { Misbehaviour , MOCK_MISBEHAVIOUR_TYPE_URL } ;
21
- use crate :: testapp:: ibc:: clients:: mock:: proto:: {
22
- ClientState as RawMockClientState , Header as RawMockHeader ,
23
- } ;
21
+ use crate :: testapp:: ibc:: clients:: mock:: proto:: ClientState as RawMockClientState ;
24
22
25
23
pub const MOCK_CLIENT_STATE_TYPE_URL : & str = "/ibc.mock.ClientState" ;
26
24
pub const MOCK_CLIENT_TYPE : & str = "9999-mock" ;
@@ -35,14 +33,16 @@ pub fn client_type() -> ClientType {
35
33
#[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
36
34
pub struct MockClientState {
37
35
pub header : MockHeader ,
38
- pub frozen_height : Option < Height > ,
36
+ pub trusting_period : Duration ,
37
+ pub frozen : bool ,
39
38
}
40
39
41
40
impl MockClientState {
42
41
pub fn new ( header : MockHeader ) -> Self {
43
42
Self {
44
43
header,
45
- frozen_height : None ,
44
+ trusting_period : Duration :: from_nanos ( 0 ) ,
45
+ frozen : false ,
46
46
}
47
47
}
48
48
@@ -54,15 +54,29 @@ impl MockClientState {
54
54
None
55
55
}
56
56
57
- pub fn with_frozen_height ( self , frozen_height : Height ) -> Self {
57
+ pub fn with_trusting_period ( self , trusting_period : Duration ) -> Self {
58
+ Self {
59
+ trusting_period,
60
+ ..self
61
+ }
62
+ }
63
+
64
+ pub fn frozen ( self ) -> Self {
58
65
Self {
59
- frozen_height : Some ( frozen_height) ,
66
+ frozen : true ,
67
+ ..self
68
+ }
69
+ }
70
+
71
+ pub fn unfrozen ( self ) -> Self {
72
+ Self {
73
+ frozen : false ,
60
74
..self
61
75
}
62
76
}
63
77
64
78
pub fn is_frozen ( & self ) -> bool {
65
- self . frozen_height . is_some ( )
79
+ self . frozen
66
80
}
67
81
68
82
fn expired ( & self , _elapsed : Duration ) -> bool {
@@ -76,17 +90,29 @@ impl TryFrom<RawMockClientState> for MockClientState {
76
90
type Error = ClientError ;
77
91
78
92
fn try_from ( raw : RawMockClientState ) -> Result < Self , Self :: Error > {
79
- Ok ( Self :: new ( raw. header . expect ( "Never fails" ) . try_into ( ) ?) )
93
+ Ok ( Self {
94
+ header : raw
95
+ . header
96
+ . ok_or ( ClientError :: Other {
97
+ description : "header is not present" . into ( ) ,
98
+ } ) ?
99
+ . try_into ( ) ?,
100
+ trusting_period : Duration :: from_nanos ( raw. trusting_period ) ,
101
+ frozen : raw. frozen ,
102
+ } )
80
103
}
81
104
}
82
105
83
106
impl From < MockClientState > for RawMockClientState {
84
107
fn from ( value : MockClientState ) -> Self {
85
108
RawMockClientState {
86
- header : Some ( RawMockHeader {
87
- height : Some ( value. header . height ( ) . into ( ) ) ,
88
- timestamp : value. header . timestamp . nanoseconds ( ) ,
89
- } ) ,
109
+ header : Some ( value. header . into ( ) ) ,
110
+ trusting_period : value
111
+ . trusting_period
112
+ . as_nanos ( )
113
+ . try_into ( )
114
+ . expect ( "no error" ) ,
115
+ frozen : value. frozen ,
90
116
}
91
117
}
92
118
}
@@ -354,7 +380,7 @@ where
354
380
client_id : & ClientId ,
355
381
_client_message : Any ,
356
382
) -> Result < ( ) , ClientError > {
357
- let frozen_client_state = self . with_frozen_height ( Height :: min ( 0 ) ) ;
383
+ let frozen_client_state = self . frozen ( ) ;
358
384
359
385
ctx. store_client_state (
360
386
ClientStatePath :: new ( client_id. clone ( ) ) ,
0 commit comments