File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
20
20
- Remove check for compatible ` scale ` and ` scale-info ` versions - [ #1370 ] ( https://github.com/paritytech/cargo-contract/pull/1370 )
21
21
- Add workspace support -[ #1358 ] ( https://github.com/paritytech/cargo-contract/pull/1358 )
22
22
23
+ ### Fixed
24
+ - Do not allow to execute calls on immutable contract messages - [ #1397 ] ( https://github.com/paritytech/cargo-contract/pull/1397 )
25
+
23
26
## [ 4.0.0-alpha]
24
27
25
28
Replaces the yanked ` 3.1.0 ` due to issues with supporting * both* Rust versions < ` 1.70 `
Original file line number Diff line number Diff line change @@ -267,6 +267,23 @@ impl CallExec {
267
267
& self ,
268
268
gas_limit : Option < Weight > ,
269
269
) -> Result < DisplayEvents , ErrorVariant > {
270
+ if !self
271
+ . transcoder ( )
272
+ . metadata ( )
273
+ . spec ( )
274
+ . messages ( )
275
+ . iter ( )
276
+ . find ( |msg| msg. label ( ) == & self . message )
277
+ . expect ( "message exist after calling CallExec::done()" )
278
+ . mutates ( )
279
+ {
280
+ let inner = anyhow ! (
281
+ "Tried to execute a call on the immutable contract message '{}'. Please do a dry-run instead." ,
282
+ & self . message
283
+ ) ;
284
+ return Err ( inner. into ( ) ) ;
285
+ }
286
+
270
287
// use user specified values where provided, otherwise estimate
271
288
let gas_limit = match gas_limit {
272
289
Some ( gas_limit) => gas_limit,
Original file line number Diff line number Diff line change @@ -96,14 +96,14 @@ impl ContractsNodeProcess {
96
96
) ;
97
97
let result = OnlineClient :: new ( ) . await ;
98
98
if let Ok ( client) = result {
99
- break Ok ( client)
99
+ break Ok ( client) ;
100
100
}
101
101
if attempts < MAX_ATTEMPTS {
102
102
attempts += 1 ;
103
- continue
103
+ continue ;
104
104
}
105
105
if let Err ( err) = result {
106
- break Err ( err)
106
+ break Err ( err) ;
107
107
}
108
108
} ;
109
109
match client {
@@ -509,6 +509,13 @@ async fn api_build_upload_instantiate_call() {
509
509
. to_string ( ) ;
510
510
assert ! ( value. contains( "true" ) , "{:#?}" , value) ;
511
511
512
+ // call the contract on the immutable "get" message trying to execute
513
+ // this should fail because "get" is immutable
514
+ match call. call ( None ) . await {
515
+ Err ( crate :: ErrorVariant :: Generic ( _) ) => { }
516
+ _ => panic ! ( "immutable call was not prevented" ) ,
517
+ }
518
+
512
519
// call the contract
513
520
// flip the value
514
521
let call = CallCommandBuilder :: default ( )
You can’t perform that action at this time.
0 commit comments