Test/Alpha: allows distinct port for distinct test.

This commit is contained in:
Grégoire Henry 2017-10-28 20:32:39 +02:00 committed by Benjamin Canou
parent 47d77acfd7
commit c5d15d3640
6 changed files with 44 additions and 38 deletions

View File

@ -13,8 +13,8 @@ let (//) = Filename.concat
let () = Random.self_init () let () = Random.self_init ()
let rpc_config : Client_rpcs.config = { let rpc_config = ref {
host = "localhost" ; Client_rpcs.host = "localhost" ;
port = 8192 + Random.int 8192 ; port = 8192 + Random.int 8192 ;
tls = false ; tls = false ;
logger = Client_rpcs.null_logger ; logger = Client_rpcs.null_logger ;
@ -28,11 +28,16 @@ let dictator_sk =
let activate_alpha () = let activate_alpha () =
let fitness = Fitness_repr.from_int64 0L in let fitness = Fitness_repr.from_int64 0L in
Client_embedded_genesis.Client_proto_main.mine Client_embedded_genesis.Client_proto_main.mine
rpc_config (`Head 0) !rpc_config (`Head 0)
(Activate Client_proto_main.protocol) (Activate Client_proto_main.protocol)
fitness dictator_sk fitness dictator_sk
let init ?(sandbox = "sandbox.json") () = let init ?(sandbox = "sandbox.json") ?rpc_port () =
begin
match rpc_port with
| None -> ()
| Some port -> rpc_config := { !rpc_config with port }
end ;
(* Handles relative path on OSX *) (* Handles relative path on OSX *)
let executable_path = let executable_path =
if Filename.is_relative Sys.argv.(0) if Filename.is_relative Sys.argv.(0)
@ -42,14 +47,14 @@ let init ?(sandbox = "sandbox.json") () =
Unix.chdir ".." ; Unix.chdir ".." ;
let pid = let pid =
Node_helpers.fork_node Node_helpers.fork_node
~port:rpc_config.port ~port:!rpc_config.port
~sandbox:(Filename.dirname executable_path // sandbox) ~sandbox:(Filename.dirname executable_path // sandbox)
() in () in
activate_alpha () >>=? fun hash -> activate_alpha () >>=? fun hash ->
return (pid, hash) return (pid, hash)
let level block = let level block =
Client_proto_rpcs.Context.level rpc_config block Client_proto_rpcs.Context.level !rpc_config block
module Account = struct module Account = struct
@ -178,7 +183,7 @@ module Account = struct
~amount () = ~amount () =
let amount = match Tez.of_cents amount with None -> Tez.zero | Some a -> a in let amount = match Tez.of_cents amount with None -> Tez.zero | Some a -> a in
let fee = match Tez.of_cents fee with None -> Tez.zero | Some a -> a in let fee = match Tez.of_cents fee with None -> Tez.zero | Some a -> a in
Client_proto_context.transfer rpc_config Client_proto_context.transfer !rpc_config
block block
~source:account.contract ~source:account.contract
~src_pk:account.pk ~src_pk:account.pk
@ -205,7 +210,7 @@ module Account = struct
let delegatable, delegate = match delegate with let delegatable, delegate = match delegate with
| None -> false, None | None -> false, None
| Some delegate -> true, Some delegate in | Some delegate -> true, Some delegate in
Client_proto_context.originate_account rpc_config block Client_proto_context.originate_account !rpc_config block
~source:src.contract ~source:src.contract
~src_pk:src.pk ~src_pk:src.pk
~src_sk:src.sk ~src_sk:src.sk
@ -225,19 +230,19 @@ module Account = struct
let fee = match Tez.of_cents fee with let fee = match Tez.of_cents fee with
| None -> Tez.zero | None -> Tez.zero
| Some amount -> amount in | Some amount -> amount in
Client_proto_context.delegate_contract rpc_config block Client_proto_context.delegate_contract !rpc_config block
~source:contract ~source:contract
~manager_sk ~manager_sk
~fee ~fee
delegate_opt delegate_opt
let balance ?(block = `Prevalidation) (account : t) = let balance ?(block = `Prevalidation) (account : t) =
Client_proto_rpcs.Context.Contract.balance rpc_config Client_proto_rpcs.Context.Contract.balance !rpc_config
block account.contract block account.contract
(* TODO: gather contract related functions in a Contract module? *) (* TODO: gather contract related functions in a Contract module? *)
let delegate ?(block = `Prevalidation) (contract : Contract.t) = let delegate ?(block = `Prevalidation) (contract : Contract.t) =
Client_proto_rpcs.Context.Contract.delegate rpc_config Client_proto_rpcs.Context.Contract.delegate !rpc_config
block contract block contract
end end
@ -247,12 +252,12 @@ module Protocol = struct
open Account open Account
let voting_period_kind ?(block = `Prevalidation) () = let voting_period_kind ?(block = `Prevalidation) () =
Client_proto_rpcs.Context.voting_period_kind rpc_config block Client_proto_rpcs.Context.voting_period_kind !rpc_config block
let proposals ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) proposals = let proposals ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) proposals =
Client_node_rpcs.Blocks.info rpc_config block >>=? fun block_info -> Client_node_rpcs.Blocks.info !rpc_config block >>=? fun block_info ->
Client_proto_rpcs.Context.next_level rpc_config block >>=? fun next_level -> Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun next_level ->
Client_proto_rpcs.Helpers.Forge.Delegate.proposals rpc_config block Client_proto_rpcs.Helpers.Forge.Delegate.proposals !rpc_config block
~net_id:block_info.net_id ~net_id:block_info.net_id
~branch:block_info.hash ~branch:block_info.hash
~source:pk ~source:pk
@ -263,9 +268,9 @@ module Protocol = struct
return (Tezos_data.Operation.of_bytes_exn signed_bytes) return (Tezos_data.Operation.of_bytes_exn signed_bytes)
let ballot ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) ~proposal ballot = let ballot ?(block = `Prevalidation) ~src:({ pk; sk } : Account.t) ~proposal ballot =
Client_node_rpcs.Blocks.info rpc_config block >>=? fun block_info -> Client_node_rpcs.Blocks.info !rpc_config block >>=? fun block_info ->
Client_proto_rpcs.Context.next_level rpc_config block >>=? fun next_level -> Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun next_level ->
Client_proto_rpcs.Helpers.Forge.Delegate.ballot rpc_config block Client_proto_rpcs.Helpers.Forge.Delegate.ballot !rpc_config block
~net_id:block_info.net_id ~net_id:block_info.net_id
~branch:block_info.hash ~branch:block_info.hash
~source:pk ~source:pk
@ -388,7 +393,7 @@ module Assert = struct
end end
let check_protocol ?msg ~block h = let check_protocol ?msg ~block h =
Client_node_rpcs.Blocks.protocol rpc_config block >>=? fun block_proto -> Client_node_rpcs.Blocks.protocol !rpc_config block >>=? fun block_proto ->
return @@ Assert.equal return @@ Assert.equal
?msg:(Assert.format_msg msg) ?msg:(Assert.format_msg msg)
~prn:Protocol_hash.to_b58check ~prn:Protocol_hash.to_b58check
@ -396,7 +401,7 @@ module Assert = struct
block_proto h block_proto h
let check_voting_period_kind ?msg ~block kind = let check_voting_period_kind ?msg ~block kind =
Client_proto_rpcs.Context.voting_period_kind rpc_config block Client_proto_rpcs.Context.voting_period_kind !rpc_config block
>>=? fun current_kind -> >>=? fun current_kind ->
return @@ Assert.equal return @@ Assert.equal
?msg:(Assert.format_msg msg) ?msg:(Assert.format_msg msg)
@ -415,7 +420,7 @@ module Mining = struct
| Ok nonce -> nonce in | Ok nonce -> nonce in
let seed_nonce_hash = Nonce.hash seed_nonce in let seed_nonce_hash = Nonce.hash seed_nonce in
Client_mining_forge.forge_block Client_mining_forge.forge_block
rpc_config !rpc_config
block block
~operations ~operations
~force:true ~force:true
@ -427,7 +432,7 @@ module Mining = struct
() ()
let endorsement_reward block = let endorsement_reward block =
Client_proto_rpcs.Header.priority rpc_config block >>=? fun prio -> Client_proto_rpcs.Header.priority !rpc_config block >>=? fun prio ->
Mining.endorsement_reward ~block_priority:prio >|= Mining.endorsement_reward ~block_priority:prio >|=
Environment.wrap_error >>|? Environment.wrap_error >>|?
Tez.to_cents Tez.to_cents
@ -442,8 +447,8 @@ module Endorse = struct
source source
slot = slot =
let block = Client_rpcs.last_mined_block block in let block = Client_rpcs.last_mined_block block in
Client_node_rpcs.Blocks.info rpc_config block >>=? fun { hash ; net_id } -> Client_node_rpcs.Blocks.info !rpc_config block >>=? fun { hash ; net_id } ->
Client_proto_rpcs.Helpers.Forge.Delegate.endorsement rpc_config Client_proto_rpcs.Helpers.Forge.Delegate.endorsement !rpc_config
block block
~net_id:net_id ~net_id:net_id
~branch:hash ~branch:hash
@ -460,7 +465,7 @@ module Endorse = struct
delegate delegate
level = level =
Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate
rpc_config ~max_priority ~first_level:level ~last_level:level !rpc_config ~max_priority ~first_level:level ~last_level:level
block delegate () >>=? fun possibilities -> block delegate () >>=? fun possibilities ->
let slots = let slots =
List.map (fun (_,slot) -> slot) List.map (fun (_,slot) -> slot)
@ -471,7 +476,7 @@ module Endorse = struct
?slot ?slot
(contract : Account.t) (contract : Account.t)
block = block =
Client_proto_rpcs.Context.next_level rpc_config block >>=? fun { level } -> Client_proto_rpcs.Context.next_level !rpc_config block >>=? fun { level } ->
begin begin
match slot with match slot with
| Some slot -> return slot | Some slot -> return slot
@ -490,7 +495,7 @@ module Endorse = struct
let endorsers_list block = let endorsers_list block =
let get_endorser_list result (account : Account.t) level block = let get_endorser_list result (account : Account.t) level block =
Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate
rpc_config block account.pkh !rpc_config block account.pkh
~max_priority:16 ~max_priority:16
~first_level:level ~first_level:level
~last_level:level () >>|? fun slots -> ~last_level:level () >>|? fun slots ->
@ -498,7 +503,7 @@ module Endorse = struct
in in
let { Account.b1 ; b2 ; b3 ; b4 ; b5 } = Account.bootstrap_accounts in let { Account.b1 ; b2 ; b3 ; b4 ; b5 } = Account.bootstrap_accounts in
let result = Array.make 16 b1 in let result = Array.make 16 b1 in
Client_proto_rpcs.Context.level rpc_config block >>=? fun level -> Client_proto_rpcs.Context.level !rpc_config block >>=? fun level ->
let level = Raw_level.succ @@ level.level in let level = Raw_level.succ @@ level.level in
get_endorser_list result b1 level block >>=? fun () -> get_endorser_list result b1 level block >>=? fun () ->
get_endorser_list result b2 level block >>=? fun () -> get_endorser_list result b2 level block >>=? fun () ->
@ -510,11 +515,11 @@ module Endorse = struct
let endorsement_rights let endorsement_rights
?(max_priority = 1024) ?(max_priority = 1024)
(contract : Account.t) block = (contract : Account.t) block =
Client_proto_rpcs.Context.level rpc_config block >>=? fun level -> Client_proto_rpcs.Context.level !rpc_config block >>=? fun level ->
let delegate = contract.pkh in let delegate = contract.pkh in
let level = level.level in let level = level.level in
Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate Client_proto_rpcs.Helpers.Rights.endorsement_rights_for_delegate
rpc_config !rpc_config
~max_priority ~max_priority
~first_level:level ~first_level:level
~last_level:level ~last_level:level
@ -523,6 +528,6 @@ module Endorse = struct
end end
let display_level block = let display_level block =
Client_proto_rpcs.Context.level rpc_config block >>=? fun lvl -> Client_proto_rpcs.Context.level !rpc_config block >>=? fun lvl ->
Format.eprintf "Level: %a@." Level.pp_full lvl ; Format.eprintf "Level: %a@." Level.pp_full lvl ;
return () return ()

View File

@ -9,7 +9,10 @@
module Ed25519 = Environment.Ed25519 module Ed25519 = Environment.Ed25519
val init : ?sandbox:string -> unit -> (int * Block_hash.t) tzresult Lwt.t val init :
?sandbox:string ->
?rpc_port:int ->
unit -> (int * Block_hash.t) tzresult Lwt.t
(** [init ()] sets up the test environment, and return the PID of (** [init ()] sets up the test environment, and return the PID of
forked Tezos node and the block info of the block from where the forked Tezos node and the block info of the block from where the
tests will begin. *) tests will begin. *)
@ -192,6 +195,4 @@ module Assert : sig
end end
val rpc_config: Client_rpcs.config
val display_level: Client_proto_rpcs.block -> unit tzresult Lwt.t val display_level: Client_proto_rpcs.block -> unit tzresult Lwt.t

View File

@ -237,7 +237,7 @@ let run genesis =
return () return ()
let main () = let main () =
Helpers.init () >>=? fun (_node_pid, genesis) -> Helpers.init ~rpc_port:18100 () >>=? fun (_node_pid, genesis) ->
run (`Hash genesis) run (`Hash genesis)

View File

@ -79,7 +79,7 @@ let run blkid ({ b1 ; b2 ; _ } : Helpers.Account.bootstrap_accounts) =
return blkh return blkh
let main () = let main () =
Helpers.init () >>=? fun (_node_pid, hash) -> Helpers.init ~rpc_port:18200 () >>=? fun (_node_pid, hash) ->
run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh -> run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh ->
return () return ()

View File

@ -105,7 +105,7 @@ let run blkid ({ b1 ; b2 ; b3 ; _ } : Helpers.Account.bootstrap_accounts) =
return blkh return blkh
let main () = let main () =
Helpers.init () >>=? fun (_node_pid, hash) -> Helpers.init ~rpc_port:18300 () >>=? fun (_node_pid, hash) ->
run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh -> run (`Hash hash) Helpers.Account.bootstrap_accounts >>=? fun _blkh ->
return () return ()

View File

@ -84,7 +84,7 @@ let run_change_to_demo_proto block
return (`Hash head) return (`Hash head)
let change_to_demo_proto () = let change_to_demo_proto () =
init ~sandbox:"sandbox-vote.json" () >>=? fun (_node_pid, hash) -> init ~sandbox:"sandbox-vote.json" ~rpc_port:18400 () >>=? fun (_node_pid, hash) ->
run_change_to_demo_proto (`Hash hash) Account.bootstrap_accounts >>=? fun _blkh -> run_change_to_demo_proto (`Hash hash) Account.bootstrap_accounts >>=? fun _blkh ->
return () return ()