Skip to content

Commit e8a77f5

Browse files
authored
Merge pull request #11 from bandprotocol/fix-test-case
Update wasm for "ask_count_gas_used" test
2 parents e42932a + 96ffda1 commit e8a77f5

File tree

1 file changed

+37
-35
lines changed

1 file changed

+37
-35
lines changed

packages/vm/src/lib.rs

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -503,41 +503,43 @@ mod test {
503503
assert_eq!(gas_used, 800013 as u64);
504504
}
505505

506-
// #[test]
507-
// fn test_ask_count_gas_used() {
508-
// let wasm = wat2wasm(
509-
// r#"(module
510-
// (type (func (param i64 i64 i64 i64)))
511-
// (import "env" "ask_external_data" (func $ask_external_data (type 0)))
512-
// (func
513-
// (local $idx i32)
514-
// (i64.const 1)
515-
// (i64.const 1)
516-
// (i64.const 1048576)
517-
// (i64.const 4)
518-
// call 0
519-
// (local.set $idx (i32.const 0))
520-
// (block
521-
// (loop
522-
// (local.set $idx (local.get $idx) (i32.const 1) (i32.add) )
523-
// (br_if 0 (i32.lt_u (local.get $idx) (i32.const 100000)))
524-
// )
525-
// )
526-
// )
527-
// (func (;"execute": Resolves with result "beeb";)
528-
// )
529-
// (memory 17)
530-
// (data (i32.const 1048576) "beeb") (;str = "beeb";)
531-
// (export "prepare" (func 1))
532-
// (export "execute" (func 2)))
533-
// "#,
534-
// );
535-
// let code = compile(&wasm).unwrap();
536-
// let mut cache = Cache::new(CacheOptions { cache_size: 10000 });
537-
// let env = MockEnv {};
538-
// let gas_used = run(&mut cache, &code, 4294967290, true, env).unwrap();
539-
// assert_eq!(gas_used, 1000015 as u32);
540-
// }
506+
#[test]
507+
fn test_ask_count_gas_used() {
508+
let wasm = wat2wasm(
509+
r#"(module
510+
(type (func (param i64 i64 i64 i64) (result)))
511+
(import "env" "ask_external_data" (func (type 0)))
512+
(func
513+
(local $idx i32)
514+
515+
(i64.const 1)
516+
(i64.const 1)
517+
(i64.const 1048576)
518+
(i64.const 4)
519+
call 0
520+
521+
(local.set $idx (i32.const 0))
522+
(block
523+
(loop
524+
(local.set $idx (local.get $idx) (i32.const 1) (i32.add) )
525+
(br_if 0 (i32.lt_u (local.get $idx) (i32.const 100000)))
526+
)
527+
)
528+
)
529+
(func (;"execute": Resolves with result "beeb";))
530+
(memory (export "memory") 17)
531+
(data (i32.const 1048576) "beeb")
532+
(export "prepare" (func 1))
533+
(export "execute" (func 2)))
534+
"#,
535+
);
536+
537+
let code = compile(&wasm).unwrap();
538+
let mut cache = Cache::new(CacheOptions { cache_size: 10000 });
539+
let env = MockEnv {};
540+
let gas_used = run(&mut cache, &code, 4294967290, true, env).unwrap();
541+
assert_eq!(gas_used, 830018 as u64);
542+
}
541543

542544
#[test]
543545
fn test_inject_memory_no_memory() {

0 commit comments

Comments
 (0)