Skip to content

Commit

Permalink
update to the new API and fix the tests in the alert contract
Browse files Browse the repository at this point in the history
  • Loading branch information
konnov committed Dec 23, 2024
1 parent 89ac036 commit 45a5e31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions ContractExamples/contracts/alert/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ());
// <X>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, ());
// <X>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))
]
);

Expand Down
2 changes: 1 addition & 1 deletion ContractExamples/contracts/megacontract/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ());
// <X>Client is automagically created.
let client = MegaContractClient::new(&env, &contract_id);

Expand Down
2 changes: 1 addition & 1 deletion ContractExamples/contracts/setter/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ());
// <X>Client is automagically created.
let client = SetterContractClient::new(&env, &contract_id);

Expand Down

0 comments on commit 45a5e31

Please sign in to comment.