Skip to content

Commit

Permalink
Add value delimiter and tests args (#2280)
Browse files Browse the repository at this point in the history
## Description
This PR adds the possibility to define multiple relayers with ','
delimiter in args. It also adds a test for the relayer argument.

## Checklist
- [x] Breaking changes are clearly marked as such in the PR description
and changelog
- [x] New behavior is reflected in tests
- [x] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [x] I have reviewed the code myself
- [x] I have created follow-up issues caused by this PR and linked them
here
  • Loading branch information
AurelienFT authored Oct 3, 2024
1 parent 6111cef commit 8be3b47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2189](https://github.com/FuelLabs/fuel-core/pull/2151): Select next DA height to never include more than u16::MAX -1 transactions from L1.
- [2162](https://github.com/FuelLabs/fuel-core/pull/2162): Pool structure with dependencies, etc.. for the next transaction pool module. Also adds insertion/verification process in PoolV2 and tests refactoring
- [2265](https://github.com/FuelLabs/fuel-core/pull/2265): Integrate Block Committer API for DA Block Costs.
- [2280](https://github.com/FuelLabs/fuel-core/pull/2280): Allow comma separated relayer addresses in cli

### Changed

Expand Down
26 changes: 25 additions & 1 deletion bin/fuel-core/src/cli/run/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct RelayerArgs {

/// Uri addresses to ethereum client. It can be in format of `http://localhost:8545/` or `ws://localhost:8545/`.
/// If not set relayer will not start.
#[arg(long = "relayer", env)]
#[arg(long = "relayer", value_delimiter = ',', env)]
#[arg(required_if_eq("enable_relayer", "true"))]
#[arg(requires_if(IsPresent, "enable_relayer"))]
pub relayer: Option<Vec<url::Url>>,
Expand Down Expand Up @@ -70,3 +70,27 @@ impl RelayerArgs {
Some(config)
}
}

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

#[derive(Debug, Clone, Parser)]
pub struct Command {
#[clap(flatten)]
relayer: RelayerArgs,
}

#[test_case(&[""] => Ok(None); "no args")]
#[test_case(&["", "--enable-relayer", "--relayer=https://test.com"] => Ok(Some(vec![url::Url::parse("https://test.com").unwrap()])); "one relayer")]
#[test_case(&["", "--enable-relayer", "--relayer=https://test.com", "--relayer=https://test2.com"] => Ok(Some(vec![url::Url::parse("https://test.com").unwrap(), url::Url::parse("https://test2.com").unwrap()])); "two relayers in different args")]
#[test_case(&["", "--enable-relayer", "--relayer=https://test.com,https://test2.com"] => Ok(Some(vec![url::Url::parse("https://test.com").unwrap(), url::Url::parse("https://test2.com").unwrap()])); "two relayers in same arg")]
fn parse_relayer_urls(args: &[&str]) -> Result<Option<Vec<url::Url>>, String> {
let command: Command =
Command::try_parse_from(args).map_err(|e| e.to_string())?;
let args = command.relayer;
Ok(args.relayer)
}
}

0 comments on commit 8be3b47

Please sign in to comment.