@@ -1383,10 +1383,10 @@ def test_get_multisig_transactions_not_decoded(
1383
1383
self .assertEqual (response .status_code , status .HTTP_200_OK )
1384
1384
self .assertIsNone (response .data ["results" ][0 ]["data_decoded" ])
1385
1385
1386
- ContractQuerySet .cache_trusted_addresses_for_delegate_call .clear ()
1387
1386
ContractFactory (
1388
1387
address = multisig_transaction .to , trusted_for_delegate_call = True
1389
1388
)
1389
+ ContractQuerySet .cache_trusted_addresses_for_delegate_call .clear ()
1390
1390
# Force don't use cache because we are not cleaning the cache on contracts change
1391
1391
with mock .patch (
1392
1392
"safe_transaction_service.history.views.settings.CACHE_VIEW_DEFAULT_TIMEOUT" ,
@@ -2332,62 +2332,82 @@ def test_post_multisig_transaction_with_delegate_call(self):
2332
2332
safe_owner_1 = Account .create ()
2333
2333
safe = self .deploy_test_safe (owners = [safe_owner_1 .address ])
2334
2334
safe_address = safe .address
2335
-
2336
- response = self .client .get (
2337
- reverse ("v1:history:multisig-transactions" , args = (safe_address ,)),
2338
- format = "json" ,
2339
- )
2340
- self .assertEqual (response .status_code , status .HTTP_200_OK )
2341
- self .assertEqual (response .data ["count" ], 0 )
2342
-
2343
- data = {
2344
- "to" : Account .create ().address ,
2345
- "value" : 0 ,
2346
- "data" : "0x12121212" ,
2347
- "operation" : 1 ,
2348
- "nonce" : 0 ,
2349
- "safeTxGas" : 0 ,
2350
- "baseGas" : 0 ,
2351
- "gasPrice" : 0 ,
2352
- "gasToken" : "0x0000000000000000000000000000000000000000" ,
2353
- "refundReceiver" : "0x0000000000000000000000000000000000000000" ,
2354
- "sender" : safe_owner_1 .address ,
2355
- }
2356
- safe_tx = safe .build_multisig_tx (
2357
- data ["to" ],
2358
- data ["value" ],
2359
- data ["data" ],
2360
- data ["operation" ],
2361
- data ["safeTxGas" ],
2362
- data ["baseGas" ],
2363
- data ["gasPrice" ],
2364
- data ["gasToken" ],
2365
- data ["refundReceiver" ],
2366
- safe_nonce = data ["nonce" ],
2367
- )
2368
- data ["contractTransactionHash" ] = to_0x_hex_str (safe_tx .safe_tx_hash )
2369
-
2370
- with self .settings (
2371
- DISABLE_CREATION_MULTISIG_TRANSACTIONS_WITH_DELEGATE_CALL_OPERATION = True
2372
- ):
2373
- response = self .client .post (
2335
+ try :
2336
+ response = self .client .get (
2374
2337
reverse ("v1:history:multisig-transactions" , args = (safe_address ,)),
2375
2338
format = "json" ,
2376
- data = data ,
2377
2339
)
2378
- self .assertEqual (response .status_code , status .HTTP_422_UNPROCESSABLE_ENTITY )
2379
-
2380
- with self .settings (
2381
- DISABLE_CREATION_MULTISIG_TRANSACTIONS_WITH_DELEGATE_CALL_OPERATION = False
2382
- ):
2383
- response = self .client .post (
2384
- reverse ("v1:history:multisig-transactions" , args = (safe_address ,)),
2385
- format = "json" ,
2386
- data = data ,
2340
+ self .assertEqual (response .status_code , status .HTTP_200_OK )
2341
+ self .assertEqual (response .data ["count" ], 0 )
2342
+
2343
+ data = {
2344
+ "to" : Account .create ().address ,
2345
+ "value" : 0 ,
2346
+ "data" : "0x12121212" ,
2347
+ "operation" : SafeOperationEnum .DELEGATE_CALL .value ,
2348
+ "nonce" : 0 ,
2349
+ "safeTxGas" : 0 ,
2350
+ "baseGas" : 0 ,
2351
+ "gasPrice" : 0 ,
2352
+ "gasToken" : "0x0000000000000000000000000000000000000000" ,
2353
+ "refundReceiver" : "0x0000000000000000000000000000000000000000" ,
2354
+ "sender" : safe_owner_1 .address ,
2355
+ }
2356
+ safe_tx = safe .build_multisig_tx (
2357
+ data ["to" ],
2358
+ data ["value" ],
2359
+ data ["data" ],
2360
+ data ["operation" ],
2361
+ data ["safeTxGas" ],
2362
+ data ["baseGas" ],
2363
+ data ["gasPrice" ],
2364
+ data ["gasToken" ],
2365
+ data ["refundReceiver" ],
2366
+ safe_nonce = data ["nonce" ],
2387
2367
)
2388
- self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2389
- multisig_transaction_db = MultisigTransaction .objects .first ()
2390
- self .assertEqual (multisig_transaction_db .operation , 1 )
2368
+ data ["contractTransactionHash" ] = to_0x_hex_str (safe_tx .safe_tx_hash )
2369
+
2370
+ ContractQuerySet .cache_trusted_addresses_for_delegate_call .clear ()
2371
+ # Disable creation with delegate call and not trusted contract
2372
+ with self .settings (
2373
+ DISABLE_CREATION_MULTISIG_TRANSACTIONS_WITH_DELEGATE_CALL_OPERATION = True
2374
+ ):
2375
+ response = self .client .post (
2376
+ reverse ("v1:history:multisig-transactions" , args = (safe_address ,)),
2377
+ format = "json" ,
2378
+ data = data ,
2379
+ )
2380
+ self .assertEqual (
2381
+ response .status_code , status .HTTP_422_UNPROCESSABLE_ENTITY
2382
+ )
2383
+
2384
+ # Enable creation with delegate call
2385
+ with self .settings (
2386
+ DISABLE_CREATION_MULTISIG_TRANSACTIONS_WITH_DELEGATE_CALL_OPERATION = False
2387
+ ):
2388
+ response = self .client .post (
2389
+ reverse ("v1:history:multisig-transactions" , args = (safe_address ,)),
2390
+ format = "json" ,
2391
+ data = data ,
2392
+ )
2393
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2394
+ multisig_transaction_db = MultisigTransaction .objects .first ()
2395
+ self .assertEqual (multisig_transaction_db .operation , 1 )
2396
+
2397
+ # Disable creation with delegate call and trusted contract
2398
+ ContractFactory (address = data ["to" ], trusted_for_delegate_call = True )
2399
+ ContractQuerySet .cache_trusted_addresses_for_delegate_call .clear ()
2400
+ with self .settings (
2401
+ DISABLE_CREATION_MULTISIG_TRANSACTIONS_WITH_DELEGATE_CALL_OPERATION = True
2402
+ ):
2403
+ response = self .client .post (
2404
+ reverse ("v1:history:multisig-transactions" , args = (safe_address ,)),
2405
+ format = "json" ,
2406
+ data = data ,
2407
+ )
2408
+ self .assertEqual (response .status_code , status .HTTP_201_CREATED )
2409
+ finally :
2410
+ ContractQuerySet .cache_trusted_addresses_for_delegate_call .clear ()
2391
2411
2392
2412
def test_safe_balances_view (self ):
2393
2413
safe_address = Account .create ().address
0 commit comments