Skip to content

Commit

Permalink
Add test reproducing the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Oct 7, 2023
1 parent 3579e83 commit a440660
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/vm/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,42 @@ mod tests {
}
}

#[test]
fn call_execute_on_recompiled_contract() {
let options = make_testing_options();
let cache = unsafe { Cache::new(options.clone()).unwrap() };
let checksum = cache.save_wasm(CONTRACT).unwrap();

// Remove compiled module from disk
remove_dir_all(options.base_dir.join(CACHE_DIR).join(MODULES_DIR)).unwrap();

// Recompiles the Wasm (miss on all caches)
let backend = mock_backend(&[]);
let mut instance = cache
.get_instance(&checksum, backend, TESTING_OPTIONS)
.unwrap();
assert_eq!(cache.stats().hits_pinned_memory_cache, 0);
assert_eq!(cache.stats().hits_memory_cache, 0);
assert_eq!(cache.stats().hits_fs_cache, 0);
assert_eq!(cache.stats().misses, 1);

// instantiate
let info = mock_info("creator", &coins(1000, "earth"));
let msg = br#"{"verifier": "verifies", "beneficiary": "benefits"}"#;
let response = call_instantiate::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg)
.unwrap()
.unwrap();
assert_eq!(response.messages.len(), 0);

// execute
let info = mock_info("verifies", &coins(15, "earth"));
let msg = br#"{"release":{}}"#;
let response = call_execute::<_, _, _, Empty>(&mut instance, &mock_env(), &info, msg)
.unwrap()
.unwrap();
assert_eq!(response.messages.len(), 1);
}

#[test]
fn use_multiple_cached_instances_of_same_contract() {
let cache = unsafe { Cache::new(make_testing_options()).unwrap() };
Expand Down

0 comments on commit a440660

Please sign in to comment.