2017-04-06 00:40:02 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2017-04-06 00:40:02 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
module Helpers = Proto_alpha_helpers
|
|
|
|
module Assert = Helpers.Assert
|
|
|
|
|
|
|
|
let run blkid ({ b1 ; b2 ; b3 ; _ } : Helpers.Account.bootstrap_accounts) =
|
|
|
|
|
2017-11-20 06:37:06 +04:00
|
|
|
Helpers.Baking.bake blkid b1 [] >>=? fun blkh ->
|
2017-04-06 00:40:02 +04:00
|
|
|
let foo = Helpers.Account.create "foo" in
|
|
|
|
let bar = Helpers.Account.create "bar" in
|
|
|
|
|
2017-11-29 21:06:17 +04:00
|
|
|
let tez v =
|
|
|
|
match Tez.( *? ) Tez.one v with
|
|
|
|
| Error _ -> Pervasives.failwith "cents"
|
|
|
|
| Ok r -> r in
|
|
|
|
|
2017-04-06 00:40:02 +04:00
|
|
|
(* Send from a sender with no balance (never seen). *)
|
|
|
|
(* TODO: Is it OK to get Storage_error and not something more specific? *)
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account:foo
|
|
|
|
~destination:b1.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~amount:(tez 1000L) () >>= fun result ->
|
2017-04-06 00:40:02 +04:00
|
|
|
Assert.unknown_contract ~msg:__LOC__ result ;
|
|
|
|
|
|
|
|
(* Send 1000 tz to "foo". *)
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account:b1
|
|
|
|
~destination:foo.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~fee:Tez.zero
|
|
|
|
~amount:(tez 1000L) () >>=? fun (_oph, contracts) ->
|
|
|
|
Assert.balance_equal ~msg:__LOC__ foo 1000_000_000L >>=? fun () ->
|
2017-04-06 00:40:02 +04:00
|
|
|
|
|
|
|
(* Check that a basic transfer originates no contracts. *)
|
|
|
|
Assert.equal_int ~msg:__LOC__ 0 (List.length contracts) ;
|
|
|
|
|
|
|
|
(* Check sender/receiver balance post transaction *)
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account:foo
|
|
|
|
~destination:bar.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~fee:Tez.zero
|
|
|
|
~amount:(tez 50L) () >>=? fun _contracts ->
|
|
|
|
Assert.balance_equal ~msg:__LOC__ foo 950_000_000L >>=? fun () ->
|
|
|
|
Assert.balance_equal ~msg:__LOC__ bar 50_000_000L >>=? fun () ->
|
2017-04-06 00:40:02 +04:00
|
|
|
|
|
|
|
(* Check balance too low. *)
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account:bar
|
|
|
|
~destination:foo.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~amount:(tez 1000L) () >>= fun result ->
|
2017-04-06 00:40:02 +04:00
|
|
|
Assert.balance_too_low ~msg:__LOC__ result ;
|
|
|
|
|
|
|
|
(* Check spendability of a spendable contract *)
|
|
|
|
Helpers.Account.originate
|
|
|
|
~src:foo
|
|
|
|
~manager_pkh:foo.pkh
|
2017-11-29 21:06:17 +04:00
|
|
|
~balance:(tez 50L) () >>=? fun (_oph, spendable) ->
|
2017-04-06 00:40:02 +04:00
|
|
|
Format.printf "Created contract %a@." Contract.pp spendable ;
|
|
|
|
let account = { foo with contract = spendable } in
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account
|
|
|
|
~destination:foo.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~amount:(tez 10L) () >>=? fun _contracts ->
|
2017-04-06 00:40:02 +04:00
|
|
|
|
|
|
|
(* Try spending a default account with unmatching pk/sk pairs. *)
|
|
|
|
let account = { b1 with sk = b2.sk } in
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account
|
|
|
|
~destination:b2.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~amount:(tez 10L) () >>= fun result ->
|
2017-04-06 00:40:02 +04:00
|
|
|
Assert.generic_economic_error ~msg:__LOC__ result ;
|
|
|
|
|
|
|
|
(* Try spending a default account with keys not matching the
|
|
|
|
contract pkh. *)
|
|
|
|
let account = { b1 with contract = b2.contract } in
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account
|
|
|
|
~destination:b3.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~amount:(tez 10L) () >>= fun result ->
|
2017-04-06 00:40:02 +04:00
|
|
|
Assert.inconsistent_pkh ~msg:__LOC__ result ;
|
|
|
|
|
|
|
|
(* Try spending an originated contract without the manager's key. *)
|
|
|
|
let account = { b1 with contract = spendable } in
|
|
|
|
Helpers.Account.transfer
|
|
|
|
~account
|
|
|
|
~destination:b2.contract
|
2017-11-29 21:06:17 +04:00
|
|
|
~amount:(tez 10L) () >>= fun result ->
|
2017-11-09 14:50:42 +04:00
|
|
|
Assert.inconsistent_public_key ~msg:__LOC__ result ;
|
2017-04-06 00:40:02 +04:00
|
|
|
|
|
|
|
return blkh
|
|
|
|
|
|
|
|
let main () =
|
2017-10-28 22:32:39 +04:00
|
|
|
Helpers.init ~rpc_port:18300 () >>=? fun (_node_pid, hash) ->
|
2017-04-06 00:40:02 +04:00
|
|
|
run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh ->
|
|
|
|
return ()
|
|
|
|
|
|
|
|
let tests = [
|
|
|
|
"main", (fun _ -> main ()) ;
|
|
|
|
]
|
|
|
|
|
|
|
|
let () =
|
|
|
|
Test.run "transactions." tests
|