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
31 changes: 16 additions & 15 deletions contracts/escrow/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Event topic Symbol constructors for the Callora Escrow contract.
///
/// This module centralises all event topic strings into dedicated functions,
/// ensuring byte-identity is preserved and preventing accidental topic name
/// drift across call sites.
//!
//! This module centralises all event topic strings into dedicated functions,
//! ensuring byte-identity is preserved and preventing accidental topic name
//! drift across call sites.

use soroban_sdk::{Env, Symbol};

Expand Down Expand Up @@ -95,43 +95,44 @@ pub fn event_version_v1(env: &Env) -> Symbol {
Symbol::new(env, "callora.v1")
}

#config(test)]]mod tests {
#[cfg(test)]
mod tests {
use super::*;
use soroban_sdk:Env;
use soroban_sdk::Env;

/// Snapshot: proves event_init still maps to exactly the bytes for "init".
#[test]
fn test_event_init_bytes() {
let env = Env::default();
assert_eq(event_init(&env), Symbol::new(&env, "init"));
assert_eq!(event_init(&env), Symbol::new(&env, "init"));
}

/// Snapshot: proves event_cooldown_set still maps to exactly the bytes for "cooldown_set".
#[test]
fn test_event_cooldown_set_bytes() {
let env = Env::default();
assert_eq(event_cooldown_set(&env), Symbol::new(&env, "cooldown_set"));
assert_eq!(event_cooldown_set(&env), Symbol::new(&env, "cooldown_set"));
}

/// Snapshot: proves event_action still maps to exactly the bytes for "action".
#[test]
fn test_event_action_bytes() {
let env = Env::default();
assert_eq(event_action(&env), Symbol::new(&env, "action"));
assert_eq!(event_action(&env), Symbol::new(&env, "action"));
}

/// Snapshot: proves event_signer_rotated maps to exactly the bytes for "signer_rotated".
#[test]
fn test_event_signer_rotated_bytes() {
let env = Env::default();
assert_eq(event_signer_rotated(&env), Symbol::new(&env, "signer_rotated"));
assert_eq!(event_signer_rotated(&env), Symbol::new(&env, "signer_rotated"));
}

/// Snapshot: proves event_admin_nominated still maps to exactly the bytes for "admin_nominated".
#[test]
fn test_event_admin_nominated_bytes() {
let env = Env::default();
assert_eq(
assert_eq!(
event_admin_nominated(&env),
Symbol::new(&env, "admin_nominated")
);
Expand All @@ -141,7 +142,7 @@ pub fn event_version_v1(env: &Env) -> Symbol {
#[test]
fn test_event_admin_accepted_bytes() {
let env = Env::default();
assert_eq(
assert_eq!(
event_admin_accepted(&env),
Symbol::new(&env, "admin_accepted")
);
Expand All @@ -151,7 +152,7 @@ pub fn event_version_v1(env: &Env) -> Symbol {
#[test]
fn test_event_asset_approved_bytes() {
let env = Env::default();
assert_eq(
assert_eq!(
event_asset_approved(&env),
Symbol::new(&env, "asset_approved")
);
Expand All @@ -161,7 +162,7 @@ pub fn event_version_v1(env: &Env) -> Symbol {
#[test]
fn test_event_asset_removed_bytes() {
let env = Env::default();
assert_eq(
assert_eq!(
event_asset_removed(&env),
Symbol::new(&env, "asset_removed")
);
Expand All @@ -171,7 +172,7 @@ pub fn event_version_v1(env: &Env) -> Symbol {
#[test]
fn test_event_escrow_created_bytes() {
let env = Env::default();
assert_eq(
assert_eq!(
event_escrow_created(&env),
Symbol::new(&env, "escrow_created")
);
Expand Down
4 changes: 2 additions & 2 deletions contracts/escrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl CalloraEscrow {
/// # Errors
/// * [`EscrowError::Unauthorized`] -- caller is not the current admin.
/// * [`EscrowError::NotInitialized`] -- contract not initialized.
/// * [`EscrowError::SameSigner`] -- `new_signer` equals the current signer.
/// * [`EscrowError::InvalidInput`] -- `new_signer` equals the current signer.
/// * [`EscrowError::CooldownActive`] -- a `rotate` ran within the cool-off window.
///
/// # Events
Expand All @@ -463,7 +463,7 @@ impl CalloraEscrow {
.get(&StorageKey::Signer)
.ok_or(EscrowError::NotInitialized)?;
if old_signer == new_signer {
return Err(EscrowError::SameSigner);
return Err(EscrowError::InvalidInput);
}

env.storage()
Expand Down
7 changes: 4 additions & 3 deletions contracts/escrow/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{
CalloraEscrow, CalloraEscrowClient, EscrowError, ACTION_RELEASE, ACTION_ROTATE,
ACTION_UNPAUSE,
};
use soroban_sdk::testutils::{Address as _, Ledger as _};
use soroban_sdk::{Address, Env, Symbol};
use soroban_sdk::testutils::{Address as _, Events as _, Ledger as _};
use soroban_sdk::{Address, Env, Symbol, TryIntoVal};

/// Helper: read the current instance storage entry count for the contract.
fn instance_entry_count(env: &Env, contract_id: &Address) -> u32 {
Expand Down Expand Up @@ -451,7 +451,8 @@ fn test_rotate_signer_emits_old_and_new_signer() {

let events = env.events().all();
let (_, topics, data) = events.last().unwrap();
assert_eq!(topics, (Symbol::new(&env, "signer_rotated"),).into());
let topic: Symbol = topics.get(0).unwrap().try_into_val(&env).unwrap();
assert_eq!(topic, Symbol::new(&env, "signer_rotated"));
let payload: (Address, Address) = data.try_into_val(&env).unwrap();
assert_eq!(payload, (old_signer, new_signer));
}
Expand Down
Loading
Loading