Test: inject operation and block atomically
This commit is contained in:
parent
f39eca214a
commit
f96ecbf667
@ -50,6 +50,7 @@ module Operation : sig
|
|||||||
|
|
||||||
include HASHABLE_DATA with type t := t
|
include HASHABLE_DATA with type t := t
|
||||||
and type hash := Operation_hash.t
|
and type hash := Operation_hash.t
|
||||||
|
val of_bytes_exn: MBytes.t -> t
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -74,6 +75,7 @@ module Block_header : sig
|
|||||||
|
|
||||||
include HASHABLE_DATA with type t := t
|
include HASHABLE_DATA with type t := t
|
||||||
and type hash := Block_hash.t
|
and type hash := Block_hash.t
|
||||||
|
val of_bytes_exn: MBytes.t -> t
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -91,5 +93,6 @@ module Protocol : sig
|
|||||||
|
|
||||||
include HASHABLE_DATA with type t := t
|
include HASHABLE_DATA with type t := t
|
||||||
and type hash := Protocol_hash.t
|
and type hash := Protocol_hash.t
|
||||||
|
val of_bytes_exn: MBytes.t -> t
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -247,7 +247,7 @@ module Protocol = struct
|
|||||||
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 inject_proposals ?async ?force ?(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
|
||||||
@ -257,11 +257,9 @@ module Protocol = struct
|
|||||||
~proposals
|
~proposals
|
||||||
() >>=? fun bytes ->
|
() >>=? fun bytes ->
|
||||||
let signed_bytes = Environment.Ed25519.Signature.append sk bytes in
|
let signed_bytes = Environment.Ed25519.Signature.append sk bytes in
|
||||||
Client_node_rpcs.inject_operation
|
return (Tezos_data.Operation.of_bytes_exn signed_bytes)
|
||||||
rpc_config ?async ?force signed_bytes >>=? fun oph ->
|
|
||||||
return oph
|
|
||||||
|
|
||||||
let inject_ballot ?async ?force ?(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
|
||||||
@ -272,9 +270,7 @@ module Protocol = struct
|
|||||||
~ballot
|
~ballot
|
||||||
() >>=? fun bytes ->
|
() >>=? fun bytes ->
|
||||||
let signed_bytes = Environment.Ed25519.Signature.append sk bytes in
|
let signed_bytes = Environment.Ed25519.Signature.append sk bytes in
|
||||||
Client_node_rpcs.inject_operation
|
return (Tezos_data.Operation.of_bytes_exn signed_bytes)
|
||||||
rpc_config ?async ?force signed_bytes >>=? fun oph ->
|
|
||||||
return oph
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -301,16 +297,16 @@ module Assert = struct
|
|||||||
let prn = Tez.to_string in
|
let prn = Tez.to_string in
|
||||||
Assert.equal ?msg ~prn ~eq tz1 tz2
|
Assert.equal ?msg ~prn ~eq tz1 tz2
|
||||||
|
|
||||||
let balance_equal ~msg account expected_balance =
|
let balance_equal ?block ~msg account expected_balance =
|
||||||
Account.balance account >>=? fun actual_balance ->
|
Account.balance ?block account >>=? fun actual_balance ->
|
||||||
match Tez.of_cents expected_balance with
|
match Tez.of_cents expected_balance with
|
||||||
| None ->
|
| None ->
|
||||||
failwith "invalid tez constant"
|
failwith "invalid tez constant"
|
||||||
| Some expected_balance ->
|
| Some expected_balance ->
|
||||||
return (equal_tez ~msg actual_balance expected_balance)
|
return (equal_tez ~msg actual_balance expected_balance)
|
||||||
|
|
||||||
let delegate_equal ~msg contract expected_delegate =
|
let delegate_equal ?block ~msg contract expected_delegate =
|
||||||
Account.delegate contract >>|? fun actual_delegate ->
|
Account.delegate ?block contract >>|? fun actual_delegate ->
|
||||||
equal_pkh ~msg actual_delegate expected_delegate
|
equal_pkh ~msg actual_delegate expected_delegate
|
||||||
|
|
||||||
let ecoproto_error f = function
|
let ecoproto_error f = function
|
||||||
@ -445,15 +441,16 @@ module Mining = struct
|
|||||||
~fitness
|
~fitness
|
||||||
~seed_nonce
|
~seed_nonce
|
||||||
~src_sk
|
~src_sk
|
||||||
operation_list =
|
operations =
|
||||||
let block = match block with `Prevalidation -> `Head 0 | block -> block in
|
let block = match block with `Prevalidation -> `Head 0 | block -> block in
|
||||||
Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi ->
|
Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi ->
|
||||||
let proto_level = Utils.unopt ~default:bi.proto_level proto_level in
|
let proto_level = Utils.unopt ~default:bi.proto_level proto_level in
|
||||||
let seed_nonce_hash = Nonce.hash seed_nonce in
|
let seed_nonce_hash = Nonce.hash seed_nonce in
|
||||||
Client_proto_rpcs.Context.next_level rpc_config block >>=? fun level ->
|
Client_proto_rpcs.Context.next_level rpc_config block >>=? fun level ->
|
||||||
|
let operation_hashes = List.map Tezos_data.Operation.hash operations in
|
||||||
let operations_hash =
|
let operations_hash =
|
||||||
Operation_list_list_hash.compute
|
Operation_list_list_hash.compute
|
||||||
[Operation_list_hash.compute operation_list] in
|
[Operation_list_hash.compute operation_hashes] in
|
||||||
let shell =
|
let shell =
|
||||||
{ Block_header.net_id = bi.net_id ; predecessor = bi.hash ;
|
{ Block_header.net_id = bi.net_id ; predecessor = bi.hash ;
|
||||||
timestamp ; fitness ; operations_hash ;
|
timestamp ; fitness ; operations_hash ;
|
||||||
@ -476,11 +473,12 @@ module Mining = struct
|
|||||||
() >>=? fun unsigned_header ->
|
() >>=? fun unsigned_header ->
|
||||||
let signed_header = Environment.Ed25519.Signature.append src_sk unsigned_header in
|
let signed_header = Environment.Ed25519.Signature.append src_sk unsigned_header in
|
||||||
Client_node_rpcs.inject_block rpc_config
|
Client_node_rpcs.inject_block rpc_config
|
||||||
?force signed_header [List.map (fun h -> Client_node_rpcs.Hash h) operation_list] >>=? fun block_hash ->
|
?force signed_header
|
||||||
|
[List.map (fun h -> Client_node_rpcs.Blob h) operations] >>=? fun block_hash ->
|
||||||
return block_hash
|
return block_hash
|
||||||
|
|
||||||
let mine
|
let mine
|
||||||
?(force = false)
|
?(force = true)
|
||||||
?(operations = [])
|
?(operations = [])
|
||||||
?(fitness_gap = 1)
|
?(fitness_gap = 1)
|
||||||
?proto_level
|
?proto_level
|
||||||
@ -523,27 +521,21 @@ end
|
|||||||
|
|
||||||
module Endorse = struct
|
module Endorse = struct
|
||||||
|
|
||||||
let inject_endorsement
|
let forge_endorsement
|
||||||
block
|
block
|
||||||
_level
|
|
||||||
?async
|
|
||||||
?force
|
|
||||||
src_sk
|
src_sk
|
||||||
source
|
source
|
||||||
slot =
|
slot =
|
||||||
Client_blocks.get_block_hash rpc_config block >>=? fun block_hash ->
|
Client_blocks.get_block_info rpc_config block >>=? fun { hash ; net_id } ->
|
||||||
Client_node_rpcs.Blocks.net rpc_config block >>=? fun net ->
|
|
||||||
Client_proto_rpcs.Helpers.Forge.Delegate.endorsement rpc_config
|
Client_proto_rpcs.Helpers.Forge.Delegate.endorsement rpc_config
|
||||||
block
|
block
|
||||||
~net
|
~net:net_id
|
||||||
~source
|
~source
|
||||||
~block:block_hash
|
~block:hash
|
||||||
~slot:slot
|
~slot:slot
|
||||||
() >>=? fun bytes ->
|
() >>=? fun bytes ->
|
||||||
let signed_bytes = Environment.Ed25519.Signature.append src_sk bytes in
|
let signed_bytes = Environment.Ed25519.Signature.append src_sk bytes in
|
||||||
Client_node_rpcs.inject_operation
|
return (Tezos_data.Operation.of_bytes_exn signed_bytes)
|
||||||
rpc_config ?force ?async signed_bytes >>=? fun oph ->
|
|
||||||
return oph
|
|
||||||
|
|
||||||
let signing_slots
|
let signing_slots
|
||||||
?(max_priority = 1024)
|
?(max_priority = 1024)
|
||||||
@ -559,12 +551,10 @@ module Endorse = struct
|
|||||||
return slots
|
return slots
|
||||||
|
|
||||||
let endorse
|
let endorse
|
||||||
?(force = false)
|
|
||||||
?slot
|
?slot
|
||||||
(contract : Account.t)
|
(contract : Account.t)
|
||||||
block =
|
block =
|
||||||
Client_proto_rpcs.Context.level rpc_config block >>=? fun level ->
|
Client_proto_rpcs.Context.next_level rpc_config block >>=? fun { level } ->
|
||||||
let level = Raw_level.succ @@ level.level in
|
|
||||||
begin
|
begin
|
||||||
match slot with
|
match slot with
|
||||||
| Some slot -> return slot
|
| Some slot -> return slot
|
||||||
@ -577,9 +567,7 @@ module Endorse = struct
|
|||||||
failwith "No slot found at level %a" Raw_level.pp level
|
failwith "No slot found at level %a" Raw_level.pp level
|
||||||
end
|
end
|
||||||
end >>=? fun slot ->
|
end >>=? fun slot ->
|
||||||
inject_endorsement
|
forge_endorsement block contract.sk contract.pk slot
|
||||||
block level contract.sk contract.pk slot ~force >>=? fun oph ->
|
|
||||||
return oph
|
|
||||||
|
|
||||||
(* FIXME @vb: I don't understand this function, copied from @cago. *)
|
(* FIXME @vb: I don't understand this function, copied from @cago. *)
|
||||||
let endorsers_list block { Account.b1 ; b2 ; b3 ; b4 ; b5 } =
|
let endorsers_list block { Account.b1 ; b2 ; b3 ; b4 ; b5 } =
|
||||||
|
@ -120,11 +120,11 @@ module Mining : sig
|
|||||||
fitness:Fitness.t ->
|
fitness:Fitness.t ->
|
||||||
seed_nonce:Nonce.nonce ->
|
seed_nonce:Nonce.nonce ->
|
||||||
src_sk:secret_key ->
|
src_sk:secret_key ->
|
||||||
Operation_hash.t list -> Block_hash.t tzresult Lwt.t
|
Operation.raw list -> Block_hash.t tzresult Lwt.t
|
||||||
|
|
||||||
val mine :
|
val mine :
|
||||||
?force:bool ->
|
?force:bool ->
|
||||||
?operations:Operation_hash.t list ->
|
?operations:Operation.raw list ->
|
||||||
?fitness_gap:int ->
|
?fitness_gap:int ->
|
||||||
?proto_level:int ->
|
?proto_level:int ->
|
||||||
Account.t ->
|
Account.t ->
|
||||||
@ -140,11 +140,10 @@ end
|
|||||||
module Endorse : sig
|
module Endorse : sig
|
||||||
|
|
||||||
val endorse :
|
val endorse :
|
||||||
?force:bool ->
|
|
||||||
?slot:int ->
|
?slot:int ->
|
||||||
Account.t ->
|
Account.t ->
|
||||||
Client_alpha.Client_proto_rpcs.block ->
|
Client_alpha.Client_proto_rpcs.block ->
|
||||||
Operation_hash.t tzresult Lwt.t
|
Operation.raw tzresult Lwt.t
|
||||||
|
|
||||||
val endorsers_list :
|
val endorsers_list :
|
||||||
Client_alpha.Client_proto_rpcs.block ->
|
Client_alpha.Client_proto_rpcs.block ->
|
||||||
@ -161,22 +160,18 @@ end
|
|||||||
|
|
||||||
module Protocol : sig
|
module Protocol : sig
|
||||||
|
|
||||||
val inject_proposals :
|
val proposals :
|
||||||
?async:bool ->
|
|
||||||
?force:bool ->
|
|
||||||
?block:Client_node_rpcs.Blocks.block ->
|
?block:Client_node_rpcs.Blocks.block ->
|
||||||
src:Account.t ->
|
src:Account.t ->
|
||||||
Hash.Protocol_hash.t list ->
|
Protocol_hash.t list ->
|
||||||
Hash.Operation_list_hash.elt tzresult Lwt.t
|
Operation.raw tzresult Lwt.t
|
||||||
|
|
||||||
val inject_ballot :
|
val ballot :
|
||||||
?async:bool ->
|
|
||||||
?force:bool ->
|
|
||||||
?block:Client_node_rpcs.Blocks.block ->
|
?block:Client_node_rpcs.Blocks.block ->
|
||||||
src:Account.t ->
|
src:Account.t ->
|
||||||
proposal:Hash.Protocol_hash.t ->
|
proposal:Protocol_hash.t ->
|
||||||
Vote.ballot ->
|
Vote.ballot ->
|
||||||
Hash.Operation_list_hash.elt tzresult Lwt.t
|
Operation.raw tzresult Lwt.t
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -185,13 +180,15 @@ module Assert : sig
|
|||||||
include module type of Assert
|
include module type of Assert
|
||||||
|
|
||||||
val balance_equal:
|
val balance_equal:
|
||||||
|
?block:Client_node_rpcs.Blocks.block ->
|
||||||
msg:string -> Account.t -> int64 -> unit tzresult Lwt.t
|
msg:string -> Account.t -> int64 -> unit tzresult Lwt.t
|
||||||
val delegate_equal:
|
val delegate_equal:
|
||||||
|
?block:Client_node_rpcs.Blocks.block ->
|
||||||
msg:string -> Contract.t -> public_key_hash option -> unit tzresult Lwt.t
|
msg:string -> Contract.t -> public_key_hash option -> unit tzresult Lwt.t
|
||||||
|
|
||||||
val ecoproto_error:
|
val ecoproto_error:
|
||||||
(Register_client_embedded_proto_alpha.Packed_protocol.error -> bool) ->
|
(Register_client_embedded_proto_alpha.Packed_protocol.error -> bool) ->
|
||||||
Error_monad.error -> bool
|
error -> bool
|
||||||
|
|
||||||
val generic_economic_error : msg:string -> 'a tzresult -> unit
|
val generic_economic_error : msg:string -> 'a tzresult -> unit
|
||||||
|
|
||||||
@ -218,7 +215,7 @@ module Assert : sig
|
|||||||
|
|
||||||
val check_protocol :
|
val check_protocol :
|
||||||
?msg:string -> block:Client_node_rpcs.Blocks.block ->
|
?msg:string -> block:Client_node_rpcs.Blocks.block ->
|
||||||
Hash.Protocol_hash.t -> unit tzresult Lwt.t
|
Protocol_hash.t -> unit tzresult Lwt.t
|
||||||
|
|
||||||
val check_voting_period_kind :
|
val check_voting_period_kind :
|
||||||
?msg:string -> block:Client_node_rpcs.Blocks.block ->
|
?msg:string -> block:Client_node_rpcs.Blocks.block ->
|
||||||
|
@ -25,14 +25,14 @@ let test_double_endorsement contract block =
|
|||||||
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b1) >>=? fun b2' ->
|
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b1) >>=? fun b2' ->
|
||||||
|
|
||||||
(* branch root *)
|
(* branch root *)
|
||||||
Helpers.Endorse.endorse ~force:true contract (`Hash b2) >>=? fun ops ->
|
Helpers.Endorse.endorse contract (`Hash b2) >>=? fun op ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] contract (`Hash b2) >>=? fun _b3 ->
|
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ op ] contract (`Hash b2) >>=? fun _b3 ->
|
||||||
|
|
||||||
Helpers.Endorse.endorse ~force:true contract (`Hash b2') >>=? fun ops ->
|
Helpers.Endorse.endorse contract (`Hash b2') >>=? fun op ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] contract (`Hash b2') >>=? fun b3' ->
|
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ op ] contract (`Hash b2') >>=? fun b3' ->
|
||||||
|
|
||||||
Helpers.Endorse.endorse ~force:true contract (`Hash b3') >>=? fun ops ->
|
Helpers.Endorse.endorse contract (`Hash b3') >>=? fun op ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] contract (`Hash b3') >>=? fun b4' ->
|
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ op ] contract (`Hash b3') >>=? fun b4' ->
|
||||||
|
|
||||||
(* TODO: Inject double endorsement op ! *)
|
(* TODO: Inject double endorsement op ! *)
|
||||||
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b4')
|
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b4')
|
||||||
@ -59,21 +59,38 @@ let contain_tzerror ?(msg="") ~f t =
|
|||||||
failwith "@[<v 2>Unexpected error@ %a@]" pp_print_error error
|
failwith "@[<v 2>Unexpected error@ %a@]" pp_print_error error
|
||||||
| _ -> return ()
|
| _ -> return ()
|
||||||
|
|
||||||
let test_wrong_delegate contract block =
|
let test_wrong_delegate ~miner contract head =
|
||||||
|
let block = `Hash head in
|
||||||
contain_tzerror ~msg:__LOC__ ~f:begin Assert.ecoproto_error (function
|
contain_tzerror ~msg:__LOC__ ~f:begin Assert.ecoproto_error (function
|
||||||
| Mining.Wrong_delegate _ -> true
|
| Mining.Wrong_delegate _ -> true
|
||||||
| _ -> false)
|
| _ -> false)
|
||||||
|
end begin
|
||||||
|
Helpers.Endorse.endorse ~slot:1 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] miner block >>=? fun _ ->
|
||||||
|
Helpers.Endorse.endorse ~slot:2 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] miner block >>=? fun _ ->
|
||||||
|
Helpers.Endorse.endorse ~slot:3 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] miner block >>=? fun _ ->
|
||||||
|
Helpers.Endorse.endorse ~slot:4 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] miner block >>=? fun _ ->
|
||||||
|
Helpers.Endorse.endorse ~slot:5 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] miner block >>=? fun _ ->
|
||||||
|
return ()
|
||||||
end
|
end
|
||||||
(Helpers.Endorse.endorse ~slot:1 ~force:true contract block >>=? fun _ ->
|
|
||||||
Helpers.Endorse.endorse ~slot:2 ~force:true contract block >>=? fun _ ->
|
|
||||||
Helpers.Endorse.endorse ~slot:3 ~force:true contract block >>=? fun _ ->
|
|
||||||
Helpers.Endorse.endorse ~slot:4 ~force:true contract block >>=? fun _ ->
|
|
||||||
Helpers.Endorse.endorse ~slot:5 ~force:true contract block)
|
|
||||||
|
|
||||||
let test_invalid_endorsement_slot contract block =
|
let test_invalid_endorsement_slot contract block =
|
||||||
Helpers.Endorse.endorse ~slot:~-1 ~force:true contract block >>= fun res ->
|
Helpers.Endorse.endorse ~slot:~-1 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] contract block >>= fun res ->
|
||||||
Assert.invalid_endorsement_slot ~msg:__LOC__ res ;
|
Assert.invalid_endorsement_slot ~msg:__LOC__ res ;
|
||||||
Helpers.Endorse.endorse ~slot:16 ~force:true contract block >>= fun res ->
|
Helpers.Endorse.endorse ~slot:16 contract block >>=? fun op ->
|
||||||
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ op ] contract block >>= fun res ->
|
||||||
Assert.invalid_endorsement_slot ~msg:__LOC__ res ;
|
Assert.invalid_endorsement_slot ~msg:__LOC__ res ;
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
@ -93,11 +110,12 @@ let test_endorsement_rewards
|
|||||||
(* #1 endorse & inject in a block *)
|
(* #1 endorse & inject in a block *)
|
||||||
Helpers.Endorse.endorsers_list block baccounts >>=? fun accounts ->
|
Helpers.Endorse.endorsers_list block baccounts >>=? fun accounts ->
|
||||||
get_endorser_except [ b1 ] accounts >>=? fun (account0, slot0) ->
|
get_endorser_except [ b1 ] accounts >>=? fun (account0, slot0) ->
|
||||||
Helpers.Account.balance account0 >>=? fun balance0 ->
|
Helpers.Account.balance ~block account0 >>=? fun balance0 ->
|
||||||
Helpers.Endorse.endorse ~slot:slot0 ~force:true account0 block >>=? fun ops ->
|
Helpers.Endorse.endorse ~slot:slot0 account0 block >>=? fun ops ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 block >>=? fun head0 ->
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ ops ] b1 block >>=? fun head0 ->
|
||||||
Helpers.display_level (`Hash head0) >>=? fun () ->
|
Helpers.display_level (`Hash head0) >>=? fun () ->
|
||||||
Assert.balance_equal ~msg:__LOC__ account0
|
Assert.balance_equal ~block:(`Hash head0) ~msg:__LOC__ account0
|
||||||
(Int64.sub (Tez.to_cents balance0) bond) >>=? fun () ->
|
(Int64.sub (Tez.to_cents balance0) bond) >>=? fun () ->
|
||||||
|
|
||||||
|
|
||||||
@ -105,44 +123,30 @@ let test_endorsement_rewards
|
|||||||
let block0 = `Hash head0 in
|
let block0 = `Hash head0 in
|
||||||
Helpers.Endorse.endorsers_list block0 baccounts >>=? fun accounts ->
|
Helpers.Endorse.endorsers_list block0 baccounts >>=? fun accounts ->
|
||||||
get_endorser_except [ b1 ; account0 ] accounts >>=? fun (account1, slot1) ->
|
get_endorser_except [ b1 ; account0 ] accounts >>=? fun (account1, slot1) ->
|
||||||
Helpers.Account.balance account1 >>=? fun balance1 ->
|
Helpers.Account.balance ~block:block0 account1 >>=? fun balance1 ->
|
||||||
Helpers.Endorse.endorse ~slot:slot1 ~force:true account1 block0 >>=? fun ops ->
|
Helpers.Endorse.endorse ~slot:slot1 account1 block0 >>=? fun ops ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 block0 >>=? fun head1 ->
|
Helpers.Mining.mine
|
||||||
|
~fitness_gap:2 ~operations:[ ops ] b1 block0 >>=? fun head1 ->
|
||||||
Helpers.display_level (`Hash head1) >>=? fun () ->
|
Helpers.display_level (`Hash head1) >>=? fun () ->
|
||||||
Assert.balance_equal ~msg:__LOC__ account1
|
Assert.balance_equal ~block:(`Hash head1) ~msg:__LOC__ account1
|
||||||
(Int64.sub (Tez.to_cents balance1) bond) >>=? fun () ->
|
(Int64.sub (Tez.to_cents balance1) bond) >>=? fun () ->
|
||||||
|
|
||||||
|
(* Check rewards after one cycle for account0 *)
|
||||||
(* #3 endorse but the operation is not included in a block, so no reward *)
|
|
||||||
let block1 = `Hash head1 in
|
|
||||||
Helpers.Endorse.endorsers_list block1 baccounts >>=? fun accounts ->
|
|
||||||
get_endorser_except [ b1 ; account0 ; account1 ] accounts >>=? fun (account2, slot2) ->
|
|
||||||
Helpers.Account.balance account2 >>=? fun balance2 ->
|
|
||||||
Helpers.Endorse.endorse ~slot:slot2 ~force:true account2 block1 >>=? fun _ops ->
|
|
||||||
Assert.balance_equal ~msg:__LOC__ account2
|
|
||||||
(Int64.sub (Tez.to_cents balance2) bond) >>=? fun () ->
|
|
||||||
|
|
||||||
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head1) >>=? fun head2 ->
|
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head1) >>=? fun head2 ->
|
||||||
Helpers.display_level (`Hash head2) >>=? fun () ->
|
Helpers.display_level (`Hash head2) >>=? fun () ->
|
||||||
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head2) >>=? fun head3 ->
|
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head2) >>=? fun head3 ->
|
||||||
Helpers.display_level (`Hash head3) >>=? fun () ->
|
Helpers.display_level (`Hash head3) >>=? fun () ->
|
||||||
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head3) >>=? fun head4 ->
|
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head3) >>=? fun head4 ->
|
||||||
Helpers.display_level (`Hash head4) >>=? fun () ->
|
Helpers.display_level (`Hash head4) >>=? fun () ->
|
||||||
|
|
||||||
(* Check rewards after one cycle for account0 *)
|
|
||||||
Helpers.Mining.endorsement_reward b1 block0 >>=? fun rw0 ->
|
Helpers.Mining.endorsement_reward b1 block0 >>=? fun rw0 ->
|
||||||
Assert.balance_equal ~msg:__LOC__ account0
|
Assert.balance_equal ~block:(`Hash head4) ~msg:__LOC__ account0
|
||||||
(Int64.add (Tez.to_cents balance0) rw0) >>=? fun () ->
|
(Int64.add (Tez.to_cents balance0) rw0) >>=? fun () ->
|
||||||
|
|
||||||
(* Check rewards after one cycle for account1 *)
|
(* Check rewards after one cycle for account1 *)
|
||||||
Helpers.Mining.endorsement_reward b1 block1 >>=? fun rw1 ->
|
Helpers.Mining.endorsement_reward b1 (`Hash head1) >>=? fun rw1 ->
|
||||||
Assert.balance_equal ~msg:__LOC__ account1
|
Assert.balance_equal ~block:(`Hash head4) ~msg:__LOC__ account1
|
||||||
(Int64.add (Tez.to_cents balance1) rw1) >>=? fun () ->
|
(Int64.add (Tez.to_cents balance1) rw1) >>=? fun () ->
|
||||||
|
|
||||||
(* Check no rewards after one cycle for account2 *)
|
|
||||||
Assert.balance_equal
|
|
||||||
~msg:__LOC__ account2 (Tez.to_cents balance2) >>=? fun () ->
|
|
||||||
|
|
||||||
(* #2 endorse and check reward only on the good chain *)
|
(* #2 endorse and check reward only on the good chain *)
|
||||||
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head4) >>=? fun head ->
|
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head4) >>=? fun head ->
|
||||||
Helpers.display_level (`Hash head) >>=? fun () ->
|
Helpers.display_level (`Hash head) >>=? fun () ->
|
||||||
@ -152,20 +156,20 @@ let test_endorsement_rewards
|
|||||||
(* working on head *)
|
(* working on head *)
|
||||||
Helpers.Endorse.endorsers_list (`Hash head) baccounts >>=? fun accounts ->
|
Helpers.Endorse.endorsers_list (`Hash head) baccounts >>=? fun accounts ->
|
||||||
get_endorser_except [ b1 ] accounts >>=? fun (account3, slot3) ->
|
get_endorser_except [ b1 ] accounts >>=? fun (account3, slot3) ->
|
||||||
Helpers.Account.balance account3 >>=? fun balance3 ->
|
Helpers.Account.balance ~block:(`Hash head) account3 >>=? fun balance3 ->
|
||||||
Helpers.Endorse.endorse
|
Helpers.Endorse.endorse
|
||||||
~slot:slot3 ~force:true account3 (`Hash head) >>=? fun ops ->
|
~slot:slot3 account3 (`Hash head) >>=? fun ops ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 (`Hash head) >>=? fun new_head ->
|
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 (`Hash head) >>=? fun new_head ->
|
||||||
Helpers.display_level (`Hash new_head) >>=? fun () ->
|
Helpers.display_level (`Hash new_head) >>=? fun () ->
|
||||||
|
|
||||||
(* working on fork *)
|
(* working on fork *)
|
||||||
Helpers.Endorse.endorsers_list (`Hash fork) baccounts >>=? fun accounts ->
|
Helpers.Endorse.endorsers_list (`Hash fork) baccounts >>=? fun accounts ->
|
||||||
get_endorser_except [ b1 ] accounts >>=? fun (account4, slot4) ->
|
get_endorser_except [ b1 ] accounts >>=? fun (account4, slot4) ->
|
||||||
Helpers.Account.balance account4 >>=? fun _balance4 ->
|
Helpers.Account.balance ~block:(`Hash new_head) account4 >>=? fun _balance4 ->
|
||||||
Helpers.Endorse.endorse ~slot:slot4 ~force:true account4 (`Hash fork) >>=? fun ops ->
|
Helpers.Endorse.endorse ~slot:slot4 account4 (`Hash fork) >>=? fun ops ->
|
||||||
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 (`Hash fork) >>=? fun _new_fork ->
|
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 (`Hash fork) >>=? fun _new_fork ->
|
||||||
Helpers.display_level (`Hash _new_fork) >>=? fun () ->
|
Helpers.display_level (`Hash _new_fork) >>=? fun () ->
|
||||||
Helpers.Account.balance account4 >>=? fun balance4 ->
|
Helpers.Account.balance ~block:(`Hash new_head) account4 >>=? fun balance4 ->
|
||||||
|
|
||||||
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash new_head) >>=? fun head ->
|
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash new_head) >>=? fun head ->
|
||||||
Helpers.display_level (`Hash head) >>=? fun () ->
|
Helpers.display_level (`Hash head) >>=? fun () ->
|
||||||
@ -174,7 +178,7 @@ let test_endorsement_rewards
|
|||||||
|
|
||||||
(* Check rewards after one cycle *)
|
(* Check rewards after one cycle *)
|
||||||
Helpers.Mining.endorsement_reward b1 (`Hash new_head) >>=? fun reward ->
|
Helpers.Mining.endorsement_reward b1 (`Hash new_head) >>=? fun reward ->
|
||||||
Assert.balance_equal ~msg:__LOC__ account3
|
Assert.balance_equal ~block:(`Hash head) ~msg:__LOC__ account3
|
||||||
(Int64.add (Tez.to_cents balance3) reward) >>=? fun () ->
|
(Int64.add (Tez.to_cents balance3) reward) >>=? fun () ->
|
||||||
|
|
||||||
(* Check no reward for the fork *)
|
(* Check no reward for the fork *)
|
||||||
@ -182,8 +186,9 @@ let test_endorsement_rewards
|
|||||||
if account3 = account4 then return ()
|
if account3 = account4 then return ()
|
||||||
(* if account4 is different from account3, we need to check that there
|
(* if account4 is different from account3, we need to check that there
|
||||||
is no reward for him since the endorsement was in the fork branch *)
|
is no reward for him since the endorsement was in the fork branch *)
|
||||||
else Assert.balance_equal ~msg:__LOC__ account4 (Tez.to_cents balance4)
|
else Assert.balance_equal ~block:(`Hash head) ~msg:__LOC__ account4 (Tez.to_cents balance4)
|
||||||
end >>=? fun () -> return head
|
end >>=? fun () ->
|
||||||
|
return head
|
||||||
|
|
||||||
let test_endorsement_rights contract block =
|
let test_endorsement_rights contract block =
|
||||||
Helpers.Endorse.endorsement_rights contract block >>|? fun possibilities ->
|
Helpers.Endorse.endorsement_rights contract block >>|? fun possibilities ->
|
||||||
@ -200,11 +205,11 @@ let run head (({ b1 ; b2 ; b3 ; b4 ; b5 } : Helpers.Account.bootstrap_accounts)
|
|||||||
test_endorsement_rights b1 head >>=? fun has_right_to_endorse ->
|
test_endorsement_rights b1 head >>=? fun has_right_to_endorse ->
|
||||||
Assert.equal_bool ~msg:__LOC__ has_right_to_endorse true ;
|
Assert.equal_bool ~msg:__LOC__ has_right_to_endorse true ;
|
||||||
|
|
||||||
Assert.balance_equal ~msg:__LOC__ b1 4_000_000_00L >>=? fun () ->
|
Assert.balance_equal ~block:head ~msg:__LOC__ b1 4_000_000_00L >>=? fun () ->
|
||||||
Assert.balance_equal ~msg:__LOC__ b2 4_000_000_00L >>=? fun () ->
|
Assert.balance_equal ~block:head ~msg:__LOC__ b2 4_000_000_00L >>=? fun () ->
|
||||||
Assert.balance_equal ~msg:__LOC__ b3 4_000_000_00L >>=? fun () ->
|
Assert.balance_equal ~block:head ~msg:__LOC__ b3 4_000_000_00L >>=? fun () ->
|
||||||
Assert.balance_equal ~msg:__LOC__ b4 4_000_000_00L >>=? fun () ->
|
Assert.balance_equal ~block:head ~msg:__LOC__ b4 4_000_000_00L >>=? fun () ->
|
||||||
Assert.balance_equal ~msg:__LOC__ b5 4_000_000_00L >>=? fun () ->
|
Assert.balance_equal ~block:head ~msg:__LOC__ b5 4_000_000_00L >>=? fun () ->
|
||||||
|
|
||||||
(* Check Rewards *)
|
(* Check Rewards *)
|
||||||
test_endorsement_rewards head baccounts >>=? fun head ->
|
test_endorsement_rewards head baccounts >>=? fun head ->
|
||||||
@ -212,8 +217,8 @@ let run head (({ b1 ; b2 ; b3 ; b4 ; b5 } : Helpers.Account.bootstrap_accounts)
|
|||||||
(* Endorse with a contract with wrong delegate:
|
(* Endorse with a contract with wrong delegate:
|
||||||
- contract with no endorsement rights
|
- contract with no endorsement rights
|
||||||
- contract which signs at every available slots *)
|
- contract which signs at every available slots *)
|
||||||
test_wrong_delegate default_account (`Hash head) >>=? fun () ->
|
test_wrong_delegate ~miner:b1 default_account head >>=? fun () ->
|
||||||
test_wrong_delegate b5 (`Hash head) >>=? fun () ->
|
test_wrong_delegate ~miner:b1 b5 head >>=? fun () ->
|
||||||
|
|
||||||
(* Endorse with a wrong slot : -1 and max (16) *)
|
(* Endorse with a wrong slot : -1 and max (16) *)
|
||||||
test_invalid_endorsement_slot b3 (`Hash head) >>=? fun () ->
|
test_invalid_endorsement_slot b3 (`Hash head) >>=? fun () ->
|
||||||
|
@ -28,14 +28,13 @@ let run_change_to_demo_proto block ({ b1 ; b2 ; b3 ; b4 ; b5 } : Account.bootstr
|
|||||||
Mining.mine b2 (`Hash head) >>=? fun head ->
|
Mining.mine b2 (`Hash head) >>=? fun head ->
|
||||||
|
|
||||||
(* 1. Propose the 'demo' protocol as b1 (during the Proposal period) *)
|
(* 1. Propose the 'demo' protocol as b1 (during the Proposal period) *)
|
||||||
Protocol.inject_proposals
|
Protocol.proposals
|
||||||
~force:true
|
|
||||||
~block:(`Hash head)
|
~block:(`Hash head)
|
||||||
~src:b1
|
~src:b1
|
||||||
[demo_protocol] >>=? fun oph ->
|
[demo_protocol] >>=? fun op ->
|
||||||
|
|
||||||
(* Mine blocks to switch to next vote period (Testing_vote) *)
|
(* Mine blocks to switch to next vote period (Testing_vote) *)
|
||||||
Mining.mine ~operations:[oph] b3 (`Hash head) >>=? fun head ->
|
Mining.mine ~operations:[op] b3 (`Hash head) >>=? fun head ->
|
||||||
Format.eprintf "Entering `Testing_vote` voting period@.";
|
Format.eprintf "Entering `Testing_vote` voting period@.";
|
||||||
Mining.mine b4 (`Hash head) >>=? fun head ->
|
Mining.mine b4 (`Hash head) >>=? fun head ->
|
||||||
Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head)
|
Assert.check_voting_period_kind ~msg:__LOC__ ~block:(`Hash head)
|
||||||
@ -44,8 +43,7 @@ let run_change_to_demo_proto block ({ b1 ; b2 ; b3 ; b4 ; b5 } : Account.bootstr
|
|||||||
(* 2. Vote unanimously for a proposal *)
|
(* 2. Vote unanimously for a proposal *)
|
||||||
|
|
||||||
let vote_for_demo ~src ~block ballot =
|
let vote_for_demo ~src ~block ballot =
|
||||||
Protocol.inject_ballot
|
Protocol.ballot
|
||||||
~force:true
|
|
||||||
~block
|
~block
|
||||||
~src
|
~src
|
||||||
~proposal:demo_protocol
|
~proposal:demo_protocol
|
||||||
|
Loading…
Reference in New Issue
Block a user