Skip to content

Commit 0d3b5fb

Browse files
authored
chore(fortuna)-add-network-id-api (#2904)
* chore(fortuna)-add-network-id-api * fortuna update
1 parent 48147e2 commit 0d3b5fb

File tree

4 files changed

+83
-16
lines changed

4 files changed

+83
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fortuna"
3-
version = "8.2.4"
3+
version = "8.2.5"
44
edition = "2021"
55

66
[lib]

apps/fortuna/src/api.rs

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ mod test {
596596

597597
#[tokio::test]
598598
async fn test_chain_configs_with_data() {
599+
use crate::api::get_chain_configs;
600+
use axum::{routing::get, Router};
601+
599602
// Create a config with actual chain data
600603
let mut config_chains = HashMap::new();
601604
config_chains.insert(
@@ -673,16 +676,72 @@ mod test {
673676
},
674677
};
675678

676-
let metrics_registry = Arc::new(RwLock::new(Registry::default()));
677-
let api_state = ApiState::new(
678-
Arc::new(RwLock::new(HashMap::new())),
679-
metrics_registry,
680-
Arc::new(History::new().await.unwrap()),
681-
&config,
682-
)
683-
.await;
679+
// Create initialized blockchain states with network IDs
680+
let eth_read = Arc::new(MockEntropyReader::with_requests(10, &[]));
681+
let avax_read = Arc::new(MockEntropyReader::with_requests(10, &[]));
684682

685-
let app = api::routes(api_state);
683+
let eth_state = MonitoredHashChainState::new(
684+
ETH_CHAIN.clone(),
685+
Default::default(),
686+
"ethereum".into(),
687+
PROVIDER,
688+
);
689+
690+
let eth_blockchain_state = BlockchainState {
691+
id: "ethereum".into(),
692+
network_id: 1, // Ethereum mainnet
693+
state: Arc::new(eth_state),
694+
contract: eth_read.clone(),
695+
provider_address: PROVIDER,
696+
reveal_delay_blocks: 1,
697+
confirmed_block_status: BlockStatus::Latest,
698+
};
699+
700+
let avax_state = MonitoredHashChainState::new(
701+
AVAX_CHAIN.clone(),
702+
Default::default(),
703+
"avalanche".into(),
704+
PROVIDER,
705+
);
706+
707+
let avax_blockchain_state = BlockchainState {
708+
id: "avalanche".into(),
709+
network_id: 43114, // Avalanche C-Chain
710+
state: Arc::new(avax_state),
711+
contract: avax_read.clone(),
712+
provider_address: PROVIDER,
713+
reveal_delay_blocks: 2,
714+
confirmed_block_status: BlockStatus::Latest,
715+
};
716+
717+
// Create chains HashMap with initialized states
718+
let mut chains = HashMap::new();
719+
chains.insert(
720+
"ethereum".into(),
721+
ApiBlockChainState::Initialized(eth_blockchain_state),
722+
);
723+
chains.insert(
724+
"avalanche".into(),
725+
ApiBlockChainState::Initialized(avax_blockchain_state),
726+
);
727+
728+
// Minimal ApiState for this endpoint
729+
let api_state = ApiState {
730+
chains: Arc::new(RwLock::new(chains)),
731+
history: Arc::new(History::new().await.unwrap()),
732+
metrics_registry: Arc::new(RwLock::new(Registry::default())),
733+
metrics: Arc::new(crate::api::ApiMetrics {
734+
http_requests: prometheus_client::metrics::family::Family::default(),
735+
}),
736+
explorer_metrics: Arc::new(
737+
crate::api::ExplorerMetrics::new(Arc::new(RwLock::new(Registry::default()))).await,
738+
),
739+
config,
740+
};
741+
742+
let app = Router::new()
743+
.route("/v1/chains/configs", get(get_chain_configs))
744+
.with_state(api_state);
686745
let server = TestServer::new(app).unwrap();
687746

688747
// Test the chain configs endpoint
@@ -706,7 +765,8 @@ mod test {
706765
);
707766
assert_eq!(eth_config.reveal_delay_blocks, 1);
708767
assert_eq!(eth_config.gas_limit, 500000);
709-
assert_eq!(eth_config.fee, 1500000000000000);
768+
assert_eq!(eth_config.default_fee, 1500000000000000);
769+
assert_eq!(eth_config.network_id, 1); // Ethereum mainnet
710770

711771
// Find avalanche config
712772
let avax_config = configs
@@ -719,6 +779,7 @@ mod test {
719779
);
720780
assert_eq!(avax_config.reveal_delay_blocks, 2);
721781
assert_eq!(avax_config.gas_limit, 600000);
722-
assert_eq!(avax_config.fee, 2000000000000000);
782+
assert_eq!(avax_config.default_fee, 2000000000000000);
783+
assert_eq!(avax_config.network_id, 43114); // Avalanche C-Chain
723784
}
724785
}

apps/fortuna/src/api/config.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
use {
2-
crate::api::{ApiState, RestError},
2+
crate::api::{ApiBlockChainState, ApiState, RestError},
33
axum::{extract::State, Json},
44
serde::Serialize,
55
};
66

77
#[derive(Serialize, serde::Deserialize)]
88
pub struct ChainConfigSummary {
99
pub name: String,
10+
pub network_id: u64,
1011
pub contract_addr: String,
1112
pub reveal_delay_blocks: u64,
1213
pub gas_limit: u32,
13-
pub fee: u128,
14+
pub default_fee: u128,
1415
}
1516

1617
pub async fn get_chain_configs(
1718
State(state): State<ApiState>,
1819
) -> Result<Json<Vec<ChainConfigSummary>>, RestError> {
1920
let mut configs = Vec::new();
2021
for (name, chain) in state.config.chains.iter() {
22+
let network_id = match state.chains.read().await.get(name) {
23+
Some(ApiBlockChainState::Initialized(blockchain_state)) => blockchain_state.network_id,
24+
_ => 0,
25+
};
2126
configs.push(ChainConfigSummary {
2227
name: name.clone(),
28+
network_id,
2329
contract_addr: format!("0x{:x}", chain.contract_addr),
2430
reveal_delay_blocks: chain.reveal_delay_blocks,
2531
gas_limit: chain.gas_limit,
26-
fee: chain.fee,
32+
default_fee: chain.fee,
2733
});
2834
}
2935
Ok(Json(configs))

0 commit comments

Comments
 (0)