@@ -18,6 +18,9 @@ pub struct FakeObserver {
18
18
/// [get_current_epoch]: ChainObserver::get_current_epoch
19
19
pub current_time_point : RwLock < Option < TimePoint > > ,
20
20
21
+ /// The current chain point
22
+ pub current_chain_point : RwLock < Option < ChainPoint > > ,
23
+
21
24
/// A list of [TxDatum], used by [get_current_datums]
22
25
///
23
26
/// [get_current_datums]: ChainObserver::get_current_datums
@@ -30,6 +33,7 @@ impl FakeObserver {
30
33
Self {
31
34
signers : RwLock :: new ( vec ! [ ] ) ,
32
35
current_time_point : RwLock :: new ( current_time_point) ,
36
+ current_chain_point : RwLock :: new ( None ) ,
33
37
datums : RwLock :: new ( vec ! [ ] ) ,
34
38
}
35
39
}
@@ -52,6 +56,13 @@ impl FakeObserver {
52
56
* signers = new_signers;
53
57
}
54
58
59
+ /// Set the chain point that will use to compute the result of
60
+ /// [get_current_chain_point][ChainObserver::get_current_chain_point].
61
+ pub async fn set_current_chain_point ( & self , new_current_chain_point : Option < ChainPoint > ) {
62
+ let mut current_chain_point = self . current_chain_point . write ( ) . await ;
63
+ * current_chain_point = new_current_chain_point;
64
+ }
65
+
55
66
/// Set the datums that will use to compute the result of
56
67
/// [get_current_datums][ChainObserver::get_current_datums].
57
68
pub async fn set_datums ( & self , new_datums : Vec < TxDatum > ) {
@@ -88,6 +99,10 @@ impl ChainObserver for FakeObserver {
88
99
. map ( |time_point| time_point. epoch ) )
89
100
}
90
101
102
+ async fn get_current_chain_point ( & self ) -> Result < Option < ChainPoint > , ChainObserverError > {
103
+ Ok ( self . current_chain_point . read ( ) . await . clone ( ) )
104
+ }
105
+
91
106
async fn get_current_stake_distribution (
92
107
& self ,
93
108
) -> Result < Option < StakeDistribution > , ChainObserverError > {
@@ -124,6 +139,21 @@ mod tests {
124
139
assert_eq ! ( Some ( time_point. epoch) , current_epoch) ;
125
140
}
126
141
142
+ #[ tokio:: test]
143
+ async fn test_get_current_chain_point ( ) {
144
+ let fake_observer = FakeObserver :: new ( None ) ;
145
+ fake_observer
146
+ . set_current_chain_point ( Some ( fake_data:: chain_point ( ) ) )
147
+ . await ;
148
+ let chain_point = fake_observer. get_current_chain_point ( ) . await . unwrap ( ) ;
149
+
150
+ assert_eq ! (
151
+ Some ( fake_data:: chain_point( ) ) ,
152
+ chain_point,
153
+ "get current chain point should not fail"
154
+ ) ;
155
+ }
156
+
127
157
#[ tokio:: test]
128
158
async fn test_get_current_stake_distribution ( ) {
129
159
let fake_observer = FakeObserver :: new ( None ) ;
0 commit comments