forked from Vero-protocol/vero-core-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreentrancy_tests.rs
More file actions
37 lines (31 loc) · 990 Bytes
/
Copy pathreentrancy_tests.rs
File metadata and controls
37 lines (31 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Reentrancy protection tests.
#[cfg(test)]
mod tests {
use crate::guards::{enter_reentrancy_guard, exit_reentrancy_guard};
use soroban_sdk::{contract, contractimpl, Env};
#[contract]
pub struct TestContract;
#[contractimpl]
impl TestContract {}
#[test]
#[should_panic]
fn guard_panics_when_entered_twice() {
let env = Env::default();
let contract_id = env.register_contract(None, TestContract);
env.as_contract(&contract_id, || {
enter_reentrancy_guard(&env);
enter_reentrancy_guard(&env);
});
}
#[test]
fn guard_can_be_reentered_after_exit() {
let env = Env::default();
let contract_id = env.register_contract(None, TestContract);
env.as_contract(&contract_id, || {
enter_reentrancy_guard(&env);
exit_reentrancy_guard(&env);
enter_reentrancy_guard(&env);
exit_reentrancy_guard(&env);
});
}
}