Skip to content

Commit 49a7f58

Browse files
authored
Merge branch 'feat/audit-trails-dev' into chore/add-return-values-for-at
2 parents 6e879f6 + 1f13c12 commit 49a7f58

3 files changed

Lines changed: 54 additions & 28 deletions

File tree

audit-trail-rs/src/package.rs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
4238
pub(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)]
7668
pub(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
}

bindings/wasm/audit_trail_wasm/examples/src/02_add_and_read_records.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export async function addAndReadRecords(): Promise<void> {
5858
assert.equal(seedRecord.data.toString(), "seed record");
5959
assert.equal(secondRecord.data.toString(), "record 2");
6060

61+
const count = await recordAdminRecords.recordCount();
62+
console.log(`Current record count: ${count}`);
63+
assert.equal(count, 3n, `expected 3 records, got ${count}`);
64+
6165
// Pagination uses the previous page cursor to continue from the next record.
6266
const firstPage = await recordAdminRecords.listPage(undefined, 2);
6367
const secondPage = await recordAdminRecords.listPage(firstPage.nextCursor, 2);

bindings/wasm/audit_trail_wasm/examples/src/advanced/11_manage_record_tags.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,13 @@ export async function manageRecordTags(): Promise<void> {
9696
}
9797
assert.equal(removeFinanceSucceeded, false, "a tag referenced by a role or record must not be removable");
9898

99-
// TagAdmin removes "legal" tag — should succeed because nothing uses it.
100-
await tagAdminClient.trail(trailId).tags().remove("legal").withGasBudget(TEST_GAS_BUDGET).buildAndExecute(
101-
tagAdminClient,
102-
);
99+
// TagAdmin removes "legal" tag because nothing uses it.
100+
await tagAdminClient
101+
.trail(trailId)
102+
.tags()
103+
.remove("legal")
104+
.withGasBudget(TEST_GAS_BUDGET)
105+
.buildAndExecute(tagAdminClient);
103106

104107
onChainTrail = await adminClient.trail(trailId).get();
105108
console.log("Registry after removing \"legal\":", onChainTrail.tags.map((t) => t.tag), "\n");

0 commit comments

Comments
 (0)