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
2 changes: 2 additions & 0 deletions contracts/invoice-escrow/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn escrow_created(
due_dt: u64,
token: &Address,
inv_token: &Address,
commitment: &soroban_sdk::BytesN<32>,
) {
env.events().publish(
(Symbol::new(env, "escrow_created"),),
Expand All @@ -25,6 +26,7 @@ pub fn escrow_created(
due_dt,
token,
inv_token,
commitment,
),
);
}
Expand Down
14 changes: 13 additions & 1 deletion contracts/invoice-escrow/src/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ use invoice_token::{InvoiceToken, InvoiceTokenClient};
use soroban_sdk::token::{Client as TokenClient, StellarAssetClient as AssetClient};
use soroban_sdk::{
testutils::{Address as _, Ledger as _},
Address, Env, String as SorobanString, Symbol,
Address, Bytes, BytesN, Env, String as SorobanString, Symbol,
};

/// Helper function to create a test commitment hash (SHA-256 format)
fn test_commitment(env: &Env, data: &str) -> BytesN<32> {
let mut array = [0u8; 32];
let bytes = data.as_bytes();
let len = bytes.len().min(32);
array[..len].copy_from_slice(&bytes[..len]);
BytesN::from_array(env, &array)
}

#[test]
fn test_integration_escrow_lifecycle_happy_path() {
let env = Env::default();
Expand Down Expand Up @@ -62,6 +71,7 @@ fn test_integration_escrow_lifecycle_happy_path() {
&due_date,
&payment_token_id.address(),
&inv_token_id,
&test_commitment(&env, "test_invoice_data"),
);

// 8. Fund Escrow (Buyer buys the invoice)
Expand Down Expand Up @@ -149,6 +159,7 @@ fn test_integration_refund_lifecycle() {
&due_date,
&payment_token_id.address(),
&inv_token_id,
&test_commitment(&env, "test_invoice_data"),
);

escrow_client.fund_escrow(&invoice_id, &buyer, &amount);
Expand Down Expand Up @@ -219,6 +230,7 @@ fn test_integration_token_locked_during_active_escrow() {
&due_date,
&payment_token_id.address(),
&inv_token_id,
&test_commitment(&env, "test_invoice_data"),
);

// Token is locked even before funding (initialized locked)
Expand Down
4 changes: 4 additions & 0 deletions contracts/invoice-escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl InvoiceEscrow {
/// Create an escrow for an invoice. Caller (seller) must be authenticated.
/// face_value: what the debtor owes (amount to be paid at settlement)
/// purchase_price: what the investor pays (discount applied here)
/// commitment: immutable on-chain anchor (SHA-256 hash of off-chain invoice data)
pub fn create_escrow(
env: Env,
invoice_id: Symbol,
Expand All @@ -53,6 +54,7 @@ impl InvoiceEscrow {
due_date: u64,
payment_token: Address,
invoice_token: Address,
commitment: soroban_sdk::BytesN<32>,
) -> Result<(), Error> {
seller.require_auth();
if face_value <= 0 || purchase_price <= 0 {
Expand All @@ -75,6 +77,7 @@ impl InvoiceEscrow {
inv_token: invoice_token.clone(),
paid_amt: 0,
status: EscrowStatus::Created,
commitment: commitment.clone(),
};
storage::set_escrow(&env, invoice_id.clone(), &data);
events::escrow_created(
Expand All @@ -87,6 +90,7 @@ impl InvoiceEscrow {
due_date,
&payment_token,
&invoice_token,
&commitment,
);
Ok(())
}
Expand Down
Loading
Loading