Start applying 'expect failure' in tests
This commit is contained in:
parent
ad827cf060
commit
e52f01caa6
@ -14,6 +14,7 @@ type error +=
|
|||||||
| Unspendable_contract of Contract_repr.contract (* `Permanent *)
|
| Unspendable_contract of Contract_repr.contract (* `Permanent *)
|
||||||
| Non_existing_contract of Contract_repr.contract (* `Temporary *)
|
| Non_existing_contract of Contract_repr.contract (* `Temporary *)
|
||||||
| Empty_implicit_contract of Signature.Public_key_hash.t (* `Temporary *)
|
| Empty_implicit_contract of Signature.Public_key_hash.t (* `Temporary *)
|
||||||
|
| Empty_transaction of Contract_repr.t (* `Temporary *)
|
||||||
| Inconsistent_hash of Signature.Public_key.t * Signature.Public_key_hash.t * Signature.Public_key_hash.t (* `Permanent *)
|
| Inconsistent_hash of Signature.Public_key.t * Signature.Public_key_hash.t * Signature.Public_key_hash.t (* `Permanent *)
|
||||||
| Inconsistent_public_key of Signature.Public_key.t * Signature.Public_key.t (* `Permanent *)
|
| Inconsistent_public_key of Signature.Public_key.t * Signature.Public_key.t (* `Permanent *)
|
||||||
| Failure of string (* `Permanent *)
|
| Failure of string (* `Permanent *)
|
||||||
|
@ -95,6 +95,8 @@ let get_constants b =
|
|||||||
|
|
||||||
module Contract = struct
|
module Contract = struct
|
||||||
|
|
||||||
|
let pp = Alpha_context.Contract.pp
|
||||||
|
|
||||||
let pkh c = Alpha_context.Contract.is_implicit c |> function
|
let pkh c = Alpha_context.Contract.is_implicit c |> function
|
||||||
| Some p -> return p
|
| Some p -> return p
|
||||||
| None -> failwith "pkh: only for implicit contracts"
|
| None -> failwith "pkh: only for implicit contracts"
|
||||||
|
@ -34,6 +34,7 @@ val get_constants: t -> Constants.t tzresult Lwt.t
|
|||||||
|
|
||||||
module Contract : sig
|
module Contract : sig
|
||||||
|
|
||||||
|
val pp : Format.formatter -> Contract.t -> unit
|
||||||
val pkh: Contract.t -> public_key_hash tzresult Lwt.t
|
val pkh: Contract.t -> public_key_hash tzresult Lwt.t
|
||||||
|
|
||||||
type balance_kind = Main | Deposit | Fees | Rewards
|
type balance_kind = Main | Deposit | Fees | Rewards
|
||||||
|
@ -95,9 +95,7 @@ let detect_script_failure :
|
|||||||
| Applied _ -> Ok ()
|
| Applied _ -> Ok ()
|
||||||
| Skipped _ -> assert false
|
| Skipped _ -> assert false
|
||||||
| Failed (_, errs) ->
|
| Failed (_, errs) ->
|
||||||
record_trace
|
Alpha_environment.wrap_error (Error errs) in
|
||||||
(failure "The transfer simulation failed.")
|
|
||||||
(Alpha_environment.wrap_error (Error errs)) in
|
|
||||||
List.fold_left
|
List.fold_left
|
||||||
(fun acc (Internal_operation_result (_, r)) ->
|
(fun acc (Internal_operation_result (_, r)) ->
|
||||||
acc >>? fun () ->
|
acc >>? fun () ->
|
||||||
@ -114,14 +112,20 @@ let detect_script_failure :
|
|||||||
detect_script_failure rest in
|
detect_script_failure rest in
|
||||||
fun { contents } -> detect_script_failure contents
|
fun { contents } -> detect_script_failure contents
|
||||||
|
|
||||||
let add_operation ?(allow_failure=false) st op =
|
let add_operation ?expect_failure st op =
|
||||||
let open Apply_operation_result in
|
let open Apply_operation_result in
|
||||||
M.apply_operation st.state op >>=? function
|
M.apply_operation st.state op >>=? function
|
||||||
| state, Operation_metadata result ->
|
| state, Operation_metadata result ->
|
||||||
begin if allow_failure then
|
Lwt.return @@ detect_script_failure result >>= fun result ->
|
||||||
return ()
|
begin match expect_failure with
|
||||||
else
|
| None ->
|
||||||
Lwt.return @@ detect_script_failure result
|
Lwt.return result
|
||||||
|
| Some f ->
|
||||||
|
match result with
|
||||||
|
| Ok _ ->
|
||||||
|
failwith "Error expected while adding operation"
|
||||||
|
| Error e ->
|
||||||
|
f e
|
||||||
end >>=? fun () ->
|
end >>=? fun () ->
|
||||||
return { st with state ; rev_operations = op :: st.rev_operations }
|
return { st with state ; rev_operations = op :: st.rev_operations }
|
||||||
| state, No_operation_metadata ->
|
| state, No_operation_metadata ->
|
||||||
|
@ -24,7 +24,7 @@ val begin_construction:
|
|||||||
Block.t -> incremental tzresult Lwt.t
|
Block.t -> incremental tzresult Lwt.t
|
||||||
|
|
||||||
val add_operation:
|
val add_operation:
|
||||||
?allow_failure:bool ->
|
?expect_failure:(error list -> unit tzresult Lwt.t) ->
|
||||||
incremental -> Operation.packed -> incremental tzresult Lwt.t
|
incremental -> Operation.packed -> incremental tzresult Lwt.t
|
||||||
|
|
||||||
val finalize_block: incremental -> Block.t tzresult Lwt.t
|
val finalize_block: incremental -> Block.t tzresult Lwt.t
|
||||||
|
@ -19,12 +19,12 @@ open Test_tez
|
|||||||
destination contract with or without the fee of transfer.
|
destination contract with or without the fee of transfer.
|
||||||
2- Check the equivalent of the balance of the source/destination
|
2- Check the equivalent of the balance of the source/destination
|
||||||
contract before and after the transfer *)
|
contract before and after the transfer *)
|
||||||
let transfer_and_check_balances ~loc b ?(fee=Tez.zero) src dst amount =
|
let transfer_and_check_balances ~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 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 () ->
|
Assert.balance_was_debited ~loc (I b) src bal_src amount_fee >>=? 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)
|
||||||
@ -67,10 +67,11 @@ let register_two_contracts () =
|
|||||||
(** 1- Create a block and two contracts/accounts;
|
(** 1- Create a block and two contracts/accounts;
|
||||||
2- Add a single transfer into this block;
|
2- Add a single transfer into this block;
|
||||||
3- Bake this block. *)
|
3- Bake this block. *)
|
||||||
let single_transfer ?fee amount =
|
let single_transfer ?fee ?expect_failure amount =
|
||||||
register_two_contracts () >>=? fun (b, contract_1, contract_2) ->
|
register_two_contracts () >>=? fun (b, contract_1, contract_2) ->
|
||||||
Incremental.begin_construction b >>=? fun b ->
|
Incremental.begin_construction b >>=? fun b ->
|
||||||
transfer_and_check_balances ~loc:__LOC__ ?fee b contract_1 contract_2 amount >>=? fun (b,_) ->
|
transfer_and_check_balances ~loc:__LOC__ ?fee ?expect_failure
|
||||||
|
b contract_1 contract_2 amount >>=? fun (b,_) ->
|
||||||
Incremental.finalize_block b >>=? fun _ ->
|
Incremental.finalize_block b >>=? fun _ ->
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
@ -80,7 +81,13 @@ let block_with_a_single_transfer () =
|
|||||||
|
|
||||||
(** single transfer without fee *)
|
(** single transfer without fee *)
|
||||||
let transfer_zero_tez () =
|
let transfer_zero_tez () =
|
||||||
single_transfer Tez.zero
|
single_transfer ~expect_failure:(
|
||||||
|
function
|
||||||
|
| Alpha_environment.Ecoproto_error (Contract_storage.Empty_transaction _) :: _ ->
|
||||||
|
return ()
|
||||||
|
| _ ->
|
||||||
|
failwith "Empty transaction should fail")
|
||||||
|
Tez.zero
|
||||||
|
|
||||||
(** single transfer with fee *)
|
(** single transfer with fee *)
|
||||||
let block_with_a_single_transfer_with_fee () =
|
let block_with_a_single_transfer_with_fee () =
|
||||||
|
Loading…
Reference in New Issue
Block a user