-
Notifications
You must be signed in to change notification settings - Fork 239
Support inbuilt devnet accounts #3761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 61 commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
7267154
Add `DevetClient`
franciszekjob ab2a7cd
Support inbuilt devnet accounts
franciszekjob 0e933b4
Rename `DevnetClient` -> `DevnetProvider`
franciszekjob 2f7bd43
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob 5db4ffe
Remove `account_exists_in_accounts_file`
franciszekjob 7a57e73
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob 9c42ddd
Add `account_exists_in_accounts_file`
franciszekjob c2baa3e
Refactor test
franciszekjob 31e77fa
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob 2213285
Remove functions
franciszekjob 8640934
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob 245d69f
Fix imports
franciszekjob ec03598
Add tests
franciszekjob 64c8c5b
Fix typo
franciszekjob fff8c9d
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob ef13d2a
Fix test
franciszekjob dbb17a0
Fix newline
franciszekjob a534600
Add `use_devnet_account_with_node_not_being_devnet` test
franciszekjob b3e4cfb
Fix tests
franciszekjob f8a4019
Fix tests
franciszekjob fa4af76
Little refactor
franciszekjob 656dd30
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob 1604d50
Remove enters
franciszekjob ce48a81
Remove enters
franciszekjob 944c3a2
Update warning message
franciszekjob d7ea750
Fix devnet path
franciszekjob 53de064
Use fixed version of cairo deps
cptartur b32ed80
Release 0.50.0
cptartur 3227541
Close #3723
cptartur 11215b7
Update tests
cptartur 1d8443a
Lint
cptartur 9d52309
Merge branch 'master' into 3603-devnet-client
franciszekjob 7354f77
Merge branch '3603-devnet-client' into 3603-2-support-inbuilt-devnet-…
franciszekjob bb2f942
Merge branch 'release-0.50.0' into 3603-devnet-client
franciszekjob 646c0ea
Merge branch '3603-devnet-client' into 3603-2-support-inbuilt-devnet-…
franciszekjob 42e7847
Update CHANGELOG.md
cptartur 66fa96c
Release 0.50.0 lint (#3769)
cptartur f71fce4
Merge branch 'release-0.50.0' into 3603-devnet-client
franciszekjob efc0be7
Merge branch 'master' of https://github.com/foundry-rs/starknet-found…
franciszekjob 29d976d
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob dc03f27
Apply code review suggestion
franciszekjob 3a1f463
Fix `Cargo.lock`
franciszekjob 78c6cbd
git
franciszekjob 3850d70
Apply code review suggestion
franciszekjob 98d254b
Fix error message
franciszekjob 7adb617
Merge branch '3603-2-support-inbuilt-devnet-accounts' of https://gith…
franciszekjob ec6f02e
Remove files
franciszekjob c9ca88d
Fix errors
franciszekjob a6c8252
Fix changelog
franciszekjob de848e8
Remove redundant comments
franciszekjob 2718462
Apply code review suggestion
franciszekjob 354b537
Merge branch '3603-devnet-client' into 3603-2-support-inbuilt-devnet-…
franciszekjob 24802a6
Apply code review suggestions
franciszekjob fd67052
Add `DevnetProvider.ensure_alive()`
franciszekjob fe1214d
Apply code review suggestion
franciszekjob 9a5c346
Merge branch '3603-devnet-client' of https://github.com/foundry-rs/st…
franciszekjob 0fcf44c
Ensure devnet is alive in `get_account_from_devnet`
franciszekjob 2d52837
Merge branch '3603-2-support-inbuilt-devnet-accounts' of https://gith…
franciszekjob 9c97bf1
Formatting
franciszekjob d8edc5f
Fix test
franciszekjob 4a4899d
Apply code review suggestions
franciszekjob fc0bb1d
Remove assertions
franciszekjob 3180a75
Apply code review suggestion
franciszekjob 02b9c6e
Fix test
franciszekjob fdb41d4
Fix linting
franciszekjob 30717f3
Merge branch '3603-devnet-client' into 3603-2-support-inbuilt-devnet-…
franciszekjob 623041b
Disallow devnet accounts usage with sepolia and mainnet networks
franciszekjob bd3bd47
Merge branch '3603-2-support-inbuilt-devnet-accounts' of https://gith…
franciszekjob 1072c02
Add `use_devnet_account_with_network_flags`
franciszekjob e7af6c5
Fix devnet path
franciszekjob 5f47a99
Update error msg
franciszekjob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
use crate::AccountData; | ||
use ::serde::{Deserialize, Serialize, de::DeserializeOwned}; | ||
use anyhow::{Context, Error, ensure}; | ||
use reqwest::Client; | ||
use serde_json::json; | ||
use starknet_types_core::felt::Felt; | ||
use url::Url; | ||
|
||
/// A Devnet-RPC client. | ||
#[derive(Debug, Clone)] | ||
pub struct DevnetProvider { | ||
client: Client, | ||
url: Url, | ||
} | ||
|
||
/// All Devnet-RPC methods as listed in the official docs. | ||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)] | ||
pub enum DevnetProviderMethod { | ||
#[serde(rename = "devnet_getConfig")] | ||
GetConfig, | ||
|
||
#[serde(rename = "devnet_getPredeployedAccounts")] | ||
GetPredeployedAccounts, | ||
} | ||
|
||
impl DevnetProvider { | ||
#[must_use] | ||
pub fn new(url: &str) -> Self { | ||
let url = Url::parse(url).expect("Invalid URL"); | ||
Self { | ||
client: Client::new(), | ||
url, | ||
} | ||
} | ||
} | ||
|
||
impl DevnetProvider { | ||
async fn send_request<P, R>(&self, method: DevnetProviderMethod, params: P) -> anyhow::Result<R> | ||
where | ||
P: Serialize + Send + Sync, | ||
R: DeserializeOwned, | ||
{ | ||
let res = self | ||
.client | ||
.post(self.url.clone()) | ||
.header("Content-Type", "application/json") | ||
.json(&json!({ | ||
"jsonrpc": "2.0", | ||
"method": method, | ||
"params": params, | ||
"id": 1, | ||
})) | ||
.send() | ||
.await | ||
.context("Failed to send request")? | ||
.json::<serde_json::Value>() | ||
.await | ||
.context("Failed to parse response")?; | ||
|
||
if let Some(error) = res.get("error") { | ||
Err(anyhow::anyhow!(error.to_string())) | ||
} else if let Some(result) = res.get("result") { | ||
serde_json::from_value(result.clone()).map_err(anyhow::Error::from) | ||
} else { | ||
panic!("Malformed RPC response: {res}") | ||
} | ||
} | ||
|
||
/// Fetches the current Devnet configuration. | ||
pub async fn get_config(&self) -> Result<Config, Error> { | ||
self.send_request(DevnetProviderMethod::GetConfig, json!({})) | ||
.await | ||
} | ||
|
||
/// Fetches the list of predeployed accounts in Devnet. | ||
pub async fn get_predeployed_accounts(&self) -> Result<Vec<PredeployedAccount>, Error> { | ||
self.send_request(DevnetProviderMethod::GetPredeployedAccounts, json!({})) | ||
.await | ||
} | ||
|
||
/// Ensures the Devnet instance is alive. | ||
pub async fn ensure_alive(&self) -> Result<(), Error> { | ||
let is_alive = self | ||
.client | ||
.get(format!( | ||
"{}/is_alive", | ||
self.url.to_string().replace("/rpc", "") | ||
)) | ||
.send() | ||
.await | ||
.map(|res| res.status().is_success()) | ||
.unwrap_or(false); | ||
|
||
ensure!( | ||
is_alive, | ||
"Node at {} is not responding to the Devnet health check (GET `/is_alive`). It may not be a Devnet instance or it may be down.", | ||
self.url | ||
); | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Config { | ||
pub seed: u32, | ||
pub account_contract_class_hash: Felt, | ||
pub total_accounts: u8, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct PredeployedAccount { | ||
pub address: Felt, | ||
pub private_key: Felt, | ||
pub public_key: Felt, | ||
} | ||
|
||
impl From<&PredeployedAccount> for AccountData { | ||
fn from(predeployed_account: &PredeployedAccount) -> Self { | ||
Self { | ||
address: Some(predeployed_account.address), | ||
private_key: predeployed_account.private_key, | ||
public_key: predeployed_account.public_key, | ||
class_hash: None, | ||
salt: None, | ||
deployed: None, | ||
legacy: None, | ||
account_type: None, | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.