Alpha: minor changes in unit tests

This commit is contained in:
Grégoire Henry 2017-04-11 00:57:04 +02:00
parent a731a47d3c
commit e276b0566e
5 changed files with 23 additions and 22 deletions

View File

@ -422,6 +422,7 @@ module Mining = struct
let mine
?(force = false)
?(operations = [])
~fitness_gap
contract
block =
Client_mining_blocks.info rpc_config block >>=? fun bi ->
@ -438,8 +439,7 @@ module Mining = struct
Register_client_embedded_proto_alpha.wrap_error) >>=? fun fitness ->
let fitness =
Fitness_repr.from_int64 @@
Int64.add fitness (Int64.of_int @@ List.length operations + 1) in
Level.pp_full Format.str_formatter bi.level ;
Int64.add fitness (Int64.of_int fitness_gap) in
inject_block
~force
~priority

View File

@ -122,6 +122,7 @@ module Mining : sig
val mine :
?force:bool ->
?operations:Operation_hash.t list ->
fitness_gap:int ->
Account.t ->
Client_node_rpcs.Blocks.block ->
Block_hash.t tzresult Lwt.t

View File

@ -16,25 +16,25 @@ module Assert = Helpers.Assert
let test_double_endorsement contract block =
(* Double endorsement for the same level *)
Helpers.Mining.mine contract block >>=? fun b1 ->
Helpers.Mining.mine ~fitness_gap:1 contract block >>=? fun b1 ->
(* branch root *)
Helpers.Mining.mine contract (`Hash b1) >>=? fun b2 ->
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b1) >>=? fun b2 ->
(* changing branch *)
Helpers.Mining.mine contract (`Hash b1) >>=? fun b2' ->
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b1) >>=? fun b2' ->
(* branch root *)
Helpers.Endorse.endorse ~force:true contract (`Hash b2) >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] contract (`Hash b2) >>=? fun _b3 ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] contract (`Hash b2) >>=? fun _b3 ->
Helpers.Endorse.endorse ~force:true contract (`Hash b2') >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] contract (`Hash b2') >>=? fun b3' ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] contract (`Hash b2') >>=? fun b3' ->
Helpers.Endorse.endorse ~force:true contract (`Hash b3') >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] contract (`Hash b3') >>=? fun b4' ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] contract (`Hash b3') >>=? fun b4' ->
(* TODO: Inject double endorsement op ! *)
Helpers.Mining.mine contract (`Hash b4')
Helpers.Mining.mine ~fitness_gap:1 contract (`Hash b4')
(* FIXME: Mining.Invalid_signature is unclassified *)
let test_invalid_signature block =
@ -47,7 +47,7 @@ let test_invalid_signature block =
DYfTKhq7rDQujdn5WWzwUMeV3agaZ6J2vPQT58jJAJPi" in
let account =
Helpers.Account.create ~keys:(secret_key, public_key) "WRONG SIGNATURE" in
Helpers.Mining.mine account block >>= fun res ->
Helpers.Mining.mine ~fitness_gap:1 account block >>= fun res ->
Assert.generic_economic_error ~msg:__LOC__ res ;
return ()
@ -94,7 +94,7 @@ let test_endorsement_rewards
get_endorser_except_b1 accounts >>=? fun (account0, slot0) ->
Helpers.Account.balance account0 >>=? fun balance0 ->
Helpers.Endorse.endorse ~slot:slot0 ~force:true account0 block >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] b1 block >>=? fun head0 ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 block >>=? fun head0 ->
Assert.balance_equal ~msg:__LOC__ account0
(Int64.sub (Tez.to_cents balance0) bond) >>=? fun () ->
@ -104,7 +104,7 @@ let test_endorsement_rewards
get_endorser_except_b1 accounts >>=? fun (account1, slot1) ->
Helpers.Account.balance account1 >>=? fun balance1 ->
Helpers.Endorse.endorse ~slot:slot1 ~force:true account1 block0 >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] b1 block0 >>=? fun head1 ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 block0 >>=? fun head1 ->
Assert.balance_equal ~msg:__LOC__ account1
(Int64.sub (Tez.to_cents balance1) bond) >>=? fun () ->
@ -117,8 +117,8 @@ let test_endorsement_rewards
Assert.balance_equal ~msg:__LOC__ account2
(Int64.sub (Tez.to_cents balance2) bond) >>=? fun () ->
Helpers.Mining.mine b1 (`Hash head1) >>=? fun head2 ->
Helpers.Mining.mine b1 (`Hash head2) >>=? fun head3 ->
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head1) >>=? fun head2 ->
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head2) >>=? fun head3 ->
(* Check rewards after one cycle for account0 *)
Helpers.Mining.endorsement_reward b1 block0 >>=? fun rw0 ->
@ -135,8 +135,8 @@ let test_endorsement_rewards
~msg:__LOC__ account2 (Tez.to_cents balance2) >>=? fun () ->
(* #2 endorse and check reward only on the good chain *)
Helpers.Mining.mine b1 (`Hash head3) >>=? fun head ->
Helpers.Mining.mine b1 (`Hash head3) >>=? fun fork ->
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head3) >>=? fun head ->
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head3) >>=? fun fork ->
(* working on head *)
Helpers.Endorse.endorsers_list (`Hash head) baccounts >>=? fun accounts ->
@ -144,18 +144,18 @@ let test_endorsement_rewards
Helpers.Account.balance account3 >>=? fun balance3 ->
Helpers.Endorse.endorse
~slot:slot3 ~force:true account3 (`Hash head) >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] b1 (`Hash head) >>=? fun new_head ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 (`Hash head) >>=? fun new_head ->
(* working on fork *)
Helpers.Endorse.endorsers_list (`Hash fork) baccounts >>=? fun accounts ->
get_endorser_except_b1 accounts >>=? fun (account4, slot4) ->
Helpers.Account.balance account4 >>=? fun _balance4 ->
Helpers.Endorse.endorse ~slot:slot4 ~force:true account4 (`Hash fork) >>=? fun ops ->
Helpers.Mining.mine ~operations:[ ops ] b1 (`Hash fork) >>=? fun _new_fork ->
Helpers.Mining.mine ~fitness_gap:2 ~operations:[ ops ] b1 (`Hash fork) >>=? fun _new_fork ->
Helpers.Account.balance account4 >>=? fun balance4 ->
Helpers.Mining.mine b1 (`Hash new_head) >>=? fun head ->
Helpers.Mining.mine b1 (`Hash head) >>=? fun head ->
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash new_head) >>=? fun head ->
Helpers.Mining.mine ~fitness_gap:1 b1 (`Hash head) >>=? fun head ->
(* Check rewards after one cycle *)
Helpers.Mining.endorsement_reward b1 (`Hash new_head) >>=? fun reward ->

View File

@ -15,7 +15,7 @@ module Assert = Helpers.Assert
let run blkid ({ b1 ; b2 ; _ } : Helpers.Account.bootstrap_accounts) =
Helpers.Mining.mine b1 blkid >>=? fun blkh ->
Helpers.Mining.mine ~fitness_gap:1 b1 blkid >>=? fun blkh ->
let foo = Helpers.Account.create "foo" in
(* Origination with amount = 0 tez *)

View File

@ -15,7 +15,7 @@ module Assert = Helpers.Assert
let run blkid ({ b1 ; b2 ; b3 ; _ } : Helpers.Account.bootstrap_accounts) =
Helpers.Mining.mine b1 blkid >>=? fun blkh ->
Helpers.Mining.mine ~fitness_gap:1 b1 blkid >>=? fun blkh ->
let foo = Helpers.Account.create "foo" in
let bar = Helpers.Account.create "bar" in