Tests: fix double_endorsement tests
This commit is contained in:
parent
b5c275c5fa
commit
392f6cec46
@ -135,14 +135,20 @@ let different_delegates () =
|
|||||||
Context.init 2 >>=? fun (b, _) ->
|
Context.init 2 >>=? fun (b, _) ->
|
||||||
|
|
||||||
Block.bake b >>=? fun b ->
|
Block.bake b >>=? fun b ->
|
||||||
Block.bake b >>=? fun blk_a ->
|
block_fork b >>=? fun (blk_a, blk_b) ->
|
||||||
Block.bake b >>=? fun blk_b ->
|
Context.get_endorser (B blk_a) >>=? fun (endorser_a, _a_slots) ->
|
||||||
get_first_different_endorsers (B blk_a) >>=? fun (endorser_a, endorser_b) ->
|
get_first_different_endorsers (B blk_b) >>=? fun (endorser_b1c, endorser_b2c) ->
|
||||||
|
let endorser_b =
|
||||||
|
if Signature.Public_key_hash.(=) endorser_a endorser_b1c.delegate
|
||||||
|
then endorser_b2c.delegate
|
||||||
|
else endorser_b1c.delegate
|
||||||
|
in
|
||||||
|
|
||||||
Op.endorsement ~delegate:endorser_a.delegate (B blk_a) () >>=? fun e_a ->
|
Op.endorsement ~delegate:endorser_a (B blk_a) () >>=? fun e_a ->
|
||||||
Op.endorsement ~delegate:endorser_b.delegate (B blk_b) () >>=? fun e_b ->
|
Op.endorsement ~delegate:endorser_b (B blk_b) () >>=? fun e_b ->
|
||||||
Op.double_endorsement (B blk_a) e_a e_b >>=? fun operation ->
|
Block.bake ~operation:(Operation.pack e_b) blk_b >>=? fun _ ->
|
||||||
Block.bake ~operation blk_a >>= fun res ->
|
Op.double_endorsement (B blk_b) e_a e_b >>=? fun operation ->
|
||||||
|
Block.bake ~operation blk_b >>= fun res ->
|
||||||
Assert.proto_error ~loc:__LOC__ res begin function
|
Assert.proto_error ~loc:__LOC__ res begin function
|
||||||
| Apply.Inconsistent_double_endorsement_evidence _ -> true
|
| Apply.Inconsistent_double_endorsement_evidence _ -> true
|
||||||
| _ -> false end
|
| _ -> false end
|
||||||
@ -150,28 +156,33 @@ let different_delegates () =
|
|||||||
(** Check that a double endorsement evidence that exposes a ill-formed
|
(** Check that a double endorsement evidence that exposes a ill-formed
|
||||||
endorsement fails. *)
|
endorsement fails. *)
|
||||||
let wrong_delegate () =
|
let wrong_delegate () =
|
||||||
Context.init 2 >>=? fun (b, _) ->
|
Context.init ~endorsers_per_block:1 2 >>=? fun (b, contracts) ->
|
||||||
|
Error_monad.map_s (Context.Contract.manager (B b)) contracts >>=? fun accounts ->
|
||||||
|
let pkh1 = (List.nth accounts 0).Account.pkh in
|
||||||
|
let pkh2 = (List.nth accounts 1).Account.pkh in
|
||||||
|
|
||||||
block_fork b >>=? fun (blk_a, blk_b) ->
|
block_fork b >>=? fun (blk_a, blk_b) ->
|
||||||
get_first_different_endorsers (B blk_a)
|
Context.get_endorser (B blk_a) >>=? fun (endorser_a, _) ->
|
||||||
>>=? fun (_endorser_a, endorser_b) ->
|
Op.endorsement ~delegate:endorser_a (B blk_a) () >>=? fun endorsement_a ->
|
||||||
|
Context.get_endorser (B blk_b) >>=? fun (endorser_b, _) ->
|
||||||
|
let delegate =
|
||||||
|
if Signature.Public_key_hash.equal pkh1 endorser_b
|
||||||
|
then pkh2
|
||||||
|
else pkh1
|
||||||
|
in
|
||||||
|
Op.endorsement ~delegate (B blk_b) () >>=? fun endorsement_b ->
|
||||||
|
|
||||||
Op.endorsement ~delegate:endorser_b.delegate (B blk_a) () >>=? fun endorsement_a ->
|
Op.double_endorsement (B blk_b) endorsement_a endorsement_b >>=? fun operation ->
|
||||||
Op.endorsement ~delegate:endorser_b.delegate (B blk_b) () >>=? fun endorsement_b ->
|
Block.bake ~operation blk_b >>= fun e ->
|
||||||
|
|
||||||
Op.double_endorsement (B blk_a) endorsement_a endorsement_b >>=? fun operation ->
|
|
||||||
Block.bake ~operation blk_a >>= fun e ->
|
|
||||||
Assert.proto_error ~loc:__LOC__ e begin function
|
Assert.proto_error ~loc:__LOC__ e begin function
|
||||||
| Operation_repr.Invalid_signature -> true
|
| Baking.Unexpected_endorsement -> true
|
||||||
| _ -> false end
|
| _ -> false end
|
||||||
|
|
||||||
let tests = [
|
let tests = [
|
||||||
Test.tztest "valid double endorsement evidence" `Quick valid_double_endorsement_evidence ;
|
Test.tztest "valid double endorsement evidence" `Quick valid_double_endorsement_evidence ;
|
||||||
|
|
||||||
Test.tztest "invalid double endorsement evidence" `Quick invalid_double_endorsement ;
|
Test.tztest "invalid double endorsement evidence" `Quick invalid_double_endorsement ;
|
||||||
Test.tztest "too early double endorsement evidence" `Quick too_early_double_endorsement_evidence ;
|
Test.tztest "too early double endorsement evidence" `Quick too_early_double_endorsement_evidence ;
|
||||||
Test.tztest "too late double endorsement evidence" `Quick too_late_double_endorsement_evidence ;
|
Test.tztest "too late double endorsement evidence" `Quick too_late_double_endorsement_evidence ;
|
||||||
Test.tztest "different delegates" `Quick different_delegates ;
|
Test.tztest "different delegates" `Quick different_delegates ;
|
||||||
Test.tztest "wrong delegate" `Quick wrong_delegate ;
|
Test.tztest "wrong delegate" `Quick wrong_delegate ;
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ let max_endorsement () =
|
|||||||
(B b) ~nb_endorsement endorser_account previous_balance
|
(B b) ~nb_endorsement endorser_account previous_balance
|
||||||
) (List.combine delegates previous_balances)
|
) (List.combine delegates previous_balances)
|
||||||
|
|
||||||
(** Check that an endorser balance is consistent with a different piority *)
|
(** Check that an endorser balance is consistent with a different priority *)
|
||||||
let consistent_priority () =
|
let consistent_priority () =
|
||||||
Context.init 32 >>=? fun (b, _) ->
|
Context.init 32 >>=? fun (b, _) ->
|
||||||
Block.get_next_baker ~policy:(By_priority 15) b >>=? fun (baker_account, _, _) ->
|
Block.get_next_baker ~policy:(By_priority 15) b >>=? fun (baker_account, _, _) ->
|
||||||
@ -122,7 +122,7 @@ let consistent_priority () =
|
|||||||
assert_endorser_balance_consistency ~loc:__LOC__ ~priority:15
|
assert_endorser_balance_consistency ~loc:__LOC__ ~priority:15
|
||||||
(B b) ~nb_endorsement:(List.length endorser.slots) endorser.delegate balance
|
(B b) ~nb_endorsement:(List.length endorser.slots) endorser.delegate balance
|
||||||
|
|
||||||
(** Check every 32 endorser's balances are consistent with a different piority *)
|
(** Check every 32 endorser's balances are consistent with a different priority *)
|
||||||
let consistent_priorities () =
|
let consistent_priorities () =
|
||||||
let priorities = 15 -- 31 in
|
let priorities = 15 -- 31 in
|
||||||
Context.init 64 >>=? fun (b, _) ->
|
Context.init 64 >>=? fun (b, _) ->
|
||||||
@ -178,7 +178,7 @@ let wrong_endorsement_predecessor () =
|
|||||||
|
|
||||||
Context.get_endorser (B b) >>=? fun (genesis_endorser, _slots) ->
|
Context.get_endorser (B b) >>=? fun (genesis_endorser, _slots) ->
|
||||||
Block.bake b >>=? fun b' ->
|
Block.bake b >>=? fun b' ->
|
||||||
Op.endorsement ~delegate:genesis_endorser ~signing_context:(B b') (B b) () >>=? fun operation ->
|
Op.endorsement ~delegate:genesis_endorser ~signing_context:(B b) (B b') () >>=? fun operation ->
|
||||||
let operation = Operation.pack operation in
|
let operation = Operation.pack operation in
|
||||||
Block.bake ~operation b' >>= fun res ->
|
Block.bake ~operation b' >>= fun res ->
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ let duplicate_endorsement () =
|
|||||||
Incremental.add_operation inc operation >>= fun res ->
|
Incremental.add_operation inc operation >>= fun res ->
|
||||||
|
|
||||||
Assert.proto_error ~loc:__LOC__ res begin function
|
Assert.proto_error ~loc:__LOC__ res begin function
|
||||||
| Baking.Unexpected_endorsement -> true
|
| Apply.Duplicate_endorsement _ -> true
|
||||||
| _ -> false
|
| _ -> false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -224,8 +224,7 @@ let no_enough_for_deposit () =
|
|||||||
Error_monad.map_s (fun c ->
|
Error_monad.map_s (fun c ->
|
||||||
Context.Contract.manager (B b) c >>=? fun m -> return (m, c)) contracts >>=?
|
Context.Contract.manager (B b) c >>=? fun m -> return (m, c)) contracts >>=?
|
||||||
fun managers ->
|
fun managers ->
|
||||||
let slot = 0 in
|
Context.get_endorser (B b) >>=? fun (endorser,_) ->
|
||||||
Context.get_endorser (B b) slot >>=? fun endorser ->
|
|
||||||
let _, contract_other_than_endorser =
|
let _, contract_other_than_endorser =
|
||||||
List.find (fun (c, _) -> not (Signature.Public_key_hash.equal c.Account.pkh endorser))
|
List.find (fun (c, _) -> not (Signature.Public_key_hash.equal c.Account.pkh endorser))
|
||||||
managers
|
managers
|
||||||
@ -234,7 +233,7 @@ let no_enough_for_deposit () =
|
|||||||
List.find (fun (c, _) -> (Signature.Public_key_hash.equal c.Account.pkh endorser))
|
List.find (fun (c, _) -> (Signature.Public_key_hash.equal c.Account.pkh endorser))
|
||||||
managers
|
managers
|
||||||
in
|
in
|
||||||
Op.endorsement ~delegate:endorser (B b) [slot] >>=? fun op_endo ->
|
Op.endorsement ~delegate:endorser (B b) () >>=? fun op_endo ->
|
||||||
Context.Contract.balance (B b)
|
Context.Contract.balance (B b)
|
||||||
(Contract.implicit_contract endorser) >>=? fun initial_balance ->
|
(Contract.implicit_contract endorser) >>=? fun initial_balance ->
|
||||||
Op.transaction (B b) contract_of_endorser contract_other_than_endorser initial_balance >>=? fun op_trans ->
|
Op.transaction (B b) contract_of_endorser contract_other_than_endorser initial_balance >>=? fun op_trans ->
|
||||||
|
Loading…
Reference in New Issue
Block a user