Skip to content

Commit 377b2fd

Browse files
committed
test: add test for update asset status logging
1 parent f799f6c commit 377b2fd

3 files changed

Lines changed: 977 additions & 2 deletions

File tree

contracts/assetsup/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl AssetUpContract {
9292
// Log appropriate audit action based on status
9393
let (action, details) = match new_status {
9494
AssetStatus::InMaintenance => (
95-
String::from_str(&env, "IN_MAINTAINANCE"),
95+
String::from_str(&env, "IN_MAINTENANCE"),
9696
String::from_str(&env, "Asset in maintenance"),
9797
),
9898
AssetStatus::Disposed => (

contracts/assetsup/src/tests/asset.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
extern crate std;
44

5-
use soroban_sdk::{Address, BytesN, Env, String, testutils::Address as _};
5+
use soroban_sdk::testutils::{Address as _, BytesN as _};
6+
7+
use soroban_sdk::{Address, BytesN, Env, String};
68

79
use crate::{
810
asset::Asset,
@@ -101,3 +103,40 @@ fn test_register_asset_duplicate() {
101103
// Second registration with same ID should panic (Err propagated)
102104
client.register_asset(&asset);
103105
}
106+
107+
#[test]
108+
fn test_update_status_creates_audit_log() {
109+
let (env, client, _admin) = setup_test_environment();
110+
let owner = Address::generate(&env);
111+
112+
// Create and register asset first
113+
let asset = Asset {
114+
id: BytesN::random(&env),
115+
name: String::from_str(&env, "Test Asset"),
116+
asset_type: AssetType::Physical,
117+
category: String::from_str(&env, "Test Category"),
118+
branch_id: 1,
119+
department_id: 1,
120+
status: AssetStatus::Active,
121+
purchase_date: 12345,
122+
purchase_cost: 1000,
123+
current_value: 900,
124+
warranty_expiry: 67890,
125+
stellar_token_id: BytesN::random(&env),
126+
owner: owner.clone(),
127+
};
128+
129+
client.register_asset(&asset);
130+
131+
// Update to Maintained status
132+
client.update_asset_status(&asset.id, &AssetStatus::InMaintenance);
133+
134+
// Verify audit logs
135+
let logs = client.get_asset_audit_logs(&asset.id);
136+
assert_eq!(logs.len(), 2); // Procurement + Maintenance
137+
assert_eq!(
138+
logs.get(1).unwrap().action,
139+
String::from_str(&env, "IN_MAINTENANCE")
140+
);
141+
assert_eq!(logs.get(1).unwrap().actor, owner);
142+
}

0 commit comments

Comments
 (0)