1
+ use std:: collections:: HashMap ;
2
+
3
+ use hex:: encode;
4
+
1
5
use crate :: adapter:: { Adapter , AdapterError , Config } ;
2
6
use crate :: sanity:: SanityChecker ;
3
- use hex:: encode;
4
- use std:: collections:: HashMap ;
5
7
6
8
#[ derive( Debug ) ]
7
9
pub struct DummyParticipant {
@@ -67,6 +69,30 @@ impl Adapter for DummyAdapter<'_> {
67
69
}
68
70
}
69
71
72
+ /// Finds the auth. token in the HashMap of DummyParticipants if exists
73
+ /// Example:
74
+ ///
75
+ /// ```
76
+ /// use std::collections::HashMap;
77
+ /// use adapter::dummy::{DummyParticipant, DummyAdapter};
78
+ /// use adapter::{ConfigBuilder, Adapter};
79
+ ///
80
+ /// let mut participants = HashMap::new();
81
+ /// participants.insert(
82
+ /// "identity_key",
83
+ /// DummyParticipant {
84
+ /// identity: "identity".to_string(),
85
+ /// token: "token".to_string(),
86
+ /// },
87
+ /// );
88
+ ///
89
+ ///let adapter = DummyAdapter {
90
+ /// config: ConfigBuilder::new("identity").build(),
91
+ /// participants,
92
+ ///};
93
+ ///
94
+ ///assert_eq!(Ok("token".to_string()), adapter.get_auth("identity"));
95
+ /// ```
70
96
fn get_auth ( & self , validator : & str ) -> Result < String , AdapterError < ' _ > > {
71
97
match self
72
98
. participants
@@ -81,9 +107,10 @@ impl Adapter for DummyAdapter<'_> {
81
107
82
108
#[ cfg( test) ]
83
109
mod test {
84
- use super :: * ;
85
110
use crate :: adapter:: ConfigBuilder ;
86
111
112
+ use super :: * ;
113
+
87
114
#[ test]
88
115
fn dummy_adapter_sings_state_root_and_verifies_it ( ) {
89
116
let config = ConfigBuilder :: new ( "identity" ) . build ( ) ;
@@ -130,23 +157,4 @@ mod test {
130
157
adapter. get_auth( "non-existing" ) . unwrap_err( )
131
158
) ;
132
159
}
133
-
134
- #[ test]
135
- fn get_auth_with_existing_participator ( ) {
136
- let mut participants = HashMap :: new ( ) ;
137
- participants. insert (
138
- "identity_key" ,
139
- DummyParticipant {
140
- identity : "identity" . to_string ( ) ,
141
- token : "token" . to_string ( ) ,
142
- } ,
143
- ) ;
144
-
145
- let adapter = DummyAdapter {
146
- config : ConfigBuilder :: new ( "identity" ) . build ( ) ,
147
- participants,
148
- } ;
149
-
150
- assert_eq ! ( Ok ( "token" . to_string( ) ) , adapter. get_auth( "identity" ) ) ;
151
- }
152
160
}
0 commit comments