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
12 changes: 12 additions & 0 deletions contracts/src/event_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ pub enum EventType {
CourseEnrollment,
}

// Marketplace-specific events
#[contracttype]
#[derive(Clone)]
pub enum MarketplaceEvent {
ListingCreated,
ListingUpdated,
BidPlaced,
SaleCompleted,
ListingCancelled,
}


#[contracttype]
#[derive(Clone)]
pub struct EventLog {
Expand Down
16 changes: 8 additions & 8 deletions contracts/src/marketplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl MarketplaceContract {
.set(&MarketplaceKey::ListingCount, &listing_id);

env.events().publish(
(symbol_short!("market"), symbol_short!("listed")),
(symbol_short!("marketplace"), symbol_short!("created")),
(listing_id, credential_id, seller, price),
);

Expand Down Expand Up @@ -157,7 +157,7 @@ impl MarketplaceContract {
);

env.events().publish(
(symbol_short!("market"), symbol_short!("sold")),
(symbol_short!("marketplace"), symbol_short!("sale_completed")),
(listing_id, buyer, seller_amount, royalty_amount),
);
}
Expand All @@ -182,7 +182,7 @@ impl MarketplaceContract {
);

env.events().publish(
(symbol_short!("market"), symbol_short!("rented")),
(symbol_short!("marketplace"), symbol_short!("rented")),
(credential_id, tenant, expiry, price),
);
}
Expand Down Expand Up @@ -219,7 +219,7 @@ impl MarketplaceContract {
);

env.events().publish(
(symbol_short!("stake"), symbol_short!("staked")),
(symbol_short!("marketplace"), symbol_short!("staked")),
(credential_id, staker, amount),
);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ impl MarketplaceContract {
);

env.events().publish(
(symbol_short!("stake"), symbol_short!("claimed")),
(symbol_short!("marketplace"), symbol_short!("rewards_claimed")),
(staker, total_reward),
);

Expand Down Expand Up @@ -289,7 +289,7 @@ impl MarketplaceContract {
.set(&MarketplaceKey::DisputeCount, &dispute_id);

env.events().publish(
(symbol_short!("dispute"), symbol_short!("opened")),
(symbol_short!("marketplace"), symbol_short!("dispute_opened")),
(dispute_id, listing_id, buyer),
);

Expand Down Expand Up @@ -322,7 +322,7 @@ impl MarketplaceContract {
.set(&MarketplaceKey::Dispute(dispute_id), &dispute);

env.events().publish(
(symbol_short!("dispute"), symbol_short!("resolved")),
(symbol_short!("marketplace"), symbol_short!("dispute_resolved")),
(dispute_id, dispute.status),
);
}
Expand All @@ -339,7 +339,7 @@ impl MarketplaceContract {
env.storage().instance().set(&symbol_short!("escrow_t"), &release_time);

env.events().publish(
(symbol_short!("market"), symbol_short!("escrow")),
(symbol_short!("marketplace"), symbol_short!("escrow_initiated")),
(escrow_id, buyer, listing_id, release_time),
);

Expand Down
16 changes: 15 additions & 1 deletion contracts/src/marketplace_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::marketplace::{MarketplaceContract, MarketplaceContractClient, Marketp
use crate::utils::storage::StorageKey;
use soroban_sdk::{
testutils::{Address as _, Ledger},
Address, Env, String,
Address, Env, String, symbol_short,
};

#[test]
Expand Down Expand Up @@ -42,8 +42,14 @@ fn test_listing_and_purchase() {

let listing_id = client.list_credential(&seller, &credential_id, &price, &royalty_bps);
assert_eq!(listing_id, 1);
// Verify ListingCreated event
let events = env.events().all();
assert!(events.iter().any(|(topics, _): &(_, _)| *topics == (symbol_short!("marketplace"), symbol_short!("created"))));

client.purchase_credential(&buyer, &listing_id);
// Verify SaleCompleted event
let events = env.events().all();
assert!(events.iter().any(|(topics, _): &(_, _)| *topics == (symbol_short!("marketplace"), symbol_short!("sale_completed"))));

// Trade count should increment
let price_after = client.calculate_bonding_price(&credential_id);
Expand All @@ -70,6 +76,9 @@ fn test_licensing_and_bonding_curve() {

// Rent
client.rent_credential(&tenant, &credential_id, &3600);
// Verify Rented event
let events = env.events().all();
assert!(events.iter().any(|(topics, _): &(_, _)| *topics == (symbol_short!("marketplace"), symbol_short!("rented"))));

// Bonding curve check: we need trades to increase price
// Since rent_credential doesn't increment TradeCount in the current implementation (only purchase does),
Expand Down Expand Up @@ -127,6 +136,11 @@ fn test_dispute_resolution() {

let dispute_id = client.open_dispute(&buyer, &listing_id, &reason);
assert_eq!(dispute_id, 1);
let events = env.events().all();
assert!(events.iter().any(|(topics, _): &(_, _)| *topics == (symbol_short!("marketplace"), symbol_short!("dispute_opened"))));

client.resolve_dispute(&admin, &dispute_id, &true);
// Verify DisputeResolved event
let events = env.events().all();
assert!(events.iter().any(|(topics, _): &(_, _)| *topics == (symbol_short!("marketplace"), symbol_short!("dispute_resolved"))));
}
Loading