@@ -12,7 +12,9 @@ use near_o11y::testonly::init_test_logger;
12
12
use near_parameters:: { ActionCosts , RuntimeConfigStore , RuntimeFeesConfig } ;
13
13
use near_primitives:: action:: { GlobalContractDeployMode , GlobalContractIdentifier } ;
14
14
use near_primitives:: epoch_manager:: EpochConfigStore ;
15
- use near_primitives:: errors:: { ActionError , ActionErrorKind , TxExecutionError } ;
15
+ use near_primitives:: errors:: {
16
+ ActionError , ActionErrorKind , FunctionCallError , MethodResolveError , TxExecutionError ,
17
+ } ;
16
18
use near_primitives:: hash:: CryptoHash ;
17
19
use near_primitives:: shard_layout:: ShardLayout ;
18
20
use near_primitives:: test_utils:: create_user_test_signer;
@@ -80,6 +82,46 @@ fn test_use_non_existent_global_contract() {
80
82
env. shutdown ( ) ;
81
83
}
82
84
85
+ #[ cfg_attr( not( feature = "nightly_protocol" ) , ignore) ]
86
+ #[ test]
87
+ fn test_global_contract_update ( ) {
88
+ let mut env = GlobalContractsTestEnv :: setup ( 1000 * ONE_NEAR ) ;
89
+ let use_accounts = [ env. account_shard_0 . clone ( ) , env. account_shard_1 . clone ( ) ] ;
90
+
91
+ env. deploy_trivial_global_contract ( GlobalContractDeployMode :: AccountId ) ;
92
+
93
+ for account in & use_accounts {
94
+ env. use_global_contract (
95
+ account,
96
+ GlobalContractIdentifier :: AccountId ( env. deploy_account . clone ( ) ) ,
97
+ ) ;
98
+
99
+ // Currently deployed trivial contract doesn't have any methods,
100
+ // so we expect any function call to fail with MethodNotFound error
101
+ let call_tx = env. call_global_contract_tx ( account) ;
102
+ let call_outcome = env. execute_tx ( call_tx) ;
103
+ assert_matches ! (
104
+ call_outcome. status,
105
+ FinalExecutionStatus :: Failure ( TxExecutionError :: ActionError ( ActionError {
106
+ kind: ActionErrorKind :: FunctionCallError ( FunctionCallError :: MethodResolveError (
107
+ MethodResolveError :: MethodNotFound
108
+ ) ) ,
109
+ index: _
110
+ } ) )
111
+ ) ;
112
+ }
113
+
114
+ env. deploy_global_contract ( GlobalContractDeployMode :: AccountId ) ;
115
+
116
+ for account in & use_accounts {
117
+ // Function call should be successful after deploying rs contract
118
+ // containing the function we call here
119
+ env. call_global_contract ( account) ;
120
+ }
121
+
122
+ env. shutdown ( ) ;
123
+ }
124
+
83
125
fn test_deploy_and_call_global_contract ( deploy_mode : GlobalContractDeployMode ) {
84
126
const INITIAL_BALANCE : Balance = 1000 * ONE_NEAR ;
85
127
let mut env = GlobalContractsTestEnv :: setup ( INITIAL_BALANCE ) ;
@@ -185,25 +227,41 @@ impl GlobalContractsTestEnv {
185
227
}
186
228
}
187
229
188
- fn deploy_global_contract_tx (
230
+ fn deploy_global_contract_custom_tx (
189
231
& mut self ,
190
232
deploy_mode : GlobalContractDeployMode ,
233
+ contract_code : Vec < u8 > ,
191
234
) -> SignedTransaction {
192
235
SignedTransaction :: deploy_global_contract (
193
236
self . next_nonce ( ) ,
194
237
self . deploy_account . clone ( ) ,
195
- self . contract . code ( ) . to_vec ( ) ,
238
+ contract_code ,
196
239
& create_user_test_signer ( & self . deploy_account ) ,
197
240
self . get_tx_block_hash ( ) ,
198
241
deploy_mode,
199
242
)
200
243
}
201
244
245
+ fn deploy_global_contract_tx (
246
+ & mut self ,
247
+ deploy_mode : GlobalContractDeployMode ,
248
+ ) -> SignedTransaction {
249
+ self . deploy_global_contract_custom_tx ( deploy_mode, self . contract . code ( ) . to_vec ( ) )
250
+ }
251
+
202
252
fn deploy_global_contract ( & mut self , deploy_mode : GlobalContractDeployMode ) {
203
253
let tx = self . deploy_global_contract_tx ( deploy_mode) ;
204
254
self . run_tx ( tx) ;
205
255
}
206
256
257
+ fn deploy_trivial_global_contract ( & mut self , deploy_mode : GlobalContractDeployMode ) {
258
+ let tx = self . deploy_global_contract_custom_tx (
259
+ deploy_mode,
260
+ near_test_contracts:: trivial_contract ( ) . to_vec ( ) ,
261
+ ) ;
262
+ self . run_tx ( tx) ;
263
+ }
264
+
207
265
fn deploy_regular_contract ( & mut self , account : & AccountId ) {
208
266
let tx = SignedTransaction :: deploy_contract (
209
267
self . next_nonce ( ) ,
@@ -234,8 +292,8 @@ impl GlobalContractsTestEnv {
234
292
self . run_tx ( tx) ;
235
293
}
236
294
237
- fn call_global_contract ( & mut self , account : & AccountId ) {
238
- let tx = SignedTransaction :: call (
295
+ fn call_global_contract_tx ( & mut self , account : & AccountId ) -> SignedTransaction {
296
+ SignedTransaction :: call (
239
297
self . next_nonce ( ) ,
240
298
account. clone ( ) ,
241
299
account. clone ( ) ,
@@ -245,7 +303,11 @@ impl GlobalContractsTestEnv {
245
303
vec ! [ ] ,
246
304
300 * TGAS ,
247
305
self . get_tx_block_hash ( ) ,
248
- ) ;
306
+ )
307
+ }
308
+
309
+ fn call_global_contract ( & mut self , account : & AccountId ) {
310
+ let tx = self . call_global_contract_tx ( account) ;
249
311
self . run_tx ( tx) ;
250
312
}
251
313
0 commit comments