ligo/src/proto_alpha/lib_protocol/test/test_origination.ml

89 lines
2.9 KiB
OCaml
Raw Normal View History

2018-01-16 01:09:25 +04:00
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2016. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
2018-02-05 23:51:58 +04:00
open Proto_alpha
open Error_monad
2018-01-16 01:09:25 +04:00
let name = "Isolate Origination"
module Logger = Logging.Make(struct let name = name end)
exception No_error
open Isolate_helpers
2018-02-05 23:51:58 +04:00
open Helpers_block
2018-01-16 01:09:25 +04:00
let (>>?=) = Assert.(>>?=)
let (>>=??) = Assert.(>>=??)
2018-02-05 23:51:58 +04:00
let originate root ?(tc=root.tezos_context) ?baker ?spendable ?fee ?delegatable src amount =
let delegatable = Option.unopt ~default:true delegatable in
let spendable = Option.unopt ~default:true spendable in
let fee = Option.unopt ~default:10 fee in
Apply.origination_pred
?baker
~tc
~pred: root
(src, amount, spendable, delegatable, fee)
let test_simple_origination () =
Init.main () >>=? fun root ->
2018-01-16 01:09:25 +04:00
let src = List.hd Account.bootstrap_accounts in
(* 0 balance should fail *)
2018-02-05 23:51:58 +04:00
originate root src 0 >>= Assert.wrap >>= fun result ->
2018-01-16 01:09:25 +04:00
Assert.initial_amount_too_low ~msg: __LOC__ result ;
(* .5 Balance should fail *)
2018-02-05 23:51:58 +04:00
originate root src 50 >>= Assert.wrap >>= fun result ->
2018-01-16 01:09:25 +04:00
Assert.initial_amount_too_low ~msg: __LOC__ result ;
(* 2. Balance should work *)
2018-02-05 23:51:58 +04:00
originate root src 200 >>= Assert.ok >>= fun _ ->
2018-01-16 01:09:25 +04:00
return ()
2018-02-05 23:51:58 +04:00
let delegate root ?(tc=root.tezos_context) ?baker ?fee src delegate =
let fee = Option.unopt ~default:10 fee in
Apply.delegation_pred
?baker
~tc
~pred: root
(src, delegate, fee)
let test_delegation () =
2018-01-16 01:09:25 +04:00
2018-02-05 23:51:58 +04:00
Init.main () >>=? fun root ->
2018-01-16 01:09:25 +04:00
let account_a = List.nth Account.bootstrap_accounts 0 in
let account_b = List.nth Account.bootstrap_accounts 1 in
(* Delegatable should change delegate *)
2018-02-05 23:51:58 +04:00
originate root ~delegatable: true account_a 200
2018-01-16 01:09:25 +04:00
>>=? fun ((contracts, _errs), tc) ->
let contract = List.hd contracts in
let account_ac = {account_a with contract} in
2018-02-05 23:51:58 +04:00
delegate root ~tc account_ac account_b.hpub >>= Assert.ok ~msg: __LOC__ >>= fun _ ->
2018-01-16 01:09:25 +04:00
(* Not-Delegatable should not change delegate *)
2018-02-05 23:51:58 +04:00
originate root ~delegatable: false account_a 200
2018-01-16 01:09:25 +04:00
>>=? fun ((contracts, _errs), tc) ->
let contract = List.hd contracts in
let account_a = {account_a with contract} in
2018-02-05 23:51:58 +04:00
delegate root ~tc account_a account_b.hpub >>= Assert.wrap >>= fun res ->
2018-01-16 01:09:25 +04:00
Assert.non_delegatable ~msg: __LOC__ res ;
return ()
2018-02-05 23:51:58 +04:00
let tests =
List.map
(fun (n, f) -> (n, (fun () -> f () >>= Assert.wrap)))
[ "simple", test_simple_origination ;
"delegate", test_delegation ;
2018-02-05 23:51:58 +04:00
]
2018-01-16 01:09:25 +04:00