Skip to content

Commit 6faf4f8

Browse files
store: Add clear_stale_call_cache test
Signed-off-by: Maksim Dimitrov <[email protected]>
1 parent 3c8fa09 commit 6faf4f8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

store/test-store/tests/postgres/chain_head.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,39 @@ fn eth_call_cache() {
490490
})
491491
}
492492

493+
#[test]
494+
/// Tests mainly query correctness. Requires data in order not to hit early returns when no stale contracts are found.
495+
fn test_clear_stale_call_cache() {
496+
let chain = vec![];
497+
run_test_async(chain, |store, _, _| async move {
498+
let logger = LOGGER.cheap_clone();
499+
let address = H160([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]);
500+
let call: [u8; 6] = [1, 2, 3, 4, 5, 6];
501+
let return_value: [u8; 3] = [7, 8, 9];
502+
503+
// Insert a call cache entry, otherwise it will hit an early return and won't test all queries
504+
let call = call::Request::new(address, call.to_vec(), 0);
505+
store
506+
.set_call(
507+
&logger,
508+
call.cheap_clone(),
509+
BLOCK_ONE.block_ptr(),
510+
call::Retval::Value(Bytes::from(return_value)),
511+
)
512+
.unwrap();
513+
514+
// Confirm the call cache entry is there
515+
let ret = store.get_call(&call, BLOCK_ONE.block_ptr()).unwrap();
516+
assert!(ret.is_some());
517+
518+
// Note: The storage field is not accessible from here, so we cannot fetch the Schema for the private chain
519+
// and manually populate the cache and meta tables or alter the accessed_at timestamp.
520+
// We can only test that the function runs to completion without error.
521+
let result = store.clear_stale_call_cache(7).await;
522+
assert!(result.is_ok());
523+
});
524+
}
525+
493526
#[test]
494527
/// Tests only query correctness. No data is involved.
495528
fn test_transaction_receipts_in_block_function() {

0 commit comments

Comments
 (0)