pub mod audit;
pub mod conditions;
pub mod error;
pub mod escrow;
pub mod multisig;
pub mod oracle;
pub mod types;
pub use error::{EscrowError, Result};
pub use escrow::{EscrowBuilder, EscrowContract, EscrowManager};
pub use types::{
AgentId, ConditionResult, EscrowConfig, EscrowId, EscrowParticipant,
EscrowRole, EscrowStatus, OracleId, ReleaseCondition,
};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const NAME: &str = env!("CARGO_PKG_NAME");
#[cfg(test)]
mod tests {
use super::*;
use audit::AuditLogger;
use bitcoin::Network;
use escrow::EscrowBuilder;
use multisig::create_participant;
use types::EscrowRole;
#[test]
fn test_library_version() {
assert!(!VERSION.is_empty());
assert_eq!(NAME, "ai-agent-bitcoin-escrow");
}
#[test]
fn test_full_escrow_workflow() {
let (buyer, _) = create_participant(EscrowRole::Buyer, "buyer-1".to_string(), Network::Testnet).unwrap();
let (seller, _) = create_participant(EscrowRole::Seller, "seller-1".to_string(), Network::Testnet).unwrap();
let (arbiter, _) = create_participant(EscrowRole::Arbiter, "arbiter-1".to_string(), Network::Testnet).unwrap();
let contract = EscrowBuilder::new()
.network(Network::Testnet)
.threshold(2)
.participant(buyer)
.participant(seller)
.participant(arbiter)
.description("Test bounty payment")
.build()
.unwrap();
assert_eq!(contract.status, EscrowStatus::Created);
assert_eq!(contract.participants.len(), 3);
assert_eq!(contract.config.threshold, 2);
let mut contract = contract;
contract.initialize_multisig().unwrap();
assert!(contract.multisig.is_some());
let address = contract.escrow_address().unwrap();
assert!(!address.to_string().is_empty());
}
#[tokio::test]
async fn test_escrow_manager_workflow() {
let audit = AuditLogger::in_memory();
let mut manager = EscrowManager::new(audit);
let contract = manager
.create_contract(
EscrowConfig::default(),
Some("Test escrow".to_string()),
"test-agent".to_string(),
)
.unwrap();
let contract_id = contract.id.clone();
let (buyer, _) = create_participant(EscrowRole::Buyer, "buyer-1".to_string(), Network::Testnet).unwrap();
let (seller, _) = create_participant(EscrowRole::Seller, "seller-1".to_string(), Network::Testnet).unwrap();
let (arbiter, _) = create_participant(EscrowRole::Arbiter, "arbiter-1".to_string(), Network::Testnet).unwrap();
manager
.add_participant(&contract_id, buyer, "test-agent".to_string())
.unwrap();
manager
.add_participant(&contract_id, seller, "test-agent".to_string())
.unwrap();
manager
.add_participant(&contract_id, arbiter, "test-agent".to_string())
.unwrap();
let address = manager.initialize_multisig(&contract_id).unwrap();
assert!(!address.to_string().is_empty());
let entries = manager.audit().get_entries(&contract_id);
assert!(entries.len() >= 4); }
}