Skip to content

Commit 45a5e31

Browse files
committed
update to the new API and fix the tests in the alert contract
1 parent 89ac036 commit 45a5e31

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

ContractExamples/contracts/alert/src/test.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,41 @@ use soroban_sdk::{
77
};
88

99
#[test]
10-
fn test() {
10+
fn test_ok() {
1111
let env = Env::default();
1212
let tx_hash: String = String::from_str(&env, "txhash");
1313

14-
let contract_id = env.register_contract(None, Alert);
14+
let contract_id = env.register(Alert, ());
1515
// <X>Client is automagically created.
1616
let client = AlertClient::new(&env, &contract_id);
1717

18-
1918
assert_eq!(client.emit_and_store_violation(&tx_hash, &VerificationStatus::NoViolation), VerificationStatus::NoViolation);
2019
// NoViolation triggers an emit but no store
2120
assert_eq!(
2221
env.events().all(),
23-
vec![&env, (contract_id.clone(),(ALERTS, OK).into_val(&env),VerificationStatus::NoViolation.into_val(&env))]
22+
vec![&env, (contract_id.clone(),(ALERTS, OK).into_val(&env), VerificationStatus::NoViolation.into_val(&env))]
2423
);
2524

2625
// should be empty
2726
let alerts = client.alerts();
2827
assert!(alerts.is_empty());
28+
}
29+
30+
#[test]
31+
fn test_violation() {
32+
let env = Env::default();
33+
let tx_hash: String = String::from_str(&env, "txhash");
34+
35+
let contract_id = env.register(Alert, ());
36+
// <X>Client is automagically created.
37+
let client = AlertClient::new(&env, &contract_id);
2938

3039
// Violation triggers an emit and a store
3140
assert_eq!(client.emit_and_store_violation(&tx_hash, &VerificationStatus::Violation), VerificationStatus::Violation);
3241
assert_eq!(
3342
env.events().all(),
3443
vec![&env,
35-
(contract_id.clone(),(ALERTS, OK).into_val(&env),VerificationStatus::NoViolation.into_val(&env)),
36-
(contract_id.clone(),(ALERTS, VIOLATION).into_val(&env),VerificationStatus::Violation.into_val(&env))
44+
(contract_id.clone(),(ALERTS, VIOLATION).into_val(&env), VerificationStatus::Violation.into_val(&env))
3745
]
3846
);
3947

ContractExamples/contracts/megacontract/src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn test() {
1313
let env = Env::default();
1414
let addr = Address::generate(&env);
1515

16-
let contract_id = env.register_contract(None, MegaContract);
16+
let contract_id = env.register(MegaContract, ());
1717
// <X>Client is automagically created.
1818
let client = MegaContractClient::new(&env, &contract_id);
1919

ContractExamples/contracts/setter/src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn test() {
2121
let env = Env::default();
2222
let addr = Address::generate(&env);
2323

24-
let contract_id = env.register_contract(None, SetterContract);
24+
let contract_id = env.register(SetterContract, ());
2525
// <X>Client is automagically created.
2626
let client = SetterContractClient::new(&env, &contract_id);
2727

0 commit comments

Comments
 (0)