diff --git a/manifest/main.ml b/manifest/main.ml index 8a8149d9d8ed1fe6daa9577eee9c8e6f0cdab59c..1fbe40703da8468561e0225cc568bcdabbb75c73 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -3171,6 +3171,25 @@ end = struct tezos_base_test_helpers |> open_; ] in + let _integration_precheck = + if N.(number >= 014) then + Some + (test + "main" + ~path:(path // "lib_protocol/test/integration/precheck") + ~opam:(sf "tezos-protocol-%s-tests" name_dash) + ~deps: + [ + alcotest_lwt; + tezos_base |> open_ ~m:"TzPervasives" + |> open_ ~m:"TzPervasives.Error_monad.Legacy_monad_globals"; + main |> open_; + client |> if_some |> open_; + test_helpers |> if_some |> open_; + tezos_base_test_helpers |> open_; + ]) + else None + in let _integration = test "main" diff --git a/src/proto_alpha/lib_protocol/test/helpers/incremental.ml b/src/proto_alpha/lib_protocol/test/helpers/incremental.ml index 3551de4e92c99ba0dfb87089a8b4ad9b2e11d3dd..c93dfd5c1d457e1fcae0e143418fe76f080cf3dd 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/incremental.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/incremental.ml @@ -156,9 +156,7 @@ let detect_script_failure : in fun {contents} -> detect_script_failure contents -let add_operation ?expect_failure ?expect_apply_failure ?(check_size = true) st - op = - let open Apply_results in +let apply_operation ?(check_size = true) st op = (if check_size then let operation_size = Data_encoding.Binary.length Operation.encoding op in if operation_size > Constants_repr.max_operation_data_length then @@ -168,7 +166,27 @@ let add_operation ?expect_failure ?expect_apply_failure ?(check_size = true) st "The operation size is %d, it exceeds the constant maximum size %d" operation_size Constants_repr.max_operation_data_length))) ; - apply_operation st.state op >|= Environment.wrap_tzresult >>= fun result -> + apply_operation st.state op >|= Environment.wrap_tzresult + +let precheck_operation ?expect_failure ?check_size st op = + apply_operation ?check_size st op >>= fun result -> + match (expect_failure, result) with + | Some _, Ok _ -> failwith "Error expected while prechecking operation" + | Some f, Error err -> f err >|=? fun () -> st + | None, Error err -> failwith "Error %a was not expected" pp_print_trace err + | None, Ok (state, (Operation_metadata _ as metadata)) + | None, Ok (state, (No_operation_metadata as metadata)) -> + return + { + st with + state; + rev_operations = op :: st.rev_operations; + rev_tickets = metadata :: st.rev_tickets; + } + +let add_operation ?expect_failure ?expect_apply_failure ?check_size st op = + let open Apply_results in + apply_operation ?check_size st op >>= fun result -> match (expect_failure, result) with | Some _, Ok _ -> failwith "Error expected while adding operation" | Some f, Error err -> f err >|=? fun () -> st diff --git a/src/proto_alpha/lib_protocol/test/helpers/incremental.mli b/src/proto_alpha/lib_protocol/test/helpers/incremental.mli index f6dab21cb0433d8eb57af2890eaa2ebeced79d30..53a824fde6b5df853bb3ebc7410fbbc3d527f17e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/incremental.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/incremental.mli @@ -40,6 +40,15 @@ val validation_state : incremental -> validation_state val level : incremental -> int32 +(** [begin_construction ?mempool_mode predecessor] uses + [Main.begin_construction] to create a validation state on top of + [predecessor]. + + Optional arguments allow to override defaults: + + {ul {li [?mempool_mode:bool]: set the validation state to + [partial_construction], [construction] otherwise (default).}} +*) val begin_construction : ?timestamp:Time.Protocol.t -> ?seed_nonce_hash:Nonce_hash.t -> @@ -48,6 +57,51 @@ val begin_construction : Block.t -> incremental tzresult Lwt.t +(** [precheck_operation ?expect_failure ?check_size i op] tries to + precheck [op] in the validation state of [i]. If the precheck + succeeds, the function returns the incremental value with a + validation state updated after the precheck. Otherwise raise the + error from the prechecking of [op]. + + Optional arguments allow to override defaults: + + {ul {li [?expect_failure:(error list -> unit tzresult Lwt.t)]: + precheck of [op] is expected to fail and [expect_failure] should + handle the error. In case precheck does not fail and an + [expect_failure] is provided, [precheck_operation] fails.} + + {li [?check_size:bool]: enable the check that an operation size + should not exceed [Constants_repr.max_operation_data_length]. + Enabled (set to [true]) by default. }} *) +val precheck_operation : + ?expect_failure:(error list -> unit tzresult Lwt.t) -> + ?check_size:bool -> + incremental -> + Operation.packed -> + incremental tzresult Lwt.t + +(** [add_operation ?expect_failure ?expect_apply_failure ?check_size i + op] tries to apply [op] in the validation state of [i]. If the + precheck of [op] succeeds, the function returns the incremental + value with a validation state updated after the application of + [op]. Otherwise raise the error from the prechecking of [op]. + + Optional arguments allow to override defaults: + + {ul {li [?expect_failure:(error list -> unit tzresult Lwt.t)]: + precheck of [op] is expected to fail and [expect_failure] should + handle the error. In case precheck does not fail and + [expect_failure] is provided, [precheck_operation] fails.} + + {ul {li [?expect_apply_failure:(error list -> unit tzresult + Lwt.t)]: application of [op] is expected to fail and + [expect_apply_failure] should handle the error. In case the + application of [op] does not fail and [expect_apply_failure] is + provided, [add_operation] fails.} + + {li [?check_size:bool]: enable the check that an operation size + should not exceed [Constants_repr.max_operation_data_length]. + Enabled (set to [true]) by default. }} *) val add_operation : ?expect_failure:(error list -> unit tzresult Lwt.t) -> ?expect_apply_failure:(error list -> unit tzresult Lwt.t) -> @@ -56,6 +110,10 @@ val add_operation : Operation.packed -> incremental tzresult Lwt.t +(** [finalize_block i] creates a [Block.t] based on the + validation_state and the operations contained in [i]. The function + calls [Main.finalize_block] to compute a new context. +*) val finalize_block : incremental -> Block.t tzresult Lwt.t val rpc_ctxt : incremental Environment.RPC_context.simple diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 53da6f52100bf357dc2340db844c18e7c3156b27..54ad5fe783c7b6594426ccd10c08e1c1730d077b 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -255,13 +255,7 @@ let combine_operations ?public_key ?counter ?spurious_operation ~source ctxt Environment.wrap_tzresult @@ Operation.of_list operations >>?= fun operations -> return @@ sign account.sk ctxt operations -(* FIXME tezos/tezos#2979 - - The [force_reveal] option should default to false, but this - requires going over nearly all existing protocol operation - integration tests. Instead, we went for the minimal interference - path and left original behaviour as default. *) -let manager_operation ?(force_reveal = true) ?counter ?(fee = Tez.zero) +let manager_operation ?(force_reveal = false) ?counter ?(fee = Tez.zero) ?(gas_limit = High) ?storage_limit ?public_key ~source ctxt operation = (match counter with | Some counter -> return counter diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index df18aab209c118a35895d7e9594031a18076a5f1..4432852798cd10e8dbaf01be9702d68dcaf366d5 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -94,7 +94,7 @@ val transaction : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val unsafe_transaction : ?force_reveal:bool -> ?counter:counter -> @@ -174,7 +174,7 @@ val failing_noop : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val contract_origination : ?force_reveal:bool -> ?counter:Z.t -> @@ -309,7 +309,7 @@ val tx_rollup_origination : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val tx_rollup_submit_batch : ?force_reveal:bool -> ?counter:Z.t -> @@ -330,7 +330,7 @@ val tx_rollup_submit_batch : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val tx_rollup_commit : ?force_reveal:bool -> ?counter:Z.t -> @@ -350,7 +350,7 @@ val tx_rollup_commit : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default..}} *) val tx_rollup_return_bond : ?force_reveal:bool -> ?counter:Z.t -> @@ -369,7 +369,7 @@ val tx_rollup_return_bond : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val tx_rollup_finalize : ?force_reveal:bool -> ?counter:Z.t -> @@ -404,7 +404,7 @@ val tx_rollup_remove_commitment : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}} *) + yet. Disabled (set to [false]) by default.}} *) val tx_rollup_dispatch_tickets : ?force_reveal:bool -> ?counter:counter -> @@ -444,7 +444,7 @@ val tx_rollup_dispatch_tickets : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val transfer_ticket : ?force_reveal:bool -> ?counter:counter -> @@ -468,7 +468,7 @@ val transfer_ticket : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val tx_rollup_reject : ?force_reveal:bool -> ?counter:Z.t -> @@ -498,7 +498,7 @@ val tx_rollup_reject : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val sc_rollup_origination : ?force_reveal:bool -> ?counter:counter -> @@ -520,7 +520,7 @@ val sc_rollup_origination : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}} *) + yet. Disabled (set to [false]) by default.}} *) val sc_rollup_publish : ?force_reveal:bool -> ?counter:Z.t -> @@ -540,7 +540,7 @@ val sc_rollup_publish : {ul {li [?force_reveal:bool]: prepend the operation to reveal [source]'s public key if the latter has not been revealed - yet. Enabled (set to [true]) by default.}}*) + yet. Disabled (set to [false]) by default.}} *) val sc_rollup_cement : ?force_reveal:bool -> ?counter:Z.t -> diff --git a/src/proto_alpha/lib_protocol/test/helpers/transfers.ml b/src/proto_alpha/lib_protocol/test/helpers/transfers.ml index 086e7d4530bf4481c2b7dddfb248e90687d42487..66dbee89ca42362bbbd8ad3283c1dd14a238c20c 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/transfers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/transfers.ml @@ -35,6 +35,7 @@ let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee = Tez.zero) let* bal_dst = Context.Contract.balance (I b) dst in let* op = Op.transaction + ~force_reveal:true ~gas_limit:(Custom_gas (Alpha_context.Gas.Arith.integral_of_int_exn 3000)) (I b) ~fee diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml index ff23291382401122a1eb01b986c5221ba5decb9f..037c5a408f348f0cd21a8907befebf5c858560e5 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml @@ -256,7 +256,12 @@ let test_deactivation_then_empty_then_self_delegation_then_recredit () = let amount = match balance -? origination_burn with Ok r -> r | Error _ -> assert false in - Op.transaction (B b) deactivated_contract sink_contract amount + Op.transaction + ~force_reveal:true + (B b) + deactivated_contract + sink_contract + amount >>=? fun empty_contract -> Block.bake ~policy:(By_account m2.pkh) ~operation:empty_contract b >>=? fun b0 -> @@ -270,7 +275,12 @@ let test_deactivation_then_empty_then_self_delegation_then_recredit () = (* the account is still deactivated *) check_no_stake ~loc:__LOC__ b deactivated_account >>=? fun () -> (**** recredit *) - Op.transaction (B b1) sink_contract deactivated_contract amount + Op.transaction + ~force_reveal:true + (B b1) + sink_contract + deactivated_contract + amount >>=? fun recredit_contract -> Block.bake ~policy:(By_account m2.pkh) ~operation:recredit_contract b1 >>=? fun b2 -> @@ -304,12 +314,12 @@ let test_delegation () = | Some pkh -> assert (Signature.Public_key_hash.equal pkh m1.pkh)) ; let constants = Default_parameters.constants_test in let one_roll = constants.tokens_per_roll in - Op.transaction (B b) a1 a3 one_roll >>=? fun transact -> + Op.transaction ~force_reveal:true (B b) a1 a3 one_roll >>=? fun transact -> Block.bake ~policy:(By_account m2.pkh) b ~operation:transact >>=? fun b -> Context.Contract.delegate_opt (B b) a3 >>=? fun delegate -> (match delegate with None -> () | Some _ -> assert false) ; check_no_stake ~loc:__LOC__ b m3 >>=? fun () -> - Op.delegation (B b) a3 (Some m3.pkh) >>=? fun delegation -> + Op.delegation ~force_reveal:true (B b) a3 (Some m3.pkh) >>=? fun delegation -> Block.bake ~policy:(By_account m2.pkh) b ~operation:delegation >>=? fun b -> Context.Contract.delegate_opt (B b) a3 >>=? fun delegate -> (match delegate with diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml index 086678fa2c547c7fe4262e04ebd7fe55e65dfbb0..7e2edd398781727dfc7e299a33d5ba1034c1fb9f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml @@ -141,13 +141,18 @@ let delegate_can_be_changed_from_unregistered_contract ~fee () = Context.Contract.balance (I i) bootstrap0 >>=? fun balance -> Incremental.add_operation i credit_contract >>=? fun i -> (* delegate to bootstrap0 *) - Op.delegation ~fee:Tez.zero (I i) unregistered (Some manager0.pkh) + Op.delegation + ~force_reveal:true + ~fee:Tez.zero + (I i) + unregistered + (Some manager0.pkh) >>=? fun set_delegate -> Incremental.add_operation i set_delegate >>=? fun i -> Context.Contract.delegate (I i) unregistered >>=? fun delegate -> Assert.equal_pkh ~loc:__LOC__ delegate manager0.pkh >>=? fun () -> (* change delegation to bootstrap1 *) - Op.delegation ~fee (I i) unregistered (Some manager1.pkh) + Op.delegation ~force_reveal:true ~fee (I i) unregistered (Some manager1.pkh) >>=? fun change_delegate -> if fee > balance then expect_too_low_balance_error i change_delegate else @@ -168,12 +173,23 @@ let delegate_can_be_removed_from_unregistered_contract ~fee () = Incremental.begin_construction b >>=? fun i -> Context.Contract.manager (I i) bootstrap >>=? fun manager -> let credit = of_int 10 in - Op.transaction ~fee:Tez.zero (I i) bootstrap unregistered credit + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + unregistered + credit >>=? fun credit_contract -> Context.Contract.balance (I i) bootstrap >>=? fun balance -> Incremental.add_operation i credit_contract >>=? fun i -> (* delegate to bootstrap *) - Op.delegation ~fee:Tez.zero (I i) unregistered (Some manager.pkh) + Op.delegation + ~force_reveal:true + ~fee:Tez.zero + (I i) + unregistered + (Some manager.pkh) >>=? fun set_delegate -> Incremental.add_operation i set_delegate >>=? fun i -> Context.Contract.delegate (I i) unregistered >>=? fun delegate -> @@ -504,12 +520,23 @@ let test_unregistered_delegate_key_init_delegation ~fee () = let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* initial credit for the delegated contract *) let credit = of_int 10 in - Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract credit + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + impl_contract + credit >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract credit >>=? fun _ -> (* try to delegate *) - Op.delegation ~fee (I i) impl_contract (Some unregistered_delegate_pkh) + Op.delegation + ~force_reveal:true + ~fee + (I i) + impl_contract + (Some unregistered_delegate_pkh) >>=? fun delegate_op -> if fee > credit then expect_too_low_balance_error i delegate_op else @@ -542,12 +569,23 @@ let test_unregistered_delegate_key_switch_delegation ~fee () = let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* initial credit for the delegated contract *) let credit = of_int 10 in - Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract credit + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + impl_contract + credit >>=? fun init_credit -> Incremental.add_operation i init_credit >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract credit >>=? fun _ -> (* set and check the initial delegate *) - Op.delegation ~fee:Tez.zero (I i) impl_contract (Some bootstrap_pkh) + Op.delegation + ~force_reveal:true + ~fee:Tez.zero + (I i) + impl_contract + (Some bootstrap_pkh) >>=? fun delegate_op -> Incremental.add_operation i delegate_op >>=? fun i -> Context.Contract.delegate (I i) bootstrap >>=? fun delegate_pkh -> @@ -617,7 +655,13 @@ let test_unregistered_delegate_key_init_delegation_credit ~fee ~amount () = let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) - Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract amount + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + impl_contract + amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> @@ -629,7 +673,12 @@ let test_unregistered_delegate_key_init_delegation_credit ~fee ~amount () = Incremental.add_operation i init_credit >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract balance >>=? fun _ -> (* try to delegate *) - Op.delegation ~fee (I i) impl_contract (Some unregistered_delegate_pkh) + Op.delegation + ~force_reveal:true + ~fee + (I i) + impl_contract + (Some unregistered_delegate_pkh) >>=? fun delegate_op -> if fee > credit then expect_too_low_balance_error i delegate_op else @@ -658,7 +707,13 @@ let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) - Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract amount + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + impl_contract + amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> @@ -670,7 +725,12 @@ let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Incremental.add_operation i init_credit >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract balance >>=? fun _ -> (* set and check the initial delegate *) - Op.delegation ~fee:Tez.zero (I i) impl_contract (Some bootstrap_pkh) + Op.delegation + ~force_reveal:true + ~fee:Tez.zero + (I i) + impl_contract + (Some bootstrap_pkh) >>=? fun delegate_op -> Incremental.add_operation i delegate_op >>=? fun i -> Context.Contract.delegate (I i) bootstrap >>=? fun delegate_pkh -> @@ -702,12 +762,13 @@ let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () let unregistered_pkh = Account.(unregistered_account.pkh) in let impl_contract = Contract.Implicit unregistered_pkh in (* credit + check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* debit + check balance *) - Op.transaction (I i) impl_contract bootstrap amount >>=? fun debit_contract -> + Op.transaction ~force_reveal:true (I i) impl_contract bootstrap amount + >>=? fun debit_contract -> Incremental.add_operation i debit_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.zero >>=? fun _ -> (* origination with delegate argument *) @@ -746,12 +807,24 @@ let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) - Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract amount + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + impl_contract + amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* debit + check balance *) - Op.transaction ~fee:Tez.zero (I i) impl_contract bootstrap amount + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + impl_contract + bootstrap + amount >>=? fun debit_contract -> Incremental.add_operation i debit_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.zero >>=? fun _ -> @@ -762,7 +835,12 @@ let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () Incremental.add_operation i credit_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract credit >>=? fun _ -> (* try to delegate *) - Op.delegation ~fee (I i) impl_contract (Some unregistered_delegate_pkh) + Op.delegation + ~force_reveal:true + ~fee + (I i) + impl_contract + (Some unregistered_delegate_pkh) >>=? fun delegate_op -> if fee > credit then expect_too_low_balance_error i delegate_op else @@ -792,12 +870,19 @@ let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) - Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract amount + Op.transaction + ~force_reveal:true + ~fee:Tez.zero + (I i) + bootstrap + impl_contract + amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* debit + check balance *) - Op.transaction (I i) impl_contract bootstrap amount >>=? fun debit_contract -> + Op.transaction ~force_reveal:true (I i) impl_contract bootstrap amount + >>=? fun debit_contract -> Incremental.add_operation i debit_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.zero >>=? fun _ -> (* delegation - initial credit for the delegated contract *) @@ -807,7 +892,12 @@ let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount Incremental.add_operation i credit_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract credit >>=? fun _ -> (* set and check the initial delegate *) - Op.delegation ~fee:Tez.zero (I i) impl_contract (Some bootstrap_pkh) + Op.delegation + ~force_reveal:true + ~fee:Tez.zero + (I i) + impl_contract + (Some bootstrap_pkh) >>=? fun delegate_op -> Incremental.add_operation i delegate_op >>=? fun i -> Context.Contract.delegate (I i) bootstrap >>=? fun delegate_pkh -> @@ -857,12 +947,12 @@ let test_failed_self_delegation_emptied_implicit_contract amount () = let unregistered_pkh = Account.(account.pkh) in let impl_contract = Contract.Implicit unregistered_pkh in (* credit implicit contract and check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* empty implicit contract and check balance *) - Op.transaction (I i) impl_contract bootstrap amount + Op.transaction ~force_reveal:true (I i) impl_contract bootstrap amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract Tez.zero >>=? fun _ -> @@ -883,12 +973,16 @@ let test_emptying_delegated_implicit_contract_fails amount () = let unregistered_pkh = Account.(account.pkh) in let impl_contract = Contract.Implicit unregistered_pkh in (* credit unregistered implicit contract and check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* delegate the contract to the bootstrap *) - Op.delegation (I i) impl_contract (Some bootstrap_manager.pkh) + Op.delegation + ~force_reveal:true + (I i) + impl_contract + (Some bootstrap_manager.pkh) >>=? fun delegation -> Incremental.add_operation i delegation >>=? fun i -> (* empty implicit contract and expect error since the contract is delegated *) @@ -917,12 +1011,12 @@ let test_valid_delegate_registration_init_delegation_credit amount () = let delegate_pkh = Account.(delegate_account.pkh) in let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ + check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* self delegation + verification *) - Op.delegation (I i) impl_contract (Some delegate_pkh) + Op.delegation ~force_reveal:true (I i) impl_contract (Some delegate_pkh) >>=? fun self_delegation -> Incremental.add_operation i self_delegation >>=? fun i -> Context.Contract.delegate (I i) impl_contract >>=? fun delegate -> @@ -941,7 +1035,7 @@ let test_valid_delegate_registration_init_delegation_credit amount () = | _ -> false) >>=? fun _ -> (* delegation to the newly registered key *) - Op.delegation (I i) delegator (Some delegate_account.pkh) + Op.delegation ~force_reveal:true (I i) delegator (Some delegate_account.pkh) >>=? fun delegation -> Incremental.add_operation i delegation >>=? fun i -> (* check delegation *) @@ -960,12 +1054,12 @@ let test_valid_delegate_registration_switch_delegation_credit amount () = let delegate_pkh = Account.(delegate_account.pkh) in let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ + check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* self delegation + verification *) - Op.delegation (I i) impl_contract (Some delegate_pkh) + Op.delegation ~force_reveal:true (I i) impl_contract (Some delegate_pkh) >>=? fun self_delegation -> Incremental.add_operation i self_delegation >>=? fun i -> Context.Contract.delegate (I i) impl_contract >>=? fun delegate -> @@ -978,7 +1072,7 @@ let test_valid_delegate_registration_switch_delegation_credit amount () = >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> Context.Contract.manager (I i) bootstrap >>=? fun bootstrap_manager -> - Op.delegation (I i) delegator (Some bootstrap_manager.pkh) + Op.delegation ~force_reveal:true (I i) delegator (Some bootstrap_manager.pkh) >>=? fun delegation -> Incremental.add_operation i delegation >>=? fun i -> (* test delegate of new contract is bootstrap *) @@ -1001,12 +1095,12 @@ let test_valid_delegate_registration_init_delegation_credit_debit amount () = let delegate_pkh = Account.(delegate_account.pkh) in let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ+ check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* self delegation + verification *) - Op.delegation (I i) impl_contract (Some delegate_pkh) + Op.delegation ~force_reveal:true (I i) impl_contract (Some delegate_pkh) >>=? fun self_delegation -> Incremental.add_operation i self_delegation >>=? fun i -> Context.Contract.delegate (I i) impl_contract >>=? fun delegate -> @@ -1035,7 +1129,7 @@ let test_valid_delegate_registration_init_delegation_credit_debit amount () = | _ -> false) >>=? fun _ -> (* delegation to the newly registered key *) - Op.delegation (I i) delegator (Some delegate_account.pkh) + Op.delegation ~force_reveal:true (I i) delegator (Some delegate_account.pkh) >>=? fun delegation -> Incremental.add_operation i delegation >>=? fun i -> (* check delegation *) @@ -1055,12 +1149,12 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = let delegate_pkh = Account.(delegate_account.pkh) in let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ + check balance *) - Op.transaction (I i) bootstrap impl_contract amount + Op.transaction ~force_reveal:true (I i) bootstrap impl_contract amount >>=? fun create_contract -> Incremental.add_operation i create_contract >>=? fun i -> Assert.balance_is ~loc:__LOC__ (I i) impl_contract amount >>=? fun _ -> (* self delegation + verification *) - Op.delegation (I i) impl_contract (Some delegate_pkh) + Op.delegation ~force_reveal:true (I i) impl_contract (Some delegate_pkh) >>=? fun self_delegation -> Incremental.add_operation i self_delegation >>=? fun i -> Context.Contract.delegate (I i) impl_contract >>=? fun delegate -> @@ -1080,7 +1174,7 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> Context.Contract.manager (I i) bootstrap >>=? fun bootstrap_manager -> - Op.delegation (I i) delegator (Some bootstrap_manager.pkh) + Op.delegation ~force_reveal:true (I i) delegator (Some bootstrap_manager.pkh) >>=? fun delegation -> Incremental.add_operation i delegation >>=? fun i -> (* test delegate of new contract is bootstrap *) @@ -1088,7 +1182,7 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = Assert.equal_pkh ~loc:__LOC__ delegator_delegate bootstrap_manager.pkh >>=? fun _ -> (* delegation with newly registered key *) - Op.delegation (I i) delegator (Some delegate_account.pkh) + Op.delegation ~force_reveal:true (I i) delegator (Some delegate_account.pkh) >>=? fun delegation -> Incremental.add_operation i delegation >>=? fun i -> Context.Contract.delegate (I i) delegator >>=? fun delegator_delegate -> @@ -1106,12 +1200,13 @@ let test_double_registration () = let pkh = Account.(account.pkh) in let impl_contract = Contract.Implicit pkh in (* credit 1μꜩ+ check balance *) - Op.transaction (I i) bootstrap impl_contract Tez.one_mutez + Op.transaction ~force_reveal:true (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 -> + Op.delegation ~force_reveal:true (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 -> @@ -1126,12 +1221,13 @@ let test_double_registration_when_empty () = let pkh = Account.(account.pkh) in let impl_contract = Contract.Implicit pkh in (* credit 1μꜩ+ check balance *) - Op.transaction (I i) bootstrap impl_contract Tez.one_mutez + Op.transaction ~force_reveal:true (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 -> + Op.delegation ~force_reveal:true (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 @@ -1151,15 +1247,16 @@ let test_double_registration_when_recredited () = let pkh = Account.(account.pkh) in let impl_contract = Contract.Implicit pkh in (* credit 1μꜩ+ check balance *) - Op.transaction (I i) bootstrap impl_contract Tez.one_mutez + Op.transaction ~force_reveal:true (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 -> + Op.delegation ~force_reveal:true (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 + Op.transaction ~force_reveal:true (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 _ -> @@ -1179,9 +1276,11 @@ let test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = let {Account.pkh; _} = Account.new_account () in let {Account.pkh = delegate_pkh; _} = Account.new_account () in let contract = Alpha_context.Contract.Implicit pkh in - Op.transaction (I i) bootstrap contract (of_int 10) >>=? fun op -> + Op.transaction ~force_reveal:true (I i) bootstrap contract (of_int 10) + >>=? fun op -> Incremental.add_operation i op >>=? fun i -> - Op.delegation ~fee (I i) contract (Some delegate_pkh) >>=? fun op -> + Op.delegation ~force_reveal:true ~fee (I i) contract (Some delegate_pkh) + >>=? fun op -> Context.Contract.balance (I i) contract >>=? fun balance -> if fee > balance then expect_too_low_balance_error i op else @@ -1251,7 +1350,8 @@ let test_registered_self_delegate_key_init_delegation () = in let contract = Alpha_context.Contract.Implicit pkh in let delegate_contract = Alpha_context.Contract.Implicit delegate_pkh in - Op.transaction (I i) bootstrap contract (of_int 10) >>=? fun op -> + Op.transaction ~force_reveal:true (I i) bootstrap contract (of_int 10) + >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Op.transaction (I i) bootstrap delegate_contract (of_int 1) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> @@ -1259,7 +1359,8 @@ let test_registered_self_delegate_key_init_delegation () = Incremental.add_operation i op >>=? fun i -> Op.delegation (I i) delegate_contract (Some delegate_pkh) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> - Op.delegation (I i) contract (Some delegate_pkh) >>=? fun op -> + Op.delegation ~force_reveal:true (I i) contract (Some delegate_pkh) + >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Context.Contract.delegate (I i) contract >>=? fun delegate -> Assert.equal_pkh ~loc:__LOC__ delegate delegate_pkh >>=? fun () -> return_unit diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml index 8b9e7b9b476976313c309dc3363a54bc339ef247..59775d21cbca60ea8ecf694a7357ed612dd52757 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml @@ -91,13 +91,19 @@ let test_invariants () = let new_account = (Account.new_account ()).pkh in let new_contract = Contract.Implicit new_account in (* we first put some money in new_account *) - Op.transaction (B genesis) contract2 new_contract spendable_balance2 + Op.transaction + ~force_reveal:true + (B genesis) + contract2 + new_contract + spendable_balance2 >>=? fun transfer -> Block.bake ~operation:transfer genesis >>=? fun b -> Context.Contract.balance (B b) new_contract >>=? fun new_account_balance -> Assert.equal_tez ~loc:__LOC__ new_account_balance spendable_balance2 >>=? fun () -> - Op.delegation (B b) new_contract (Some account1) >>=? fun delegation -> + Op.delegation ~force_reveal:true (B b) new_contract (Some account1) + >>=? fun delegation -> Block.bake ~operation:delegation b >>=? fun b1 -> Block.bake_until_n_cycle_end constants.preserved_cycles b1 >>=? fun b2 -> Context.Delegate.staking_balance (B b2) account1 @@ -420,7 +426,12 @@ let test_frozen_deposits_with_delegation () = Context.Contract.balance (B genesis) contract2 >>=? fun delegated_amount -> let new_account = Account.new_account () in let new_contract = Contract.Implicit new_account.pkh in - Op.transaction (B genesis) contract2 new_contract delegated_amount + Op.transaction + ~force_reveal:true + (B genesis) + contract2 + new_contract + delegated_amount >>=? fun transfer -> Block.bake ~operation:transfer genesis >>=? fun b -> Context.Delegate.staking_balance (B b) account2 @@ -430,7 +441,8 @@ let test_frozen_deposits_with_delegation () = in Assert.equal_tez ~loc:__LOC__ new_staking_balance expected_new_staking_balance >>=? fun () -> - Op.delegation (B b) new_contract (Some account1) >>=? fun delegation -> + Op.delegation ~force_reveal:true (B b) new_contract (Some account1) + >>=? fun delegation -> Block.bake ~operation:delegation b >>=? fun b -> let expected_new_staking_balance = Test_tez.(initial_staking_balance +! delegated_amount) @@ -485,8 +497,9 @@ let test_frozen_deposits_with_overdelegation () = Context.Contract.balance (B genesis) contract2 >>=? fun amount' -> let new_account = (Account.new_account ()).pkh in let new_contract = Contract.Implicit new_account in - Op.transaction (B genesis) contract1 new_contract amount >>=? fun transfer1 -> - Op.transaction (B genesis) contract2 new_contract amount' + Op.transaction ~force_reveal:true (B genesis) contract1 new_contract amount + >>=? fun transfer1 -> + Op.transaction ~force_reveal:true (B genesis) contract2 new_contract amount' >>=? fun transfer2 -> Block.bake ~operations:[transfer1; transfer2] genesis >>=? fun b -> let expected_new_staking_balance = @@ -506,7 +519,8 @@ let test_frozen_deposits_with_overdelegation () = new_staking_balance' expected_new_staking_balance' >>=? fun () -> - Op.delegation (B b) new_contract (Some account1) >>=? fun delegation -> + Op.delegation ~force_reveal:true (B b) new_contract (Some account1) + >>=? fun delegation -> Block.bake ~operation:delegation b >>=? fun b -> Context.Delegate.staking_balance (B b) account1 >>=? fun new_staking_balance -> @@ -565,8 +579,9 @@ let test_set_limit_with_overdelegation () = let limit = Test_tez.(initial_staking_balance *! 15L /! 100L) in let new_account = (Account.new_account ()).pkh in let new_contract = Contract.Implicit new_account in - Op.transaction (B genesis) contract1 new_contract amount >>=? fun transfer1 -> - Op.transaction (B genesis) contract2 new_contract amount' + Op.transaction ~force_reveal:true (B genesis) contract1 new_contract amount + >>=? fun transfer1 -> + Op.transaction ~force_reveal:true (B genesis) contract2 new_contract amount' >>=? fun transfer2 -> Block.bake ~operations:[transfer1; transfer2] genesis >>=? fun b -> Op.set_deposits_limit (B b) contract1 (Some limit) >>=? fun set_deposits -> @@ -588,7 +603,8 @@ let test_set_limit_with_overdelegation () = new_staking_balance' expected_new_staking_balance' >>=? fun () -> - Op.delegation (B b) new_contract (Some account1) >>=? fun delegation -> + Op.delegation ~force_reveal:true (B b) new_contract (Some account1) + >>=? fun delegation -> Block.bake ~operation:delegation b >>=? fun b -> (* Finish the cycle to update the frozen deposits *) Block.bake_until_cycle_end b >>=? fun b -> @@ -628,16 +644,23 @@ let test_error_is_thrown_when_smaller_upper_bound_for_frozen_window () = Context.Contract.balance (B genesis) contract2 >>=? fun delegated_amount -> let new_account = Account.new_account () in let new_contract = Contract.Implicit new_account.pkh in - Op.transaction (B genesis) contract2 new_contract delegated_amount + Op.transaction + ~force_reveal:true + (B genesis) + contract2 + new_contract + delegated_amount >>=? fun transfer -> Block.bake ~operation:transfer genesis >>=? fun b -> - Op.delegation (B b) new_contract (Some account1) >>=? fun delegation -> + Op.delegation ~force_reveal:true (B b) new_contract (Some account1) + >>=? fun delegation -> Block.bake ~operation:delegation b >>=? fun b -> Block.bake_until_cycle_end b >>=? fun b -> (* After 1 cycle, namely, at cycle 2, [account1] transfers all its spendable balance. *) Context.Contract.balance (B b) contract1 >>=? fun balance1 -> - Op.transaction (B b) contract1 contract2 balance1 >>=? fun operation -> + Op.transaction ~force_reveal:true (B b) contract1 contract2 balance1 + >>=? fun operation -> Block.bake ~operation b >>=? fun b -> Block.bake_until_n_cycle_end constants.preserved_cycles b >>=? fun _ -> (* By this time, after [preserved_cycles] passed after [account1] has emptied diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/main.ml b/src/proto_alpha/lib_protocol/test/integration/operations/main.ml index bc7536e31332513270ec8fb6c6baeb0eeb35d023..d7944e194a8ee48e4554b1474ff41ea456d67510 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/main.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/main.ml @@ -43,7 +43,5 @@ let () = ("failing_noop operation", Test_failing_noop.tests); ("tx rollup", Test_tx_rollup.tests); ("sc rollup", Test_sc_rollup.tests); - ("precheck manager", Test_manager_operation_precheck.tests); - ("precheck batched manager", Test_batched_manager_operation_precheck.tests); ] |> Lwt_main.run diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml index 5ae39c8608a54e9d1bbf1f16e6826f7482d0bfd7..d34b68459dd45a429f0fc1eb81bb3e763ec550b9 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml @@ -186,11 +186,13 @@ let test_transfer_zero_implicit_with_bal_src_as_fee () = let src_pkh = account.Account.pkh in Incremental.begin_construction b >>=? fun i -> let src = Contract.Implicit src_pkh in - Op.transaction (I i) dest src (Tez.of_mutez_exn 100L) >>=? fun op -> + Op.transaction ~force_reveal:true (I i) dest src (Tez.of_mutez_exn 100L) + >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Context.Contract.balance (I i) src >>=? fun bal_src -> Assert.equal_tez ~loc:__LOC__ bal_src (Tez.of_mutez_exn 100L) >>=? fun () -> - Op.transaction (I i) ~fee:bal_src src dest Tez.zero >>=? fun op -> + Op.transaction ~force_reveal:true (I i) ~fee:bal_src src dest Tez.zero + >>=? fun op -> (* Transferring zero tez should result in an application failure as the implicit contract has been depleted. *) let expect_apply_failure = function @@ -307,7 +309,11 @@ let test_transfer_from_implicit_to_originated_contract () = amount1 >>=? fun (b, _) -> (* originated contract *) - Op.contract_origination (I b) contract ~script:Op.dummy_script + Op.contract_origination + ~force_reveal:true + (I b) + contract + ~script:Op.dummy_script >>=? fun (operation, new_contract) -> Incremental.add_operation b operation >>=? fun b -> two_over_n_of_balance b bootstrap_contract 4L >>=? fun amount2 -> @@ -668,7 +674,7 @@ let tests = Tztest.tztest "missing transaction" `Quick test_missing_transaction; (* transfer from/to implicit/originated contracts*) Tztest.tztest - "transfer from an implicit to implicit contract " + "transfer from an implicit to implicit contract" `Quick test_transfer_from_implicit_to_implicit_contract; Tztest.tztest diff --git a/src/proto_alpha/lib_protocol/test/integration/precheck/dune b/src/proto_alpha/lib_protocol/test/integration/precheck/dune new file mode 100644 index 0000000000000000000000000000000000000000..ebb763391fb83ea01b8ce18e3910983a8a91989b --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/integration/precheck/dune @@ -0,0 +1,25 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(executable + (name main) + (libraries + alcotest-lwt + tezos-base + tezos-protocol-alpha + tezos-client-alpha + tezos-alpha-test-helpers + tezos-base-test-helpers) + (flags + (:standard) + -open Tezos_base.TzPervasives + -open Tezos_base.TzPervasives.Error_monad.Legacy_monad_globals + -open Tezos_protocol_alpha + -open Tezos_client_alpha + -open Tezos_alpha_test_helpers + -open Tezos_base_test_helpers)) + +(rule + (alias runtest) + (package tezos-protocol-alpha-tests) + (action (run %{dep:./main.exe}))) diff --git a/src/proto_alpha/lib_protocol/test/integration/precheck/main.ml b/src/proto_alpha/lib_protocol/test/integration/precheck/main.ml new file mode 100644 index 0000000000000000000000000000000000000000..9e58c8ee0a29d40a59b7ffd8ee1f32ee950b930d --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/integration/precheck/main.ml @@ -0,0 +1,47 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Nomadic Labs *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(** Testing + ------- + Component: Protocol + Invocation: dune runtest src/proto_alpha/lib_protocol/test/integration/precheck + Subject: Integration > Precheck +*) + +let () = + Alcotest_lwt.run + "protocol > integration > precheck" + [ + ("sanity checks", Test_manager_operation_precheck.sanity_tests); + ("Single: gas checks", Test_manager_operation_precheck.gas_tests); + ("Single: storage checks", Test_manager_operation_precheck.storage_tests); + ("Single: fees checks", Test_manager_operation_precheck.fee_tests); + ("Single: contract checks", Test_manager_operation_precheck.contract_tests); + ( "Batched: contract checks", + Test_batched_manager_operation_precheck.contract_tests ); + ("Batched: gas checks", Test_batched_manager_operation_precheck.gas_tests); + ("Batched: fees checks", Test_batched_manager_operation_precheck.fee_tests); + ] + |> Lwt_main.run diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/precheck/manager_operation_helpers.ml similarity index 86% rename from src/proto_alpha/lib_protocol/test/integration/operations/manager_operation_helpers.ml rename to src/proto_alpha/lib_protocol/test/integration/precheck/manager_operation_helpers.ml index 07286f020c53f9f5410b0a53f5a497ebcbdea27d..12fd3916ef60c06e3cc53391ce657d075994a01f 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/precheck/manager_operation_helpers.ml @@ -68,6 +68,7 @@ let init_context ?hard_gas_limit_per_block () = let counter = Z.zero in let* fund_rollup_account = Op.transaction + ~force_reveal:true ~counter ~gas_limit (B b) @@ -78,7 +79,12 @@ let init_context ?hard_gas_limit_per_block () = let* b = Block.bake ~operation:fund_rollup_account b in let counter2 = Z.succ counter in let* rollup_origination, tx_rollup = - Op.tx_rollup_origination ~counter:counter2 ~gas_limit (B b) rollup_contract + Op.tx_rollup_origination + ~force_reveal:true + ~counter:counter2 + ~gas_limit + (B b) + rollup_contract in let* _, sc_rollup = Op.sc_rollup_origination @@ -162,13 +168,18 @@ let init_delegated_implicit () = in let* operation = Op.delegation + ~force_reveal:true (B infos.block) infos.contract2 (Some (Context.Contract.pkh infos.contract2)) in let* block = Block.bake infos.block ~operation in let* operation = - Op.delegation (B block) infos.contract1 (Some infos.account2.pkh) + Op.delegation + ~force_reveal:true + (B block) + infos.contract1 + (Some infos.account2.pkh) in let* block = Block.bake block ~operation in let* del_opt_new = Context.Contract.delegate_opt (B block) infos.contract1 in @@ -190,7 +201,11 @@ let init_self_delegated_implicit () = del_opt in let* operation = - Op.delegation (B infos.block) infos.contract1 (Some infos.account1.pkh) + Op.delegation + ~force_reveal:true + (B infos.block) + infos.contract1 + (Some infos.account1.pkh) in let* block = Block.bake infos.block ~operation in let* del_opt_new = Context.Contract.delegate_opt (B block) infos.contract1 in @@ -754,7 +769,13 @@ let rec create_Tztest_batches test tests_msg operations = aux (hdmsg kop) (test kop) ops @ create_Tztest_batches test tests_msg kops (* Diagnostic helpers. *) +(* The purpose of diagnostic helpers is to state the correct observation + according to the precheck result of a test. *) +(* For a manager operation a [probes] contains the values required for observing + its precheck success. Its source, fees (sum for a batch), gas_limit + (sum of gas_limit of the batch), and the increment of the counters aka 1 for + a single operation, n for a batch of n manager operations. *) type probes = { source : Signature.Public_key_hash.t; fee : Tez.tez; @@ -777,6 +798,7 @@ let rec contents_infos : let _ = Assert.equal_pkh ~loc:__LOC__ manop.source probes.source in return {fee; source = probes.source; gas_limit; nb_counter} +(* Computes a [probes] from a list of manager contents. *) let manager_content_infos op = let (Operation_data {contents; _}) = op.protocol_data in match contents with @@ -784,13 +806,31 @@ let manager_content_infos op = | Cons (Manager_operation _, _) as op -> contents_infos op | _ -> assert false -let observe ?g_in contract b_in c_in probes i = +(* [observe] asserts the success of precheck only. + Given on one side, a [contract], its initial balance [b_in], its initial + counter [c_in] and potentially the initial gas [g_in] before its prechecking; + and, on the other side, its [probes] and the context after its precheck [i]; + if precheck succeeds then we observe in [i] that: + - [contract] balance decreases by [probes.fee] when [only_precheck] marks that only the precheck + succeeds + - [contract] balance decreases at least by [probes.fee] when ![only_precheck] marks + that the application has succeeded, + - its counter [c_in] increases by [probes.nb_counter], and + - the available gas in the block in [i] decreases by [g_in].*) +let observe ~only_precheck contract b_in c_in g_in probes i = let open Lwt_result_syntax in let* b_out = Context.Contract.balance (I i) contract in let g_out = Gas.block_level (Incremental.alpha_ctxt i) in let* c_out = Context.Contract.counter (I i) contract in let*? b_expected = b_in -? probes.fee in - let* _ = Assert.equal_tez ~loc:__LOC__ b_out b_expected in + let b_cmp = + Assert.equal + ~loc:__LOC__ + (if only_precheck then Tez.( = ) else Tez.( <= )) + "Balance update" + Tez.pp + in + let* _ = b_cmp b_out b_expected in let c_expected = Z.add c_in probes.nb_counter in let _ = Assert.equal @@ -801,26 +841,16 @@ let observe ?g_in contract b_in c_in probes i = c_out c_expected in - match g_in with - | Some g_in -> - let g_expected = Gas.Arith.sub g_in (Gas.Arith.fp probes.gas_limit) in - Assert.equal - ~loc:__LOC__ - Gas.Arith.equal - "Gas consumption" - Gas.Arith.pp - g_out - g_expected - | None -> return_unit - -let precheck_ko_diagnostic ?(mempool_mode = false) (infos : infos) op - expect_failure = - let open Lwt_result_syntax in - let* i = Incremental.begin_construction infos.block ~mempool_mode in - let* _ = Incremental.add_operation ~expect_failure i op in - return_unit - -let apply_with_diagnostic ?expect_apply_failure (infos : infos) op = + let g_expected = Gas.Arith.sub g_in (Gas.Arith.fp probes.gas_limit) in + Assert.equal + ~loc:__LOC__ + Gas.Arith.equal + "Gas consumption" + Gas.Arith.pp + g_out + g_expected + +let precheck_with_diagnostic ~only_precheck (infos : infos) op = let open Lwt_result_syntax in let* i = Incremental.begin_construction infos.block in let* prbs = manager_content_infos op in @@ -828,18 +858,36 @@ let apply_with_diagnostic ?expect_apply_failure (infos : infos) op = let* b_in = Context.Contract.balance (I i) contract in let* c_in = Context.Contract.counter (I i) contract in let g_in = Gas.block_level (Incremental.alpha_ctxt i) in - let* i = Incremental.add_operation ?expect_apply_failure i op in - observe ~g_in contract b_in c_in prbs i - -(* If the precheck of an operation succeed, whether the application - fail or not, the fees must be paid, the block gas consumption - should be decreased and the counter of operation should be - incremented. *) -let apply_ko_diagnostic (infos : infos) op expect_apply_failure = - apply_with_diagnostic ~expect_apply_failure (infos : infos) op - -let apply_ok_diagnostic (infos : infos) op = - apply_with_diagnostic (infos : infos) op + let* i = Incremental.precheck_operation i op in + let* _ = Incremental.finalize_block i in + observe ~only_precheck contract b_in c_in g_in prbs i + +(* If only the precheck of an operation succeed; e.g. the rest + of the application failed: + - the fees must be paid, + - the block gas consumption should be decreased, and + - the counter of operation should be incremented + as defined by [observe] with [only_precheck]. *) +let only_precheck_diagnostic (infos : infos) op = + precheck_with_diagnostic ~only_precheck:true infos op + +(* If an manager operation application succeed, the precheck + effects must be observed: + - the fees must be paid, + - the block gas consumption should be decreased, and + - the counter of operation should be incremented + as defined by [observe] with ![only_precheck]. *) +let precheck_diagnostic (infos : infos) op = + precheck_with_diagnostic ~only_precheck:false infos op + +(* [precheck_ko_diagnostic] wraps the [expect_failure] when [op] precheck + failed. It is used in test that expects precheck [op] to fail. *) +let precheck_ko_diagnostic ?(mempool_mode = false) (infos : infos) op + expect_failure = + let open Lwt_result_syntax in + let* i = Incremental.begin_construction infos.block ~mempool_mode in + let* _ = Incremental.add_operation ~expect_failure i op in + return_unit (* List of operation kind that must run on generic tests. This list should be extended for each new manager_operation kind. *) @@ -873,45 +921,22 @@ let subjects = K_Dal_publish_slot_header; ] -let except_not_consumer_in_precheck_subjects = - List.filter - (function - | K_Set_deposits_limit | K_Reveal | K_Self_delegation | K_Delegation - | K_Undelegation | K_Tx_rollup_origination | K_Tx_rollup_submit_batch - | K_Tx_rollup_finalize | K_Tx_rollup_commit | K_Tx_rollup_return_bond - | K_Tx_rollup_remove_commitment | K_Tx_rollup_reject - | K_Sc_rollup_add_messages | K_Sc_rollup_origination | K_Sc_rollup_refute - | K_Sc_rollup_timeout | K_Sc_rollup_cement | K_Sc_rollup_publish - | K_Sc_rollup_execute_outbox_message | K_Sc_rollup_recover_bond - | K_Dal_publish_slot_header -> - false - | _ -> true) - subjects - -let except_self_delegated_and_revelation_subjects = - List.filter - (function K_Self_delegation | K_Reveal -> false | _ -> true) - subjects - -let revealed_except_set_deposits_limit_and_submit_batch_subjects = - List.filter - (function - | K_Set_deposits_limit | K_Tx_rollup_submit_batch | K_Reveal - (* FIXME https://gitlab.com/tezos/tezos/-/issues/3210 *) - | K_Dal_publish_slot_header -> - false - | _ -> true) - subjects - -let revealed_only_set_deposits_limit_and_submit_batch_subjects = - List.filter - (function - | K_Set_deposits_limit | K_Tx_rollup_submit_batch - (* FIXME https://gitlab.com/tezos/tezos/-/issues/3210 *) - | K_Dal_publish_slot_header -> - true - | _ -> false) - subjects +let is_consumer = function + | K_Set_deposits_limit | K_Reveal | K_Self_delegation | K_Delegation + | K_Undelegation | K_Tx_rollup_origination | K_Tx_rollup_submit_batch + | K_Tx_rollup_finalize | K_Tx_rollup_commit | K_Tx_rollup_return_bond + | K_Tx_rollup_remove_commitment | K_Tx_rollup_reject + | K_Sc_rollup_add_messages | K_Sc_rollup_origination | K_Sc_rollup_refute + | K_Sc_rollup_timeout | K_Sc_rollup_cement | K_Sc_rollup_publish + | K_Sc_rollup_execute_outbox_message | K_Sc_rollup_recover_bond + | K_Dal_publish_slot_header -> + false + | K_Transaction | K_Origination | K_Register_global_constant + | K_Tx_rollup_dispatch_tickets | K_Transfer_ticket -> + true + +let gas_consumer_in_precheck_subjects, not_gas_consumer_in_precheck_subjects = + List.partition is_consumer subjects let revealed_subjects = List.filter (function K_Reveal -> false | _ -> true) subjects diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_batched_manager_operation_precheck.ml b/src/proto_alpha/lib_protocol/test/integration/precheck/test_batched_manager_operation_precheck.ml similarity index 93% rename from src/proto_alpha/lib_protocol/test/integration/operations/test_batched_manager_operation_precheck.ml rename to src/proto_alpha/lib_protocol/test/integration/precheck/test_batched_manager_operation_precheck.ml index d2acfd9f11ccf6b5eb395431a55a03d124374da3..ed2a54779f4a62dc446d6975daa041f15de50e36 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_batched_manager_operation_precheck.ml +++ b/src/proto_alpha/lib_protocol/test/integration/precheck/test_batched_manager_operation_precheck.ml @@ -27,8 +27,8 @@ ------- Component: Protocol (precheck manager) Invocation: dune exec \ - src/proto_alpha/lib_protocol/test/integration/operations/main.exe \ - -- test "^precheck batched manager$" + src/proto_alpha/lib_protocol/test/integration/precheck/main.exe \ + -- test "^Batched" Subject: Precheck manager operation. *) @@ -38,7 +38,8 @@ open Manager_operation_helpers (* Tests on operation batches. *) -(* Reveal in the middle: reveal should be in first position. *) +(* Revelation should not occur elsewhere than in first position + in a batch.*) let batch_reveal_in_the_middle_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -83,7 +84,7 @@ let generate_batches_reveal_in_the_middle () = "reveal should occur only at the beginning of a batch." revealed_subjects -(* 2 Reveals in a batch: only one reveal per batch. *) +(* A batch of manager operation contains at most one Revelation.*) let batch_two_reveals_diagnostic (infos : infos) op = let expected_failure errs = match errs with @@ -126,7 +127,7 @@ let generate_tests_batches_two_reveals () = "Only one revelation per batch." revealed_subjects -(* 2 sources in a batch: only one source per batch. *) +(* Every manager operation in a batch concerns the same source.*) let batch_two_sources_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -159,17 +160,14 @@ let test_batch_two_sources kind1 kind2 () = in batch_two_sources_diagnostic infos batch -let revealed_except_self_delegation_subjects = - List.filter (function K_Reveal -> false | _ -> true) subjects - -(* With self_delegation, the occurred error is counter inconsistency. *) let generate_batches_two_sources () = create_Tztest_batches test_batch_two_sources "Only one source per batch." - revealed_except_self_delegation_subjects + revealed_subjects -(* Counters in a batch should be a sequence. *) +(* Counters in a batch should be a sequence from the successor of + the stored counter associated to source in the initial context. *) let test_batch_inconsistent_counters kind1 kind2 () = let open Lwt_result_syntax in let* infos = init_context () in @@ -304,7 +302,7 @@ let generate_batches_emptying_balance_in_the_middle () = "Fee payment emptying balance should occurs at the end of the batch." revealed_subjects -(* Exceeding block gas by a batch. *) +(* A batch of manager operation must not exceed the initial available gas in the block. *) let test_batch_exceeding_block_gas ~mempool_mode kind1 kind2 () = let open Lwt_result_syntax in let* infos = init_context ~hard_gas_limit_per_block:gb_limit () in @@ -398,7 +396,8 @@ let generate_batches_exceeding_block_gas_mp_mode () = "Too much gas consumption in mempool mode." revealed_subjects -(* Emptying balance at the end of a batch. *) +(* A batch that consumes all the balance for fees only at the end of + the batch passes precheck.*) let test_batch_balance_just_enough kind1 kind2 () = let open Lwt_result_syntax in let* infos = init_context () in @@ -434,8 +433,8 @@ let test_batch_balance_just_enough kind1 kind2 () = (Context.B infos.block) [reveal; op_case2; op2_case2] in - let* _ = apply_ko_diagnostic infos case2 (fun _ -> return_unit) in - apply_ko_diagnostic infos case3 (fun _ -> return_unit) + let* _ = precheck_diagnostic infos case2 in + precheck_diagnostic infos case3 let generate_batches_balance_just_enough () = create_Tztest_batches @@ -464,20 +463,24 @@ let test_batch_reveal_transaction_ok () = [reveal; transaction] in let* _i = Incremental.begin_construction infos.block in - apply_ko_diagnostic infos batch (fun _ -> return_unit) + precheck_diagnostic infos batch -let tests = +let contract_tests = generate_batches_reveal_in_the_middle () @ generate_tests_batches_two_reveals () @ generate_batches_two_sources () @ generate_batches_inconsistent_counters () - @ generate_batches_emptying_balance_in_the_middle () - @ generate_batches_exceeding_block_gas () - @ generate_batches_exceeding_block_gas_mp_mode () - @ generate_batches_balance_just_enough () @ [ Tztest.tztest - "Prechecked batch with a reveal and a transaction." + "Prechecked a batch with a reveal and a transaction." `Quick test_batch_reveal_transaction_ok; ] + +let gas_tests = + generate_batches_exceeding_block_gas () + @ generate_batches_exceeding_block_gas_mp_mode () + +let fee_tests = + generate_batches_emptying_balance_in_the_middle () + @ generate_batches_balance_just_enough () diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_manager_operation_precheck.ml b/src/proto_alpha/lib_protocol/test/integration/precheck/test_manager_operation_precheck.ml similarity index 73% rename from src/proto_alpha/lib_protocol/test/integration/operations/test_manager_operation_precheck.ml rename to src/proto_alpha/lib_protocol/test/integration/precheck/test_manager_operation_precheck.ml index 611f0bde4eb9170038a07f7634ef3a75d8c7305f..e9e2ca11ed121dcdfc7f9542451aba253e2ccf93 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_manager_operation_precheck.ml +++ b/src/proto_alpha/lib_protocol/test/integration/precheck/test_manager_operation_precheck.ml @@ -27,8 +27,8 @@ ------- Component: Protocol (precheck manager) Invocation: dune exec \ - src/proto_alpha/lib_protocol/test/integration/operations/main.exe \ - -- test "^precheck manager$" + src/proto_alpha/lib_protocol/test/integration/precheck/main.exe \ + -- test "^Single$" Subject: Precheck manager operation. *) @@ -106,7 +106,15 @@ let test_ensure_manager_operation_coverage () = `Quick (fun () -> ensure_manager_operation_coverage ()) -(* Too low gas limit. *) +(* Negative tests assert the case where precheck must fail. *) + +(* Precheck fails if the gas limit is too low. + + This test asserts that the precheck of a manager's operation + with a too low gas limit fails at precheck with an + [Gas_quota_exceeded_init_deserialize] error. + This test applies on manager operations that do not + consume gas in their specific part of precheck. *) let low_gas_limit_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -136,9 +144,13 @@ let generate_low_gas_limit () = create_Tztest test_low_gas_limit "Gas_limit too low." - except_not_consumer_in_precheck_subjects + gas_consumer_in_precheck_subjects + +(* Precheck fails if the gas limit is too high. -(* Too high gas limit. *) + This test asserts that the precheck of a manager operation with + a gas limit too high fails at precheck with an [Gas_limit_too_high] + error. It applies on every kind of manager operation. *) let high_gas_limit_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -163,7 +175,11 @@ let test_high_gas_limit kind () = let generate_high_gas_limit () = create_Tztest test_high_gas_limit "Gas_limit too high." subjects -(* Too high storage limit. *) +(* Precheck fails if the storage limit is too high. + + This test asserts that a manager operation with a storage limit + too high fails at precheck with [Storage_limit_too_high] error. + It applies to every kind of manager operation. *) let high_storage_limit_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -194,7 +210,12 @@ let test_high_storage_limit kind () = let generate_high_storage_limit () = create_Tztest test_high_gas_limit "Storage_limit too high." subjects -(* Counter in the future. *) +(* Precheck fails if the counter is in the future. + + This test asserts that a manager operation with a counter in the + future -- aka greater than the successor of the manager's counter + stored in the current context -- fails with [Counter_in_the_future] error. + It applies to every kind of manager operation. *) let high_counter_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -220,7 +241,12 @@ let test_high_counter kind () = let generate_high_counter () = create_Tztest test_high_counter "Counter too high." subjects -(* Counter in the past. *) +(* Precheck fails if the counter is in the past. + + This test asserts that a manager operation with a counter in the past -- aka + smaller than the successor of the manager's counter stored in the current + context -- fails with [Counter_in_the_past] error. + It applies to every kind of manager operation. *) let low_counter_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -249,7 +275,11 @@ let test_low_counter kind () = let generate_low_counter () = create_Tztest test_low_counter "Counter too low." subjects -(* Not allocated source. *) +(* Precheck fails if the source is not allocated. + + This test asserts that a manager operation which manager's contract + is not allocated fails with [Empty_implicit_contract] error. + It applies on every kind of manager operation. *) let not_allocated_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -275,7 +305,11 @@ let test_not_allocated kind () = let generate_not_allocated () = create_Tztest test_not_allocated "not allocated source." subjects -(* Unrevealed source. *) +(* Precheck fails if the source is unrevealed. + + This test asserts that a manager operation with an unrevealed source's + contract fails at precheck with [Unrevealed_manager_key]. + It applies on every kind of manager operation except [Revelation]. *) let unrevealed_key_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -304,7 +338,11 @@ let generate_unrevealed_key () = "unrevealed source (find_manager_public_key)." revealed_subjects -(* Not enough balance to pay fees. *) +(* Precheck fails if the source's balance is not enough to pay the fees. + + This test asserts that precheck of a manager operation fails if the + source's balance is lesser than the manager operation's fee. + It applies on every kind of manager operation. *) let high_fee_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -330,7 +368,14 @@ let test_high_fee kind () = let generate_tests_high_fee () = create_Tztest test_high_fee "not enough for fee payment." subjects -(* Emptying delegated implicit contract. *) +(* Precheck fails if the fee payment empties the balance of a + delegated implicit contract. + + This test asserts that in case that: + - the source is a delegated implicit contract, and + - the fee is the exact balance of source. + then, precheck fails with [Empty_implicit_delegated_contract] error. + It applies to every kind of manager operation except [Revelation].*) let emptying_delegated_implicit_diagnostic (infos : infos) op = let expect_failure errs = match errs with @@ -350,7 +395,7 @@ let emptying_delegated_implicit_diagnostic (infos : infos) op = let test_emptying_delegated_implicit kind () = let open Lwt_result_syntax in let* infos = init_delegated_implicit () in - let fee = Tez.one in + let* fee = Context.Contract.balance (B infos.block) infos.contract1 in let* op = select_op ~fee ~force_reveal:false ~source:infos.contract1 kind infos in @@ -359,10 +404,16 @@ let test_emptying_delegated_implicit kind () = let generate_tests_emptying_delegated_implicit () = create_Tztest test_emptying_delegated_implicit - "just enough to empty a delegated source." + "just enough funds to empty a delegated source." revealed_subjects -(* Exceeding block gas. *) +(* Precheck fails if there is not enough available gas in the block. + + This test asserts that precheck fails with: + - [Gas_limit_too_high;Block_quota_exceeded] in mempool mode, + | [Block_quota_exceeded] in other mode + with gas limit exceeds the available gas in the block. + It applies to every kind of manager operation. *) let exceeding_block_gas_diagnostic ~mempool_mode (infos : infos) op = let expect_failure errs = match errs with @@ -411,51 +462,45 @@ let generate_tests_exceeding_block_gas_mp_mode () = "too much gas consumption in mempool mode." subjects -(* Positive tests. *) - -(* Fee payment but emptying an self_delegated implicit. *) +(* Positive tests. + + Tests that precheck succeeds when: + - it empties the balance of a self_delegated implicit source, + - it empties the balance of an undelegated implicit source, and + - in case: + - the counter is the successor of the one stored in the context, + - the fee is lesser than the balance, + - the storage limit is lesser than the maximum authorized storage, + - the gas limit is: + - lesser than the available gas in the block, + - less than the maximum gas consumable by an operation, and + - greater than the minimum gas consumable by an operation. + Notice that the first two only precheck succeeds while in the last case, + the full application also succeeds. + In the first 2 case, we observe in the output context that: + - the counter is the successor of the one stored in the initial context, + - the balance decreased by fee, + - the available gas in the block decreased by gas limit. + In the last case, we observe in the output context that: + - the counter is the successor of the one stored in the initial context, + - the balance is at least decreased by fee, + - the available gas in the block decreased by gas limit. *) + +(* Fee payment that emptying a self_delegated implicit. *) let test_emptying_self_delegated_implicit kind () = let open Lwt_result_syntax in let* infos = init_self_delegated_implicit () in - let fee = Tez.one in - let* op = - select_op ~fee ~force_reveal:false ~source:infos.contract1 kind infos - in - apply_ko_diagnostic infos op (fun _ -> return_unit) - -let test_emptying_self_delegated_implicit2 kind () = - let open Lwt_result_syntax in - let* infos = init_self_delegated_implicit () in - let fee = Tez.one in + let* fee = Context.Contract.balance (B infos.block) infos.contract1 in let* op = select_op ~fee ~force_reveal:false ~source:infos.contract1 kind infos in - apply_ok_diagnostic infos op + only_precheck_diagnostic infos op let generate_tests_emptying_self_delegated_implicit () = create_Tztest test_emptying_self_delegated_implicit - "fee payment and just enough to empty a self-delegated source." - revealed_except_set_deposits_limit_and_submit_batch_subjects - @ create_Tztest - test_emptying_self_delegated_implicit2 - "fee payment and just enough to empty a self-delegated source." - revealed_only_set_deposits_limit_and_submit_batch_subjects - -(* Fee payment but emptying an undelegated implicit, test positive. *) -let emptying_undelegated_implicit_diagnostic (infos : infos) op = - let expect_failure errs = - match errs with - | [Environment.Ecoproto_error (Contract_storage.Empty_implicit_contract _)] - -> - return_unit - | err -> - failwith - "Error trace:@, %a does not match the expected one" - Error_monad.pp_print_trace - err - in - apply_ko_diagnostic infos op expect_failure + "passes precheck and empties a self-delegated source." + subjects (* Minimum gas cost to pass the precheck: - cost_of_manager_operation for the generic part @@ -467,8 +512,8 @@ let empiric_minimal_gas_cost_for_precheck = let test_emptying_undelegated_implicit kind () = let open Lwt_result_syntax in let* infos = init_context () in - let fee = Tez.one in let gas_limit = Op.Custom_gas empiric_minimal_gas_cost_for_precheck in + let* fee = Context.Contract.balance (B infos.block) infos.contract1 in let* op = select_op ~fee @@ -478,24 +523,42 @@ let test_emptying_undelegated_implicit kind () = kind infos in - emptying_undelegated_implicit_diagnostic infos op + only_precheck_diagnostic infos op let generate_tests_emptying_undelegated_implicit () = create_Tztest test_emptying_undelegated_implicit - "(Positive test) fee payment and just enough to empty an undelegated \ - source." + "passes precheck and empties an undelegated source." subjects -let tests = - (test_ensure_manager_operation_coverage () :: generate_low_gas_limit ()) - @ generate_high_gas_limit () +(* Fee payment.*) +let test_precheck kind () = + let open Lwt_result_syntax in + let* infos = init_context () in + let* counter = Context.Contract.counter (B infos.block) infos.contract1 in + let source = infos.contract1 in + let* operation = select_op ~counter ~force_reveal:true ~source kind infos in + precheck_diagnostic infos operation + +let generate_tests_precheck () = + create_Tztest test_precheck "passes precheck." subjects + +let sanity_tests = + test_ensure_manager_operation_coverage () :: generate_tests_precheck () + +let gas_tests = + generate_low_gas_limit () @ generate_high_gas_limit () @ generate_tests_exceeding_block_gas () @ generate_tests_exceeding_block_gas_mp_mode () - @ generate_high_storage_limit () - @ generate_high_counter () @ generate_low_counter () - @ generate_not_allocated () @ generate_tests_high_fee () + +let storage_tests = generate_high_storage_limit () + +let fee_tests = + generate_tests_high_fee () @ generate_tests_emptying_delegated_implicit () @ generate_tests_emptying_self_delegated_implicit () - @ generate_unrevealed_key () @ generate_tests_emptying_undelegated_implicit () + +let contract_tests = + generate_high_counter () @ generate_low_counter () @ generate_not_allocated () + @ generate_unrevealed_key ()