@@ -112,12 +112,20 @@ pub enum BlockchainError {
112112 "EIP-7702 fields received but is not supported by the current hardfork.\n \n You can use it by running anvil with '--hardfork prague' or later."
113113 ) ]
114114 EIP7702TransactionUnsupportedAtHardfork ,
115+ // Only suggest flags this build actually has: `--optimism` needs the optimism feature and
116+ // `--network base` needs the base one.
115117 #[ cfg_attr(
116- feature = "base" ,
118+ all ( feature = "base" , feature = "optimism" ) ,
117119 error(
118120 "deposit transaction received but is not supported.\n \n You can use it by running anvil with '--optimism' or '--network base'."
119121 )
120122 ) ]
123+ #[ cfg_attr(
124+ all( feature = "base" , not( feature = "optimism" ) ) ,
125+ error(
126+ "deposit transaction received but is not supported.\n \n You can use it by running anvil with '--network base'."
127+ )
128+ ) ]
121129 #[ cfg_attr(
122130 not( feature = "base" ) ,
123131 error(
@@ -646,3 +654,29 @@ impl<T: Serialize> ToRpcResponseResult for Result<T> {
646654 }
647655 }
648656}
657+
658+ #[ cfg( test) ]
659+ mod tests {
660+ use super :: BlockchainError ;
661+
662+ /// The hint has to name flags this build actually exposes: `--optimism` only exists with the
663+ /// optimism feature and `--network base` only with the base one.
664+ ///
665+ /// Only meaningful where the variant is reachable; with neither feature nothing constructs it.
666+ #[ test]
667+ #[ cfg( any( feature = "base" , feature = "optimism" ) ) ]
668+ fn deposit_unsupported_hint_only_names_available_flags ( ) {
669+ let message = BlockchainError :: DepositTransactionUnsupported . to_string ( ) ;
670+
671+ assert_eq ! (
672+ message. contains( "'--optimism'" ) ,
673+ cfg!( feature = "optimism" ) ,
674+ "optimism hint does not match this build: {message}"
675+ ) ;
676+ assert_eq ! (
677+ message. contains( "'--network base'" ) ,
678+ cfg!( feature = "base" ) ,
679+ "base hint does not match this build: {message}"
680+ ) ;
681+ }
682+ }
0 commit comments