diff --git a/src/proto_alpha/lib_protocol/test/delegation.ml b/src/proto_alpha/lib_protocol/test/delegation.ml index 956d9452a..816cfbb48 100644 --- a/src/proto_alpha/lib_protocol/test/delegation.ml +++ b/src/proto_alpha/lib_protocol/test/delegation.ml @@ -882,7 +882,7 @@ let valid_delegate_registration_switch_delegation_credit_debit amount () = Assert.equal_pkh ~loc:__LOC__ orig_delegate delegate_pkh (** C- a second self-delegation should raise an `Active_delegate` error *) -(* with implicit contract with some credits *) +(* with implicit contract with some credit *) let double_registration () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b >>=? fun i -> @@ -932,6 +932,37 @@ let double_registration_when_empty () = | Delegate_storage.Active_delegate -> true | _ -> false) +(* with implicit contract emptied then recredited after first self-delegation *) +let double_registration_when_recredited () = + Context.init 1 >>=? fun (b, bootstrap_contracts) -> + Incremental.begin_construction b >>=? fun i -> + let bootstrap = List.hd bootstrap_contracts in + let account = Account.new_account () in + let pkh = Account.(account.pkh) in + let impl_contract = Contract.implicit_contract pkh in + (* credit 1μꜩ+ check balance *) + Op.transaction (I i) bootstrap impl_contract Tez.one_mutez >>=? fun create_contract -> + Incremental.add_operation i create_contract >>=? fun i -> + Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.one_mutez >>=? fun _ -> + (* self delegation *) + Op.delegation (I i) impl_contract (Some pkh) >>=? fun self_delegation -> + Incremental.add_operation i self_delegation >>=? fun i -> + (* empty the delegate account *) + Op.transaction (I i) impl_contract bootstrap Tez.one_mutez >>=? fun empty_contract -> + Incremental.add_operation i empty_contract >>=? fun i -> + Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.zero >>=? fun _ -> + (* credit 1μꜩ+ check balance *) + Op.transaction (I i) bootstrap impl_contract Tez.one_mutez >>=? fun create_contract -> + Incremental.add_operation i create_contract >>=? fun i -> + Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.one_mutez >>=? fun _ -> + (* second self-delegation *) + Op.delegation (I i) impl_contract (Some pkh) >>=? fun second_registration -> + Incremental.add_operation i second_registration >>= fun err -> + + Assert.proto_error ~loc:__LOC__ err (function + | Delegate_storage.Active_delegate -> true + | _ -> false) + let tests_delegate_registration = [ (*** unregistered delegate key: no self-delegation ***) @@ -1012,6 +1043,7 @@ let tests_delegate_registration = (*** double registration ***) Test.tztest "double registration" `Quick double_registration ; Test.tztest "double registration when delegate account is emptied" `Quick double_registration_when_empty ; + Test.tztest "double registration when delegate account is emptied and then recredited" `Quick double_registration_when_recredited ; ]