Skip to content

Commit

Permalink
Get wallet pubkey id if not available
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgranhao committed Feb 7, 2024
1 parent 5c9dc87 commit 4f93f87
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion honey-badger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Auth {
.ok_or_permanent_failure("Newly refreshed token is not valid long enough")
}

pub fn get_wallet_pubkey_id(&self) -> Option<String> {
pub fn get_wallet_pubkey_id(&self) -> Result<String> {
self.provider.lock().unwrap().get_wallet_pubkey_id()
}

Expand Down
10 changes: 8 additions & 2 deletions honey-badger/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,14 @@ impl AuthProvider {
Ok(access_token)
}

pub fn get_wallet_pubkey_id(&self) -> Option<String> {
self.wallet_pubkey_id.clone()
pub fn get_wallet_pubkey_id(&mut self) -> Result<String> {
if let Some(wallet_pubkey_id) = &self.wallet_pubkey_id {
Ok(wallet_pubkey_id.clone())
} else {
let (_, _, wallet_pub_key_id) = self.start_basic_session()?;
self.wallet_pubkey_id = Some(wallet_pub_key_id.clone());
Ok(wallet_pub_key_id)
}
}

pub fn accept_terms_and_conditions(
Expand Down
47 changes: 26 additions & 21 deletions honey-badger/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ fn test_invalid_url() {
)
.unwrap();

let id = auth.get_wallet_pubkey_id();
assert!(id.is_none());
let result = auth.get_wallet_pubkey_id();
assert!(matches!(
result,
Err(Error::RuntimeError {
code: GraphQlRuntimeErrorCode::NetworkError,
..
})
));

let result = auth.query_token();
assert!(matches!(
Expand All @@ -55,8 +61,14 @@ fn test_502_return() {
)
.unwrap();

let id = auth.get_wallet_pubkey_id();
assert!(id.is_none());
let result = auth.get_wallet_pubkey_id();
assert!(matches!(
result,
Err(Error::RuntimeError {
code: GraphQlRuntimeErrorCode::RemoteServiceUnavailable,
..
})
));

let result = auth.query_token();
assert!(matches!(
Expand All @@ -80,21 +92,19 @@ fn test_basic_auth() {
)
.unwrap();

let id = auth.get_wallet_pubkey_id();
assert!(id.is_none());
let _id = auth.get_wallet_pubkey_id().unwrap();

let token = auth.query_token().unwrap();
let next_token = auth.query_token().unwrap();
assert_eq!(token, next_token);

let id = auth.get_wallet_pubkey_id();
assert!(id.is_some());
let id = auth.get_wallet_pubkey_id().unwrap();

sleep(Duration::from_secs(1));
let refreshed_token = auth.refresh_token().unwrap();
assert_ne!(token, refreshed_token);

assert_eq!(auth.get_wallet_pubkey_id(), id);
assert_eq!(auth.get_wallet_pubkey_id().unwrap(), id);
}

#[test]
Expand All @@ -109,21 +119,19 @@ fn test_owner_auth() {
)
.unwrap();

let id = auth.get_wallet_pubkey_id();
assert!(id.is_none());
let _id = auth.get_wallet_pubkey_id().unwrap();

let token = auth.query_token().unwrap();
let next_token = auth.query_token().unwrap();
assert_eq!(token, next_token);

let id = auth.get_wallet_pubkey_id();
assert!(id.is_some());
let id = auth.get_wallet_pubkey_id().unwrap();

sleep(Duration::from_secs(1));
let refreshed_token = auth.refresh_token().unwrap();
assert_ne!(token, refreshed_token);

assert_eq!(auth.get_wallet_pubkey_id(), id);
assert_eq!(auth.get_wallet_pubkey_id().unwrap(), id);
}

#[test]
Expand All @@ -138,8 +146,7 @@ fn test_employee_with_no_owner_auth() {
)
.unwrap();

let id = auth.get_wallet_pubkey_id();
assert!(id.is_none());
let _id = auth.get_wallet_pubkey_id().unwrap();

let result = auth.query_token();
assert!(matches!(result, Err(Error::InvalidInput { .. })));
Expand All @@ -159,21 +166,19 @@ fn test_employee_auth() {
)
.unwrap();

let id = auth.get_wallet_pubkey_id();
assert!(id.is_none());
let _id = auth.get_wallet_pubkey_id().unwrap();

let token = auth.query_token().unwrap();
let next_token = auth.query_token().unwrap();
assert_eq!(token, next_token);

let id = auth.get_wallet_pubkey_id();
assert!(id.is_some());
let id = auth.get_wallet_pubkey_id().unwrap();

sleep(Duration::from_secs(1));
let refreshed_token = auth.refresh_token().unwrap();
assert_ne!(token, refreshed_token);

assert_eq!(auth.get_wallet_pubkey_id(), id);
assert_eq!(auth.get_wallet_pubkey_id().unwrap(), id);
}

#[test]
Expand Down

0 comments on commit 4f93f87

Please sign in to comment.