Merge remote-tracking branch 'origin/dev' into rinderknecht-dev
This commit is contained in:
commit
7ae8d9340b
@ -1,6 +1,9 @@
|
|||||||
ARG target
|
ARG target
|
||||||
FROM ocaml/opam2:${target}
|
FROM ocaml/opam2:${target}
|
||||||
|
|
||||||
|
ARG ci_job_id
|
||||||
|
ENV CI_JOB_ID=$ci_job_id
|
||||||
|
|
||||||
RUN opam switch 4.07 && eval $(opam env)
|
RUN opam switch 4.07 && eval $(opam env)
|
||||||
|
|
||||||
USER root
|
USER root
|
||||||
@ -26,7 +29,7 @@ RUN opam update
|
|||||||
|
|
||||||
# Install ligo
|
# Install ligo
|
||||||
RUN sh scripts/install_vendors_deps.sh
|
RUN sh scripts/install_vendors_deps.sh
|
||||||
RUN opam install -y ./src
|
RUN opam install -y .
|
||||||
|
|
||||||
# Use the ligo binary as a default command
|
# Use the ligo binary as a default command
|
||||||
ENTRYPOINT [ "/home/opam/.opam/4.07/bin/ligo" ]
|
ENTRYPOINT [ "/home/opam/.opam/4.07/bin/ligo" ]
|
||||||
|
@ -8,4 +8,4 @@ dockerfile="./docker/distribution/generic/build.Dockerfile"
|
|||||||
echo "Building LIGO for $target"
|
echo "Building LIGO for $target"
|
||||||
echo "Using Dockerfile: $dockerfile"
|
echo "Using Dockerfile: $dockerfile"
|
||||||
echo "Tagging as: $tag_build\n"
|
echo "Tagging as: $tag_build\n"
|
||||||
docker build --build-arg target="$target" -t "$tag_build" -f "$dockerfile" .
|
docker build --build-arg ci_job_id="${CI_JOB_ID}" --build-arg target="$target" -t "$tag_build" -f "$dockerfile" .
|
||||||
|
@ -14,7 +14,8 @@ then
|
|||||||
m4 \
|
m4 \
|
||||||
libcap \
|
libcap \
|
||||||
bubblewrap \
|
bubblewrap \
|
||||||
rsync
|
rsync \
|
||||||
|
git
|
||||||
|
|
||||||
else
|
else
|
||||||
apt-get update -qq
|
apt-get update -qq
|
||||||
@ -27,5 +28,6 @@ else
|
|||||||
m4 \
|
m4 \
|
||||||
libcap-dev \
|
libcap-dev \
|
||||||
bubblewrap \
|
bubblewrap \
|
||||||
rsync
|
rsync \
|
||||||
|
git
|
||||||
fi
|
fi
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Install local dependencies
|
# Install local dependencies
|
||||||
opam install -y --deps-only --with-test $(find src vendors -name \*.opam)
|
opam install -y --deps-only --with-test ./ligo.opam $(find vendors -name \*.opam)
|
||||||
opam install -y $(find vendors -name \*.opam)
|
opam install -y $(find vendors -name \*.opam)
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
printf '' | opam switch create . ocaml-base-compiler.4.07.1 # toto ocaml-base-compiler.4.06.1
|
printf '' | opam switch create . ocaml-base-compiler.4.07.1 --no-install
|
||||||
eval $(opam config env)
|
eval $(opam config env)
|
||||||
|
@ -899,3 +899,16 @@ let%expect_test _ =
|
|||||||
PAIR ;
|
PAIR ;
|
||||||
DIP { DROP 5 } } ;
|
DIP { DROP 5 } } ;
|
||||||
DIP { DROP } } } |}]
|
DIP { DROP } } } |}]
|
||||||
|
|
||||||
|
let%expect_test _ =
|
||||||
|
run_ligo_good [ "compile-contract" ; contract "implicit.mligo" ; "main" ] ;
|
||||||
|
[%expect {|
|
||||||
|
{ parameter key_hash ;
|
||||||
|
storage unit ;
|
||||||
|
code { DUP ;
|
||||||
|
CAR ;
|
||||||
|
IMPLICIT_ACCOUNT ;
|
||||||
|
UNIT ;
|
||||||
|
NIL operation ;
|
||||||
|
PAIR ;
|
||||||
|
DIP { DROP 2 } } } |}]
|
||||||
|
@ -920,8 +920,9 @@ module Compiler = struct
|
|||||||
| C_UNIT -> ok @@ simple_constant @@ prim I_UNIT
|
| C_UNIT -> ok @@ simple_constant @@ prim I_UNIT
|
||||||
| C_BALANCE -> ok @@ simple_constant @@ prim I_BALANCE
|
| C_BALANCE -> ok @@ simple_constant @@ prim I_BALANCE
|
||||||
| C_AMOUNT -> ok @@ simple_constant @@ prim I_AMOUNT
|
| C_AMOUNT -> ok @@ simple_constant @@ prim I_AMOUNT
|
||||||
| C_ADDRESS -> ok @@ simple_constant @@ prim I_ADDRESS
|
| C_ADDRESS -> ok @@ simple_unary @@ prim I_ADDRESS
|
||||||
| C_SELF_ADDRESS -> ok @@ simple_constant @@ seq [prim I_SELF; prim I_ADDRESS]
|
| C_SELF_ADDRESS -> ok @@ simple_constant @@ seq [prim I_SELF; prim I_ADDRESS]
|
||||||
|
| C_IMPLICIT_ACCOUNT -> ok @@ simple_unary @@ prim I_IMPLICIT_ACCOUNT
|
||||||
| C_NOW -> ok @@ simple_constant @@ prim I_NOW
|
| C_NOW -> ok @@ simple_constant @@ prim I_NOW
|
||||||
| C_CALL -> ok @@ simple_ternary @@ prim I_TRANSFER_TOKENS
|
| C_CALL -> ok @@ simple_ternary @@ prim I_TRANSFER_TOKENS
|
||||||
| C_SOURCE -> ok @@ simple_constant @@ prim I_SOURCE
|
| C_SOURCE -> ok @@ simple_constant @@ prim I_SOURCE
|
||||||
|
@ -1 +1,5 @@
|
|||||||
function main (const c: contract(unit)) : address is address(c)
|
// function main (const c: contract(unit)) : address is address(c)
|
||||||
|
|
||||||
|
function main (const p : key_hash) : address is block {
|
||||||
|
const c : contract(unit) = implicit_account(p) ;
|
||||||
|
} with address(c)
|
@ -1 +1,3 @@
|
|||||||
let main (c: unit contract) : address = Current.address c
|
let main (p : key_hash) =
|
||||||
|
let c : unit contract = Current.implicit_account p in
|
||||||
|
Current.address c
|
@ -1 +1,4 @@
|
|||||||
let main = (c: contract(unit)): address => Current.address(c);
|
let main = (p : key_hash) : address => {
|
||||||
|
let c : contract(unit) = Current.implicit_account(p) ;
|
||||||
|
Current.address(c) ;
|
||||||
|
};
|
||||||
|
3
src/test/contracts/implicit.mligo
Normal file
3
src/test/contracts/implicit.mligo
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
let main (p : key_hash) (s : unit) =
|
||||||
|
let c : unit contract = Current.implicit_account p in
|
||||||
|
(([] : operation list), unit)
|
35
src/test/contracts/replaceable_id.ligo
Normal file
35
src/test/contracts/replaceable_id.ligo
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// storage type
|
||||||
|
type storage_t is address;
|
||||||
|
|
||||||
|
// entry points parameter types
|
||||||
|
type change_addr_pt is address
|
||||||
|
|
||||||
|
type message_t is list (operation) ;
|
||||||
|
type pass_message_pt is (unit -> message_t)
|
||||||
|
|
||||||
|
type contract_return_t is (list(operation) * storage_t)
|
||||||
|
|
||||||
|
type entry_point_t is
|
||||||
|
| Change_address of change_addr_pt
|
||||||
|
| Pass_message of pass_message_pt
|
||||||
|
|
||||||
|
function change_address (const param : change_addr_pt;
|
||||||
|
const s : storage_t) : contract_return_t is
|
||||||
|
begin
|
||||||
|
if sender =/= s then failwith("Unauthorized sender")
|
||||||
|
else skip
|
||||||
|
end with ((nil : list(operation)), param)
|
||||||
|
|
||||||
|
function pass_message ( const param: pass_message_pt;
|
||||||
|
const s : storage_t ) : contract_return_t is
|
||||||
|
begin
|
||||||
|
if sender =/= s then failwith("Unauthorized sender") else skip ;
|
||||||
|
var message : pass_message_pt := param ;
|
||||||
|
end with (param(unit),s)
|
||||||
|
|
||||||
|
function main(const param : entry_point_t; const s : storage_t) : contract_return_t is
|
||||||
|
block {skip} with
|
||||||
|
case param of
|
||||||
|
| Change_address (p) -> change_address(p,s)
|
||||||
|
| Pass_message (p) -> pass_message(p,s)
|
||||||
|
end
|
@ -1624,17 +1624,26 @@ let balance_constant_religo () : unit result =
|
|||||||
expect_eq program "main" input expected
|
expect_eq program "main" input expected
|
||||||
|
|
||||||
|
|
||||||
|
let addr_test program =
|
||||||
|
let open Proto_alpha_utils.Memory_proto_alpha in
|
||||||
|
let addr = Protocol.Alpha_context.Contract.to_b58check @@
|
||||||
|
(List.nth dummy_environment.identities 0).implicit_contract in
|
||||||
|
let open Tezos_crypto in
|
||||||
|
let key_hash = Signature.Public_key_hash.to_b58check @@
|
||||||
|
(List.nth dummy_environment.identities 0).public_key_hash in
|
||||||
|
expect_eq program "main" (e_key_hash key_hash) (e_address addr)
|
||||||
|
|
||||||
let address () : unit result =
|
let address () : unit result =
|
||||||
let%bind _ = type_file "./contracts/address.ligo" in
|
let%bind program = type_file "./contracts/address.ligo" in
|
||||||
ok ()
|
addr_test program
|
||||||
|
|
||||||
let address_mligo () : unit result =
|
let address_mligo () : unit result =
|
||||||
let%bind _ = mtype_file "./contracts/address.mligo" in
|
let%bind program = mtype_file "./contracts/address.mligo" in
|
||||||
ok ()
|
addr_test program
|
||||||
|
|
||||||
let address_religo () : unit result =
|
let address_religo () : unit result =
|
||||||
let%bind _ = retype_file "./contracts/address.religo" in
|
let%bind program = retype_file "./contracts/address.religo" in
|
||||||
ok ()
|
addr_test program
|
||||||
|
|
||||||
|
|
||||||
let self_address () : unit result =
|
let self_address () : unit result =
|
||||||
|
90
src/test/replaceable_id_tests.ml
Normal file
90
src/test/replaceable_id_tests.ml
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
open Trace
|
||||||
|
open Test_helpers
|
||||||
|
|
||||||
|
let type_file f =
|
||||||
|
let%bind simplified = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in
|
||||||
|
let%bind typed,state = Ligo.Compile.Of_simplified.compile simplified in
|
||||||
|
ok @@ (typed,state)
|
||||||
|
|
||||||
|
let get_program =
|
||||||
|
let s = ref None in
|
||||||
|
fun () -> match !s with
|
||||||
|
| Some s -> ok s
|
||||||
|
| None -> (
|
||||||
|
let%bind program = type_file "./contracts/replaceable_id.ligo" in
|
||||||
|
s := Some program ;
|
||||||
|
ok program
|
||||||
|
)
|
||||||
|
|
||||||
|
let compile_main () =
|
||||||
|
let%bind simplified = Ligo.Compile.Of_source.compile "./contracts/replaceable_id.ligo" (Syntax_name "pascaligo") in
|
||||||
|
let%bind typed_prg,_ = Ligo.Compile.Of_simplified.compile simplified in
|
||||||
|
let%bind mini_c_prg = Ligo.Compile.Of_typed.compile typed_prg in
|
||||||
|
let%bind michelson_prg = Ligo.Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg "main" in
|
||||||
|
let%bind (_contract: Tezos_utils.Michelson.michelson) =
|
||||||
|
(* fails if the given entry point is not a valid contract *)
|
||||||
|
Ligo.Compile.Of_mini_c.build_contract michelson_prg in
|
||||||
|
ok ()
|
||||||
|
open Ast_simplified
|
||||||
|
|
||||||
|
let empty_op_list =
|
||||||
|
(e_typed_list [] t_operation)
|
||||||
|
let empty_message = e_lambda (Var.of_name "arguments")
|
||||||
|
(Some t_unit) (Some (t_list t_operation))
|
||||||
|
empty_op_list
|
||||||
|
|
||||||
|
let storage id = e_address @@ addr id
|
||||||
|
let entry_change_addr id = e_constructor "Change_address"
|
||||||
|
@@ e_address @@ addr @@ id
|
||||||
|
let entry_pass_message = e_constructor "Pass_message"
|
||||||
|
@@ empty_message
|
||||||
|
|
||||||
|
let change_addr_success () =
|
||||||
|
let%bind program,_ = get_program () in
|
||||||
|
let init_storage = storage 1 in
|
||||||
|
let param = entry_change_addr 2 in
|
||||||
|
let options =
|
||||||
|
let source = contract 1 in
|
||||||
|
Proto_alpha_utils.Memory_proto_alpha.make_options ~source () in
|
||||||
|
expect_eq ~options program "main"
|
||||||
|
(e_pair param init_storage) (e_pair empty_op_list (storage 2))
|
||||||
|
|
||||||
|
let change_addr_fail () =
|
||||||
|
let%bind program,_ = get_program () in
|
||||||
|
let init_storage = storage 1 in
|
||||||
|
let param = entry_change_addr 2 in
|
||||||
|
let options =
|
||||||
|
let source = contract 3 in
|
||||||
|
Proto_alpha_utils.Memory_proto_alpha.make_options ~source () in
|
||||||
|
let exp_failwith = "Unauthorized sender" in
|
||||||
|
expect_string_failwith ~options program "main"
|
||||||
|
(e_pair param init_storage) exp_failwith
|
||||||
|
|
||||||
|
let pass_message_success () =
|
||||||
|
let%bind program,_ = get_program () in
|
||||||
|
let init_storage = storage 1 in
|
||||||
|
let param = entry_pass_message in
|
||||||
|
let options =
|
||||||
|
let source = contract 1 in
|
||||||
|
Proto_alpha_utils.Memory_proto_alpha.make_options ~source () in
|
||||||
|
expect_eq ~options program "main"
|
||||||
|
(e_pair param init_storage) (e_pair empty_op_list init_storage)
|
||||||
|
|
||||||
|
let pass_message_fail () =
|
||||||
|
let%bind program,_ = get_program () in
|
||||||
|
let init_storage = storage 1 in
|
||||||
|
let param = entry_pass_message in
|
||||||
|
let options =
|
||||||
|
let source = contract 2 in
|
||||||
|
Proto_alpha_utils.Memory_proto_alpha.make_options ~source () in
|
||||||
|
let exp_failwith = "Unauthorized sender" in
|
||||||
|
expect_string_failwith ~options program "main"
|
||||||
|
(e_pair param init_storage) exp_failwith
|
||||||
|
|
||||||
|
let main = test_suite "Replaceable ID" [
|
||||||
|
test "compile" compile_main ;
|
||||||
|
test "change_addr_success" change_addr_success ;
|
||||||
|
test "change_addr_fail" change_addr_fail ;
|
||||||
|
test "pass_message_success" pass_message_success ;
|
||||||
|
test "pass_message_fail" pass_message_fail ;
|
||||||
|
]
|
@ -12,5 +12,6 @@ let () =
|
|||||||
Vote_tests.main ;
|
Vote_tests.main ;
|
||||||
Multisig_tests.main ;
|
Multisig_tests.main ;
|
||||||
Multisig_v2_tests.main ;
|
Multisig_v2_tests.main ;
|
||||||
|
Replaceable_id_tests.main ;
|
||||||
] ;
|
] ;
|
||||||
()
|
()
|
||||||
|
Loading…
Reference in New Issue
Block a user