-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fn to find out if Host can be finished (#1182)
### What Add fn to find out if Host can be finished. ### Why So that the SDK can ask the Host if it has no more references left and it is able to be finished without calling try_finish which is destructive. I plan to use this in: - stellar/rs-soroban-sdk#1137
- Loading branch information
1 parent
4f4a7f3
commit 6d26ca6
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ mod symbol; | |
mod tuple; | ||
mod vec; | ||
|
||
mod finish; | ||
mod metering_benchmark; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::Host; | ||
|
||
#[test] | ||
fn can_finish_on_one_reference() { | ||
let host1 = Host::test_host_with_recording_footprint(); | ||
assert!(host1.can_finish()); | ||
assert!(host1.try_finish().is_ok()); | ||
} | ||
|
||
#[test] | ||
fn cant_finish_on_multiple_reference() { | ||
let host1 = Host::test_host_with_recording_footprint(); | ||
let host2 = host1.clone(); | ||
assert!(!host1.can_finish()); | ||
assert!(!host2.can_finish()); | ||
assert!(host1.try_finish().is_err()); | ||
_ = host2; | ||
} | ||
|
||
#[test] | ||
fn can_finish_on_reduced_to_one_reference_count() { | ||
let host1 = Host::test_host_with_recording_footprint(); | ||
{ | ||
let host2 = host1.clone(); | ||
assert!(!host1.can_finish()); | ||
assert!(!host2.can_finish()); | ||
_ = host1; | ||
} | ||
assert!(host1.can_finish()); | ||
assert!(host1.try_finish().is_ok()); | ||
} |