diff --git a/programs/descro/src/instructions/dispute.rs b/programs/descro/src/instructions/dispute.rs index b5db3ca..5ebd13b 100644 --- a/programs/descro/src/instructions/dispute.rs +++ b/programs/descro/src/instructions/dispute.rs @@ -20,6 +20,8 @@ pub struct Dispute<'info> { } pub fn handler(ctx: Context) -> Result<()> { - ctx.accounts.escrow_account.state = EscrowState::Disputed; + let escrow = &mut ctx.accounts.escrow_account; + escrow.state = EscrowState::Disputed; + escrow.dispute_raised_at = Some(Clock::get()?.unix_timestamp); Ok(()) } diff --git a/programs/descro/tests/test_dispute.rs b/programs/descro/tests/test_dispute.rs index 1179fa3..0369618 100644 --- a/programs/descro/tests/test_dispute.rs +++ b/programs/descro/tests/test_dispute.rs @@ -62,3 +62,19 @@ fn third_party_cannot_dispute() { &resolver, )); } + +#[test] +fn dispute_records_timestamp() { + let (mut svm, seller, buyer, _resolver) = setup(); + send( + &mut svm, + ix_create_escrow(&seller.pubkey(), &buyer.pubkey(), AMOUNT, None, ESCROW_ID), + &seller, + ); + send(&mut svm, ix_deposit(&buyer.pubkey(), &seller.pubkey(), ESCROW_ID), &buyer); + send(&mut svm, ix_dispute(&buyer.pubkey(), &seller.pubkey(), ESCROW_ID), &buyer); + + let escrow = read_escrow(&svm, &seller.pubkey(), ESCROW_ID); + assert!(escrow.dispute_raised_at.is_some()); + assert!(escrow.dispute_raised_at.unwrap() >= 0); +}