Alpha: fix tests w.r.t. the new origination policy

This commit is contained in:
Benjamin Canou 2018-11-21 20:00:12 +01:00 committed by Pierre Boutillier
parent a991396e10
commit aebe8319d5
No known key found for this signature in database
GPG Key ID: C2F73508B56A193C
2 changed files with 24 additions and 14 deletions

View File

@ -153,7 +153,9 @@ let deactivation_then_empty_then_self_delegation () =
Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> Context.Contract.balance (B b) deactivated_contract >>=? fun balance ->
let sink_account = Account.new_account () in let sink_account = Account.new_account () in
let sink_contract = Contract.implicit_contract sink_account.pkh 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 -> Block.bake ~policy:(By_account m2.pkh) ~operation:empty_contract b >>=? fun b ->
(* self delegation *) (* self delegation *)
Op.delegation (B b) deactivated_contract (Some deactivated_account.pkh) >>=? fun 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 () = let deactivation_then_empty_then_self_delegation_then_recredit () =
run_until_deactivation () >>=? run_until_deactivation () >>=?
fun (b, ((deactivated_contract, deactivated_account) as deactivated, start_balance), fun (b, ((deactivated_contract, deactivated_account) as deactivated, balance),
(_a2, m2)) -> (_a2, m2)) ->
(* empty the contract *) (* empty the contract *)
Context.Contract.balance (B b) deactivated_contract >>=? fun balance ->
let sink_account = Account.new_account () in let sink_account = Account.new_account () in
let sink_contract = Contract.implicit_contract sink_account.pkh 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 -> Block.bake ~policy:(By_account m2.pkh) ~operation:empty_contract b >>=? fun b ->
(* self delegation *) (* self delegation *)
Op.delegation (B b) deactivated_contract (Some deactivated_account.pkh) >>=? fun 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 -> Block.bake ~policy:(By_account m2.pkh) ~operation:self_delegation b >>=? fun b ->
(* recredit *) (* 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 -> Block.bake ~policy:(By_account m2.pkh) ~operation:recredit_contract b >>=? fun b ->
check_activate_staking_balance ~loc:__LOC__ ~deactivated:false b deactivated >>=? fun () -> check_activate_staking_balance ~loc:__LOC__ ~deactivated:false b deactivated >>=? fun () ->
Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> 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 check_rolls b deactivated_account
let delegation () = let delegation () =
@ -192,7 +195,6 @@ let delegation () =
let m3 = Account.new_account () in let m3 = Account.new_account () in
Account.add_account m3; 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) a1 >>=? fun m1 ->
Context.Contract.manager (B b) a2 >>=? fun m2 -> Context.Contract.manager (B b) a2 >>=? fun m2 ->
let a3 = Contract.implicit_contract m3.pkh in let a3 = Contract.implicit_contract m3.pkh in
@ -205,7 +207,7 @@ let delegation () =
assert (Signature.Public_key_hash.equal pkh m1.pkh) assert (Signature.Public_key_hash.equal pkh m1.pkh)
end; 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 -> Block.bake ~policy:(By_account m2.pkh) b ~operation:transact >>=? fun b ->

View File

@ -47,13 +47,21 @@ open Test_tez
- A block that added a valid operation - A block that added a valid operation
- 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 -> Tez.(+?) fee amount >>?= fun amount_fee ->
Context.Contract.balance (I b) src >>=? fun bal_src -> Context.Contract.balance (I b) src >>=? fun bal_src ->
Context.Contract.balance (I b) dst >>=? fun bal_dst -> Context.Contract.balance (I b) dst >>=? fun bal_dst ->
Op.transaction (I b) ~fee src dst amount >>=? fun op -> Op.transaction (I b) ~fee src dst amount >>=? fun op ->
Incremental.add_operation ?expect_failure b op >>=? fun b -> 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 () -> Assert.balance_was_credited ~loc (I b) dst bal_dst amount >>=? fun () ->
return (b, op) return (b, op)
@ -264,14 +272,14 @@ let transfer_from_implicit_to_implicit_contract () =
let src = Contract.implicit_contract account_a.Account.pkh in 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 3L >>=? fun amount1 ->
two_nth_of_balance b bootstrap_contract 10L >>=? fun fee1 -> 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, _) -> bootstrap_contract src amount1 >>=? fun (b, _) ->
(* create an implicit contract as a destination contract *) (* create an implicit contract as a destination contract *)
let dest = Contract.implicit_contract account_b.pkh in 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 4L >>=? fun amount2 ->
two_nth_of_balance b bootstrap_contract 10L >>=? fun fee2 -> two_nth_of_balance b bootstrap_contract 10L >>=? fun fee2 ->
(* transfer from implicit contract to another implicit contract *) (* 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, _) -> src dest amount2 >>=? fun (b, _) ->
Incremental.finalize_block b >>=? fun _ -> Incremental.finalize_block b >>=? fun _ ->
return_unit return_unit
@ -287,7 +295,7 @@ let transfer_from_implicit_to_originated_contract () =
Incremental.begin_construction b >>=? fun b -> Incremental.begin_construction b >>=? fun b ->
two_nth_of_balance b bootstrap_contract 3L >>=? fun amount1 -> two_nth_of_balance b bootstrap_contract 3L >>=? fun amount1 ->
(* transfer the money to implicit contract *) (* 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, _) -> >>=? fun (b, _) ->
(* originated contract *) (* originated contract *)
Op.origination (I b) contract >>=? fun (operation, new_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) -> Op.origination (I b) contract_1 >>=? fun (operation, new_contract) ->
Incremental.add_operation b operation >>=? fun b -> Incremental.add_operation b operation >>=? fun b ->
(* transfer from originated contract to implicit contract *) (* 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, _) -> >>=? fun (b, _) ->
Incremental.finalize_block b >>=? fun _ -> Incremental.finalize_block b >>=? fun _ ->
return_unit return_unit