@@ -34,10 +34,6 @@ static AUDIT_TRAIL_PACKAGE_REGISTRY: LazyLock<RwLock<PackageRegistry>> = LazyLoc
3434 )
3535} ) ;
3636
37- /// Runtime overrides for TfComponents package information.
38- static TF_COMPONENTS_OVERRIDE_REGISTRY : LazyLock < RwLock < PackageRegistry > > =
39- LazyLock :: new ( || RwLock :: new ( PackageRegistry :: default ( ) ) ) ;
40-
4137/// Returns a read lock to the package registry.
4238pub ( crate ) async fn audit_trail_package_registry ( ) -> PackageRegistryLock {
4339 AUDIT_TRAIL_PACKAGE_REGISTRY . read ( ) . await
@@ -68,10 +64,6 @@ pub(crate) fn blocking_audit_trail_registry_mut() -> PackageRegistryLockMut {
6864 AUDIT_TRAIL_PACKAGE_REGISTRY . blocking_write ( )
6965}
7066
71- pub ( crate ) async fn tf_components_override_registry_mut ( ) -> PackageRegistryLockMut {
72- TF_COMPONENTS_OVERRIDE_REGISTRY . write ( ) . await
73- }
74-
7567#[ derive( Debug , Clone , Copy ) ]
7668pub ( crate ) struct ResolvedPackageIds {
7769 pub audit_trail_package_id : ObjectID ,
@@ -104,23 +96,20 @@ pub(crate) async fn resolve_package_ids(
10496
10597 drop ( package_registry) ;
10698
107- let env = Env :: new_with_alias ( chain_id. clone ( ) , resolved_network. as_ref ( ) ) ;
10899 if let Some ( audit_trail_package_id) = package_overrides. audit_trail {
100+ let env = Env :: new_with_alias ( chain_id. clone ( ) , resolved_network. as_ref ( ) ) ;
109101 audit_trail_package_registry_mut ( )
110102 . await
111- . insert_env_history ( env. clone ( ) , vec ! [ audit_trail_package_id] ) ;
112- }
113- if let Some ( tf_components_package_id) = package_overrides. tf_component {
114- tf_components_override_registry_mut ( )
115- . await
116- . insert_env_history ( env, vec ! [ tf_components_package_id] ) ;
103+ . insert_env_history ( env, vec ! [ audit_trail_package_id] ) ;
117104 }
118-
119- let tf_components_package_id = resolve_tf_components_package_id ( resolved_network. as_ref ( ) ) . await . ok_or_else ( || {
120- Error :: InvalidConfig ( format ! (
121- "no information for a published `TfComponents` package on network {network}; try to use `AuditTrailClientReadOnly::new_with_package_overrides`"
122- ) )
123- } ) ?;
105+ let tf_components_package_id = package_overrides
106+ . tf_component
107+ . or_else ( || tf_components_registry:: tf_components_package_id ( resolved_network. as_ref ( ) ) )
108+ . ok_or_else ( || {
109+ Error :: InvalidConfig ( format ! (
110+ "no information for a published `TfComponents` package on network {network}; try to use `AuditTrailClientReadOnly::new_with_package_overrides`"
111+ ) )
112+ } ) ?;
124113
125114 Ok ( (
126115 resolved_network,
@@ -131,7 +120,37 @@ pub(crate) async fn resolve_package_ids(
131120 ) )
132121}
133122
134- pub ( crate ) async fn resolve_tf_components_package_id ( network : & str ) -> Option < ObjectID > {
135- let override_package_id = TF_COMPONENTS_OVERRIDE_REGISTRY . read ( ) . await . package_id ( network) ;
136- override_package_id. or_else ( || tf_components_registry:: tf_components_package_id ( network) )
123+ #[ cfg( test) ]
124+ mod tests {
125+
126+ use super :: * ;
127+
128+ #[ tokio:: test]
129+ async fn resolves_tf_components_package_id ( ) {
130+ let network = NetworkName :: try_from ( "testnet" ) . expect ( "valid network" ) ;
131+ let registry_package_id = tf_components_registry:: tf_components_package_id ( "testnet" )
132+ . expect ( "testnet TfComponents package is in the registry" ) ;
133+ let override_package_id = ObjectID :: random ( ) ;
134+
135+ let ( _, registry_resolved_package_ids) = resolve_package_ids ( & network, & PackageOverrides :: default ( ) )
136+ . await
137+ . expect ( "registered package IDs are valid" ) ;
138+
139+ assert_eq ! (
140+ registry_resolved_package_ids. tf_components_package_id,
141+ registry_package_id
142+ ) ;
143+
144+ let ( _, resolved_package_ids) = resolve_package_ids (
145+ & network,
146+ & PackageOverrides {
147+ audit_trail : Some ( ObjectID :: random ( ) ) ,
148+ tf_component : Some ( override_package_id) ,
149+ } ,
150+ )
151+ . await
152+ . expect ( "explicit package overrides are valid" ) ;
153+
154+ assert_eq ! ( resolved_package_ids. tf_components_package_id, override_package_id) ;
155+ }
137156}
0 commit comments