Skip to content

Commit 5af4001

Browse files
committed
Some update to the Mock test runtime.
1 parent 60495ca commit 5af4001

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

linera-sdk/src/service/test_runtime.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ where
3434
owner_balances: Mutex<Option<HashMap<AccountOwner, Amount>>>,
3535
query_application_handler: Mutex<Option<QueryApplicationHandler>>,
3636
expected_http_requests: Mutex<VecDeque<(http::Request, http::Response)>>,
37+
expected_has_trivial_storage_requests: Mutex<VecDeque<(ApplicationId, bool)>>,
3738
blobs: Mutex<Option<HashMap<DataBlobHash, Vec<u8>>>>,
3839
scheduled_operations: Mutex<Vec<Vec<u8>>>,
3940
key_value_store: KeyValueStore,
@@ -65,6 +66,7 @@ where
6566
owner_balances: Mutex::new(None),
6667
query_application_handler: Mutex::new(None),
6768
expected_http_requests: Mutex::new(VecDeque::new()),
69+
expected_has_trivial_storage_requests: Mutex::new(VecDeque::new()),
6870
blobs: Mutex::new(None),
6971
scheduled_operations: Mutex::new(vec![]),
7072
key_value_store: KeyValueStore::mock(),
@@ -411,6 +413,18 @@ where
411413
.push_back((request, response));
412414
}
413415

416+
/// Adds an expected `has_trivial_storage` call, and the response it should return in the test.
417+
pub fn add_expected_has_trivial_storage_requests(
418+
&mut self,
419+
application: ApplicationId,
420+
response: bool,
421+
) {
422+
self.expected_has_trivial_storage_requests
423+
.lock()
424+
.unwrap()
425+
.push_back((application, response));
426+
}
427+
414428
/// Makes an HTTP `request` as an oracle and returns the HTTP response.
415429
///
416430
/// Should only be used with queries where it is very likely that all validators will receive
@@ -481,6 +495,19 @@ where
481495
);
482496
}
483497

498+
/// Returns true if the corresponding contract uses a zero amount of storage.
499+
pub fn has_trivial_storage(&self, application: ApplicationId) -> bool {
500+
let maybe_request = self
501+
.expected_has_trivial_storage_requests
502+
.lock()
503+
.unwrap()
504+
.pop_front();
505+
let (expected_application_id, response) =
506+
maybe_request.expect("Unexpected has_trivial_storage request");
507+
assert_eq!(application, expected_application_id);
508+
response
509+
}
510+
484511
/// Loads a mocked value from the `slot` cache or panics with a provided `message`.
485512
fn fetch_mocked_value<T>(slot: &Mutex<Option<T>>, message: &str) -> T
486513
where

0 commit comments

Comments
 (0)