Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion contracts/invoice/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ pub fn refund_approved(env: &Env, id: u64, invoice: &Invoice) {
}

pub fn escrow_released(env: &Env, id: u64, invoice: &Invoice) {
let payload = EscrowReleasedEvent {
id,
merchant: invoice.merchant.clone(),
amount_usdc: invoice.amount_usdc,
released_at: env.ledger().timestamp(),
};
env.events()
.publish((Symbol::new(env, "escrow_released"), id), invoice.clone());
.publish((Symbol::new(env, "escrow_released"), id), payload);
}

pub fn contract_paused(env: &Env, admin: &Address) {
Expand Down
12 changes: 4 additions & 8 deletions contracts/invoice/tests/invoice_test.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use invoice::{
InvoiceContract, InvoiceContractClient, InvoiceError, InvoiceStatus, MaybeAddress, MaybeBytes,
EscrowReleasedEvent, InvoiceContract, InvoiceContractClient, InvoiceError, InvoiceStatus,
MaybeAddress, MaybeBytes,
};
use soroban_sdk::{
testutils::{Address as _, Ledger},
Address, Env,
testutils::{Address as _, Events, Ledger},
Address, Env, Symbol, TryFromVal,
};

extern crate std;
Expand Down Expand Up @@ -733,9 +734,6 @@ fn test_mark_paid_blocked_when_paused() {


// Issue #94: create_invoice must enforce merchant authorization.
// Uses cancel_invoice (which has an explicit Unauthorized check) to prove that a
// non-merchant/non-admin caller is rejected. Also verifies that the merchant's auth
// was recorded by create_invoice, confirming require_auth() is enforced.
#[test]
fn test_create_invoice_unauthorized_merchant() {
let (env, _admin, client) = setup();
Expand All @@ -750,13 +748,11 @@ fn test_create_invoice_unauthorized_merchant() {
&MaybeBytes::None,
&0,
);

let auths = env.auths();
assert!(
auths.iter().any(|(addr, _)| addr == &merchant),
"create_invoice must require merchant authorization"
);

let err = client
.try_cancel_invoice(&unauthorized, &id)
.unwrap_err()
Expand Down
Loading