Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions contracts/reputation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum Role {
pub struct ReputationScore {
pub address: Address,
pub role: Role,
/// Score in basis points (0–10000 = 0–100%)
/// Score in basis points (0\u201310000 = 0\u2013100%)
pub score: i32,
pub total_jobs: u32,
/// Sum of raw rating points (1-5) to compute aggregates off-chain
Expand Down Expand Up @@ -131,6 +131,7 @@ impl ReputationContract {
(score as i32).saturating_mul(2_000)
}

fn score_from_profile(address: &Address, role: Role, profile: &profile::Profile) -> ReputationScore {
fn score_from_profile(
address: &Address,
role: Role,
Expand Down Expand Up @@ -324,8 +325,7 @@ impl ReputationContract {
let mut profile = storage::read_profile_or_default(&env, &address);
let (new_score, total_jobs) = match role {
Role::Client => {
profile.client_score =
Self::clamp_score(profile.client_score.saturating_add(delta));
profile.client_score = Self::clamp_score(profile.client_score.saturating_add(delta));
profile.client_jobs = profile.client_jobs.saturating_add(1);
(profile.client_score, profile.client_jobs)
}
Expand Down Expand Up @@ -467,6 +467,9 @@ mod test {
#[contractimpl]
impl MockJobRegistry {
pub fn set_job(env: Env, job_id: u64, job: JobRecord) {
env.storage()
.persistent()
.set(&MockKey::Job(job_id), &job);
env.storage().persistent().set(&MockKey::Job(job_id), &job);
}

Expand Down Expand Up @@ -588,6 +591,14 @@ mod test {
assert_eq!(view.address, address);
assert_eq!(view.client.score, 5500);
assert_eq!(view.client.total_jobs, 1);
assert_eq!(view.client.total_points, 500);
assert_eq!(view.freelancer.score, 6000);
assert_eq!(view.freelancer.total_jobs, 1);
assert_eq!(view.freelancer.total_points, 1000);
}

#[test]
#[should_panic(expected = "Error(Contract, #3)")]
assert_eq!(view.client.total_points, 0);
assert_eq!(view.freelancer.score, 6000);
assert_eq!(view.freelancer.total_jobs, 1);
Expand Down Expand Up @@ -655,6 +666,7 @@ mod test {
}

#[test]
#[should_panic(expected = "Error(Contract, #2)")]
#[should_panic(expected = "Error(Contract, #2)")]
fn test_upgrade_requires_admin() {
let env = Env::default();
Expand All @@ -669,4 +681,4 @@ mod test {
let wasm_hash = BytesN::from_array(&env, &[0; 32]);
client.upgrade(&attacker, &wasm_hash);
}
}
}
Loading