Skip to content

Commit

Permalink
bump starknet deps
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Aug 15, 2024
1 parent 6057bde commit fa57578
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 55 deletions.
57 changes: 48 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ thiserror = "1.0.32"
url = "2.2.2"
rand = "0.8.4"

# Must be synced across all downstream crates
starknet = "0.11.0"
starknet-types-core = "~0.1.4"

Expand Down
3 changes: 1 addition & 2 deletions cli/src/command/auth/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ impl CreateSession {
let url = Url::parse(&self.rpc_url)?;
let chain_id = get_network_chain_id(url.clone()).await?;
let session = session::create(url, &self.policies).await?;
println!("session: {session:?}");
// session::store(chain_id, &session)?;
session::store(chain_id, &session)?;
Ok(())
}
}
Expand Down
6 changes: 3 additions & 3 deletions slot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tempfile = "3.10.1"
hyper.workspace = true
serde_with = "3.9.0"

[dependencies.account_sdk]
git = "https://github.com/cartridge-gg/controller"
# Must be synced across Dojo
# Branch `controllerabstraction` with cainome updated.
rev = "2427a9805a8e7f4b00844429f61ce577048e8d5b"
# account_sdk = { git = "https://github.com/cartridge-gg/controller", rev = "2427a9805a8e7f4b00844429f61ce577048e8d5b" }
account_sdk = { path = "../../controller/packages/account_sdk" }
59 changes: 18 additions & 41 deletions slot/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,6 @@ pub struct Policy {
pub method: String,
}

#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SessionDetails {
/// The expiration date of the session.
// TODO(kariy): change this to u64
pub expires_at: String,
/// The session's policies.
pub policies: Vec<Policy>,
pub credentials: SessionCredentials,
}

#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct SessionCredentials {
/// The signing key of the session.
pub private_key: Felt,
pub authorization: Vec<Felt>,
}

/// Retrieves the session for the given chain id of the currently authenticated user.
/// Returns `None` if no session can be found for the chain id.
///
Expand All @@ -66,7 +47,7 @@ pub fn get(chain: Felt) -> Result<Option<SessionMetadata>, Error> {
///
/// This function will return an error if there is no authenticated user.
///
pub fn store(chain: Felt, session: &SessionDetails) -> Result<PathBuf, Error> {
pub fn store(chain: Felt, session: &SessionMetadata) -> Result<PathBuf, Error> {
store_at(utils::config_dir(), chain, session)
}

Expand Down Expand Up @@ -114,7 +95,7 @@ where

/// Stores the session token of the chain id `chain` for the currently authenticated user. It will
/// use `config_dir` as the root path to store the session file.
fn store_at<P>(config_dir: P, chain: Felt, session: &SessionDetails) -> Result<PathBuf, Error>
fn store_at<P>(config_dir: P, chain: Felt, session: &SessionMetadata) -> Result<PathBuf, Error>
where
P: AsRef<Path>,
{
Expand Down Expand Up @@ -273,7 +254,7 @@ mod tests {
use crate::account::{Account, AccountCredentials};
use crate::credential::{AccessToken, Credentials};
use crate::error::Error::Unauthorized;
use crate::session::{get_at, get_user_relative_file_path, store_at, SessionDetails};
use crate::session::{get_at, get_user_relative_file_path, store_at};
use crate::utils;
use account_sdk::storage::SessionMetadata;
use starknet::{core::types::Felt, macros::felt};
Expand Down Expand Up @@ -343,24 +324,22 @@ mod tests {
let username = authenticate(&config_dir);

let chain = felt!("0x999");
let expected = SessionDetails::default();
let expected = SessionMetadata::default();
let path = store_at(&config_dir, chain, &expected).unwrap();

let user_path = get_user_relative_file_path(username, chain);
let actual = get_at(config_dir, chain).unwrap();

todo!()

// assert_eq!(Some(expected), actual);
// assert!(path.ends_with(user_path));
assert_eq!(Some(expected), actual);
assert!(path.ends_with(user_path));
}

#[test]
fn store_session_unauthenticated() {
let config_dir = utils::config_dir();

let chain = felt!("0x999");
let session = SessionDetails::default();
let session = SessionMetadata::default();

let err = store_at(config_dir, chain, &session).unwrap_err();
assert!(err.to_string().contains("No credentials found"))
Expand All @@ -378,20 +357,18 @@ mod tests {
// start the callback server
tokio::spawn(server.start());

// // call the callback url
// let session = SessionMetadata::default();
// let res = reqwest::Client::new()
// .post(url)
// .json(&session)
// .send()
// .await
// .expect("failed to call callback url");

// assert!(res.status().is_success());
// call the callback url
let session = SessionMetadata::default();
let res = reqwest::Client::new()
.post(url)
.json(&session)
.send()
.await
.expect("failed to call callback url");

// let actual = rx.recv().await.expect("failed to receive session");
// assert_eq!(session, actual)
assert!(res.status().is_success());

todo!()
let actual = rx.recv().await.expect("failed to receive session");
assert_eq!(session, actual)
}
}

0 comments on commit fa57578

Please sign in to comment.