From aebe8319d53086ca5d1016691c57540b9edbcf86 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Wed, 21 Nov 2018 20:00:12 +0100 Subject: [PATCH] Alpha: fix tests w.r.t. the new origination policy --- src/proto_alpha/lib_protocol/test/rolls.ml | 18 +++++++++-------- src/proto_alpha/lib_protocol/test/transfer.ml | 20 +++++++++++++------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/rolls.ml b/src/proto_alpha/lib_protocol/test/rolls.ml index e30266482..160209c71 100644 --- a/src/proto_alpha/lib_protocol/test/rolls.ml +++ b/src/proto_alpha/lib_protocol/test/rolls.ml @@ -153,7 +153,9 @@ let deactivation_then_empty_then_self_delegation () = 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 -> + Context.get_constants (B b) >>=? fun { parametric = { origination_burn } } -> + let amount = match Tez.(balance -? origination_burn) with Ok r -> r | Error _ -> assert false in + Op.transaction (B b) deactivated_contract sink_contract amount >>=? 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 -> @@ -166,24 +168,25 @@ let deactivation_then_empty_then_self_delegation () = let deactivation_then_empty_then_self_delegation_then_recredit () = run_until_deactivation () >>=? - fun (b, ((deactivated_contract, deactivated_account) as deactivated, start_balance), + fun (b, ((deactivated_contract, deactivated_account) as deactivated, 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 -> + Context.get_constants (B b) >>=? fun { parametric = { origination_burn } } -> + let amount = match Tez.(balance -? origination_burn) with Ok r -> r | Error _ -> assert false in + Op.transaction (B b) deactivated_contract sink_contract amount >>=? 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 -> + Op.transaction (B b) sink_contract deactivated_contract amount >>=? 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 () -> + Assert.equal_tez ~loc:__LOC__ amount balance >>=? fun () -> check_rolls b deactivated_account let delegation () = @@ -192,7 +195,6 @@ let delegation () = let m3 = Account.new_account () in Account.add_account m3; - Context.Contract.balance (B b) a1 >>=? fun balance -> Context.Contract.manager (B b) a1 >>=? fun m1 -> Context.Contract.manager (B b) a2 >>=? fun m2 -> let a3 = Contract.implicit_contract m3.pkh in @@ -205,7 +207,7 @@ let delegation () = assert (Signature.Public_key_hash.equal pkh m1.pkh) end; - Op.transaction (B b) a1 a3 balance >>=? fun transact -> + Op.transaction (B b) a1 a3 Tez.fifty_cents >>=? fun transact -> Block.bake ~policy:(By_account m2.pkh) b ~operation:transact >>=? fun b -> diff --git a/src/proto_alpha/lib_protocol/test/transfer.ml b/src/proto_alpha/lib_protocol/test/transfer.ml index 32d796021..99a32dace 100644 --- a/src/proto_alpha/lib_protocol/test/transfer.ml +++ b/src/proto_alpha/lib_protocol/test/transfer.ml @@ -47,13 +47,21 @@ open Test_tez - A block that added a valid operation - a valid operation *) -let transfer_and_check_balances ~loc b ?(fee=Tez.zero) ?expect_failure src dst amount = +let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee=Tez.zero) ?expect_failure src dst amount = Tez.(+?) fee amount >>?= fun amount_fee -> Context.Contract.balance (I b) src >>=? fun bal_src -> Context.Contract.balance (I b) dst >>=? fun bal_dst -> Op.transaction (I b) ~fee src dst amount >>=? fun op -> Incremental.add_operation ?expect_failure b op >>=? fun b -> - Assert.balance_was_debited ~loc (I b) src bal_src amount_fee >>=? fun () -> + Context.get_constants (I b) >>=? fun { parametric = { origination_burn } } -> + let amount_fee_maybe_burn = + if with_burn then + match Tez.(amount_fee +? origination_burn) with + | Ok r -> r + | Error _ -> assert false + else + amount_fee in + Assert.balance_was_debited ~loc (I b) src bal_src amount_fee_maybe_burn >>=? fun () -> Assert.balance_was_credited ~loc (I b) dst bal_dst amount >>=? fun () -> return (b, op) @@ -264,14 +272,14 @@ let transfer_from_implicit_to_implicit_contract () = let src = Contract.implicit_contract account_a.Account.pkh in two_nth_of_balance b bootstrap_contract 3L >>=? fun amount1 -> two_nth_of_balance b bootstrap_contract 10L >>=? fun fee1 -> - transfer_and_check_balances ~loc:__LOC__ ~fee:fee1 b + transfer_and_check_balances ~with_burn:true ~loc:__LOC__ ~fee:fee1 b bootstrap_contract src amount1 >>=? fun (b, _) -> (* create an implicit contract as a destination contract *) let dest = Contract.implicit_contract account_b.pkh in two_nth_of_balance b bootstrap_contract 4L >>=? fun amount2 -> two_nth_of_balance b bootstrap_contract 10L >>=? fun fee2 -> (* transfer from implicit contract to another implicit contract *) - transfer_and_check_balances ~loc:__LOC__ ~fee:fee2 b + transfer_and_check_balances ~with_burn:true ~loc:__LOC__ ~fee:fee2 b src dest amount2 >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit @@ -287,7 +295,7 @@ let transfer_from_implicit_to_originated_contract () = Incremental.begin_construction b >>=? fun b -> two_nth_of_balance b bootstrap_contract 3L >>=? fun amount1 -> (* transfer the money to implicit contract *) - transfer_and_check_balances ~loc:__LOC__ b bootstrap_contract src amount1 + transfer_and_check_balances ~with_burn:true ~loc:__LOC__ b bootstrap_contract src amount1 >>=? fun (b, _) -> (* originated contract *) Op.origination (I b) contract >>=? fun (operation, new_contract) -> @@ -328,7 +336,7 @@ let transfer_from_originated_to_implicit () = Op.origination (I b) contract_1 >>=? fun (operation, new_contract) -> Incremental.add_operation b operation >>=? fun b -> (* transfer from originated contract to implicit contract *) - transfer_and_check_balances ~loc:__LOC__ b new_contract src Alpha_context.Tez.one + transfer_and_check_balances ~with_burn:true ~loc:__LOC__ b new_contract src Alpha_context.Tez.one_mutez >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit