@@ -13,6 +13,7 @@ pub struct PocketIcClient {
1313 client : Option < Arc < PocketIc > > ,
1414 pub canister : Principal ,
1515 pub caller : Principal ,
16+ live : bool ,
1617}
1718
1819impl PocketIcClient {
@@ -22,6 +23,15 @@ impl PocketIcClient {
2223 Self :: from_client ( PocketIc :: new ( ) . await , canister, caller)
2324 }
2425
26+ /// Creates a new instance of a PocketIcClient in live mode
27+ /// The new instance is independent and have no access to canisters of other instances.
28+ pub async fn new_live ( canister : Principal , caller : Principal ) -> Self {
29+ let mut client = PocketIc :: new ( ) . await ;
30+ client. make_live ( None ) . await ;
31+
32+ Self :: from_client ( client, canister, caller)
33+ }
34+
2535 /// Crates new instance of PocketIcClient from an existing client instance.
2636 pub fn from_client < P : Into < Arc < PocketIc > > > (
2737 client : P ,
@@ -32,6 +42,21 @@ impl PocketIcClient {
3242 client : Some ( client. into ( ) ) ,
3343 canister,
3444 caller,
45+ live : false ,
46+ }
47+ }
48+
49+ /// Crates new instance of PocketIcClient from an existing client instance.
50+ pub fn from_client_live < P : Into < Arc < PocketIc > > > (
51+ client : P ,
52+ canister : Principal ,
53+ caller : Principal ,
54+ ) -> Self {
55+ Self {
56+ client : Some ( client. into ( ) ) ,
57+ canister,
58+ caller,
59+ live : true ,
3560 }
3661 }
3762
@@ -50,10 +75,17 @@ impl PocketIcClient {
5075 {
5176 let args = candid:: encode_args ( args) ?;
5277
53- let reply = self
54- . client ( )
55- . update_call ( self . canister , self . caller , method, args)
56- . await ?;
78+ let reply = if self . live {
79+ let id = self
80+ . client ( )
81+ . submit_call ( self . canister , self . caller , method, args)
82+ . await ?;
83+ self . client ( ) . await_call_no_ticks ( id) . await
84+ } else {
85+ self . client ( )
86+ . update_call ( self . canister , self . caller , method, args)
87+ . await
88+ } ?;
5789
5890 let decoded = Decode ! ( & reply, R ) ?;
5991 Ok ( decoded)
0 commit comments