@@ -41,7 +41,10 @@ async fn main() {
41
41
basic_interact. print_sum ( ) . await ;
42
42
} ,
43
43
Some ( basic_interact_cli:: InteractCliCommand :: Upgrade ( args) ) => {
44
- basic_interact. upgrade ( args. value ) . await
44
+ let owner_address = basic_interact. adder_owner_address . clone ( ) ;
45
+ basic_interact
46
+ . upgrade ( args. value , & owner_address, None )
47
+ . await
45
48
} ,
46
49
None => { } ,
47
50
}
@@ -65,7 +68,15 @@ impl AdderInteract {
65
68
66
69
let adder_owner_address =
67
70
interactor. register_wallet ( Wallet :: from_pem_file ( "adder-owner.pem" ) . unwrap ( ) ) ;
68
- let wallet_address = interactor. register_wallet ( test_wallets:: mike ( ) ) ;
71
+ // PASSWORD: "alice"
72
+ // InsertPassword::Plaintext("alice".to_string()) || InsertPassword::StandardInput
73
+ let wallet_address = interactor. register_wallet (
74
+ Wallet :: from_keystore_secret (
75
+ "alice.json" ,
76
+ InsertPassword :: Plaintext ( "alice" . to_string ( ) ) ,
77
+ )
78
+ . unwrap ( ) ,
79
+ ) ;
69
80
70
81
Self {
71
82
interactor,
@@ -93,7 +104,7 @@ impl AdderInteract {
93
104
. interactor
94
105
. tx ( )
95
106
. from ( & self . adder_owner_address )
96
- . gas ( 3_000_000 )
107
+ . gas ( 6_000_000 )
97
108
. typed ( adder_proxy:: AdderProxy )
98
109
. init ( 0u32 )
99
110
. code ( ADDER_CODE_PATH )
@@ -123,7 +134,7 @@ impl AdderInteract {
123
134
. typed ( adder_proxy:: AdderProxy )
124
135
. init ( 0u32 )
125
136
. code ( ADDER_CODE_PATH )
126
- . gas ( 3_000_000 )
137
+ . gas ( 6_000_000 )
127
138
. returns ( ReturnsNewBech32Address )
128
139
} ) ;
129
140
}
@@ -151,7 +162,7 @@ impl AdderInteract {
151
162
. to ( self . state . current_adder_address ( ) )
152
163
. typed ( adder_proxy:: AdderProxy )
153
164
. add ( value)
154
- . gas ( 3_000_000 )
165
+ . gas ( 6_000_000 )
155
166
} ) ;
156
167
}
157
168
@@ -176,7 +187,7 @@ impl AdderInteract {
176
187
. tx ( )
177
188
. from ( & self . wallet_address )
178
189
. to ( self . state . current_adder_address ( ) )
179
- . gas ( 3_000_000 )
190
+ . gas ( 6_000_000 )
180
191
. typed ( adder_proxy:: AdderProxy )
181
192
. add ( value)
182
193
. prepare_async ( )
@@ -201,45 +212,87 @@ impl AdderInteract {
201
212
println ! ( "sum: {sum}" ) ;
202
213
}
203
214
204
- async fn upgrade ( & mut self , new_value : u32 ) {
205
- let response = self
206
- . interactor
207
- . tx ( )
208
- . from ( & self . wallet_address )
209
- . to ( self . state . current_adder_address ( ) )
210
- . gas ( 3_000_000 )
211
- . typed ( adder_proxy:: AdderProxy )
212
- . upgrade ( BigUint :: from ( new_value) )
213
- . code_metadata ( CodeMetadata :: UPGRADEABLE )
214
- . code ( ADDER_CODE_PATH )
215
- . returns ( ReturnsResultUnmanaged )
216
- . prepare_async ( )
217
- . run ( )
218
- . await ;
219
-
220
- let sum = self
221
- . interactor
222
- . query ( )
223
- . to ( self . state . current_adder_address ( ) )
224
- . typed ( adder_proxy:: AdderProxy )
225
- . sum ( )
226
- . returns ( ReturnsResultUnmanaged )
227
- . prepare_async ( )
228
- . run ( )
229
- . await ;
230
- assert_eq ! ( sum, RustBigUint :: from( new_value) ) ;
215
+ async fn upgrade (
216
+ & mut self ,
217
+ new_value : u32 ,
218
+ sender : & Bech32Address ,
219
+ expected_result : Option < ( u64 , & str ) > ,
220
+ ) {
221
+ match expected_result {
222
+ Some ( ( code, msg) ) => {
223
+ let response = self
224
+ . interactor
225
+ . tx ( )
226
+ . from ( sender)
227
+ . to ( self . state . current_adder_address ( ) )
228
+ . gas ( 6_000_000 )
229
+ . typed ( adder_proxy:: AdderProxy )
230
+ . upgrade ( new_value)
231
+ . code_metadata ( CodeMetadata :: UPGRADEABLE )
232
+ . code ( ADDER_CODE_PATH )
233
+ . returns ( ExpectError ( code, msg) )
234
+ . prepare_async ( )
235
+ . run ( )
236
+ . await ;
237
+
238
+ println ! ( "response: {response:?}" ) ;
239
+ } ,
240
+ None => {
241
+ self . interactor
242
+ . tx ( )
243
+ . from ( sender)
244
+ . to ( self . state . current_adder_address ( ) )
245
+ . gas ( 6_000_000 )
246
+ . typed ( adder_proxy:: AdderProxy )
247
+ . upgrade ( new_value)
248
+ . code_metadata ( CodeMetadata :: UPGRADEABLE )
249
+ . code ( ADDER_CODE_PATH )
250
+ . prepare_async ( )
251
+ . run ( )
252
+ . await ;
231
253
232
- println ! ( "response: {response:?}" ) ;
254
+ let sum = self
255
+ . interactor
256
+ . query ( )
257
+ . to ( self . state . current_adder_address ( ) )
258
+ . typed ( adder_proxy:: AdderProxy )
259
+ . sum ( )
260
+ . returns ( ReturnsResultUnmanaged )
261
+ . prepare_async ( )
262
+ . run ( )
263
+ . await ;
264
+
265
+ assert_eq ! ( sum, RustBigUint :: from( new_value) ) ;
266
+ } ,
267
+ }
233
268
}
234
269
}
235
270
236
271
#[ tokio:: test]
237
272
#[ ignore = "run on demand" ]
238
- async fn test ( ) {
273
+ async fn upgrade_test ( ) {
239
274
let mut basic_interact = AdderInteract :: init ( ) . await ;
275
+ let wallet_address = basic_interact. wallet_address . clone ( ) ;
276
+ let adder_owner_address = basic_interact. adder_owner_address . clone ( ) ;
277
+ let error_not_owner = ( 4 , "upgrade is allowed only for owner" ) ;
240
278
241
279
basic_interact. deploy ( ) . await ;
242
280
basic_interact. add ( 1u32 ) . await ;
243
281
244
- basic_interact. upgrade ( 7u32 ) . await ;
282
+ // Sum will be 1
283
+ basic_interact. print_sum ( ) . await ;
284
+
285
+ basic_interact
286
+ . upgrade ( 7u32 , & adder_owner_address, None )
287
+ . await ;
288
+
289
+ // Sum will be the updated value of 7
290
+ basic_interact. print_sum ( ) . await ;
291
+
292
+ basic_interact
293
+ . upgrade ( 10u32 , & wallet_address, Some ( error_not_owner) )
294
+ . await ;
295
+
296
+ // Sum will remain 7
297
+ basic_interact. print_sum ( ) . await ;
245
298
}
0 commit comments