feat: Make executors_file_path optional and use a default value if None
--- don't change below this line --- ENG-4088 Took 4 minutes Took 59 seconds
This commit is contained in:
@@ -22,12 +22,11 @@ fn main() {
|
||||
Some("0x123456789abcdef123456789abcdef123456789abcdef123456789abcdef1234".to_string());
|
||||
let user_address = Bytes::from_str("0xcd09f75E2BF2A4d11F3AB23f1389FcC1621c0cc2")
|
||||
.expect("Failed to create user address");
|
||||
let executors_file_path = "src/encoding/config/executor_addresses.json";
|
||||
|
||||
let eth_chain = Chain::from(TychoCoreChain::Ethereum);
|
||||
// Initialize the encoder
|
||||
let strategy_encoder_registry =
|
||||
EVMStrategyEncoderRegistry::new(eth_chain.clone(), executors_file_path, signer_pk.clone())
|
||||
EVMStrategyEncoderRegistry::new(eth_chain.clone(), None, signer_pk.clone())
|
||||
.expect("Failed to create strategy encoder registry");
|
||||
let encoder = EVMTychoEncoder::new(strategy_encoder_registry, router_address, eth_chain)
|
||||
.expect("Failed to create encoder");
|
||||
|
||||
1
src/encoding/evm/constants.rs
Normal file
1
src/encoding/evm/constants.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub const DEFAULT_EXECUTORS_FILE_PATH: &str = "src/encoding/config/executor_addresses.json";
|
||||
@@ -3,6 +3,7 @@ use std::collections::HashMap;
|
||||
use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
evm::{
|
||||
constants::DEFAULT_EXECUTORS_FILE_PATH,
|
||||
strategy_encoder::strategy_encoders::{ExecutorStrategyEncoder, SplitSwapStrategyEncoder},
|
||||
swap_encoder::swap_encoder_registry::SwapEncoderRegistry,
|
||||
},
|
||||
@@ -22,10 +23,13 @@ pub struct EVMStrategyEncoderRegistry {
|
||||
impl StrategyEncoderRegistry for EVMStrategyEncoderRegistry {
|
||||
fn new(
|
||||
chain: Chain,
|
||||
executors_file_path: &str,
|
||||
executors_file_path: Option<&str>,
|
||||
signer_pk: Option<String>,
|
||||
) -> Result<Self, EncodingError> {
|
||||
let swap_encoder_registry = SwapEncoderRegistry::new(executors_file_path, chain.clone())?;
|
||||
let swap_encoder_registry = SwapEncoderRegistry::new(
|
||||
executors_file_path.unwrap_or(DEFAULT_EXECUTORS_FILE_PATH),
|
||||
chain.clone(),
|
||||
)?;
|
||||
|
||||
let mut strategies: HashMap<String, Box<dyn StrategyEncoder>> = HashMap::new();
|
||||
strategies.insert(
|
||||
|
||||
@@ -169,7 +169,7 @@ mod tests {
|
||||
impl StrategyEncoderRegistry for MockStrategyRegistry {
|
||||
fn new(
|
||||
_chain: Chain,
|
||||
_executors_file_path: &str,
|
||||
_executors_file_path: Option<&str>,
|
||||
_signer_pk: Option<String>,
|
||||
) -> Result<MockStrategyRegistry, EncodingError> {
|
||||
Ok(Self { strategy: Box::new(MockStrategy) })
|
||||
@@ -205,7 +205,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn get_mocked_tycho_encoder() -> EVMTychoEncoder<MockStrategyRegistry> {
|
||||
let strategy_registry = MockStrategyRegistry::new(eth_chain(), "", None).unwrap();
|
||||
let strategy_registry = MockStrategyRegistry::new(eth_chain(), None, None).unwrap();
|
||||
EVMTychoEncoder::new(
|
||||
strategy_registry,
|
||||
"0x1234567890abcdef1234567890abcdef12345678".to_string(),
|
||||
|
||||
@@ -23,7 +23,7 @@ pub trait StrategyEncoder {
|
||||
pub trait StrategyEncoderRegistry {
|
||||
fn new(
|
||||
chain: Chain,
|
||||
executors_file_path: &str,
|
||||
executors_file_path: Option<&str>,
|
||||
signer_pk: Option<String>,
|
||||
) -> Result<Self, EncodingError>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user