1+ import pytest
12from pathlib import Path
23
34from polywrap_client import PolywrapClient
4- from polywrap_core import Uri , InvokerOptions , InterfaceImplementations , Env
5- from polywrap_uri_resolvers import BaseUriResolver , SimpleFileReader
6-
5+ from polywrap_core import Uri , InvokerOptions , InterfaceImplementations , Env , UriWrapper
6+ from polywrap_uri_resolvers import BaseUriResolver , SimpleFileReader , StaticResolver
7+ from polywrap_result import Result , Ok , Err
78from polywrap_client .client import PolywrapClientConfig
8-
9-
10- async def test_invoke ():
9+ from polywrap_wasm import WRAP_MANIFEST_PATH , WRAP_MODULE_PATH , IFileReader , WasmWrapper
10+
11+ @pytest .fixture
12+ def simple_wrap_module ():
13+ wrap_path = Path (__file__ ).parent / "cases" / "simple-invoke" / "wrap.wasm"
14+ with open (wrap_path , "rb" ) as f :
15+ yield f .read ()
16+
17+
18+ @pytest .fixture
19+ def simple_wrap_manifest ():
20+ wrap_path = Path (__file__ ).parent / "cases" / "simple-invoke" / "wrap.info"
21+ with open (wrap_path , "rb" ) as f :
22+ yield f .read ()
23+
24+ @pytest .fixture
25+ def simple_file_reader (simple_wrap_module : bytes , simple_wrap_manifest : bytes ):
26+ class FileReader (IFileReader ):
27+ async def read_file (self , file_path : str ) -> Result [bytes ]:
28+ if file_path == WRAP_MODULE_PATH :
29+ return Ok (simple_wrap_module )
30+ if file_path == WRAP_MANIFEST_PATH :
31+ return Ok (simple_wrap_manifest )
32+ return Err .from_str (f"FileNotFound: { file_path } " )
33+
34+ yield FileReader ()
35+
36+ @pytest .mark .asyncio
37+ async def test_invoke (
38+ simple_file_reader : IFileReader ,
39+ simple_wrap_module : bytes ,
40+ simple_wrap_manifest : bytes
41+ ):
1142 client = PolywrapClient ()
1243 uri = Uri (
1344 f'fs/{ Path (__file__ ).parent .joinpath ("cases" , "simple-invoke" ).absolute ()} '
@@ -20,6 +51,27 @@ async def test_invoke():
2051
2152 assert result .unwrap () == args ["arg" ]
2253
54+ wrapper = WasmWrapper (
55+ file_reader = simple_file_reader ,
56+ wasm_module = simple_wrap_module ,
57+ manifest = simple_wrap_manifest
58+ )
59+ uri_wrapper = UriWrapper (uri = Uri ("ens/wrapper.eth" ), wrapper = wrapper )
60+ resolver = StaticResolver ._from ([uri_wrapper ])
61+
62+ config = PolywrapClientConfig (resolver = resolver )
63+ client = PolywrapClient (config = config )
64+
65+ args = {"arg" : "hello polywrap" }
66+ options = InvokerOptions (
67+ uri = Uri ("ens/wrapper.eth" ),
68+ method = "simpleMethod" ,
69+ args = args ,
70+ encode_result = False
71+ )
72+ result = await client .invoke (options )
73+
74+ assert result .unwrap () == args ["arg" ]
2375
2476async def test_subinvoke ():
2577 uri_resolver = BaseUriResolver (
0 commit comments