Merge branch 'feature/env-impurity' into 'dev'
Treat transaction environment operators as impure See merge request ligolang/ligo!346
This commit is contained in:
commit
e6cba7c34f
@ -7,16 +7,16 @@ let bad_contract basename =
|
|||||||
|
|
||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ;
|
run_ligo_good [ "measure-contract" ; contract "coase.ligo" ; "main" ] ;
|
||||||
[%expect {| 1872 bytes |}] ;
|
[%expect {| 1874 bytes |}] ;
|
||||||
|
|
||||||
run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ;
|
run_ligo_good [ "measure-contract" ; contract "multisig.ligo" ; "main" ] ;
|
||||||
[%expect {| 1187 bytes |}] ;
|
[%expect {| 1189 bytes |}] ;
|
||||||
|
|
||||||
run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ;
|
run_ligo_good [ "measure-contract" ; contract "multisig-v2.ligo" ; "main" ] ;
|
||||||
[%expect {| 2886 bytes |}] ;
|
[%expect {| 2897 bytes |}] ;
|
||||||
|
|
||||||
run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ;
|
run_ligo_good [ "measure-contract" ; contract "vote.mligo" ; "main" ] ;
|
||||||
[%expect {| 581 bytes |}] ;
|
[%expect {| 617 bytes |}] ;
|
||||||
|
|
||||||
run_ligo_good [ "compile-parameter" ; contract "coase.ligo" ; "main" ; "Buy_single (record card_to_buy = 1n end)" ] ;
|
run_ligo_good [ "compile-parameter" ; contract "coase.ligo" ; "main" ; "Buy_single (record card_to_buy = 1n end)" ] ;
|
||||||
[%expect {| (Left (Left 1)) |}] ;
|
[%expect {| (Left (Left 1)) |}] ;
|
||||||
@ -122,16 +122,18 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DUP ;
|
DUP ;
|
||||||
DIP { DUP } ;
|
|
||||||
SWAP ;
|
|
||||||
CDR ;
|
CDR ;
|
||||||
DIP { DIP 7 { DUP } ;
|
DIP { DIP 6 { DUP } ;
|
||||||
DIG 7 ;
|
DIG 6 ;
|
||||||
SENDER ;
|
SENDER ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
SOME ;
|
SOME ;
|
||||||
DIP { DIP { DUP } ; SWAP ; CAR ; CDR } } ;
|
DIP { DUP ; CAR ; CDR } } ;
|
||||||
UPDATE ;
|
UPDATE ;
|
||||||
|
DIP { DUP } ;
|
||||||
|
SWAP ;
|
||||||
|
DIP { DUP } ;
|
||||||
|
SWAP ;
|
||||||
DIP { DUP ; CDR ; SWAP ; CAR ; CAR } ;
|
DIP { DUP ; CDR ; SWAP ; CAR ; CAR } ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
@ -148,7 +150,7 @@ let%expect_test _ =
|
|||||||
DUP ;
|
DUP ;
|
||||||
NIL operation ;
|
NIL operation ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP 11 } }
|
DIP { DROP 12 } }
|
||||||
{ DUP ;
|
{ DUP ;
|
||||||
DIP { DIP 2 { DUP } ; DIG 2 } ;
|
DIP { DIP 2 { DUP } ; DIG 2 } ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
@ -317,10 +319,16 @@ let%expect_test _ =
|
|||||||
COMPARE ;
|
COMPARE ;
|
||||||
NEQ ;
|
NEQ ;
|
||||||
IF { PUSH string "Counters does not match" ; FAILWITH }
|
IF { PUSH string "Counters does not match" ; FAILWITH }
|
||||||
{ DIP 2 { DUP } ;
|
{ DUP ;
|
||||||
DIG 2 ;
|
DIP { DIP 2 { DUP } ; DIG 2 ; CAR ; CAR } ;
|
||||||
|
PAIR ;
|
||||||
|
DIP { DIP { DUP } ; SWAP ; CDR ; CAR ; CHAIN_ID ; SWAP ; PAIR } ;
|
||||||
|
PAIR ;
|
||||||
|
PACK ;
|
||||||
|
DIP 3 { DUP } ;
|
||||||
|
DIG 3 ;
|
||||||
CDR ;
|
CDR ;
|
||||||
DIP { DIP { DUP } ; SWAP ; CAR ; CAR ; PUSH nat 0 ; SWAP ; PAIR } ;
|
DIP { DIP 2 { DUP } ; DIG 2 ; CAR ; CAR ; PUSH nat 0 ; SWAP ; PAIR } ;
|
||||||
ITER { SWAP ;
|
ITER { SWAP ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DUP ;
|
DUP ;
|
||||||
@ -347,16 +355,7 @@ let%expect_test _ =
|
|||||||
COMPARE ;
|
COMPARE ;
|
||||||
EQ ;
|
EQ ;
|
||||||
IF { DUP ;
|
IF { DUP ;
|
||||||
DIP { DIP 3 { DUP } ;
|
DIP { DIP 3 { DUP } ; DIG 3 ; CDR ; DIP { DIP 7 { DUP } ; DIG 7 } } ;
|
||||||
DIG 3 ;
|
|
||||||
CDR ;
|
|
||||||
DIP { DIP 7 { DUP } ;
|
|
||||||
DIG 7 ;
|
|
||||||
DIP { DIP 9 { DUP } ; DIG 9 ; CAR ; CAR } ;
|
|
||||||
PAIR ;
|
|
||||||
DIP { DIP 8 { DUP } ; DIG 8 ; CDR ; CAR ; CHAIN_ID ; SWAP ; PAIR } ;
|
|
||||||
PAIR ;
|
|
||||||
PACK } } ;
|
|
||||||
CHECK_SIGNATURE ;
|
CHECK_SIGNATURE ;
|
||||||
IF { DIP 5 { DUP } ;
|
IF { DIP 5 { DUP } ;
|
||||||
DIG 5 ;
|
DIG 5 ;
|
||||||
@ -421,14 +420,14 @@ let%expect_test _ =
|
|||||||
DIP { DROP 7 } } ;
|
DIP { DROP 7 } } ;
|
||||||
DUP ;
|
DUP ;
|
||||||
CDR ;
|
CDR ;
|
||||||
DIP { DIP 2 { DUP } ; DIG 2 ; CDR ; CDR } ;
|
DIP { DIP 3 { DUP } ; DIG 3 ; CDR ; CDR } ;
|
||||||
COMPARE ;
|
COMPARE ;
|
||||||
LT ;
|
LT ;
|
||||||
IF { PUSH string "Not enough signatures passed the check" ; FAILWITH }
|
IF { PUSH string "Not enough signatures passed the check" ; FAILWITH }
|
||||||
{ DIP 2 { DUP } ;
|
{ DIP 3 { DUP } ;
|
||||||
DIG 2 ;
|
|
||||||
DIP 3 { DUP } ;
|
|
||||||
DIG 3 ;
|
DIG 3 ;
|
||||||
|
DIP 4 { DUP } ;
|
||||||
|
DIG 4 ;
|
||||||
CAR ;
|
CAR ;
|
||||||
CDR ;
|
CDR ;
|
||||||
PUSH nat 1 ;
|
PUSH nat 1 ;
|
||||||
@ -437,16 +436,16 @@ let%expect_test _ =
|
|||||||
SWAP ;
|
SWAP ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DIP 3 { DUP } ;
|
DIP 4 { DUP } ;
|
||||||
DIG 3 ;
|
DIG 4 ;
|
||||||
DIP { DUP } ;
|
DIP { DUP } ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
DIP { DROP 2 } } ;
|
DIP { DROP 2 } } ;
|
||||||
DIP 3 { DUP } ;
|
DIP 4 { DUP } ;
|
||||||
DIG 3 ;
|
DIG 4 ;
|
||||||
DIP { DUP } ;
|
DIP { DUP } ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
DIP { DROP 3 } } ;
|
DIP { DROP 4 } } ;
|
||||||
DIP { DUP } ;
|
DIP { DUP } ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
UNIT ;
|
UNIT ;
|
||||||
@ -576,21 +575,23 @@ let%expect_test _ =
|
|||||||
DIP { DUP } ;
|
DIP { DUP } ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
DIP { DROP 2 } } ;
|
DIP { DROP 2 } } ;
|
||||||
DIP 2 { DUP } ;
|
|
||||||
DIG 2 ;
|
|
||||||
CAR ;
|
|
||||||
DIP { DUP } ;
|
DIP { DUP } ;
|
||||||
PAIR ;
|
SWAP ;
|
||||||
DIP 2 { DUP } ;
|
|
||||||
DIG 2 ;
|
|
||||||
PUSH bool True ;
|
PUSH bool True ;
|
||||||
SENDER ;
|
SENDER ;
|
||||||
UPDATE ;
|
UPDATE ;
|
||||||
|
DIP 3 { DUP } ;
|
||||||
|
DIG 3 ;
|
||||||
|
DIP 2 { DUP } ;
|
||||||
|
DIG 2 ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
|
CAR ;
|
||||||
|
PAIR ;
|
||||||
CDR ;
|
CDR ;
|
||||||
|
DIP { DUP } ;
|
||||||
SWAP ;
|
SWAP ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP 2 } } ;
|
DIP { DROP 3 } } ;
|
||||||
DUP ;
|
DUP ;
|
||||||
CAR ;
|
CAR ;
|
||||||
DIP { DUP } ;
|
DIP { DUP } ;
|
||||||
@ -887,14 +888,16 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
DUP ;
|
DUP ;
|
||||||
CDR ;
|
CDR ;
|
||||||
DIP { DUP } ;
|
NOW ;
|
||||||
SWAP ;
|
SENDER ;
|
||||||
|
DIP 3 { DUP } ;
|
||||||
|
DIG 3 ;
|
||||||
CAR ;
|
CAR ;
|
||||||
IF_LEFT
|
IF_LEFT
|
||||||
{ DIP { DUP } ;
|
{ DIP 3 { DUP } ;
|
||||||
SWAP ;
|
DIG 3 ;
|
||||||
DIP 2 { DUP } ;
|
DIP 4 { DUP } ;
|
||||||
DIG 2 ;
|
DIG 4 ;
|
||||||
CAR ;
|
CAR ;
|
||||||
CAR ;
|
CAR ;
|
||||||
CDR ;
|
CDR ;
|
||||||
@ -906,10 +909,10 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP } }
|
DIP { DROP } }
|
||||||
{ DIP { DUP } ;
|
{ DIP 3 { DUP } ;
|
||||||
SWAP ;
|
DIG 3 ;
|
||||||
DIP 2 { DUP } ;
|
DIP 4 { DUP } ;
|
||||||
DIG 2 ;
|
DIG 4 ;
|
||||||
CDR ;
|
CDR ;
|
||||||
CDR ;
|
CDR ;
|
||||||
PUSH nat 1 ;
|
PUSH nat 1 ;
|
||||||
@ -921,12 +924,9 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP } } ;
|
DIP { DROP } } ;
|
||||||
DUP ;
|
DUP ;
|
||||||
DIP { DUP } ;
|
DIP 2 { DUP } ;
|
||||||
SWAP ;
|
DIG 2 ;
|
||||||
CDR ;
|
DIP { DIP { DUP } ; SWAP ; CDR ; CAR ; PUSH bool True } ;
|
||||||
CAR ;
|
|
||||||
PUSH bool True ;
|
|
||||||
SENDER ;
|
|
||||||
UPDATE ;
|
UPDATE ;
|
||||||
DIP { DUP ; CAR ; SWAP ; CDR ; CDR } ;
|
DIP { DUP ; CAR ; SWAP ; CDR ; CDR } ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
@ -934,7 +934,7 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
NIL operation ;
|
NIL operation ;
|
||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP 4 } } ;
|
DIP { DROP 6 } } ;
|
||||||
DIP { DROP } } } |}]
|
DIP { DROP } } } |}]
|
||||||
|
|
||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
@ -950,6 +950,28 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP 2 } } } |}]
|
DIP { DROP 2 } } } |}]
|
||||||
|
|
||||||
|
let%expect_test _ =
|
||||||
|
run_ligo_good [ "compile-contract" ; contract "amount_lambda.mligo" ; "main" ] ;
|
||||||
|
(* AMOUNT should occur inside the second lambda, but not the first lambda *)
|
||||||
|
[%expect {|
|
||||||
|
{ parameter bool ;
|
||||||
|
storage (lambda unit mutez) ;
|
||||||
|
code { DUP ;
|
||||||
|
CAR ;
|
||||||
|
IF { AMOUNT ;
|
||||||
|
DUP ;
|
||||||
|
LAMBDA
|
||||||
|
(pair mutez unit)
|
||||||
|
mutez
|
||||||
|
{ DUP ; CAR ; SWAP ; CDR ; DIP { DUP } ; SWAP ; DIP { DROP 2 } } ;
|
||||||
|
SWAP ;
|
||||||
|
APPLY ;
|
||||||
|
DIP { DROP } }
|
||||||
|
{ LAMBDA unit mutez { DROP ; AMOUNT } } ;
|
||||||
|
NIL operation ;
|
||||||
|
PAIR ;
|
||||||
|
DIP { DROP } } } |}]
|
||||||
|
|
||||||
let%expect_test _ =
|
let%expect_test _ =
|
||||||
run_ligo_bad [ "compile-contract" ; contract "bad_type_operator.ligo" ; "main" ] ;
|
run_ligo_bad [ "compile-contract" ; contract "bad_type_operator.ligo" ; "main" ] ;
|
||||||
[%expect {|
|
[%expect {|
|
||||||
|
@ -25,12 +25,13 @@ let is_pure_constant : constant' -> bool =
|
|||||||
| C_SOME
|
| C_SOME
|
||||||
| C_UPDATE | C_MAP_FIND_OPT | C_MAP_ADD | C_MAP_UPDATE
|
| C_UPDATE | C_MAP_FIND_OPT | C_MAP_ADD | C_MAP_UPDATE
|
||||||
| C_INT | C_ABS | C_IS_NAT
|
| C_INT | C_ABS | C_IS_NAT
|
||||||
| C_BALANCE | C_AMOUNT | C_ADDRESS | C_NOW | C_SOURCE | C_SENDER | C_CHAIN_ID
|
| C_ADDRESS
|
||||||
| C_SET_MEM | C_SET_ADD | C_SET_REMOVE | C_SLICE
|
| C_SET_MEM | C_SET_ADD | C_SET_REMOVE | C_SLICE
|
||||||
| C_SHA256 | C_SHA512 | C_BLAKE2b | C_CHECK_SIGNATURE
|
| C_SHA256 | C_SHA512 | C_BLAKE2b | C_CHECK_SIGNATURE
|
||||||
| C_HASH_KEY | C_BYTES_PACK | C_CONCAT
|
| C_HASH_KEY | C_BYTES_PACK | C_CONCAT
|
||||||
-> true
|
-> true
|
||||||
(* unfortunately impure: *)
|
(* unfortunately impure: *)
|
||||||
|
| C_BALANCE | C_AMOUNT | C_NOW | C_SOURCE | C_SENDER | C_CHAIN_ID
|
||||||
| C_ADD | C_SUB |C_MUL|C_DIV|C_MOD | C_LSL | C_LSR
|
| C_ADD | C_SUB |C_MUL|C_DIV|C_MOD | C_LSL | C_LSR
|
||||||
(* impure: *)
|
(* impure: *)
|
||||||
| C_ASSERTION | C_ASSERT_INFERRED
|
| C_ASSERTION | C_ASSERT_INFERRED
|
||||||
|
11
src/test/contracts/amount_lambda.mligo
Normal file
11
src/test/contracts/amount_lambda.mligo
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
(* should return a constant function *)
|
||||||
|
let f1 (x : unit) : unit -> tez =
|
||||||
|
let amt : tez = Current.amount in
|
||||||
|
fun (x : unit) -> amt
|
||||||
|
|
||||||
|
(* should return an impure function *)
|
||||||
|
let f2 (x : unit) : unit -> tez =
|
||||||
|
fun (x : unit) -> Current.amount
|
||||||
|
|
||||||
|
let main (b,s : bool * (unit -> tez)) : operation list * (unit -> tez) =
|
||||||
|
(([] : operation list), (if b then f1 () else f2 ()))
|
Loading…
Reference in New Issue
Block a user