Skip to content

Commit

Permalink
Fixes the error message for incorrect keypair's path (#1962)
Browse files Browse the repository at this point in the history
Closes #1959

## Checklist
- [x] New behavior is reflected in tests

### Before requesting review
- [x] I have reviewed the code myself
  • Loading branch information
xgreenx authored Jun 15, 2024
1 parent 83b2b70 commit 5583410
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#1964](https://github.com/FuelLabs/fuel-core/pull/1964): Add `creation_instant` as second sort key in tx pool

### Fixed
- [#1962](https://github.com/FuelLabs/fuel-core/pull/1962): Fixes the error message for incorrect keypair's path.
- [#1950](https://github.com/FuelLabs/fuel-core/pull/1950): Fix cursor `BlockHeight` encoding in `SortedTXCursor`

## [Version 0.28.0]
Expand Down
27 changes: 26 additions & 1 deletion bin/fuel-core/src/cli/run/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,13 @@ impl KeypairArg {
}
let path = PathBuf::from_str(s);
if let Ok(pathbuf) = path {
return Ok(KeypairArg::Path(pathbuf))
if pathbuf.exists() {
return Ok(KeypairArg::Path(pathbuf))
} else {
return Err(anyhow!(
"path `{pathbuf:?}` does not exist for keypair argument"
))
}
}
Err(anyhow!(
"invalid keypair argument, neither a valid key or path"
Expand Down Expand Up @@ -329,3 +335,22 @@ impl P2PArgs {
Ok(Some(config))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_invalid_path() {
// Given
let invalid_path = "/invalid/path/to/keypair";
// When
let keypair = KeypairArg::try_from_string(invalid_path);

// Then
let err = keypair.expect_err("The path is incorrect it should fail");
assert!(err
.to_string()
.contains("does not exist for keypair argument"));
}
}

0 comments on commit 5583410

Please sign in to comment.