From 1b6eca4d89678d155d7be09cd4d07ea5e66488f2 Mon Sep 17 00:00:00 2001 From: bruno Date: Thu, 28 Jun 2018 16:55:24 +0200 Subject: [PATCH] Alpha/Tests/delegation: add double delegation when empty test Slight improvement of double delegation test --- .../lib_protocol/test/delegation.ml | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/delegation.ml b/src/proto_alpha/lib_protocol/test/delegation.ml index a8e7a19b0..956d9452a 100644 --- a/src/proto_alpha/lib_protocol/test/delegation.ml +++ b/src/proto_alpha/lib_protocol/test/delegation.ml @@ -893,13 +893,41 @@ let double_registration () = (* 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 -> - (* return_unit *) + 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 -> (* 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) + +(* with implicit contract emptied after first self-delegation *) +let double_registration_when_empty () = + 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 _ -> + (* 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) @@ -983,6 +1011,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 ; ]