Predefined values for Ligodity. Added a few more tests for Ligodity.
This commit is contained in:
parent
dbe4282659
commit
bff14309e4
7
src/contracts/letin.mligo
Normal file
7
src/contracts/letin.mligo
Normal file
@ -0,0 +1,7 @@
|
||||
type storage = int * int
|
||||
|
||||
let%entry main (n: int) storage =
|
||||
let x : int * int =
|
||||
let x : int = 7
|
||||
in x + n, storage.(0) + storage.(1)
|
||||
in (([] : operation list), x)
|
10
src/contracts/list.mligo
Normal file
10
src/contracts/list.mligo
Normal file
@ -0,0 +1,10 @@
|
||||
type storage = int * int list
|
||||
|
||||
type param = int list
|
||||
|
||||
let%entry main (p : param) storage =
|
||||
let storage =
|
||||
match p with
|
||||
[] -> storage
|
||||
| hd::tl -> storage.(0) + hd, tl
|
||||
in (([] : operation list), storage)
|
13
src/contracts/match.mligo
Normal file
13
src/contracts/match.mligo
Normal file
@ -0,0 +1,13 @@
|
||||
type storage = int
|
||||
|
||||
type param =
|
||||
Add of int
|
||||
| Sub of int
|
||||
|
||||
let%entry main (p : param) storage =
|
||||
let storage =
|
||||
storage +
|
||||
(match p with
|
||||
Add n -> n
|
||||
| Sub n -> 0-n)
|
||||
in (([] : operation list), storage)
|
@ -14,8 +14,12 @@ type param = {
|
||||
}
|
||||
|
||||
let%entry attempt (p:param) storage =
|
||||
if Crypto.hash (Bytes.pack p.attempt) <> Bytes.pack storage.challenge then failwith "Failed challenge" ;
|
||||
let contract : unit contract = Operation.get_contract sender in
|
||||
let transfer : operation = Operation.transaction (unit , contract , 10.00tz) in
|
||||
let storage : storage = storage.challenge <- p.new_challenge in
|
||||
((list [] : operation list), storage)
|
||||
if Crypto.hash (Bytes.pack p.attempt) <> Bytes.pack storage.challenge
|
||||
then failwith "Failed challenge"
|
||||
else
|
||||
let contract : unit contract =
|
||||
Operation.get_contract sender in
|
||||
let transfer : operation =
|
||||
Operation.transaction (unit , contract , 10tz) in
|
||||
let storage : storage = {challenge = p.new_challenge}
|
||||
in (([] : operation list), storage)
|
||||
|
47
src/contracts/record.mligo
Normal file
47
src/contracts/record.mligo
Normal file
@ -0,0 +1,47 @@
|
||||
type foobar = {
|
||||
foo : int ;
|
||||
bar : int ;
|
||||
}
|
||||
|
||||
let fb : foobar = {
|
||||
foo = 0 ;
|
||||
bar = 0 ;
|
||||
}
|
||||
|
||||
type abc = {
|
||||
a : int ;
|
||||
b : int ;
|
||||
c : int
|
||||
}
|
||||
|
||||
let abc : abc = {
|
||||
a = 42 ;
|
||||
b = 142 ;
|
||||
c = 242
|
||||
}
|
||||
|
||||
let a : int = abc.a
|
||||
let b : int = abc.b
|
||||
let c : int = abc.c
|
||||
|
||||
let projection (r : foobar) : int = r.foo + r.bar
|
||||
|
||||
let modify (r : foobar) : foobar = {foo = 256; bar = r.bar}
|
||||
|
||||
let modify_abc (r : abc) : abc = {a = r.a; b = 2048; c = r.c}
|
||||
|
||||
type big_record = {
|
||||
a : int ;
|
||||
b : int ;
|
||||
c : int ;
|
||||
d : int ;
|
||||
e : int ;
|
||||
}
|
||||
|
||||
let br : big_record = {
|
||||
a = 23 ;
|
||||
b = 23 ;
|
||||
c = 23 ;
|
||||
d = 23 ;
|
||||
e = 23 ;
|
||||
}
|
@ -83,7 +83,54 @@ module Simplify = struct
|
||||
end
|
||||
|
||||
module Ligodity = struct
|
||||
include Pascaligo
|
||||
let constants = [
|
||||
("Current.balance", "BALANCE") ;
|
||||
("balance", "BALANCE") ;
|
||||
("Current.time", "NOW") ;
|
||||
("time", "NOW") ;
|
||||
("Current.amount" , "AMOUNT") ;
|
||||
("amount", "AMOUNT") ;
|
||||
("Current.gas", "STEPS_TO_QUOTA") ;
|
||||
("gas", "STEPS_TO_QUOTA") ;
|
||||
("Current.sender" , "SENDER") ;
|
||||
("sender", "SENDER") ;
|
||||
("Current.failwith", "FAILWITH") ;
|
||||
("failwith" , "FAILWITH") ;
|
||||
|
||||
("Crypto.hash" , "HASH") ;
|
||||
("Crypto.black2b", "BLAKE2B") ;
|
||||
("Crypto.sha256", "SHA256") ;
|
||||
("Crypto.sha512", "SHA512") ;
|
||||
("Crypto.hash_key", "HASH_KEY") ;
|
||||
("Crypto.check", "CHECK_SIGNATURE") ;
|
||||
|
||||
("Bytes.pack" , "PACK") ;
|
||||
("Bytes.unpack", "UNPACK") ;
|
||||
("Bytes.length", "SIZE") ;
|
||||
("Bytes.size" , "SIZE") ;
|
||||
("Bytes.concat", "CONCAT") ;
|
||||
("Bytes.slice", "SLICE") ;
|
||||
("Bytes.sub", "SLICE") ;
|
||||
|
||||
("String.length", "SIZE") ;
|
||||
("String.size", "SIZE") ;
|
||||
("String.slice", "SLICE") ;
|
||||
("String.sub", "SLICE") ;
|
||||
("String.concat", "CONCAT") ;
|
||||
|
||||
("List.length", "SIZE") ;
|
||||
("List.size", "SIZE") ;
|
||||
("List.iter", "ITER") ;
|
||||
|
||||
("Operation.transaction" , "CALL") ;
|
||||
("Operation.get_contract" , "GET_CONTRACT") ;
|
||||
("int" , "INT") ;
|
||||
("abs" , "ABS") ;
|
||||
("unit" , "UNIT") ;
|
||||
("source" , "SOURCE") ;
|
||||
]
|
||||
|
||||
let type_constants = type_constants
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -5,9 +5,12 @@ open AST
|
||||
|
||||
(* Rewrite "let pattern = e" as "let x = e;; let x1 = ...;; let x2 = ...;;" *)
|
||||
|
||||
(*
|
||||
module VMap = Utils.String.Map
|
||||
|
||||
(*let ghost_of value = Region.{region=ghost; value}*)
|
||||
let ghost_of value = Region.{region=ghost; value}
|
||||
*)
|
||||
|
||||
let ghost = Region.ghost
|
||||
|
||||
(* let fail_syn_unif type1 type2 : 'a =
|
||||
|
13
src/parser/ligodity/Tests/match.mml
Normal file
13
src/parser/ligodity/Tests/match.mml
Normal file
@ -0,0 +1,13 @@
|
||||
type storage = int
|
||||
|
||||
type param =
|
||||
Add of int
|
||||
| Sub of int
|
||||
|
||||
let%entry main (p : param) storage =
|
||||
let storage =
|
||||
storage +
|
||||
(match p with
|
||||
Add n -> n
|
||||
| Sub n -> 0-n)
|
||||
in (([] : operation list), storage)
|
@ -439,17 +439,6 @@ let dispatch_counter_contract () : unit result =
|
||||
e_pair (e_typed_list [] t_operation) (e_int (op 42 n)) in
|
||||
expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let basic_mligo () : unit result =
|
||||
let%bind typed = mtype_file ~debug_simplify:true "./contracts/basic.mligo" in
|
||||
let%bind result = evaluate_typed "foo" typed in
|
||||
Ligo.AST_Typed.assert_value_eq (Ligo.AST_Typed.Combinators.e_a_empty_int (42 + 127), result)
|
||||
|
||||
let counter_mligo () : unit result =
|
||||
let%bind program = mtype_file "./contracts/counter.mligo" in
|
||||
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
|
||||
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
|
||||
expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let failwith_mligo () : unit result =
|
||||
let%bind program = mtype_file "./contracts/failwith.mligo" in
|
||||
let make_input = e_pair (e_unit ()) (e_unit ()) in
|
||||
@ -464,10 +453,47 @@ let guess_the_hash_mligo () : unit result =
|
||||
|
||||
let guess_string_mligo () : unit result =
|
||||
let%bind program = mtype_file "./contracts/guess_string.mligo" in
|
||||
let make_input = fun n-> e_pair (e_int n) (e_int 42) in
|
||||
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
|
||||
let make_input = fun n -> e_pair (e_int n) (e_int 42) in
|
||||
let make_expected = fun n -> e_pair (e_typed_list [] t_operation) (e_int (42 + n))
|
||||
in expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let basic_mligo () : unit result =
|
||||
let%bind typed = mtype_file ~debug_simplify:true "./contracts/basic.mligo" in
|
||||
let%bind result = evaluate_typed "foo" typed in
|
||||
Ligo.AST_Typed.assert_value_eq
|
||||
(Ligo.AST_Typed.Combinators.e_a_empty_int (42 + 127), result)
|
||||
|
||||
let counter_mligo () : unit result =
|
||||
let%bind program = mtype_file "./contracts/counter.mligo" in
|
||||
let make_input n = e_pair (e_int n) (e_int 42) in
|
||||
let make_expected n = e_pair (e_typed_list [] t_operation) (e_int (42 + n)) in
|
||||
expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let let_in_mligo () : unit result =
|
||||
let%bind program = mtype_file "./contracts/letin.mligo" in
|
||||
let make_input n = e_pair (e_int n) (e_pair (e_int 3) (e_int 5)) in
|
||||
let make_expected n =
|
||||
e_pair (e_typed_list [] t_operation) (e_pair (e_int (7+n)) (e_int (3+5)))
|
||||
in expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let match_variant () : unit result =
|
||||
let%bind program = mtype_file "./contracts/match.mligo" in
|
||||
let make_input n =
|
||||
e_pair (e_constructor "Sub" (e_int n)) (e_int 3) in
|
||||
let make_expected n =
|
||||
e_pair (e_typed_list [] t_operation) (e_int (3-n))
|
||||
in expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let mligo_list () : unit result =
|
||||
let%bind program = mtype_file "./contracts/list.mligo" in
|
||||
let make_input n =
|
||||
e_pair (e_list [e_int n; e_int (2*n)])
|
||||
(e_pair (e_int 3) (e_list [e_int 8])) in
|
||||
let make_expected n =
|
||||
e_pair (e_typed_list [] t_operation)
|
||||
(e_pair (e_int (n+3)) (e_list [e_int (2*n)]))
|
||||
in expect_eq_n program "main" make_input make_expected
|
||||
|
||||
let main = test_suite "Integration (End to End)" [
|
||||
test "type alias" type_alias ;
|
||||
test "function" function_ ;
|
||||
@ -502,8 +528,11 @@ let main = test_suite "Integration (End to End)" [
|
||||
test "closure" closure ;
|
||||
test "shared function" shared_function ;
|
||||
test "higher order" higher_order ;
|
||||
test "basic mligo" basic_mligo ;
|
||||
test "counter contract mligo" counter_mligo ;
|
||||
test "basic (mligo)" basic_mligo ;
|
||||
test "counter contract (mligo)" counter_mligo ;
|
||||
test "let-in (mligo)" let_in_mligo ;
|
||||
test "match variant (mligo)" match_variant ;
|
||||
(* test "list matching (mligo)" mligo_list ; *)
|
||||
(* test "guess the hash mligo" guess_the_hash_mligo ; *)
|
||||
(* test "failwith mligo" failwith_mligo ; *)
|
||||
(* test "guess string mligo" guess_string_mligo ; *)
|
||||
|
Loading…
Reference in New Issue
Block a user