@@ -29,7 +29,7 @@ impl ExecutionRequestEvent {
29
29
fn on_req ( req : & ExecutionRequestEvent ) -> eyre:: Result < ( ) > {
30
30
let engine = Engine :: default ( ) ;
31
31
let mut store = Store :: new ( & engine, ( ) ) ;
32
- let module = Module :: new ( & engine, & req. code )
32
+ let module = Module :: from_binary ( & engine, & req. code )
33
33
. map_err ( |e| eyre ! ( "WASM error: {e:?}" ) ) ?;
34
34
let linker = Linker :: new ( & engine) ;
35
35
let instance = linker
@@ -107,9 +107,12 @@ fn main() -> eyre::Result<()> {
107
107
108
108
#[ cfg( test) ]
109
109
mod tests {
110
+ use super :: * ;
111
+
110
112
use reth_execution_types:: { Chain , ExecutionOutcome } ;
111
113
use reth_exex_test_utils:: { PollOnce , test_exex_context} ;
112
114
use std:: pin:: pin;
115
+ use wasmtime:: CodeBuilder ;
113
116
114
117
#[ tokio:: test]
115
118
async fn test_exex ( ) -> eyre:: Result < ( ) > {
@@ -129,4 +132,34 @@ mod tests {
129
132
130
133
Ok ( ( ) )
131
134
}
135
+
136
+ #[ test]
137
+ fn test_wasm_code_execution_success ( ) {
138
+ let source = r#"
139
+ (module
140
+ (import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
141
+ (memory (export "memory") 1)
142
+ (data (i32.const 8) "Hello, borker!\n")
143
+
144
+ (func $main (export "_start")
145
+ (i32.store (i32.const 0) (i32.const 8))
146
+ (i32.store (i32.const 4) (i32.const 14))
147
+ (call $fd_write (i32.const 1) (i32.const 0) (i32.const 1) (i32.const 0))
148
+ drop
149
+ )
150
+ )
151
+ "# ;
152
+ let code = wat2wasm ( & source) . unwrap ( ) ;
153
+ let actual_res = on_req ( & ExecutionRequestEvent { code } ) ;
154
+ dbg ! ( & actual_res) ;
155
+ assert ! ( actual_res. is_ok( ) ) ;
156
+ }
157
+
158
+ fn wat2wasm ( source : & str ) -> eyre:: Result < Vec < u8 > > {
159
+ Ok ( CodeBuilder :: new ( & Engine :: default ( ) )
160
+ . wasm_binary_or_text ( & source. as_bytes ( ) , None )
161
+ . map_err ( |e| eyre ! ( "WASM Compilation Error: {e:?}" ) ) ?
162
+ . compile_module_serialized ( )
163
+ . map_err ( |e| eyre ! ( "WASM Compilation Error: {e:?}" ) ) ?)
164
+ }
132
165
}
0 commit comments