1+ use std:: collections:: BTreeMap ;
12use std:: num:: NonZeroU64 ;
23
34use crate :: common;
45
5- use e2e_tests:: foreign_chain_mock:: { MOCK_EVM_CHAIN_ID , MockAuthExpectation , setup_evm_mock } ;
6+ use e2e_tests:: foreign_chain_mock:: setup_evm_chain_id_mock ;
67use e2e_tests:: { CLUSTER_WAIT_TIMEOUT , metrics} ;
78use httpmock:: MockServer ;
89use mpc_node_config:: {
910 AuthConfig , ForeignChainConfig , ForeignChainProviderConfig , ForeignChainsConfig ,
1011} ;
11- use near_mpc_bounded_collections:: NonEmptyBTreeMap ;
1212
13- const HEALTHY_PROVIDER : & str = "healthy" ;
14- const WRONG_NETWORK_PROVIDER : & str = "wrong-network" ;
15- /// Any chain id the mock does not serve, so the probe reads a network mismatch.
13+ /// Belongs to no real chain: the probe only compares what a provider answers against config.
14+ const EXPECTED_NETWORK : u64 = 99999 ;
15+ /// Any chain id the expected mock does not serve, so the probe reads a network mismatch.
1616const ANOTHER_NETWORK : u64 = 1 ;
1717
18- fn base_chain_config ( rpc_url : & str , expected_network : u64 , provider : & str ) -> ForeignChainConfig {
19- ForeignChainConfig {
20- timeout_sec : NonZeroU64 :: new ( 10 ) . unwrap ( ) ,
21- max_retries : NonZeroU64 :: new ( 1 ) . unwrap ( ) ,
22- expected_network_fingerprint : Some ( expected_network. to_string ( ) ) ,
23- providers : NonEmptyBTreeMap :: new (
24- provider. to_string ( ) . into ( ) ,
25- ForeignChainProviderConfig {
26- rpc_url : rpc_url. to_string ( ) ,
27- auth : AuthConfig :: None ,
28- } ,
29- ) ,
18+ fn bnb_chain_config ( providers : & [ ( & str , & str ) ] ) -> ForeignChainsConfig {
19+ let providers: BTreeMap < _ , _ > = providers
20+ . iter ( )
21+ . map ( |( name, rpc_url) | {
22+ (
23+ name. to_string ( ) . into ( ) ,
24+ ForeignChainProviderConfig {
25+ rpc_url : rpc_url. to_string ( ) ,
26+ auth : AuthConfig :: None ,
27+ } ,
28+ )
29+ } )
30+ . collect ( ) ;
31+ ForeignChainsConfig {
32+ bnb : Some ( ForeignChainConfig {
33+ timeout_sec : NonZeroU64 :: new ( 10 ) . unwrap ( ) ,
34+ max_retries : NonZeroU64 :: new ( 1 ) . unwrap ( ) ,
35+ expected_network_fingerprint : Some ( EXPECTED_NETWORK . to_string ( ) ) ,
36+ providers : providers. try_into ( ) . expect ( "a named provider" ) ,
37+ } ) ,
38+ ..Default :: default ( )
3039 }
3140}
3241
42+ /// Both nodes expect the same network and configure two BNB providers, so the healthy gauge
43+ /// separates them on one provider serving another network.
3344#[ tokio:: test]
3445#[ expect( non_snake_case) ]
3546async fn foreign_chain_probe__should_publish_provider_health_on_startup ( ) {
3647 // Given
37- let server = MockServer :: start ( ) ;
38- setup_evm_mock ( & server, MockAuthExpectation :: None ) ;
39- let url = server. url ( "/" ) ;
48+ let expected_network = MockServer :: start ( ) ;
49+ setup_evm_chain_id_mock ( & expected_network, EXPECTED_NETWORK ) ;
50+ let other_network = MockServer :: start ( ) ;
51+ setup_evm_chain_id_mock ( & other_network, ANOTHER_NETWORK ) ;
52+
53+ // The config rejects duplicate provider URLs, so the two sound providers take separate paths.
54+ let good_path = expected_network. url ( "/good_provider" ) ;
55+ let also_good_path = expected_network. url ( "/also_good_provider" ) ;
56+ let wrong_network = other_network. url ( "/wrong_network_provider" ) ;
4057
4158 // When
4259 let ( cluster, _running) = common:: must_setup_cluster (
@@ -45,18 +62,14 @@ async fn foreign_chain_probe__should_publish_provider_health_on_startup() {
4562 c. num_nodes = 2 ;
4663 c. threshold = 2 ;
4764 c. foreign_chains . node_configs = vec ! [
48- ForeignChainsConfig {
49- base: Some ( base_chain_config( & url, MOCK_EVM_CHAIN_ID , HEALTHY_PROVIDER ) ) ,
50- ..Default :: default ( )
51- } ,
52- ForeignChainsConfig {
53- base: Some ( base_chain_config(
54- & url,
55- ANOTHER_NETWORK ,
56- WRONG_NETWORK_PROVIDER ,
57- ) ) ,
58- ..Default :: default ( )
59- } ,
65+ bnb_chain_config( & [
66+ ( "good_provider" , & good_path) ,
67+ ( "also_good_provider" , & also_good_path) ,
68+ ] ) ,
69+ bnb_chain_config( & [
70+ ( "good_provider" , & good_path) ,
71+ ( "wrong_network_provider" , & wrong_network) ,
72+ ] ) ,
6073 ] ;
6174 } ,
6275 )
@@ -67,29 +80,29 @@ async fn foreign_chain_probe__should_publish_provider_health_on_startup() {
6780 & cluster,
6881 & [ 0 , 1 ] ,
6982 metrics:: FOREIGN_CHAIN_RPC_PROVIDERS_CONFIGURED ,
70- |value| value == 1 ,
83+ |value| value == 2 ,
7184 CLUSTER_WAIT_TIMEOUT ,
7285 )
7386 . await
74- . expect ( "both nodes should report one configured Base provider " ) ;
87+ . expect ( "both nodes should report two configured BNB providers " ) ;
7588
7689 common:: wait_metric_on_nodes (
7790 & cluster,
7891 & [ 0 ] ,
7992 metrics:: FOREIGN_CHAIN_RPC_PROVIDERS_HEALTHY ,
80- |value| value == 1 ,
93+ |value| value == 2 ,
8194 CLUSTER_WAIT_TIMEOUT ,
8295 )
8396 . await
84- . expect ( "the provider serving the expected network should be healthy" ) ;
97+ . expect ( "both providers serving the expected network should be healthy" ) ;
8598
8699 common:: wait_metric_on_nodes (
87100 & cluster,
88101 & [ 1 ] ,
89102 metrics:: FOREIGN_CHAIN_RPC_PROVIDERS_HEALTHY ,
90- |value| value == 0 ,
103+ |value| value == 1 ,
91104 CLUSTER_WAIT_TIMEOUT ,
92105 )
93106 . await
94- . expect ( "the provider serving another network should not be healthy" ) ;
107+ . expect ( "only the provider serving the expected network should be healthy" ) ;
95108}
0 commit comments