From 45a5e31ca4a77d2a0b9e581b325ed43692b8b8e4 Mon Sep 17 00:00:00 2001 From: Igor Konnov Date: Mon, 23 Dec 2024 10:27:48 +0100 Subject: [PATCH] update to the new API and fix the tests in the alert contract --- ContractExamples/contracts/alert/src/test.rs | 20 +++++++++++++------ .../contracts/megacontract/src/test.rs | 2 +- ContractExamples/contracts/setter/src/test.rs | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ContractExamples/contracts/alert/src/test.rs b/ContractExamples/contracts/alert/src/test.rs index 9be34d2c..600604da 100644 --- a/ContractExamples/contracts/alert/src/test.rs +++ b/ContractExamples/contracts/alert/src/test.rs @@ -7,33 +7,41 @@ use soroban_sdk::{ }; #[test] -fn test() { +fn test_ok() { let env = Env::default(); let tx_hash: String = String::from_str(&env, "txhash"); - let contract_id = env.register_contract(None, Alert); + let contract_id = env.register(Alert, ()); // Client is automagically created. let client = AlertClient::new(&env, &contract_id); - assert_eq!(client.emit_and_store_violation(&tx_hash, &VerificationStatus::NoViolation), VerificationStatus::NoViolation); // NoViolation triggers an emit but no store assert_eq!( env.events().all(), - vec![&env, (contract_id.clone(),(ALERTS, OK).into_val(&env),VerificationStatus::NoViolation.into_val(&env))] + vec![&env, (contract_id.clone(),(ALERTS, OK).into_val(&env), VerificationStatus::NoViolation.into_val(&env))] ); // should be empty let alerts = client.alerts(); assert!(alerts.is_empty()); +} + +#[test] +fn test_violation() { + let env = Env::default(); + let tx_hash: String = String::from_str(&env, "txhash"); + + let contract_id = env.register(Alert, ()); + // Client is automagically created. + let client = AlertClient::new(&env, &contract_id); // Violation triggers an emit and a store assert_eq!(client.emit_and_store_violation(&tx_hash, &VerificationStatus::Violation), VerificationStatus::Violation); assert_eq!( env.events().all(), vec![&env, - (contract_id.clone(),(ALERTS, OK).into_val(&env),VerificationStatus::NoViolation.into_val(&env)), - (contract_id.clone(),(ALERTS, VIOLATION).into_val(&env),VerificationStatus::Violation.into_val(&env)) + (contract_id.clone(),(ALERTS, VIOLATION).into_val(&env), VerificationStatus::Violation.into_val(&env)) ] ); diff --git a/ContractExamples/contracts/megacontract/src/test.rs b/ContractExamples/contracts/megacontract/src/test.rs index b7d81305..648d5113 100644 --- a/ContractExamples/contracts/megacontract/src/test.rs +++ b/ContractExamples/contracts/megacontract/src/test.rs @@ -13,7 +13,7 @@ fn test() { let env = Env::default(); let addr = Address::generate(&env); - let contract_id = env.register_contract(None, MegaContract); + let contract_id = env.register(MegaContract, ()); // Client is automagically created. let client = MegaContractClient::new(&env, &contract_id); diff --git a/ContractExamples/contracts/setter/src/test.rs b/ContractExamples/contracts/setter/src/test.rs index 426ecf9b..efcdd4ae 100644 --- a/ContractExamples/contracts/setter/src/test.rs +++ b/ContractExamples/contracts/setter/src/test.rs @@ -21,7 +21,7 @@ fn test() { let env = Env::default(); let addr = Address::generate(&env); - let contract_id = env.register_contract(None, SetterContract); + let contract_id = env.register(SetterContract, ()); // Client is automagically created. let client = SetterContractClient::new(&env, &contract_id);