66pub mod arbitrary;
77
88mod sign;
9- use std:: rc:: Rc ;
9+ use std:: { fmt :: Debug , rc:: Rc } ;
1010
1111pub use sign:: ed25519;
1212
@@ -20,7 +20,9 @@ pub mod storage;
2020
2121pub mod cost_estimate;
2222
23- use crate :: { xdr, ConstructorArgs , Env , Val , Vec } ;
23+ use crate :: {
24+ env:: internal:: Env as _, unwrap:: UnwrapInfallible , xdr, ConstructorArgs , Env , Val , Vec ,
25+ } ;
2426use soroban_ledger_snapshot:: LedgerSnapshot ;
2527
2628pub use crate :: env:: EnvTestConfig ;
@@ -413,15 +415,60 @@ pub mod budget {
413415 }
414416}
415417
418+ #[ derive( Clone ) ]
419+ pub struct ContractEvent {
420+ pub env : Env ,
421+ pub contract_id : crate :: Address ,
422+ pub topics : Vec < Val > ,
423+ pub data : Val ,
424+ }
425+
426+ impl Eq for ContractEvent { }
427+
428+ impl PartialEq for ContractEvent {
429+ fn eq ( & self , other : & Self ) -> bool {
430+ if self . contract_id != other. contract_id || self . topics != other. topics {
431+ false
432+ } else if self . data . is_object ( ) || other. data . is_object ( ) {
433+ self . env . obj_cmp ( self . data , other. data ) . unwrap_infallible ( ) == 0
434+ } else {
435+ self . data . get_payload ( ) == other. data . get_payload ( )
436+ }
437+ }
438+ }
439+
440+ impl Debug for ContractEvent {
441+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
442+ write ! (
443+ f,
444+ "ContractEvent {{ contract_id: {:?}, topics: {:?}, data: {:?} }}" ,
445+ self . contract_id, self . topics, self . data
446+ )
447+ }
448+ }
449+
450+ impl ContractEvent {
451+ pub fn new (
452+ env : & Env ,
453+ contract_id : crate :: Address ,
454+ topics : Vec < Val > ,
455+ data : Val ,
456+ ) -> ContractEvent {
457+ ContractEvent {
458+ env : env. clone ( ) ,
459+ contract_id,
460+ topics,
461+ data,
462+ }
463+ }
464+ }
465+
416466/// Test utilities for [`Events`][crate::events::Events].
417467pub trait Events {
418468 /// Returns all events that have been published by contracts.
419469 ///
420- /// Returns a [`Vec`] of three element tuples containing:
421- /// - Contract ID
422- /// - Event Topics as a [`Vec<Val>`]
423- /// - Event Data as a [`Val`]
424- fn all ( & self ) -> Vec < ( crate :: Address , Vec < Val > , Val ) > ;
470+ /// Returns a [`std::vec::Vec`] of [`ContractEvent`]s
471+ fn all ( & self ) -> std:: vec:: Vec < ContractEvent > ;
425472}
426473
427474/// Test utilities for [`Logs`][crate::logs::Logs].
0 commit comments