Skip to content

Commit fc307f8

Browse files
committed
Fixed parsing fees string
Signed-off-by: artem.ivanov <[email protected]>
1 parent 129b813 commit fc307f8

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

cli/src/commands/ledger.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,9 +1068,6 @@ fn set_request_fees(request: &mut String, wallet_handle: i32, submitter_did: &st
10681068
}
10691069

10701070
fn parse_payment_inputs(inputs: &Vec<&str>) -> Result<String, ()> {
1071-
if inputs.is_empty() {
1072-
return Err(println_err!("Inputs list is empty"));
1073-
}
10741071
serde_json::to_string(&inputs)
10751072
.map_err(|_| println_err!("Wrong data has been received"))
10761073
}
@@ -3423,6 +3420,28 @@ pub mod tests {
34233420
TestUtils::cleanup_storage();
34243421
}
34253422

3423+
#[test]
3424+
pub fn set_fees_prepare_works_for_empty_fees() {
3425+
TestUtils::cleanup_storage();
3426+
let ctx = CommandContext::new();
3427+
3428+
create_and_connect_pool(&ctx);
3429+
create_and_open_wallet(&ctx);
3430+
load_null_payment_plugin(&ctx);
3431+
new_did(&ctx, SEED_TRUSTEE);
3432+
use_did(&ctx, DID_TRUSTEE);
3433+
{
3434+
let cmd = set_fees_prepare_command::new();
3435+
let mut params = CommandParams::new();
3436+
params.insert("payment_method", NULL_PAYMENT_METHOD.to_string());
3437+
params.insert("fees", "".to_string());
3438+
cmd.execute(&ctx, &params).unwrap_err();
3439+
}
3440+
close_and_delete_wallet(&ctx);
3441+
disconnect_and_delete_pool(&ctx);
3442+
TestUtils::cleanup_storage();
3443+
}
3444+
34263445
#[test]
34273446
pub fn set_fees_prepare_works_for_no_active_wallet() {
34283447
TestUtils::cleanup_storage();

cli/src/commands/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ pub fn get_opt_bool_param(key: &str, params: &CommandParams) -> Result<Option<bo
8888

8989
pub fn get_str_array_param<'a>(name: &'a str, params: &'a CommandParams) -> Result<Vec<&'a str>, ()> {
9090
match params.get(name) {
91-
Some(v) => Ok(if v.is_empty() {Vec::new()} else { v.split(",").collect::<Vec<&'a str>>() }),
92-
None => Err(println_err!("No required \"{}\" parameter present", name))
91+
None => Err(println_err!("No required \"{}\" parameter present", name)),
92+
Some(v) if v.is_empty() => Err(println_err!("No required \"{}\" parameter present", name)),
93+
Some(v) => Ok(v.split(",").collect::<Vec<&'a str>>())
9394
}
9495
}
9596

0 commit comments

Comments
 (0)