From f05b02f74f89e79102e6c23ebe8f21750a3e0c0b Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Thu, 12 Apr 2018 21:11:33 +0200 Subject: [PATCH] Michelson: some new contracts/tests --- src/bin_client/test/contracts/cps_fact.tz | 2 +- .../lib_protocol/test/contracts/cps_fact.tz | 16 ++++++++++++++++ .../lib_protocol/test/contracts/cps_fact_2.tz | 14 ++++++++++++++ .../lib_protocol/test/test_michelson.ml | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/proto_alpha/lib_protocol/test/contracts/cps_fact.tz create mode 100644 src/proto_alpha/lib_protocol/test/contracts/cps_fact_2.tz diff --git a/src/bin_client/test/contracts/cps_fact.tz b/src/bin_client/test/contracts/cps_fact.tz index 3b6ec70ca..d26e57715 100644 --- a/src/bin_client/test/contracts/cps_fact.tz +++ b/src/bin_client/test/contracts/cps_fact.tz @@ -11,6 +11,6 @@ code { UNPAIR ; IF_NONE { NIL operation ; PAIR } { DUP ; DIP { PUSH nat 1 ; ADD ; MUL @storage } ; SWAP; - DIP { DIP { PUSH nat 4000 ; SELF; PUSH tez "0" } ; + DIP { DIP { SELF; PUSH tez "0" } ; TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS } ; SWAP ; PAIR } } } \ No newline at end of file diff --git a/src/proto_alpha/lib_protocol/test/contracts/cps_fact.tz b/src/proto_alpha/lib_protocol/test/contracts/cps_fact.tz new file mode 100644 index 000000000..d26e57715 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/contracts/cps_fact.tz @@ -0,0 +1,16 @@ +storage nat ; +parameter nat ; +code { UNPAIR ; + DIP { SELF ; ADDRESS ; SOURCE; + IFCMPEQ {} { DROP ; PUSH @storage nat 1 } }; + DUP ; + PUSH nat 1 ; + IFCMPGE + { DROP ; NIL operation ; PAIR } + { PUSH nat 1 ; SWAP ; SUB @parameter ; ISNAT ; + IF_NONE + { NIL operation ; PAIR } + { DUP ; DIP { PUSH nat 1 ; ADD ; MUL @storage } ; SWAP; + DIP { DIP { SELF; PUSH tez "0" } ; + TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS } ; + SWAP ; PAIR } } } \ No newline at end of file diff --git a/src/proto_alpha/lib_protocol/test/contracts/cps_fact_2.tz b/src/proto_alpha/lib_protocol/test/contracts/cps_fact_2.tz new file mode 100644 index 000000000..5dbcb6167 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/contracts/cps_fact_2.tz @@ -0,0 +1,14 @@ +storage unit ; +parameter (pair nat nat) ; +code { CAR ; UNPAIR ; + DUP ; + PUSH nat 1 ; + IFCMPGE + { DROP ; DROP ; UNIT ; NIL operation ; PAIR } + { PUSH nat 1 ; SWAP ; SUB @parameter ; ISNAT ; + IF_NONE + { DROP ; UNIT ; NIL operation ; PAIR } + { DUP ; DIP { PUSH nat 1 ; ADD ; MUL @storage } ; PAIR ; + DIP { SELF; PUSH tez "0" } ; + TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS ; + UNIT ; SWAP ; PAIR } } } \ No newline at end of file diff --git a/src/proto_alpha/lib_protocol/test/test_michelson.ml b/src/proto_alpha/lib_protocol/test/test_michelson.ml index b8593ce7c..c33a8d01b 100644 --- a/src/proto_alpha/lib_protocol/test/test_michelson.ml +++ b/src/proto_alpha/lib_protocol/test/test_michelson.ml @@ -422,6 +422,9 @@ let test_example () = test_output ~location: __LOC__ "diff_timestamps" "111" "(Pair 1 0)" "1" >>=? fun _ -> test_output ~location: __LOC__ "diff_timestamps" "111" "(Pair \"1970-01-01T00:03:20Z\" \"1970-01-01T00:00:00Z\")" "200" >>=? fun _ -> + (* Test internal operations *) + test_output ~location: __LOC__ "cps_fact" "0" "4" "24" >>=? fun _ -> + (* Test NOW *) let now = sb.tezos_header.shell.timestamp in let now_str = quote @@ Tezos_base.Time.to_notation now in