Skip to content

Commit c2d807b

Browse files
committed
Create test: file_system_cache_store_uses_expected_path
1 parent 19d3fb0 commit c2d807b

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

packages/vm/src/modules/file_system_cache.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,21 @@ mod tests {
116116
const TESTING_MEMORY_LIMIT: Option<Size> = Some(Size::mebi(16));
117117
const TESTING_GAS_LIMIT: u64 = 500_000_000;
118118

119+
const SOME_WAT: &str = r#"(module
120+
(type $t0 (func (param i32) (result i32)))
121+
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
122+
get_local $p0
123+
i32.const 1
124+
i32.add))
125+
"#;
126+
119127
#[test]
120128
fn file_system_cache_run() {
121129
let tmp_dir = TempDir::new().unwrap();
122130
let mut cache = unsafe { FileSystemCache::new(tmp_dir.path()).unwrap() };
123131

124132
// Create module
125-
let wasm = wat::parse_str(
126-
r#"(module
127-
(type $t0 (func (param i32) (result i32)))
128-
(func $add_one (export "add_one") (type $t0) (param $p0 i32) (result i32)
129-
get_local $p0
130-
i32.const 1
131-
i32.add))
132-
"#,
133-
)
134-
.unwrap();
133+
let wasm = wat::parse_str(SOME_WAT).unwrap();
135134
let checksum = Checksum::generate(&wasm);
136135

137136
// Module does not exist
@@ -160,4 +159,22 @@ mod tests {
160159
assert_eq!(result[0].unwrap_i32(), 43);
161160
}
162161
}
162+
163+
#[test]
164+
fn file_system_cache_store_uses_expected_path() {
165+
let tmp_dir = TempDir::new().unwrap();
166+
let mut cache = unsafe { FileSystemCache::new(tmp_dir.path()).unwrap() };
167+
168+
// Create module
169+
let wasm = wat::parse_str(SOME_WAT).unwrap();
170+
let checksum = Checksum::generate(&wasm);
171+
172+
// Store module
173+
let module = compile(&wasm, None, &[]).unwrap();
174+
cache.store(&checksum, &module).unwrap();
175+
176+
let file_path = format!("{}/v1/{}", tmp_dir.path().to_string_lossy(), checksum);
177+
let serialized_module = fs::read(file_path).unwrap();
178+
assert_eq!(serialized_module.len(), 1040);
179+
}
163180
}

0 commit comments

Comments
 (0)