From 1368eed80c5448159c5f1766e693d68f26634bbd Mon Sep 17 00:00:00 2001 From: bruno Date: Fri, 29 Jun 2018 17:11:53 +0200 Subject: [PATCH] Alpha/Tests/delegation: deactivation and self-delegation when empty --- src/proto_alpha/lib_protocol/test/rolls.ml | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/proto_alpha/lib_protocol/test/rolls.ml b/src/proto_alpha/lib_protocol/test/rolls.ml index 1404b2e37..2301ab998 100644 --- a/src/proto_alpha/lib_protocol/test/rolls.ml +++ b/src/proto_alpha/lib_protocol/test/rolls.ml @@ -129,6 +129,46 @@ let deactivation_then_self_delegation () = Assert.equal_tez ~loc:__LOC__ start_balance balance >>=? fun () -> check_rolls b deactivated_account +let deactivation_then_empty_then_self_delegation () = + run_until_deactivation () >>=? + fun (b, ((deactivated_contract, deactivated_account) as deactivated, _start_balance), + (_a2, m2)) -> + (* empty the contract *) + Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> + let sink_account = Account.new_account () in + let sink_contract = Contract.implicit_contract sink_account.pkh in + Op.transaction (B b) deactivated_contract sink_contract balance >>=? fun empty_contract -> + Block.bake ~policy:(By_account m2.pkh) ~operation:empty_contract b >>=? fun b -> + (* self delegation *) + Op.delegation (B b) deactivated_contract (Some deactivated_account.pkh) >>=? fun self_delegation -> + Block.bake ~policy:(By_account m2.pkh) ~operation:self_delegation b >>=? fun b -> + + check_activate_staking_balance ~loc:__LOC__ ~deactivated:false b deactivated >>=? fun () -> + Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> + Assert.equal_tez ~loc:__LOC__ Tez.zero balance >>=? fun () -> + check_rolls b deactivated_account + +let deactivation_then_empty_then_self_delegation_then_recredit () = + run_until_deactivation () >>=? + fun (b, ((deactivated_contract, deactivated_account) as deactivated, start_balance), + (_a2, m2)) -> + (* empty the contract *) + Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> + let sink_account = Account.new_account () in + let sink_contract = Contract.implicit_contract sink_account.pkh in + Op.transaction (B b) deactivated_contract sink_contract balance >>=? fun empty_contract -> + Block.bake ~policy:(By_account m2.pkh) ~operation:empty_contract b >>=? fun b -> + (* self delegation *) + Op.delegation (B b) deactivated_contract (Some deactivated_account.pkh) >>=? fun self_delegation -> + Block.bake ~policy:(By_account m2.pkh) ~operation:self_delegation b >>=? fun b -> + (* recredit *) + Op.transaction (B b) sink_contract deactivated_contract balance >>=? fun recredit_contract -> + Block.bake ~policy:(By_account m2.pkh) ~operation:recredit_contract b >>=? fun b -> + + check_activate_staking_balance ~loc:__LOC__ ~deactivated:false b deactivated >>=? fun () -> + Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> + Assert.equal_tez ~loc:__LOC__ start_balance balance >>=? fun () -> + check_rolls b deactivated_account let delegation () = Context.init 2 >>=? fun (b,accounts) -> @@ -180,5 +220,7 @@ let tests = [ Test.tztest "simple staking rights after baking" `Quick (simple_staking_rights_after_baking) ; Test.tztest "deactivation then bake" `Quick (deactivation_then_bake) ; Test.tztest "deactivation then self delegation" `Quick (deactivation_then_self_delegation) ; + Test.tztest "deactivation then empty then self delegation" `Quick (deactivation_then_empty_then_self_delegation) ; + Test.tztest "deactivation then empty then self delegation then recredit" `Quick (deactivation_then_empty_then_self_delegation_then_recredit) ; Test.tztest "delegation" `Quick (delegation) ; ]