1+ import asyncio
2+ from typing import Any , Dict
3+
4+ from pathlib import Path
5+ from polywrap_core import Invoker , Uri , InvokerOptions , UriWrapper , Wrapper
6+ from polywrap_plugin import PluginModule , PluginWrapper
7+ from polywrap_uri_resolvers import StaticResolver
8+ from polywrap_manifest import AnyWrapManifest
9+ from polywrap_result import Result , Ok , Err
10+ from polywrap_client import PolywrapClient , PolywrapClientConfig
11+ from pytest import fixture
12+
13+
14+ @fixture
15+ def timer_module ():
16+ class TimerModule (PluginModule [None , str ]):
17+ def __init__ (self , config : None ):
18+ super ().__init__ (config )
19+
20+ async def sleep (self , args : Dict [str , Any ], client : Invoker ):
21+ await asyncio .sleep (args ["time" ])
22+ print (f"Woke up after { args ['time' ]} seconds" )
23+ return Ok (True )
24+
25+ return TimerModule (None )
26+
27+ @fixture
28+ def simple_wrap_manifest ():
29+ wrap_path = Path (__file__ ).parent / "cases" / "simple-invoke" / "wrap.info"
30+ with open (wrap_path , "rb" ) as f :
31+ yield f .read ()
32+
33+ @fixture
34+ def timer_wrapper (timer_module : PluginModule [None , str ], simple_wrap_manifest : AnyWrapManifest ):
35+ return PluginWrapper (module = timer_module , manifest = simple_wrap_manifest )
36+
37+
38+ async def test_timer (timer_wrapper : Wrapper ):
39+ uri_wrapper = UriWrapper (uri = Uri ("ens/timer.eth" ), wrapper = timer_wrapper )
40+ resolver = StaticResolver .from_list ([uri_wrapper ]).unwrap ()
41+
42+ config = PolywrapClientConfig (resolver = resolver )
43+
44+ client = PolywrapClient (config )
45+ uri = Uri ('ens/timer.eth' ) or Uri (f'fs/{ Path (__file__ ).parent .joinpath ("cases" , "big-number" ).absolute ()} ' )
46+ args = { "time" : 1 }
47+ options = InvokerOptions (uri = uri , method = "sleep" , args = args , encode_result = False )
48+ result = await client .invoke (options )
49+ assert result .unwrap () == True
0 commit comments