Skip to content
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

Add copyable command for deployment #2727

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/sncast/src/helpers/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ impl RpcArgs {

Ok(provider)
}

#[must_use]
pub fn get_url(&self, config: &CastConfig) -> String {
self.url.clone().unwrap_or_else(|| config.url.clone())
}
}
3 changes: 2 additions & 1 deletion crates/sncast/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,10 @@ async fn run_async_command(
.clone()
.context("Required argument `--name` not provided")?
} else {
config.account
config.account.clone()
};
let result = starknet_commands::account::create::create(
create.rpc.get_url(&config),
&account,
&config.accounts_file,
config.keystore,
Expand Down
25 changes: 22 additions & 3 deletions crates/sncast/src/starknet_commands/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sncast::helpers::braavos::BraavosAccountFactory;
use sncast::helpers::configuration::CastConfig;
use sncast::helpers::constants::{
ARGENT_CLASS_HASH, BRAAVOS_BASE_ACCOUNT_CLASS_HASH, BRAAVOS_CLASS_HASH,
CREATE_KEYSTORE_PASSWORD_ENV_VAR, OZ_CLASS_HASH,
CREATE_KEYSTORE_PASSWORD_ENV_VAR, DEFAULT_ACCOUNTS_FILE, OZ_CLASS_HASH,
};
use sncast::helpers::rpc::RpcArgs;
use sncast::response::structs::AccountCreateResponse;
Expand Down Expand Up @@ -57,6 +57,7 @@ pub struct Create {

#[allow(clippy::too_many_arguments)]
pub async fn create(
rpc_url: String,
account: &str,
accounts_file: &Utf8PathBuf,
keystore: Option<Utf8PathBuf>,
Expand All @@ -81,6 +82,8 @@ pub async fn create(
.context("Invalid address")?
.parse()?;

let mut message = "Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.".to_string();

if let Some(keystore) = keystore.clone() {
let account_path = Utf8PathBuf::from(&account);
if account_path == Utf8PathBuf::default() {
Expand All @@ -106,11 +109,14 @@ pub async fn create(
)?;
} else {
write_account_to_accounts_file(account, accounts_file, chain_id, account_json.clone())?;

let deploy_command = generate_deploy_command(accounts_file, &rpc_url, account);
message.push_str(&deploy_command);
}

if add_profile.is_some() {
let config = CastConfig {
url: create.rpc.url.clone().unwrap_or_default(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't work in case where url is provided from profile

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rare but possible

url: rpc_url,
account: account.into(),
accounts_file: accounts_file.into(),
keystore,
Expand All @@ -131,7 +137,7 @@ pub async fn create(
"--add-profile flag was not set. No profile added to snfoundry.toml".to_string()
},
message: if account_json["deployed"] == json!(false) {
"Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.".to_string()
message
} else {
"Account already deployed".to_string()
},
Expand Down Expand Up @@ -314,3 +320,16 @@ fn write_account_to_file(
)?;
Ok(())
}

fn generate_deploy_command(accounts_file: &Utf8PathBuf, rpc_url: &str, account: &str) -> String {
let accounts_flag = if accounts_file.to_string().contains(DEFAULT_ACCOUNTS_FILE) {
format!(" --accounts-file {accounts_file}")
} else {
String::new()
};

format!(
"\n\nAfter prefunding the address, run:\n\
sncast{accounts_flag} account deploy --url {rpc_url} --name {account} --fee-token strk"
)
}
9 changes: 9 additions & 0 deletions crates/sncast/tests/e2e/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub async fn test_happy_case(account_type: &str) {
max_fee: [..]
message: Account successfully created. Prefund generated address with at least <max_fee> STRK tokens or an equivalent amount of ETH tokens. It is good to send more in the case of higher demand.

After prefunding the address, run:
sncast account deploy --url http://127.0.0.1:5055/rpc --name my_account --fee-token strk

To see account creation details, visit:
account: [..]
"},
Expand Down Expand Up @@ -143,6 +146,9 @@ pub async fn test_happy_case_generate_salt() {
max_fee: [..]
message: Account successfully created[..]

After prefunding the address, run:
sncast account deploy --url http://127.0.0.1:5055/rpc --name my_account --fee-token strk

To see account creation details, visit:
account: [..]
"});
Expand Down Expand Up @@ -223,6 +229,9 @@ pub async fn test_happy_case_accounts_file_already_exists() {
max_fee: [..]
message: Account successfully created[..]

After prefunding the address, run:
sncast account deploy --url http://127.0.0.1:5055/rpc --name my_account --fee-token strk

To see account creation details, visit:
account: [..]
"});
Expand Down
Loading