Skip to content

Commit

Permalink
tested JS commands aliases (added missing 'keys', 'import-account', a…
Browse files Browse the repository at this point in the history
…nd 'validator-stake' aliases)
  • Loading branch information
frol committed Jul 9, 2024
1 parent ef37494 commit 45e983b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/js_command_match/account/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::js_command_match::constants::{
};

#[derive(Debug, Clone, clap::Parser)]
#[clap(alias("create"))]
pub struct CreateAccountArgs {
new_account_id: String,
#[clap(long, aliases = USE_FAUCET_ALIASES, default_value_t = false)]
Expand Down Expand Up @@ -98,6 +97,10 @@ mod tests {
#[test]
fn create_account() {
for (input, expected_output) in [
(
format!("near create-account bob.testnet --{}", USE_FAUCET_ALIASES[0]),
"account create-account sponsor-by-faucet-service bob.testnet autogenerate-new-keypair save-to-keychain network-config testnet create"
),
(
format!("near create bob.testnet --{}", USE_FAUCET_ALIASES[0]),
"account create-account sponsor-by-faucet-service bob.testnet autogenerate-new-keypair save-to-keychain network-config testnet create"
Expand Down
5 changes: 4 additions & 1 deletion src/js_command_match/account/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::js_command_match::constants::{
};

#[derive(Debug, Clone, clap::Parser)]
#[clap(alias("delete"))]
pub struct DeleteAccountArgs {
account_id: String,
beneficiary_id: String,
Expand Down Expand Up @@ -57,6 +56,10 @@ mod tests {
#[test]
fn delete_account() {
for (input, expected_output) in [
(
format!("near delete bob.testnet alice.testnet --force"),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-keychain send")
),
(
format!("near delete-account bob.testnet alice.testnet --force"),
format!("account delete-account bob.testnet beneficiary alice.testnet network-config testnet sign-with-keychain send")
Expand Down
4 changes: 4 additions & 0 deletions src/js_command_match/account/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ mod tests {
#[test]
fn login() {
for (input, expected_output) in [
(
"near import-account".to_string(),
"account import-account using-web-wallet network-config testnet".to_string(),
),
(
"near login".to_string(),
"account import-account using-web-wallet network-config testnet".to_string(),
Expand Down
5 changes: 4 additions & 1 deletion src/js_command_match/contract/storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::js_command_match::constants::{BLOCK_ID_ALIASES, NETWORK_ID_ALIASES};

#[derive(Debug, Clone, clap::Parser)]
#[clap(alias("storage"))]
pub struct ViewStateArgs {
account_id: String,
#[clap(long)]
Expand Down Expand Up @@ -71,6 +70,10 @@ mod tests {
#[test]
fn view_state() {
for (input, expected_output) in [
(
format!("near storage counter.near-examples.testnet --prefix U1RBVEU= --{} 167860267", BLOCK_ID_ALIASES[0]),
"contract view-storage counter.near-examples.testnet keys-start-with-bytes-as-base64 'U1RBVEU=' as-json network-config testnet at-block-height 167860267"
),
(
format!("near view-state counter.near-examples.testnet --prefix U1RBVEU= --{} 167860267", BLOCK_ID_ALIASES[0]),
"contract view-storage counter.near-examples.testnet keys-start-with-bytes-as-base64 'U1RBVEU=' as-json network-config testnet at-block-height 167860267"
Expand Down
4 changes: 4 additions & 0 deletions src/js_command_match/keys/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ mod tests {
#[test]
fn list_keys() {
for (input, expected_output) in [
(
"near keys bob.testnet".to_string(),
"account list-keys bob.testnet network-config testnet now".to_string(),
),
(
"near list-keys bob.testnet".to_string(),
"account list-keys bob.testnet network-config testnet now".to_string(),
Expand Down
7 changes: 7 additions & 0 deletions src/js_command_match/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@ mod validators;
#[derive(Debug, Clone, clap::Parser)]
/// Legacy CLI commands are only supported at best-effort
pub enum JsCmd {
#[clap(alias("create"))]
CreateAccount(self::account::create::CreateAccountArgs),
#[clap(alias("delete"))]
DeleteAccount(self::account::delete::DeleteAccountArgs),
#[clap(alias("import-account"))]
Login(self::account::login::LoginArgs),
State(self::account::state::StateArgs),

Call(self::contract::call::CallArgs),
Deploy(self::contract::deploy::DeployArgs),
#[clap(alias("storage"))]
ViewState(self::contract::storage::ViewStateArgs),
View(self::contract::view::ViewArgs),

AddKey(self::keys::add::AddKeyArgs),
DeleteKey(self::keys::delete::DeleteKeyArgs),
#[clap(alias("keys"))]
ListKeys(self::keys::list::KeysArgs),

#[clap(alias("send-near"))]
Send(self::transactions::send::SendArgs),
TxStatus(self::transactions::status::TxStatusArgs),

#[clap(alias("validator-stake"))]
Stake(self::validators::StakeArgs),
Validators(self::validators::ValidatorsArgs),
}
Expand Down
5 changes: 4 additions & 1 deletion src/js_command_match/transactions/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::js_command_match::constants::{
};

#[derive(Debug, Clone, clap::Parser)]
#[clap(alias("send-near"))]
pub struct SendArgs {
pub sender: String,
pub receiver: String,
Expand Down Expand Up @@ -52,6 +51,10 @@ mod tests {
#[test]
fn send() {
for (input, expected_output) in [
(
format!("near send bob.testnet alice.testnet 1 --{}", SIGN_WITH_LEDGER_ALIASES[0]),
"tokens bob.testnet send-near alice.testnet '1 NEAR' network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send"
),
(
format!("near send-near bob.testnet alice.testnet 1 --{}", SIGN_WITH_LEDGER_ALIASES[0]),
"tokens bob.testnet send-near alice.testnet '1 NEAR' network-config testnet sign-with-ledger --seed-phrase-hd-path '44'\\''/397'\\''/0'\\''/0'\\''/1'\\''' send"
Expand Down
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,18 @@ fn main() -> crate::common::CliResult {
}
Err(error) => {
if let clap::error::ErrorKind::DisplayHelp = error.kind() {
error.exit()
error.exit();
}
if let Some(cmd) = std::env::args().nth(1) {
match cmd.as_str() {
"add-credentials" | "add-key" | "call" | "create"
| "create-account" | "delete" | "delete-account" | "delete-key"
| "deploy" | "generate-key" | "import-account" | "keys"
| "list-keys" | "login" | "send" | "send-near" | "stake"
| "state" | "storage" | "tx-status" | "validator-stake"
| "validators" | "view" | "view-storage" => error.exit(),
_ => {}
}
}
}
},
Expand Down

0 comments on commit 45e983b

Please sign in to comment.