From 237e108cf410265a06436d7872668cff7e54722c Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Mon, 14 Sep 2020 18:06:58 +0200 Subject: [PATCH 01/17] Testing: Better comments in testing files in lib_protocol --- .../lib_protocol/test/activation.ml | 70 ++++-- src/proto_alpha/lib_protocol/test/baking.ml | 33 ++- .../lib_protocol/test/combined_operations.ml | 47 ++-- .../lib_protocol/test/delegation.ml | 229 +++++++++++++----- .../lib_protocol/test/double_baking.ml | 48 ++-- .../lib_protocol/test/double_endorsement.ml | 47 ++-- .../lib_protocol/test/endorsement.ml | 72 ++++-- .../lib_protocol/test/interpretation.ml | 18 +- src/proto_alpha/lib_protocol/test/main.ml | 7 + .../lib_protocol/test/origination.ml | 69 +++--- src/proto_alpha/lib_protocol/test/qty.ml | 14 ++ src/proto_alpha/lib_protocol/test/rolls.ml | 61 ++++- src/proto_alpha/lib_protocol/test/seed.ml | 45 ++-- src/proto_alpha/lib_protocol/test/transfer.ml | 176 +++++++------- src/proto_alpha/lib_protocol/test/voting.ml | 60 ++++- 15 files changed, 686 insertions(+), 310 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/activation.ml b/src/proto_alpha/lib_protocol/test/activation.ml index 792d4b38efb6..a322b68a01b5 100644 --- a/src/proto_alpha/lib_protocol/test/activation.ml +++ b/src/proto_alpha/lib_protocol/test/activation.ml @@ -23,16 +23,21 @@ (* *) (*****************************************************************************) -(** The activation operation creates an implicit contract from a - registered commitment present in the context. It is parametrized by - a public key hash (pkh) and a secret. +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: The activation operation creates an implicit contract from a + registered commitment present in the context. It is + parametrized by a public key hash (pkh) and a secret. - The commitments are composed of : - - a blinded pkh that can be revealed by the secret ; - - an amount. + The commitments are composed of : + - a blinded pkh that can be revealed by the secret ; + - an amount. - The commitments and the secrets are generated from - /scripts/create_genesis/create_genesis.py and should be coherent. + The commitments and the secrets are generated from + /scripts/create_genesis/create_genenis.py and should be + coherent. *) open Protocol @@ -306,12 +311,17 @@ let activation_init () = Context.init ~with_commitments:true 1 >|=? fun (b, cs) -> secrets () |> fun ss -> (b, cs, ss) +(* Test. + A simple initialization +*) let simple_init_with_commitments () = activation_init () >>=? fun (blk, _contracts, _secrets) -> Block.bake blk >>=? fun _ -> return_unit -(** A single activation *) +(* Test. + A single activation +*) let single_activation () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -336,7 +346,9 @@ let single_activation () = (Contract.implicit_contract account) expected_amount -(** 10 activations, one per bake *) +(* Test. + 10 activations, one per bake +*) let multi_activation_1 () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -356,7 +368,9 @@ let multi_activation_1 () = secrets >>=? fun _ -> return_unit -(** All in one bake *) +(* Test. + All in one bake +*) let multi_activation_2 () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -378,7 +392,9 @@ let multi_activation_2 () = expected_amount) secrets -(** Transfer with activated account *) +(* Test. + Transfer with activated account +*) let activation_and_transfer () = activation_init () >>=? fun (blk, contracts, secrets) -> @@ -408,7 +424,9 @@ let activation_and_transfer () = activated_amount_before half_amount -(** Transfer to an unactivated account and then activating it *) +(* Test. + Transfer to an unactivated account and then activating it +*) let transfer_to_unactivated_then_activate () = activation_init () >>=? fun (blk, contracts, secrets) -> @@ -448,8 +466,10 @@ let transfer_to_unactivated_then_activate () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(** Invalid pkh activation : expected to fail as the context does not - contain any commitment *) +(* Test. + Invalid pkh activation: expected to fail as the context does not + contain any commitment +*) let invalid_activation_with_no_commitments () = Context.init 1 >>=? fun (blk, _) -> @@ -467,7 +487,9 @@ let invalid_activation_with_no_commitments () = | _ -> false) -(** Wrong activation : wrong secret given in the operation *) +(* Test. + Wrong activation : wrong secret given in the operation +*) let invalid_activation_wrong_secret () = activation_init () >>=? fun (blk, _, secrets) -> @@ -485,8 +507,10 @@ let invalid_activation_wrong_secret () = | _ -> false) -(** Invalid pkh activation : expected to fail as the context does not - contain an associated commitment *) +(* Test. + Invalid pkh activation : expected to fail as the context does not + contain an associated commitment +*) let invalid_activation_inexistent_pkh () = activation_init () >>=? fun (blk, _, secrets) -> @@ -505,8 +529,10 @@ let invalid_activation_inexistent_pkh () = | _ -> false) -(** Invalid pkh activation : expected to fail as the commitment has - already been claimed *) +(* Test. + Invalid pkh activation : expected to fail as the commitment has + already been claimed +*) let invalid_double_activation () = activation_init () >>=? fun (blk, _, secrets) -> @@ -529,7 +555,9 @@ let invalid_double_activation () = | _ -> false) -(** Transfer from an unactivated commitment account *) +(* Test. + Transfer from an unactivated commitment account +*) let invalid_transfer_from_unactivated_account () = activation_init () >>=? fun (blk, contracts, secrets) -> diff --git a/src/proto_alpha/lib_protocol/test/baking.ml b/src/proto_alpha/lib_protocol/test/baking.ml index 9b750d2e33fe..89a4719e70da 100644 --- a/src/proto_alpha/lib_protocol/test/baking.ml +++ b/src/proto_alpha/lib_protocol/test/baking.ml @@ -24,10 +24,20 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Rewards and bakers. +*) + open Protocol open Alpha_context -(** Tests for [bake_n] and [bake_until_end_cycle]. *) +(* Test. + In a cycle, [bake_until_cycle_end] returns a block at level + [blocks_per_cycle]. Then, [bake_n n] bakes [n] blocks. +*) let test_cycle () = Context.init 5 >>=? fun (b, _) -> @@ -35,8 +45,6 @@ let test_cycle () = >>=? fun csts -> let blocks_per_cycle = csts.parametric.blocks_per_cycle in let pp fmt x = Format.fprintf fmt "%ld" x in - (* Tests that [bake_until_cycle_end] returns a block at - level [blocks_per_cycle]. *) Block.bake b >>=? fun b -> Block.bake_until_cycle_end b @@ -51,7 +59,6 @@ let test_cycle () = (Alpha_context.Raw_level.to_int32 curr_level) blocks_per_cycle >>=? fun () -> - (* Tests that [bake_n n] bakes [n] blocks. *) Context.get_level (B b) >>?= fun l -> Block.bake_n 10 b @@ -66,8 +73,10 @@ let test_cycle () = (Alpha_context.Raw_level.to_int32 curr_level) (Int32.add (Alpha_context.Raw_level.to_int32 l) 10l) -(** Check that after baking and/or endorsing a block the baker and the - endorsers get their reward *) +(* Test. + After baking and/or endorsing a block, the baker and the endorsers + get their reward +*) let test_rewards_retrieval () = Context.init 256 >>=? fun (b, _) -> @@ -165,8 +174,10 @@ let test_rewards_retrieval () = real_endorsers) ranges -(** Tests the baking and endorsing rewards formulas against a - precomputed table *) +(* Test. + Checks the baking and endorsing rewards formulas against a precomputed + table +*) let test_rewards_formulas () = Context.init 1 >>=? fun (b, _) -> @@ -197,8 +208,10 @@ let test_rewards_formulas () = let wrap e = Lwt.return (Environment.wrap_error e) -(* Check that the rewards formulas from Context are - equivalent with the ones from Baking *) +(* Test. + Check that the rewards formulas from Context are equivalent with + the ones from Baking +*) let test_rewards_formulas_equivalence () = Context.init 1 >>=? fun (b, _) -> diff --git a/src/proto_alpha/lib_protocol/test/combined_operations.ml b/src/proto_alpha/lib_protocol/test/combined_operations.ml index 84d9b38146c8..2bfc043ca7f9 100644 --- a/src/proto_alpha/lib_protocol/test/combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/combined_operations.ml @@ -23,23 +23,32 @@ (* *) (*****************************************************************************) -(** Multiple operations can be grouped in one ensuring their - deterministic application. +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Multiple operations can be grouped in one ensuring their + deterministic application. - If an invalid operation is present in this group of operation, the - previous applied operations are backtracked leaving the context - unchanged and the following operations are skipped. Fees attributed - to the operations are collected by the baker nonetheless. + If an invalid operation is present in this group of + operation, the previous applied operations are backtracked + leaving the context unchanged and the following operations + are skipped. Fees attributed to the operations are collected + by the baker nonetheless. - Only manager operations are allowed in multiple transactions. - They must all belong to the same manager as there is only one signature. *) + Only manager operations are allowed in multiple transactions. + They must all belong to the same manager as there is only one + signature. +*) open Protocol open Test_tez let ten_tez = Tez.of_int 10 -(** Groups ten transactions between the same parties. *) +(* Test. + Groups ten transactions between the same parties. +*) let multiple_transfers () = Context.init 3 >>=? fun (blk, contracts) -> @@ -73,7 +82,9 @@ let multiple_transfers () = (Tez.of_int 10) >>=? fun () -> return_unit -(** Groups ten delegated originations. *) +(* Test. + Groups ten delegated originations. +*) let multiple_origination_and_delegation () = Context.init 2 >>=? fun (blk, contracts) -> @@ -159,9 +170,11 @@ let expect_balance_too_low = function "Contract should not have a sufficient balance : operation expected \ to fail." -(** Groups three operations, the middle one failing. - Checks that the receipt is consistent. - Variant without fees. *) +(* Test. + Groups three operations, the middle one failing. + Checks that the receipt is consistent. + Variant without fees. +*) let failing_operation_in_the_middle () = Context.init 2 >>=? fun (blk, contracts) -> @@ -216,9 +229,11 @@ let failing_operation_in_the_middle () = Assert.balance_is ~loc:__LOC__ (I inc) c2 c2_old_balance >>=? fun () -> return_unit -(** Groups three operations, the middle one failing. - Checks that the receipt is consistent. - Variant with fees, that should be spent even in case of failure. *) +(* Test. + Groups three operations, the middle one failing. + Checks that the receipt is consistent. + Variant with fees, that should be spent even in case of failure. +*) let failing_operation_in_the_middle_with_fees () = Context.init 2 >>=? fun (blk, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/delegation.ml b/src/proto_alpha/lib_protocol/test/delegation.ml index f9ddabc64207..bf72bd377881 100644 --- a/src/proto_alpha/lib_protocol/test/delegation.ml +++ b/src/proto_alpha/lib_protocol/test/delegation.ml @@ -23,16 +23,24 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Boostrap contracts. Delegate registration. +*) + open Protocol open Alpha_context open Test_tez -(**************************************************************************) -(* bootstrap contracts *) -(**************************************************************************) -(* Bootstrap contracts are heavily used in other tests. It is helpful - to test some properties of these contracts, so we can correctly - interpret the other tests that use them. *) +(*****************************************************************************) +(* Bootstrap contracts + ------------------- + Bootstrap contracts are heavily used in other tests. It is helpful to test + some properties of these contracts, so we can correctly interpret the other + tests that use them. *) +(*****************************************************************************) let expect_error err = function | err0 :: _ when err = err0 -> @@ -49,7 +57,9 @@ let expect_no_change_registered_delegate_pkh pkh = function | _ -> failwith "Delegate can not be deleted and operation should fail." -(** bootstrap contracts delegate to themselves *) +(* Test. + Bootstrap contracts delegate to themselves +*) let bootstrap_manager_is_bootstrap_delegate () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -59,7 +69,9 @@ let bootstrap_manager_is_bootstrap_delegate () = Context.Contract.manager (B b) bootstrap0 >>=? fun manager0 -> Assert.equal_pkh ~loc:__LOC__ delegate0 manager0.pkh -(** bootstrap contracts cannot change their delegate *) +(* Test. + Bootstrap contracts cannot change their delegate +*) let bootstrap_delegate_cannot_change ~fee () = Context.init 2 >>=? fun (b, bootstrap_contracts) -> @@ -102,7 +114,9 @@ let bootstrap_delegate_cannot_change ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (B b) bootstrap0 balance0 fee -(** bootstrap contracts cannot delete their delegation *) +(* Test. + Bootstrap contracts cannot delete their delegation +*) let bootstrap_delegate_cannot_be_removed ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -140,7 +154,9 @@ let bootstrap_delegate_cannot_be_removed ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) bootstrap balance fee -(** contracts not registered as delegate can change their delegation *) +(* Test. + Contracts not registered as delegate can change their delegation +*) let delegate_can_be_changed_from_unregistered_contract ~fee () = Context.init 2 >>=? fun (b, bootstrap_contracts) -> @@ -193,7 +209,9 @@ let delegate_can_be_changed_from_unregistered_contract ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) unregistered credit fee -(** contracts not registered as delegate can delete their delegation *) +(* Test. + Contracts not registered as delegate can delete their delegation +*) let delegate_can_be_removed_from_unregistered_contract ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -246,7 +264,9 @@ let delegate_can_be_removed_from_unregistered_contract ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) unregistered credit fee -(** bootstrap keys are already registered as delegate keys *) +(* Test. + Bootstrap keys are already registered as delegate keys +*) let bootstrap_manager_already_registered_delegate ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -282,8 +302,10 @@ let bootstrap_manager_already_registered_delegate ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) impl_contract balance fee -(** bootstrap manager can be set as delegate of an originated contract - (through origination operation) *) +(* Test. + Bootstrap manager can be set as delegate of an originated contract + (through origination operation) +*) let delegate_to_bootstrap_by_origination ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -417,59 +439,57 @@ let tests_bootstrap_contracts = `Quick (delegate_to_bootstrap_by_origination ~fee:(Tez.of_int 10_000_000)) ] -(**************************************************************************) -(* delegate registration *) -(**************************************************************************) -(* A delegate is a pkh. Delegates must be registered. Registration is +(*****************************************************************************) +(* Delegate registration + --------------------- + A delegate is a pkh. Delegates must be registered. Registration is done via the self-delegation of the implicit contract corresponding to the pkh. The implicit contract must be credited when the self-delegation is done. Furthermore, trying to register an already registered key raises an error. - + In this series of tests, we verify that 1- unregistered delegate keys cannot be delegated to, 2- registered keys can be delegated to, 3- registering an already registered key raises an error. - - + We consider three scenarios for setting a delegate: - through origination, - through delegation when the implicit contract has no delegate yet, - through delegation when the implicit contract already has a delegate. - + We also test that emptying the implicit contract linked to a registered delegate key does not unregister the delegate key. -*) - -(* + Valid registration - + ------------------ Unregistered key: - contract not credited and no self-delegation - contract credited but no self-delegation - contract not credited and self-delegation + + Not credited: + - no credit operation + - credit operation of 1μꜩ and then debit operation of 1μꜩ *) +(*****************************************************************************) -Not credited: -- no credit operation -- credit operation of 1μꜩ and then debit operation of 1μꜩ - -*) +(* Part A. + Unregistered delegate keys cannot be used for delegation -(** A- unregistered delegate keys cannot be used for delegation *) + Two main series of tests: without self-delegation, and with a failed attempt at self-delegation: -(* Two main series of tests: without self-delegation, and with a failed attempt at self-delegation - 1- no self-delegation - a- no credit - - no token transfer - - credit of 1μꜩ and then debit of 1μꜩ - b- with credit of 1μꜩ. - For every scenario, we try three different ways of delegating: - - through origination (init origination) - - through delegation when no delegate was assigned (init delegation) - - through delegation when a delegate was assigned (switch delegation). + 1/ no self-delegation + a/ no credit + - no token transfer + - credit of 1μꜩ and then debit of 1μꜩ + b/ with credit of 1μꜩ. + For every scenario, we try three different ways of delegating: + - through origination (init origination) + - through delegation when no delegate was assigned (init delegation) + - through delegation when a delegate was assigned (switch delegation). - 2- Self-delegation fails if the contract has no credit. We try the - two possibilities of 1a for non-credited contracts. + 2/ Self-delegation fails if the contract has no credit. We try the + two possibilities of 1a for non-credited contracts. *) let expect_unregistered_key pkh = function @@ -479,8 +499,14 @@ let expect_unregistered_key pkh = function | _ -> failwith "Delegate key is not registered: operation should fail." -(* A1: no self-delegation *) -(* no token transfer, no self-delegation *) +(* Part A. Section 1. + No self-delegation +*) + +(* Test. + No token transfer, no self-delegation. + Originated account. +*) let unregistered_delegate_key_init_origination ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -532,6 +558,10 @@ let unregistered_delegate_key_init_origination ~fee () = | _ -> false) +(* Test. + Delegation when delegate key is not assigned. Delegate account is + initialized. +*) let unregistered_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -582,6 +612,9 @@ let unregistered_delegate_key_init_delegation ~fee () = | _ -> false) +(* Test. + Re-delegation when a delegate key was already assigned. +*) let unregistered_delegate_key_switch_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -640,7 +673,10 @@ let unregistered_delegate_key_switch_delegation ~fee () = >>=? fun delegate_pkh_after -> Assert.equal_pkh ~loc:__LOC__ delegate_pkh delegate_pkh_after -(* credit of some amount, no self-delegation *) +(* Test. + Same as [unregistered_delegate_key_init_origination] and credits [amount], + no self-delegation. +*) let unregistered_delegate_key_init_origination_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -692,6 +728,10 @@ let unregistered_delegate_key_init_origination_credit ~fee ~amount () = | _ -> false) +(* Test. + Same as [unregistered_delegate_key_init_delegation] and credits the + amount [amount] of the implicit contract. +*) let unregistered_delegate_key_init_delegation_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -750,6 +790,10 @@ let unregistered_delegate_key_init_delegation_credit ~fee ~amount () = | _ -> false) +(* Test. + Same as in [unregistered_delegate_key_switch_delegation] and credits the + amount [amount] to the implicit contract. +*) let unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -817,7 +861,10 @@ let unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Assert.not_equal_pkh ~loc:__LOC__ delegate unregistered_delegate_pkh >>=? fun () -> Assert.equal_pkh ~loc:__LOC__ delegate bootstrap_pkh -(* a credit of some amount followed by a debit of the same amount, no self-delegation *) +(* Test. + A credit of some amount followed by a debit of the same amount, + no self-delegation +*) let unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -876,6 +923,10 @@ let unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = | _ -> false) +(* Test. + Same as in [unregistered_delegate_key_init_delegation] but credits then + debits the amount [amount] to the implicit contract. +*) let unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -939,6 +990,10 @@ let unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = | _ -> false) +(* Test. + Same as in [unregistered_delegate_key_switch_delegation] but credits then + debits the amount [amount] to the implicit contract. +*) let unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1010,7 +1065,13 @@ let unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = >>=? fun delegate -> Assert.not_equal_pkh ~loc:__LOC__ delegate unregistered_delegate_pkh -(* A2- self-delegation to an empty contract fails *) +(* Part A. Section 2. + Self-delegation to an empty contract fails +*) + +(* Test. + Self-delegation with zero-balance contract should fail. +*) let failed_self_delegation_no_transaction () = Context.init 1 >>=? fun (b, _) -> @@ -1035,6 +1096,10 @@ let failed_self_delegation_no_transaction () = | _ -> false) +(* Test. + Implicit contract is credited then debited of same amount (i.e., is + emptied). Self-delegation fails. +*) let failed_self_delegation_emptied_implicit_contract amount () = (* create an implicit contract *) Context.init 1 @@ -1070,6 +1135,11 @@ let failed_self_delegation_emptied_implicit_contract amount () = | _ -> false) +(* Test. + Implicit contract is credited with a non-zero quantity [amount] tz, then it + is delegated. The operation of debit of [amount] tz should fail as the + contract is already delegated. +*) let emptying_delegated_implicit_contract_fails amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1104,11 +1174,17 @@ let emptying_delegated_implicit_contract_fails amount () = | _ -> false) -(** B- valid registration: - - credit implicit contract with some ꜩ + verification of balance - - self delegation + verification - - empty contract + verification of balance + verification of not being erased / self-delegation - - create delegator implicit contract w first implicit contract as delegate + verification of delegation *) +(* Part B. + - Valid registration: + - Credit implicit contract with some ꜩ + verification of balance + - Self delegation + verification + - Empty contract + verification of balance + verification of not being erased / self-delegation + - Create delegator implicit contract w first implicit contract as delegate + verification of delegation +*) + +(* Test. + Initialized account is credited of [amount] tz, then self-delegated. +*) let valid_delegate_registration_init_delegation_credit amount () = (* create an implicit contract *) Context.init 1 @@ -1162,6 +1238,11 @@ let valid_delegate_registration_init_delegation_credit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh +(* Test. + Creates an implicit contract, credits with [amount] tz. Self-delegates. + Creates another implicit contract with bootstrap as delegate. + Re-delegates it to the first implicit contract. +*) let valid_delegate_registration_switch_delegation_credit amount () = (* create an implicit contract *) Context.init 1 @@ -1216,6 +1297,9 @@ let valid_delegate_registration_switch_delegation_credit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh +(* Test. + Creates an implicit contract. +*) let valid_delegate_registration_init_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 @@ -1284,6 +1368,13 @@ let valid_delegate_registration_init_delegation_credit_debit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh +(* Test. + A created implicit contract is credited with [amount] tz, then is + self-delegated. It is emptied (funds back into bootstrap), and + should remain existing (as registered as delegate). Another created + implicit contract is delegated to bootstrap, then should be able to + be re-delegated to the latter contract. +*) let valid_delegate_registration_switch_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 @@ -1348,9 +1439,13 @@ let valid_delegate_registration_switch_delegation_credit_debit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh -(* with implicit contract with some credit *) +(* Part C. + A second self-delegation should raise an `Active_delegate` error +*) -(** C- a second self-delegation should raise an `Active_delegate` error *) +(* Test. + Second self-delegation should fail with implicit contract with some credit. +*) let double_registration () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1383,7 +1478,10 @@ let double_registration () = | _ -> false) -(* with implicit contract emptied after first self-delegation *) +(* Test. + Second self-delegation should fail with implicit contract emptied after + first self-delegation. +*) let double_registration_when_empty () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1423,7 +1521,10 @@ let double_registration_when_empty () = | _ -> false) -(* with implicit contract emptied then recredited after first self-delegation *) +(* Test. + Second self-delegation should fail with implicit contract emptied then + recredited after first self-delegation. +*) let double_registration_when_recredited () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1470,7 +1571,9 @@ let double_registration_when_recredited () = | _ -> false) -(* self-delegation on unrevealed contract *) +(* Test. + Self-delegation on unrevealed contract +*) let unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1505,7 +1608,9 @@ let unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = >>=? fun i -> Assert.balance_was_debited ~loc:__LOC__ (I i) contract balance fee -(* self-delegation on revealed but not registered contract *) +(* Test. + Self-delegation on revealed but not registered contract +*) let unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1544,7 +1649,9 @@ let unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = >>=? fun i -> Assert.balance_was_debited ~loc:__LOC__ (I i) contract balance fee -(* self-delegation on revealed and registered contract *) +(* Test. + Self-delegation on revealed and registered contract +*) let registered_self_delegate_key_init_delegation () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/double_baking.ml b/src/proto_alpha/lib_protocol/test/double_baking.ml index f4aa22ca8bb0..92fb1ec0bc2d 100644 --- a/src/proto_alpha/lib_protocol/test/double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/double_baking.ml @@ -23,8 +23,13 @@ (* *) (*****************************************************************************) -(** Double baking evidence operation may happen when a baker - baked two different blocks on the same level. *) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Double baking evidence operation may happen when a baker + baked two different blocks on the same level. +*) open Protocol open Alpha_context @@ -65,8 +70,10 @@ let block_fork ?policy contracts b = (* Tests *) (****************************************************************) -(** Simple scenario where two blocks are baked by a same baker and - exposed by a double baking evidence operation *) +(* Test. + Simple scenario where two blocks are baked by a same baker and + exposed by a double baking evidence operation +*) let valid_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> @@ -92,7 +99,10 @@ let valid_double_baking_evidence () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(** Check that a double baking operation fails if it exposes the same two blocks *) +(* Test. + Check that a double baking operation fails if it exposes the same two + blocks +*) let same_blocks () = Context.init 2 >>=? fun (b, _contracts) -> @@ -109,8 +119,10 @@ let same_blocks () = false) >>=? fun () -> return_unit -(** Check that a double baking operation exposing two blocks with - different levels fails *) +(* Test. + Check that a double baking operation exposing two blocks with + different levels fails +*) let different_levels () = Context.init 2 >>=? fun (b, contracts) -> @@ -128,8 +140,10 @@ let different_levels () = | _ -> false) -(** Check that a double baking operation exposing two yet to be baked - blocks fails *) +(* Test. + Check that a double baking operation exposing two yet to be baked + blocks fails +*) let too_early_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> @@ -145,8 +159,10 @@ let too_early_double_baking_evidence () = | _ -> false) -(** Check that after [preserved_cycles + 1], it is not possible to - create a double baking operation anymore *) +(* Test. + Check that after [preserved_cycles + 1], it is not possible to + create a double baking operation anymore +*) let too_late_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> @@ -169,8 +185,10 @@ let too_late_double_baking_evidence () = | _ -> false) -(** Check that an invalid double baking evidence that exposes two block - baking with same level made by different bakers fails *) +(* Test. + Check that an invalid double baking evidence that exposes two block + baking with same level made by different bakers fails +*) let different_delegates () = Context.init 2 >>=? fun (b, _) -> @@ -190,8 +208,10 @@ let different_delegates () = | _ -> false) +(* Test. + Baker_2 bakes a block but baker signs it +*) let wrong_signer () = - (* Baker_2 bakes a block but baker signs it. *) let header_custom_signer baker baker_2 b = Block.Forge.forge_header ~policy:(By_account baker_2) b >>=? fun header -> diff --git a/src/proto_alpha/lib_protocol/test/double_endorsement.ml b/src/proto_alpha/lib_protocol/test/double_endorsement.ml index ca73e1b9be0f..3d4799ec7e47 100644 --- a/src/proto_alpha/lib_protocol/test/double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/double_endorsement.ml @@ -23,8 +23,13 @@ (* *) (*****************************************************************************) -(** Double endorsement evidence operation may happen when an endorser - endorsed two different blocks on the same level. *) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Double endorsement evidence operation may happen when an + endorser endorsed two different blocks on the same level. +*) open Protocol open Alpha_context @@ -63,9 +68,11 @@ let block_fork b = (* Tests *) (****************************************************************) -(** Simple scenario where two endorsements are made from the same - delegate and exposed by a double_endorsement operation. Also verify - that punishment is operated. *) +(* Test. + Simple scenario where two endorsements are made from the same + delegate and exposed by a double_endorsement operation. Also verify + that punishment is operated. +*) let valid_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> @@ -100,8 +107,10 @@ let valid_double_endorsement_evidence () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(** Check that an invalid double endorsement operation that exposes a valid - endorsement fails. *) +(* Test. + Check that an invalid double endorsement operation that exposes a valid + endorsement fails. +*) let invalid_double_endorsement () = Context.init 10 >>=? fun (b, _) -> @@ -121,8 +130,10 @@ let invalid_double_endorsement () = | _ -> false) -(** Check that a double endorsement added at the same time as a double - endorsement operation fails. *) +(* Test. + Check that a double endorsement added at the same time as a double + endorsement operation fails. +*) let too_early_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> @@ -144,8 +155,10 @@ let too_early_double_endorsement_evidence () = | _ -> false) -(** Check that after [preserved_cycles + 1], it is not possible - to create a double_endorsement anymore. *) +(* Test. + Check that after [preserved_cycles + 1], it is not possible + to create a double_endorsement anymore. +*) let too_late_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> @@ -174,8 +187,10 @@ let too_late_double_endorsement_evidence () = | _ -> false) -(** Check that an invalid double endorsement evidence that expose two - endorsements made by two different endorsers fails. *) +(* Test. + Check that an invalid double endorsement evidence that expose two + endorsements made by two different endorsers fails. +*) let different_delegates () = Context.init 2 >>=? fun (b, _) -> @@ -208,8 +223,10 @@ let different_delegates () = | _ -> false) -(** Check that a double endorsement evidence that exposes a ill-formed - endorsement fails. *) +(* Test. + Check that a double endorsement evidence that exposes a ill-formed + endorsement fails. +*) let wrong_delegate () = Context.init ~endorsers_per_block:1 2 >>=? fun (b, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/endorsement.ml b/src/proto_alpha/lib_protocol/test/endorsement.ml index 58cb03542767..e6726b856c63 100644 --- a/src/proto_alpha/lib_protocol/test/endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/endorsement.ml @@ -23,12 +23,18 @@ (* *) (*****************************************************************************) -(** Endorsing a block adds an extra layer of confidence to the Tezos' - PoS algorithm. The block endorsing operation must be included in - the following block. Each endorser possess a number of slots - corresponding to their priority. After [preserved_cycles], a reward - is given to the endorser. This reward depends on the priority of - the block that contains the endorsements. *) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Endorsing a block adds an extra layer of confidence to the + Tezos' PoS algorithm. The block endorsing operation must be + included in the following block. Each endorser possess a + number of slots corresponding to their priority. After + [preserved_cycles], a reward is given to the endorser. This + reward depends on the priority of the block that contains + the endorsements. +*) open Protocol open Alpha_context @@ -97,7 +103,9 @@ let endorsing_power endorsers = (* Tests *) (****************************************************************) -(** Apply a single endorsement from the slot 0 endorser *) +(* Test. + Apply a single endorsement from the slot 0 endorser +*) let simple_endorsement () = Context.init 5 >>=? fun (b, _) -> @@ -120,8 +128,10 @@ let simple_endorsement () = delegate initial_balance -(** Apply a maximum number of endorsements. An endorser can be - selected twice. *) +(* Test. + Apply a maximum number of endorsements. An endorser can be + selected twice. +*) let max_endorsement () = let endorsers_per_block = 16 in Context.init ~endorsers_per_block 32 @@ -167,7 +177,10 @@ let max_endorsement () = delegates previous_balances -(** Check every that endorsers' balances are consistent with different priorities *) +(* Test. + Check every that endorsers' balances are consistent with different + priorities +*) let consistent_priorities () = let priorities = 0 -- 64 in Context.init 64 @@ -221,7 +234,9 @@ let consistent_priorities () = priorities >>=? fun _b -> return_unit -(** Check that after [preserved_cycles] cycles the endorser gets his reward *) +(* Test. + Check that after [preserved_cycles] cycles the endorser gets his reward +*) let reward_retrieval () = Context.init 5 >>=? fun (b, _) -> @@ -258,9 +273,11 @@ let reward_retrieval () = balance reward -(** Check that after [preserved_cycles] cycles endorsers get their - reward. Two endorsers are used and they endorse in different - cycles. *) +(* Test. + Check that after [preserved_cycles] cycles endorsers get their + reward. Two endorsers are used and they endorse in different + cycles. +*) let reward_retrieval_two_endorsers () = Context.init 5 >>=? fun (b, _) -> @@ -418,8 +435,10 @@ let reward_retrieval_two_endorsers () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(** Wrong endorsement predecessor : apply an endorsement with an - incorrect block predecessor *) +(* Test. + Wrong endorsement predecessor : apply an endorsement with an + incorrect block predecessor +*) let wrong_endorsement_predecessor () = Context.init 5 >>=? fun (b, _) -> @@ -438,8 +457,10 @@ let wrong_endorsement_predecessor () = | _ -> false) -(** Invalid_endorsement_level : apply an endorsement with an incorrect - level (i.e. the predecessor level) *) +(* Test. + Invalid_endorsement_level : apply an endorsement with an incorrect + level (i.e. the predecessor level) +*) let invalid_endorsement_level () = Context.init 5 >>=? fun (b, _) -> @@ -458,7 +479,9 @@ let invalid_endorsement_level () = | _ -> false) -(** Duplicate endorsement : apply an endorsement that has already been done *) +(* Test. + Duplicate endorsement : apply an endorsement that has already been done +*) let duplicate_endorsement () = Context.init 5 >>=? fun (b, _) -> @@ -480,7 +503,9 @@ let duplicate_endorsement () = | _ -> false) -(** Apply a single endorsement from the slot 0 endorser *) +(* Test. + Apply a single endorsement from the slot 0 endorser +*) let not_enough_for_deposit () = Context.init 5 ~endorsers_per_block:1 >>=? fun (b_init, contracts) -> @@ -531,7 +556,9 @@ let not_enough_for_deposit () = | _ -> false) -(* check that a block with not enough endorsement cannot be baked *) +(* Test. + Check that a block with not enough endorsement cannot be baked +*) let endorsement_threshold () = let initial_endorsers = 28 in let num_accounts = 100 in @@ -590,6 +617,9 @@ let endorsement_threshold () = b >>= fun _ -> return_unit +(* Test. + Fitness gap +*) let test_fitness_gap () = let num_accounts = 5 in Context.init num_accounts diff --git a/src/proto_alpha/lib_protocol/test/interpretation.ml b/src/proto_alpha/lib_protocol/test/interpretation.ml index da8ed0874618..3ab19d5e2c5f 100644 --- a/src/proto_alpha/lib_protocol/test/interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/interpretation.ml @@ -1,3 +1,11 @@ +(* Testing + ------- + Component: Protocol + Dependencies: src/proto_alpha/lib_protocol/script_interpreter.ml + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Interpretation of Michelson scripts +*) + open Protocol open Alpha_context open Script_interpreter @@ -67,8 +75,10 @@ let run_step ctxt code param = code param -(** Runs a script with an ill-typed parameter and verifies that a - Bad_contract_parameter error is returned *) +(* Test. + Runs a script with an ill-typed parameter and verifies that a + Bad_contract_parameter error is returned +*) let test_bad_contract_parameter () = test_context () >>=? fun ctx -> @@ -120,7 +130,6 @@ let test_stack_overflow () = Alcotest.failf "Unexpected error (%s)" __LOC__ (** Test the encoding/decoding of script_interpreter.ml specific errors *) - let test_json_roundtrip name testable enc v = let v' = Data_encoding.Json.destruct enc (Data_encoding.Json.construct enc v) @@ -132,6 +141,9 @@ let test_json_roundtrip name testable enc v = v' ; return_unit +(* Test. + Encoding/decoding of script_interpreter.ml specific errors +*) let test_json_roundtrip_err name e () = test_json_roundtrip name diff --git a/src/proto_alpha/lib_protocol/test/main.ml b/src/proto_alpha/lib_protocol/test/main.ml index fcfdc965fb33..f16964104448 100644 --- a/src/proto_alpha/lib_protocol/test/main.ml +++ b/src/proto_alpha/lib_protocol/test/main.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Entrypoint +*) + let () = Alcotest_lwt.run "protocol_alpha" diff --git a/src/proto_alpha/lib_protocol/test/origination.ml b/src/proto_alpha/lib_protocol/test/origination.ml index efeec384e7e8..3ae74d0498ef 100644 --- a/src/proto_alpha/lib_protocol/test/origination.ml +++ b/src/proto_alpha/lib_protocol/test/origination.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On originating contracts. +*) + open Protocol open Test_tez @@ -114,7 +121,7 @@ let test_origination_balances ~loc:_ ?(fee = Tez.zero) ?(credit = Tez.zero) () Assert.balance_is ~loc:__LOC__ (B b) new_contract credit (******************************************************) -(** Tests *) +(* Tests *) (******************************************************) @@ -125,26 +132,33 @@ let two_nth_of_balance incr contract nth = >>=? fun balance -> Lwt.return (Tez.( /? ) balance nth >>? fun res -> Tez.( *? ) res 2L) -(*******************) -(** Basic test *) - -(*******************) - +(* Test. + Basic test. A contract is created as well as the newly originated contract + (called from origination operation). The balance before/after are checked. +*) let balances_simple () = test_origination_balances ~loc:__LOC__ () +(* Test. + Same as [balances_simple] but credits 10 tez to the originated contract + (no fees). +*) let balances_credit () = test_origination_balances ~loc:__LOC__ ~credit:ten_tez () +(* Test. + Same as [balances_credit] with 10 tez fees. +*) let balances_credit_fee () = test_origination_balances ~loc:__LOC__ ~credit:(Tez.of_int 2) ~fee:ten_tez () +(* Test. + Same as the basic test. +*) let balances_undelegatable () = test_origination_balances ~loc:__LOC__ () -(*******************) -(** ask source contract to pay a fee when originating a contract *) - -(*******************) - +(* Test. + Ask source contract to pay a fee when originating a contract +*) let pay_fee () = register_origination ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun (_b, _contract, _new_contract) -> return_unit @@ -154,12 +168,10 @@ let pay_fee () = (******************************************************) -(*******************) -(** create an originate contract where the contract - does not have enough tez to pay for the fee *) - -(*******************) - +(* Test. + Create an originate contract where the contract + does not have enough tez to pay for the fee. +*) let not_tez_in_contract_to_pay_fee () = Context.init 2 >>=? fun (b, contracts) -> @@ -195,11 +207,8 @@ let not_tez_in_contract_to_pay_fee () = | _ -> false) -(***************************************************) -(* set the endorser of the block as manager/delegate of the originated +(* Set the endorser of the block as manager/delegate of the originated account *) -(***************************************************) - let register_contract_get_endorser () = Context.init 1 >>=? fun (b, contracts) -> @@ -209,12 +218,7 @@ let register_contract_get_endorser () = Context.get_endorser (I inc) >|=? fun (account_endorser, _slots) -> (inc, contract, account_endorser) -(*******************) -(** create multiple originated contracts and - ask contract to pay the fee *) - -(*******************) - +(* Create multiple originated contracts and ask contract to pay the fee *) let n_originations n ?credit ?fee () = List.fold_left_es (fun new_contracts _ -> @@ -223,16 +227,17 @@ let n_originations n ?credit ?fee () = [] (1 -- n) +(* Test. + Creates 100 originations. +*) let multiple_originations () = n_originations 100 ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun contracts -> Assert.equal_int ~loc:__LOC__ (List.length contracts) 100 -(*******************) -(** cannot originate two contracts with the same context's counter *) - -(*******************) - +(* Test. + Cannot originate two contracts with the same context's counter +*) let counter () = Context.init 1 >>=? fun (b, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/qty.ml b/src/proto_alpha/lib_protocol/test/qty.ml index 0aeea4bb4e8a..95790c82ae40 100644 --- a/src/proto_alpha/lib_protocol/test/qty.ml +++ b/src/proto_alpha/lib_protocol/test/qty.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On tez quantities. +*) + open Protocol let known_ok_tez_literals = @@ -80,6 +87,9 @@ let is_none ?(msg = "") x = if x <> None then fail "None" "Some _" msg let is_some ?(msg = "") x = if x = None then fail "Some _" "None" msg +(* Test. + Literals which are supposed to be parsed correctly. +*) let test_known_tez_literals () = List.iter (fun (v, s) -> @@ -116,6 +126,10 @@ let test_known_tez_literals () = known_bad_tez_literals ; return_unit +(* Test. + Randomly generated tez value which is printed into string then parsed again + to test equality. +*) let test_random_tez_literals () = for _ = 0 to 100_000 do let v = Random.int64 12L in diff --git a/src/proto_alpha/lib_protocol/test/rolls.ml b/src/proto_alpha/lib_protocol/test/rolls.ml index a8f2fbd418c6..9f30f19c4ac5 100644 --- a/src/proto_alpha/lib_protocol/test/rolls.ml +++ b/src/proto_alpha/lib_protocol/test/rolls.ml @@ -23,6 +23,20 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On rolls and baking rights. + A delegate has baking rights provided that it has at least + more than [token_per_rolls] tz of staking balance. This + balance corresponds to the quantity of tez that have been + delegated to it for baking rights. After a given number of + cycles where it has not made use of its baking rights, its + account will be deactivated for baker selection. To bake + again, it will have to re-activate its account. +*) + open Protocol open Alpha_context open Test_tez @@ -46,7 +60,12 @@ let get_rolls ctxt delegate = >>=? function | None -> return_nil | Some head_roll -> traverse_rolls ctxt head_roll -let check_rolls b (account : Account.t) = +(* Baking rights consistency. Asserts that the number of rolls for + [account]'s pkh - equals to the number of expected rolls, i.e., + staking balance of [account] / (token_per_roll). As of protocol + version 007, token_per_roll = 8000. +*) +let check_rolls (b : Block.t) (account : Account.t) = Context.get_constants (B b) >>=? fun constants -> Context.Delegate.info (B b) account.pkh @@ -82,6 +101,12 @@ let check_no_rolls (b : Block.t) (account : Account.t) = get_rolls ctxt account.pkh >>=? fun rolls -> Assert.equal_int ~loc:__LOC__ (List.length rolls) 0 +(* Test. + Creates a block with two initialized contracts/accounts. Asserts + that the first account has a staking balance which equals to its + own balance, and that its staking rights are consistent + (check_rolls). +*) let simple_staking_rights () = Context.init 2 >>=? fun (b, accounts) -> @@ -95,6 +120,12 @@ let simple_staking_rights () = Assert.equal_tez ~loc:__LOC__ balance info.staking_balance >>=? fun () -> check_rolls b m1 +(* Test. + Creates a block with two initialized contracts/accounts. Bakes five + blocks. Asserts that the staking balance of the first account + equals to its balance. Then both accounts have consistent staking + rights. +*) let simple_staking_rights_after_baking () = Context.init 2 >>=? fun (b, accounts) -> @@ -151,6 +182,11 @@ let run_until_deactivation () = check_activate_staking_balance ~loc:__LOC__ ~deactivated:true b (a1, m1) >|=? fun () -> (b, ((a1, m1), balance_start), (a2, m2)) +(* Test. + From an initialized block with two contracts/accounts, the first + one is active then deactivated. After baking, checks that the + account is active again. Baking rights are ensured. +*) let deactivation_then_bake () = run_until_deactivation () >>=? fun ( b, @@ -162,6 +198,11 @@ let deactivation_then_bake () = check_activate_staking_balance ~loc:__LOC__ ~deactivated:false b deactivated >>=? fun () -> check_rolls b deactivated_account +(* Test. + A deactivated account, after baking with self-delegation, is active + again. Preservation of its balance is tested. Baking rights are + ensured. +*) let deactivation_then_self_delegation () = run_until_deactivation () >>=? fun ( b, @@ -179,6 +220,11 @@ let deactivation_then_self_delegation () = Assert.equal_tez ~loc:__LOC__ start_balance balance >>=? fun () -> check_rolls b deactivated_account +(* Test. + A deactivated account, which is emptied (into a newly created sink + account), then self-delegated, becomes activated. Its balance is + zero. Baking rights are ensured. +*) let deactivation_then_empty_then_self_delegation () = run_until_deactivation () >>=? fun ( b, @@ -217,6 +263,11 @@ let deactivation_then_empty_then_self_delegation () = Assert.equal_tez ~loc:__LOC__ Tez.zero balance >>=? fun () -> check_rolls b deactivated_account +(* Test. + A deactivated account, which is emptied, then self-delegated, then + re-credited of the sunk amount, becomes active again. Staking + rights remain consistent. +*) let deactivation_then_empty_then_self_delegation_then_recredit () = run_until_deactivation () >>=? fun ( b, @@ -258,6 +309,14 @@ let deactivation_then_empty_then_self_delegation_then_recredit () = Assert.equal_tez ~loc:__LOC__ amount balance >>=? fun () -> check_rolls b deactivated_account +(* Test. + Initializes a block with two contracts/accounts. A third new + account is also created. The first account is self-delegated. First + account sends to third one the amount of 0.5 tez. The third account + has no delegate and is consistent for baking rights. Then, it is + self-delegated and is supposed to be activated. Again, consistency + for baking rights are preserved for the first and third accounts. +*) let delegation () = Context.init 2 >>=? fun (b, accounts) -> diff --git a/src/proto_alpha/lib_protocol/test/seed.ml b/src/proto_alpha/lib_protocol/test/seed.ml index 1d18737b577f..2ab19e0d6ee9 100644 --- a/src/proto_alpha/lib_protocol/test/seed.ml +++ b/src/proto_alpha/lib_protocol/test/seed.ml @@ -23,17 +23,22 @@ (* *) (*****************************************************************************) -(** Tests about - - seed_nonce_hash included in some blocks - - revelation operation of seed_nonce that should correspond to each - seed_nonce_hash +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: - seed_nonce_hash included in some blocks + - revelation operation of seed_nonce that should correspond + to each seed_nonce_hash *) open Protocol open Test_tez -(** Tests that baking [blocks_per_commitment] blocks without a - [seed_nonce_hash] commitment fails with [Invalid_commitment] *) +(* Test. + Baking [blocks_per_commitment] blocks without a [seed_nonce_hash] + commitment fails with [Invalid_commitment] +*) let no_commitment () = Context.init 5 >>=? fun (b, _) -> @@ -63,15 +68,17 @@ let baking_reward ctxt (b : Block.t) = >>=? fun endorsing_power -> Context.get_baking_reward ctxt ~priority ~endorsing_power -(** Choose a baker, denote it by id. In the first cycle, make id bake only once. - Test that: - - after id bakes with a commitment the bond is frozen and the reward allocated - - when id reveals the nonce too early, there's an error - - when id reveals at the right time but the wrong value, there's an error - - when another baker reveals correctly, it receives the tip - - revealing twice produces an error - - after [preserved cycles] a committer that correctly revealed - receives back the bond and the reward +(* Test. + Choose a baker, denote it by id. In the first cycle, make id bake only once. + Checks that: + - after id bakes with a commitment the bond is frozen and the reward + allocated + - when id reveals the nonce too early, there's an error + - when id reveals at the right time but the wrong value, there's an error + - when another baker reveals correctly, it receives the tip + - revealing twice produces an error + - after [preserved cycles] a committer that correctly revealed + receives back the bond and the reward *) let revelation_early_wrong_right_twice () = let open Assert in @@ -218,10 +225,10 @@ let revelation_early_wrong_right_twice () = balance_is ~loc:__LOC__ (B b) id ~kind:Deposit Tez.zero >>=? fun () -> balance_is ~loc:__LOC__ (B b) id ~kind:Rewards Tez.zero -(** Tests that: - - a committer at cycle 0, which doesn't reveal at cycle 1, - at the end of the cycle 1 looses the bond and the reward - - revealing too late produces an error +(* Test. + - a committer at cycle 0, which doesn't reveal at cycle 1, + at the end of the cycle 1 looses the bond and the reward + - revealing too late produces an error *) let revelation_missing_and_late () = let open Context in diff --git a/src/proto_alpha/lib_protocol/test/transfer.ml b/src/proto_alpha/lib_protocol/test/transfer.ml index 31ac4ab26a28..7fd9baa97010 100644 --- a/src/proto_alpha/lib_protocol/test/transfer.ml +++ b/src/proto_alpha/lib_protocol/test/transfer.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Quantities transfer between contracts. +*) + open Protocol open Alpha_context open Test_tez @@ -161,15 +168,20 @@ let single_transfer ?fee ?expect_failure amount = amount >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(** single transfer without fee *) +(* Test. + Single transfer without fee +*) let block_with_a_single_transfer () = single_transfer Tez.one -(** single transfer with fee *) +(* Test. + Single transfer with fee +*) let block_with_a_single_transfer_with_fee () = single_transfer ~fee:Tez.one Tez.one -(** single transfer without fee *) - +(* Test. + Single transfer without fee +*) let transfer_zero_tez () = single_transfer ~expect_failure:(function @@ -180,11 +192,9 @@ let transfer_zero_tez () = failwith "Empty transaction should fail") Tez.zero -(********************) -(** Transfer zero tez from an implicit contract *) - -(********************) - +(* Test. + Transfer zero tez from an implicit contract +*) let transfer_zero_implicit () = Context.init 1 >>=? fun (b, contracts) -> @@ -203,11 +213,9 @@ let transfer_zero_implicit () = | _ -> false) -(********************) -(** Transfer to originated contract *) - -(********************) - +(* Test. + Transfer to originated contract +*) let transfer_to_originate_with_fee () = Context.init 1 >>=? fun (b, contracts) -> @@ -226,11 +234,9 @@ let transfer_to_originate_with_fee () = transfer_and_check_balances ~loc:__LOC__ b ~fee contract new_contract amount >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(********************) -(** Transfer from balance *) - -(********************) - +(* Test. + Transfer from balance +*) let transfer_amount_of_contract_balance () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -247,11 +253,9 @@ let transfer_amount_of_contract_balance () = transfer_and_check_balances ~loc:__LOC__ b contract_1 contract_2 balance >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(********************) -(** Transfer to itself *) - -(********************) - +(* Test. + Transfer to itself +*) let transfers_to_self () = Context.init 1 >>=? fun (b, contracts) -> @@ -267,11 +271,9 @@ let transfers_to_self () = transfer_to_itself_and_check_balances ~loc:__LOC__ b ~fee contract ten_tez >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(********************) -(** Forgot to add the valid transaction into the block *) - -(********************) - +(* Test. + Forgot to add the valid transaction into the block +*) let missing_transaction () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -291,16 +293,18 @@ let missing_transaction () = >>=? fun _ -> Incremental.finalize_block b >>=? fun _ -> return_unit (********************) -(** These following tests are for different kind of contracts: - - implicit to implicit - - implicit to originated - - originated to implicit - - originated to originated *) +(* These following tests are for different kind of contracts: + - implicit to implicit + - implicit to originated + - originated to implicit + - originated to originated +*) (********************) -(** Implicit to Implicit *) - +(* Test. + Implicit to Implicit +*) let transfer_from_implicit_to_implicit_contract () = Context.init 1 >>=? fun (b, contracts) -> @@ -340,8 +344,9 @@ let transfer_from_implicit_to_implicit_contract () = amount2 >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(** Implicit to originated *) - +(* Test. + Implicit to originated +*) let transfer_from_implicit_to_originated_contract () = Context.init 1 >>=? fun (b, contracts) -> @@ -374,7 +379,7 @@ let transfer_from_implicit_to_originated_contract () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (********************) -(** Slow tests case *) +(* Slow tests case *) (********************) @@ -386,20 +391,26 @@ let multiple_transfer n ?fee amount = n_transactions n b ?fee contract_1 contract_2 amount >>=? fun b -> Incremental.finalize_block b >>=? fun _ -> return_unit -(** 1- Create a block with two contracts; - 2- Apply 100 transfers. *) +(* Test. + 1- Create a block with two contracts; + 2- Apply 100 transfers. +*) let block_with_multiple_transfers () = multiple_transfer 99 (Tez.of_int 1000) -(** 1- Create a block with two contracts; - 2- Apply 100 transfers with 10tz fee. *) +(* Test. + 1- Create a block with two contracts; + 2- Apply 100 transfers with 10tz fee. +*) let block_with_multiple_transfers_pay_fee () = multiple_transfer 10 ~fee:ten_tez (Tez.of_int 1000) (* TODO : increase the number of operations and add a `Slow tag to it in `tests` *) -(** 1- Create a block with 8 contracts; - 2- Apply multiple transfers without fees; - 3- Apply multiple transfers with fees. *) +(* Test. + 1- Create a block with 8 contracts; + 2- Apply multiple transfers without fees; + 3- Apply multiple transfers with fees. +*) let block_with_multiple_transfers_with_without_fee () = Context.init 8 >>=? fun (b, contracts) -> @@ -438,11 +449,9 @@ let block_with_multiple_transfers_with_without_fee () = n_transactions 20 ~fee:ten b contracts.(1) contracts.(0) twenty >>=? fun b -> Incremental.finalize_block b >>=? fun _ -> return_unit -(********************) -(** Build a chain that has 10 blocks. *) - -(********************) - +(* Test. + Build a chain that has 10 blocks. +*) let build_a_chain () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -461,11 +470,9 @@ let build_a_chain () = (* Expected error test cases *) (*********************************************************************) -(********************) -(** transfer zero tez is forbidden in implicit contract *) - -(********************) - +(* Test. + Transfer zero tez is forbidden in implicit contract +*) let empty_implicit () = Context.init 1 >>=? fun (b, contracts) -> @@ -487,11 +494,9 @@ let empty_implicit () = | _ -> false) -(********************) -(** Balance is too low to transfer *) - -(********************) - +(* Test. + Balance is too low to transfer +*) let balance_too_low fee () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -524,11 +529,13 @@ let balance_too_low fee () = (* contract_2 is not credited *) Assert.balance_was_credited ~loc:__LOC__ (I i) contract_2 balance2 Tez.zero -(** 1- Create a block, and three contracts; - 2- Add a transfer that at the end the balance of a contract is - zero into this block; - 3- Add another transfer that send tez from a zero balance contract; - 4- Catch the expected error: Balance_too_low. *) +(* Test. + 1- Create a block, and three contracts; + 2- Add a transfer that at the end the balance of a contract is + zero into this block; + 3- Add another transfer that send tez from a zero balance contract; + 4- Catch the expected error: Balance_too_low. +*) let balance_too_low_two_transfers fee () = Context.init 3 >>=? fun (b, contracts) -> @@ -570,11 +577,9 @@ let balance_too_low_two_transfers fee () = (* contract_3 is not credited *) Assert.balance_was_credited ~loc:__LOC__ (I i) contract_3 balance3 Tez.zero -(********************) -(** The counter is already used for the previous operation *) - -(********************) - +(* Test. + The counter is already used for the previous operation +*) let invalid_counter () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -594,8 +599,9 @@ let invalid_counter () = | _ -> false) -(* same as before but different way to perform this error *) - +(* Test. + Same as before but different way to perform this error +*) let add_the_same_operation_twice () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -613,11 +619,9 @@ let add_the_same_operation_twice () = | _ -> false) -(********************) -(** check ownership *) - -(********************) - +(* Test. + Check ownership +*) let ownership_sender () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -632,9 +636,9 @@ let ownership_sender () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (*********************************************************************) -(** Random transfer *) +(* Random transfer *) -(** Return a pair of minimum and maximum random number *) +(* Return a pair of minimum and maximum random number *) let random_range (min, max) = let interv = max - min + 1 in let init = @@ -643,13 +647,15 @@ let random_range (min, max) = in init -(** Return a random contract *) +(* Return a random contract *) let random_contract contract_array = let i = Random.int (Array.length contract_array) in contract_array.(i) -(** Transfer by randomly choose amount 10 contracts, and randomly - choose the amount in the source contract *) +(* Test. + Transfer by randomly choose amount 10 contracts, and randomly + choose the amount in the source contract +*) let random_transfer () = Context.init 10 >>=? fun (b, contracts) -> @@ -669,7 +675,9 @@ let random_transfer () = else transfer_and_check_balances ~loc:__LOC__ b source dest amount ) >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(** Transfer random transactions *) +(* Test. + Transfer random transactions +*) let random_multi_transactions () = let n = random_range (1, 100) in multiple_transfer n (Tez.of_int 100) diff --git a/src/proto_alpha/lib_protocol/test/voting.ml b/src/proto_alpha/lib_protocol/test/voting.ml index f886f128c426..35f6abf23801 100644 --- a/src/proto_alpha/lib_protocol/test/voting.ml +++ b/src/proto_alpha/lib_protocol/test/voting.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On the voting process. +*) + open Protocol (* missing stuff in Alpha_context.Vote *) @@ -195,6 +202,9 @@ let bake_until_first_block_of_next_period b = Context.Vote.get_current_period (B b) >>=? fun {remaining; _} -> Block.bake_n Int32.(add remaining one |> to_int) b +(* Test. + A normal and successful vote sequence. +*) let test_successful_vote num_delegates () = let open Alpha_context in let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in @@ -536,8 +546,10 @@ let get_expected_participation_ema rolls voter_rolls old_participation_ema = in get_updated_participation_ema old_participation_ema participation -(* if not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- in testing vote, - go back to proposal period *) +(* Test. + If not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- + in testing vote, go back to proposal period +*) let test_not_enough_quorum_in_testing_vote num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -600,8 +612,10 @@ let test_not_enough_quorum_in_testing_vote num_delegates () = (Int32.to_int new_participation_ema) >>=? fun () -> return_unit -(* if not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- in promotion vote, - go back to proposal period *) +(* Test. + If not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- + In promotion vote, go back to proposal period +*) let test_not_enough_quorum_in_promotion_vote num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -690,6 +704,10 @@ let test_not_enough_quorum_in_promotion_vote num_delegates () = >>=? fun () -> assert_listings_not_empty b ~loc:__LOC__ >>=? fun () -> return_unit +(* Test. + Identical proposals (identified by their hash) must be counted as + one. +*) let test_multiple_identical_proposals_count_as_one () = Context.init 1 >>=? fun (b, delegates) -> @@ -728,8 +746,10 @@ let test_multiple_identical_proposals_count_as_one () = | None -> failwith "%s - Missing proposal" __LOC__ -(* assumes the initial balance of allocated by Context.init is at - least 4 time the value of the tokens_per_roll constant *) +(* Test. + Assumes the initial balance of allocated by Context.init is at + least 4 time the value of the tokens_per_roll constant +*) let test_supermajority_in_proposal there_is_a_winner () = let min_proposal_quorum = 0l in Context.init ~min_proposal_quorum ~initial_balances:[1L; 1L; 1L] 10 @@ -797,6 +817,11 @@ let test_supermajority_in_proposal there_is_a_winner () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit +(* Test. + After one voting period, if [has_quorum] then the period kind must + have been the testing vote. Otherwise, it should have remained in + place in the proposal period. +*) let test_quorum_in_proposal has_quorum () = let total_tokens = 32_000_000_000_000L in let half_tokens = Int64.div total_tokens 2L in @@ -854,6 +879,10 @@ let test_quorum_in_proposal has_quorum () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit +(* Test. + If a supermajority is reached, then the voting period must be + reached. Otherwise, it remains in proposal period. +*) let test_supermajority_in_testing_vote supermajority () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / 100)) in Context.init ~min_proposal_quorum 100 @@ -906,7 +935,9 @@ let test_supermajority_in_testing_vote supermajority () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit -(* test also how the selection scales: all delegates propose max proposals *) +(* Test. + Tests also how the selection scales: all delegates propose max proposals +*) let test_no_winning_proposal num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -930,9 +961,11 @@ let test_no_winning_proposal num_delegates () = (* we stay in the same proposal period because no winning proposal *) assert_period ~expected_kind:Proposal b __LOC__ >>=? fun () -> return_unit -(** Test that for the vote to pass with maximum possible participation_ema - (100%), it is sufficient for the vote quorum to be equal or greater than - the maximum quorum cap. *) +(* Test. + Vote to pass with maximum possible participation_ema (100%), it is + sufficient for the vote quorum to be equal or greater than the + maximum quorum cap. +*) let test_quorum_capped_maximum num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -978,9 +1011,10 @@ let test_quorum_capped_maximum num_delegates () = (* expect to move to testing because we have supermajority and enough quorum *) assert_period ~expected_kind:Testing b __LOC__ -(** Test that for the vote to pass with minimum possible participation_ema - (0%), it is sufficient for the vote quorum to be equal or greater than - the minimum quorum cap. *) +(* Test. + Vote to pass with minimum possible participation_ema (0%), it is + sufficient for the vote quorum to be equal or greater than the + minimum quorum cap. *) let test_quorum_capped_minimum num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates -- GitLab From 7a99a73d95cb43e37401c8d3dffe565082d83941 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Tue, 29 Sep 2020 16:29:42 +0200 Subject: [PATCH 02/17] Testing: Fixed missing comments from rebase on proto-proposal. --- .../lib_protocol/test/fixed_point.ml | 21 +++++++++++++++++++ .../lib_protocol/test/gas_costs.ml | 19 +++++++++++++---- .../lib_protocol/test/gas_properties.ml | 14 +++++++++++++ .../lib_protocol/test/typechecking.ml | 12 ++++++++++- 4 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/fixed_point.ml b/src/proto_alpha/lib_protocol/test/fixed_point.ml index 771c5238a718..6b0250f71bf0 100644 --- a/src/proto_alpha/lib_protocol/test/fixed_point.ml +++ b/src/proto_alpha/lib_protocol/test/fixed_point.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On fixed-point decimal numbers. +*) + open Protocol exception Fixed_point_test_error of string @@ -104,6 +111,10 @@ let arith_from_fp : (module Fixed_point_repr.Full) -> (module Arith) = end in (module Arith) +(* Test. + Roundtrips between [integral] and [Z.t] (for fixed-point + decimals). Floor and ceil preserve the integral part. +*) let integral_tests decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals @@ -142,6 +153,9 @@ let integral_tests decimals () = (err "pp_integral(integral) = pp(fp(integral))") >>=? fun () -> basic_arith "integral arith" (arith_from_integral (module FP)) +(* Test. + With zero decimals. +*) let fp_zero () = let decimals = 0 in let module FP = Fixed_point_repr.Make (struct @@ -164,6 +178,9 @@ let fp_zero () = >>=? fun () -> basic_arith "fp (0 decimals) arith" (arith_from_fp (module FP)) +(* Test. + With at one decimal. +*) let fp_nonzero decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals @@ -191,6 +208,10 @@ let fp_nonzero decimals () = FP.(ceil (add (fp (integral x)) (unsafe_fp Z.one)) = integral (Z.succ x)) (err "ceil (x + eps) = x + 1") +(* Test. + Checking the parser [FF.pp] that values are correctly converted + according to the number of decimals. +*) let fp_pp () = let module FP = Fixed_point_repr.Make (struct let decimals = 3 diff --git a/src/proto_alpha/lib_protocol/test/gas_costs.ml b/src/proto_alpha/lib_protocol/test/gas_costs.ml index 217c90086269..649a43e9d098 100644 --- a/src/proto_alpha/lib_protocol/test/gas_costs.ml +++ b/src/proto_alpha/lib_protocol/test/gas_costs.ml @@ -23,13 +23,18 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Gas costs + Current limitations: for maps, sets & compare, we only test + integer comparable keys. +*) + open Protocol open Script_ir_translator -(* Basic tests related to costs. - Current limitations: for maps, sets & compare, we only test integer - comparable keys. *) - let dummy_list = list_cons 42 list_empty let forty_two = Alpha_context.Script_int.of_int 42 @@ -228,6 +233,9 @@ let cast_cost_to_z (c : Alpha_context.Gas.cost) : Z.t = Data_encoding.Binary.to_bytes_exn Alpha_context.Gas.cost_encoding c |> Data_encoding.Binary.of_bytes_exn Data_encoding.z +(* Test. + Checks that all costs are positive values. +*) let check_cost_reprs_are_all_positive list () = List.iter_es (fun (cost_name, cost) -> @@ -239,6 +247,9 @@ let check_cost_reprs_are_all_positive list () = (Failure (Format.asprintf "Gas cost test \"%s\" failed" cost_name)))) list +(* Test. + Checks that all costs are positive values. +*) let check_costs_are_all_positive list () = let list = List.map (fun (cost_name, cost) -> (cost_name, cast_cost_to_z cost)) list diff --git a/src/proto_alpha/lib_protocol/test/gas_properties.ml b/src/proto_alpha/lib_protocol/test/gas_properties.ml index fd2ccb48949d..9d5c5878dcdd 100644 --- a/src/proto_alpha/lib_protocol/test/gas_properties.ml +++ b/src/proto_alpha/lib_protocol/test/gas_properties.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Arithmetic properties around gas. +*) + open Protocol type cost_kind = @@ -75,6 +82,9 @@ let random_cost_of_kind (cost_kind : cost_kind) = let random_cost () = random_cost_of_kind (random_cost_kind ()) +(* Test. + Consuming [Gas.free] is equivalent to consuming nothing. +*) let free_neutral since = let open Alpha_context in let open Environment.Error_monad in @@ -92,6 +102,10 @@ let free_neutral since = then ok_none else Ok (Some (cost, Gas.free)) +(* Test. + Consuming [cost1] then [cost2] is equivalent to consuming + [Gas.(cost1 +@ cost2)]. +*) let consume_commutes since = let open Alpha_context in let open Environment.Error_monad in diff --git a/src/proto_alpha/lib_protocol/test/typechecking.ml b/src/proto_alpha/lib_protocol/test/typechecking.ml index 992c2b143b78..bbe6a6401d89 100644 --- a/src/proto_alpha/lib_protocol/test/typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/typechecking.ml @@ -1,3 +1,10 @@ +(* Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Type-checking +*) + open Protocol open Alpha_context open Script_interpreter @@ -101,7 +108,10 @@ let read_file filename = let s = really_input_string ch (in_channel_length ch) in close_in ch ; s -(* Check that the custom stack overflow exception is triggered when it should be *) +(* Test. + Check that the custom stack overflow exception is triggered when it + should be. +*) let test_typecheck_stack_overflow () = test_context () >>=? fun ctxt -> -- GitLab From cb34397e789bae661dbb476efc8915f94c276a03 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Tue, 29 Sep 2020 16:53:27 +0200 Subject: [PATCH 03/17] Testing: Renamed files with prefix `test_` in lib_protocol --- src/proto_alpha/lib_protocol/test/main.ml | 38 +++++++++---------- .../{activation.ml => test_activation.ml} | 0 .../test/{baking.ml => test_baking.ml} | 0 ...rations.ml => test_combined_operations.ml} | 0 .../{delegation.ml => test_delegation.ml} | 0 ...double_baking.ml => test_double_baking.ml} | 0 ...orsement.ml => test_double_endorsement.ml} | 0 .../{endorsement.ml => test_endorsement.ml} | 0 .../{fixed_point.ml => test_fixed_point.ml} | 0 .../test/{gas_costs.ml => test_gas_costs.ml} | 0 ...s_properties.ml => test_gas_properties.ml} | 0 ...terpretation.ml => test_interpretation.ml} | 0 .../{origination.ml => test_origination.ml} | 0 .../lib_protocol/test/{qty.ml => test_qty.ml} | 0 .../test/{reveal.ml => test_reveal.ml} | 0 .../test/{rolls.ml => test_rolls.ml} | 0 .../test/{seed.ml => test_seed.ml} | 0 .../test/{transfer.ml => test_transfer.ml} | 0 .../{typechecking.ml => test_typechecking.ml} | 0 .../test/{voting.ml => test_voting.ml} | 0 20 files changed, 19 insertions(+), 19 deletions(-) rename src/proto_alpha/lib_protocol/test/{activation.ml => test_activation.ml} (100%) rename src/proto_alpha/lib_protocol/test/{baking.ml => test_baking.ml} (100%) rename src/proto_alpha/lib_protocol/test/{combined_operations.ml => test_combined_operations.ml} (100%) rename src/proto_alpha/lib_protocol/test/{delegation.ml => test_delegation.ml} (100%) rename src/proto_alpha/lib_protocol/test/{double_baking.ml => test_double_baking.ml} (100%) rename src/proto_alpha/lib_protocol/test/{double_endorsement.ml => test_double_endorsement.ml} (100%) rename src/proto_alpha/lib_protocol/test/{endorsement.ml => test_endorsement.ml} (100%) rename src/proto_alpha/lib_protocol/test/{fixed_point.ml => test_fixed_point.ml} (100%) rename src/proto_alpha/lib_protocol/test/{gas_costs.ml => test_gas_costs.ml} (100%) rename src/proto_alpha/lib_protocol/test/{gas_properties.ml => test_gas_properties.ml} (100%) rename src/proto_alpha/lib_protocol/test/{interpretation.ml => test_interpretation.ml} (100%) rename src/proto_alpha/lib_protocol/test/{origination.ml => test_origination.ml} (100%) rename src/proto_alpha/lib_protocol/test/{qty.ml => test_qty.ml} (100%) rename src/proto_alpha/lib_protocol/test/{reveal.ml => test_reveal.ml} (100%) rename src/proto_alpha/lib_protocol/test/{rolls.ml => test_rolls.ml} (100%) rename src/proto_alpha/lib_protocol/test/{seed.ml => test_seed.ml} (100%) rename src/proto_alpha/lib_protocol/test/{transfer.ml => test_transfer.ml} (100%) rename src/proto_alpha/lib_protocol/test/{typechecking.ml => test_typechecking.ml} (100%) rename src/proto_alpha/lib_protocol/test/{voting.ml => test_voting.ml} (100%) diff --git a/src/proto_alpha/lib_protocol/test/main.ml b/src/proto_alpha/lib_protocol/test/main.ml index f16964104448..7fafc8649f05 100644 --- a/src/proto_alpha/lib_protocol/test/main.ml +++ b/src/proto_alpha/lib_protocol/test/main.ml @@ -33,26 +33,26 @@ let () = Alcotest_lwt.run "protocol_alpha" - [ ("transfer", Transfer.tests); - ("origination", Origination.tests); - ("activation", Activation.tests); - ("revelation", Reveal.tests); - ("endorsement", Endorsement.tests); - ("double endorsement", Double_endorsement.tests); - ("double baking", Double_baking.tests); - ("seed", Seed.tests); - ("baking", Baking.tests); - ("delegation", Delegation.tests); - ("rolls", Rolls.tests); - ("combined", Combined_operations.tests); - ("qty", Qty.tests); - ("voting", Voting.tests); - ("interpretation", Interpretation.tests); - ("typechecking", Typechecking.tests); - ("gas properties", Gas_properties.tests); - ("fixed point computation", Fixed_point.tests); + [ ("transfer", Test_transfer.tests); + ("origination", Test_origination.tests); + ("activation", Test_activation.tests); + ("revelation", Test_reveal.tests); + ("endorsement", Test_endorsement.tests); + ("double endorsement", Test_double_endorsement.tests); + ("double baking", Test_double_baking.tests); + ("seed", Test_seed.tests); + ("baking", Test_baking.tests); + ("delegation", Test_delegation.tests); + ("rolls", Test_rolls.tests); + ("combined", Test_combined_operations.tests); + ("qty", Test_qty.tests); + ("voting", Test_voting.tests); + ("interpretation", Test_interpretation.tests); + ("typechecking", Test_typechecking.tests); + ("gas properties", Test_gas_properties.tests); + ("fixed point computation", Test_fixed_point.tests); ("gas levels", Gas_levels.tests); - ("gas cost functions", Gas_costs.tests); + ("gas cost functions", Test_gas_costs.tests); ("lazy storage diff", Lazy_storage_diff.tests); ("sapling", Test_sapling.tests); ("helpers rpcs", Test_helpers_rpcs.tests); diff --git a/src/proto_alpha/lib_protocol/test/activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/activation.ml rename to src/proto_alpha/lib_protocol/test/test_activation.ml diff --git a/src/proto_alpha/lib_protocol/test/baking.ml b/src/proto_alpha/lib_protocol/test/test_baking.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/baking.ml rename to src/proto_alpha/lib_protocol/test/test_baking.ml diff --git a/src/proto_alpha/lib_protocol/test/combined_operations.ml b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/combined_operations.ml rename to src/proto_alpha/lib_protocol/test/test_combined_operations.ml diff --git a/src/proto_alpha/lib_protocol/test/delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/delegation.ml rename to src/proto_alpha/lib_protocol/test/test_delegation.ml diff --git a/src/proto_alpha/lib_protocol/test/double_baking.ml b/src/proto_alpha/lib_protocol/test/test_double_baking.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/double_baking.ml rename to src/proto_alpha/lib_protocol/test/test_double_baking.ml diff --git a/src/proto_alpha/lib_protocol/test/double_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/double_endorsement.ml rename to src/proto_alpha/lib_protocol/test/test_double_endorsement.ml diff --git a/src/proto_alpha/lib_protocol/test/endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/endorsement.ml rename to src/proto_alpha/lib_protocol/test/test_endorsement.ml diff --git a/src/proto_alpha/lib_protocol/test/fixed_point.ml b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/fixed_point.ml rename to src/proto_alpha/lib_protocol/test/test_fixed_point.ml diff --git a/src/proto_alpha/lib_protocol/test/gas_costs.ml b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/gas_costs.ml rename to src/proto_alpha/lib_protocol/test/test_gas_costs.ml diff --git a/src/proto_alpha/lib_protocol/test/gas_properties.ml b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/gas_properties.ml rename to src/proto_alpha/lib_protocol/test/test_gas_properties.ml diff --git a/src/proto_alpha/lib_protocol/test/interpretation.ml b/src/proto_alpha/lib_protocol/test/test_interpretation.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/interpretation.ml rename to src/proto_alpha/lib_protocol/test/test_interpretation.ml diff --git a/src/proto_alpha/lib_protocol/test/origination.ml b/src/proto_alpha/lib_protocol/test/test_origination.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/origination.ml rename to src/proto_alpha/lib_protocol/test/test_origination.ml diff --git a/src/proto_alpha/lib_protocol/test/qty.ml b/src/proto_alpha/lib_protocol/test/test_qty.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/qty.ml rename to src/proto_alpha/lib_protocol/test/test_qty.ml diff --git a/src/proto_alpha/lib_protocol/test/reveal.ml b/src/proto_alpha/lib_protocol/test/test_reveal.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/reveal.ml rename to src/proto_alpha/lib_protocol/test/test_reveal.ml diff --git a/src/proto_alpha/lib_protocol/test/rolls.ml b/src/proto_alpha/lib_protocol/test/test_rolls.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/rolls.ml rename to src/proto_alpha/lib_protocol/test/test_rolls.ml diff --git a/src/proto_alpha/lib_protocol/test/seed.ml b/src/proto_alpha/lib_protocol/test/test_seed.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/seed.ml rename to src/proto_alpha/lib_protocol/test/test_seed.ml diff --git a/src/proto_alpha/lib_protocol/test/transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/transfer.ml rename to src/proto_alpha/lib_protocol/test/test_transfer.ml diff --git a/src/proto_alpha/lib_protocol/test/typechecking.ml b/src/proto_alpha/lib_protocol/test/test_typechecking.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/typechecking.ml rename to src/proto_alpha/lib_protocol/test/test_typechecking.ml diff --git a/src/proto_alpha/lib_protocol/test/voting.ml b/src/proto_alpha/lib_protocol/test/test_voting.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/voting.ml rename to src/proto_alpha/lib_protocol/test/test_voting.ml -- GitLab From 8ddf0b05a66c88bc356069fdf1c05017ba41c97a Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Tue, 3 Nov 2020 09:36:14 +0100 Subject: [PATCH 04/17] Testing: Compliance with ocamldoc. --- src/proto_alpha/lib_protocol/test/main.ml | 10 +- .../lib_protocol/test/test_activation.ml | 78 ++++----- .../lib_protocol/test/test_baking.ml | 30 ++-- .../test/test_combined_operations.ml | 54 +++---- .../lib_protocol/test/test_delegation.ml | 152 +++++++----------- .../lib_protocol/test/test_double_baking.ml | 46 +++--- .../test/test_double_endorsement.ml | 42 +++-- .../lib_protocol/test/test_endorsement.ml | 73 ++++----- .../lib_protocol/test/test_fixed_point.ml | 28 ++-- .../lib_protocol/test/test_gas_costs.ml | 22 ++- .../lib_protocol/test/test_gas_properties.ml | 19 +-- .../lib_protocol/test/test_interpretation.ml | 21 ++- .../lib_protocol/test/test_origination.ml | 40 ++--- src/proto_alpha/lib_protocol/test/test_qty.ml | 19 +-- .../lib_protocol/test/test_rolls.ml | 63 ++++---- .../lib_protocol/test/test_seed.ml | 47 +++--- .../lib_protocol/test/test_transfer.ml | 105 ++++-------- .../lib_protocol/test/test_typechecking.ml | 15 +- .../lib_protocol/test/test_voting.ml | 67 ++++---- 19 files changed, 376 insertions(+), 555 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/main.ml b/src/proto_alpha/lib_protocol/test/main.ml index 7fafc8649f05..e2b734458d73 100644 --- a/src/proto_alpha/lib_protocol/test/main.ml +++ b/src/proto_alpha/lib_protocol/test/main.ml @@ -23,11 +23,11 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Entrypoint +(** Testing + ------- + Component: Protocol + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Entrypoint *) let () = diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index a322b68a01b5..cb43e5a0b1a8 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -23,21 +23,21 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: The activation operation creates an implicit contract from a - registered commitment present in the context. It is - parametrized by a public key hash (pkh) and a secret. - - The commitments are composed of : - - a blinded pkh that can be revealed by the secret ; - - an amount. - - The commitments and the secrets are generated from - /scripts/create_genesis/create_genenis.py and should be - coherent. +(** Testing + ------- + Component: Protocol (activation) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: The activation operation creates an implicit contract from a + registered commitment present in the context. It is + parametrized by a public key hash (pkh) and a secret. + + The commitments are composed of : + - a blinded pkh that can be revealed by the secret ; + - an amount. + + The commitments and the secrets are generated from + /scripts/create_genesis/create_genenis.py and should be + coherent. *) open Protocol @@ -311,17 +311,13 @@ let activation_init () = Context.init ~with_commitments:true 1 >|=? fun (b, cs) -> secrets () |> fun ss -> (b, cs, ss) -(* Test. - A simple initialization -*) +(** A simple initialization *) let simple_init_with_commitments () = activation_init () >>=? fun (blk, _contracts, _secrets) -> Block.bake blk >>=? fun _ -> return_unit -(* Test. - A single activation -*) +(** A single activation *) let single_activation () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -346,9 +342,7 @@ let single_activation () = (Contract.implicit_contract account) expected_amount -(* Test. - 10 activations, one per bake -*) +(** 10 activations, one per bake *) let multi_activation_1 () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -368,9 +362,7 @@ let multi_activation_1 () = secrets >>=? fun _ -> return_unit -(* Test. - All in one bake -*) +(** All in one bake *) let multi_activation_2 () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -392,9 +384,7 @@ let multi_activation_2 () = expected_amount) secrets -(* Test. - Transfer with activated account -*) +(** Transfer with activated account *) let activation_and_transfer () = activation_init () >>=? fun (blk, contracts, secrets) -> @@ -424,9 +414,7 @@ let activation_and_transfer () = activated_amount_before half_amount -(* Test. - Transfer to an unactivated account and then activating it -*) +(** Transfer to an unactivated account and then activating it *) let transfer_to_unactivated_then_activate () = activation_init () >>=? fun (blk, contracts, secrets) -> @@ -466,9 +454,8 @@ let transfer_to_unactivated_then_activate () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(* Test. - Invalid pkh activation: expected to fail as the context does not - contain any commitment +(** Invalid pkh activation: expected to fail as the context does not + contain any commitment. *) let invalid_activation_with_no_commitments () = Context.init 1 @@ -487,9 +474,7 @@ let invalid_activation_with_no_commitments () = | _ -> false) -(* Test. - Wrong activation : wrong secret given in the operation -*) +(** Wrong activation: wrong secret given in the operation. *) let invalid_activation_wrong_secret () = activation_init () >>=? fun (blk, _, secrets) -> @@ -507,10 +492,8 @@ let invalid_activation_wrong_secret () = | _ -> false) -(* Test. - Invalid pkh activation : expected to fail as the context does not - contain an associated commitment -*) +(** Invalid pkh activation : expected to fail as the context does not + contain an associated commitment. *) let invalid_activation_inexistent_pkh () = activation_init () >>=? fun (blk, _, secrets) -> @@ -529,9 +512,8 @@ let invalid_activation_inexistent_pkh () = | _ -> false) -(* Test. - Invalid pkh activation : expected to fail as the commitment has - already been claimed +(** Invalid pkh activation : expected to fail as the commitment has + already been claimed. *) let invalid_double_activation () = activation_init () @@ -555,9 +537,7 @@ let invalid_double_activation () = | _ -> false) -(* Test. - Transfer from an unactivated commitment account -*) +(** Transfer from an unactivated commitment account. *) let invalid_transfer_from_unactivated_account () = activation_init () >>=? fun (blk, contracts, secrets) -> diff --git a/src/proto_alpha/lib_protocol/test/test_baking.ml b/src/proto_alpha/lib_protocol/test/test_baking.ml index 89a4719e70da..116ebcac1c5d 100644 --- a/src/proto_alpha/lib_protocol/test/test_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_baking.ml @@ -24,19 +24,18 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Rewards and bakers. +(** Testing + ------- + Component: Protocol (baking) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Rewards and bakers. *) open Protocol open Alpha_context -(* Test. - In a cycle, [bake_until_cycle_end] returns a block at level - [blocks_per_cycle]. Then, [bake_n n] bakes [n] blocks. +(** In a cycle, [bake_until_cycle_end] returns a block at level + [blocks_per_cycle]. Then, [bake_n n] bakes [n] blocks. *) let test_cycle () = Context.init 5 @@ -73,9 +72,8 @@ let test_cycle () = (Alpha_context.Raw_level.to_int32 curr_level) (Int32.add (Alpha_context.Raw_level.to_int32 l) 10l) -(* Test. - After baking and/or endorsing a block, the baker and the endorsers - get their reward +(** After baking and/or endorsing a block, the baker and the endorsers + get their reward. *) let test_rewards_retrieval () = Context.init 256 @@ -174,9 +172,8 @@ let test_rewards_retrieval () = real_endorsers) ranges -(* Test. - Checks the baking and endorsing rewards formulas against a precomputed - table +(** Checks the baking and endorsing rewards formulas against a precomputed + table. *) let test_rewards_formulas () = Context.init 1 @@ -208,9 +205,8 @@ let test_rewards_formulas () = let wrap e = Lwt.return (Environment.wrap_error e) -(* Test. - Check that the rewards formulas from Context are equivalent with - the ones from Baking +(** Check that the rewards formulas from Context are equivalent with + the ones from Baking. *) let test_rewards_formulas_equivalence () = Context.init 1 diff --git a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml index 2bfc043ca7f9..42c67458e753 100644 --- a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml @@ -23,22 +23,22 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Multiple operations can be grouped in one ensuring their - deterministic application. - - If an invalid operation is present in this group of - operation, the previous applied operations are backtracked - leaving the context unchanged and the following operations - are skipped. Fees attributed to the operations are collected - by the baker nonetheless. - - Only manager operations are allowed in multiple transactions. - They must all belong to the same manager as there is only one - signature. +(** Testing + ------- + Component: Protocol (combined operations) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Multiple operations can be grouped in one ensuring their + deterministic application. + + If an invalid operation is present in this group of + operation, the previous applied operations are backtracked + leaving the context unchanged and the following operations + are skipped. Fees attributed to the operations are collected + by the baker nonetheless. + + Only manager operations are allowed in multiple transactions. + They must all belong to the same manager as there is only one + signature. *) open Protocol @@ -46,9 +46,7 @@ open Test_tez let ten_tez = Tez.of_int 10 -(* Test. - Groups ten transactions between the same parties. -*) +(** Groups ten transactions between the same parties. *) let multiple_transfers () = Context.init 3 >>=? fun (blk, contracts) -> @@ -82,9 +80,7 @@ let multiple_transfers () = (Tez.of_int 10) >>=? fun () -> return_unit -(* Test. - Groups ten delegated originations. -*) +(** Groups ten delegated originations. *) let multiple_origination_and_delegation () = Context.init 2 >>=? fun (blk, contracts) -> @@ -170,10 +166,9 @@ let expect_balance_too_low = function "Contract should not have a sufficient balance : operation expected \ to fail." -(* Test. - Groups three operations, the middle one failing. - Checks that the receipt is consistent. - Variant without fees. +(** Groups three operations, the middle one failing. + Checks that the receipt is consistent. + Variant without fees. *) let failing_operation_in_the_middle () = Context.init 2 @@ -229,10 +224,9 @@ let failing_operation_in_the_middle () = Assert.balance_is ~loc:__LOC__ (I inc) c2 c2_old_balance >>=? fun () -> return_unit -(* Test. - Groups three operations, the middle one failing. - Checks that the receipt is consistent. - Variant with fees, that should be spent even in case of failure. +(** Groups three operations, the middle one failing. + Checks that the receipt is consistent. + Variant with fees, that should be spent even in case of failure. *) let failing_operation_in_the_middle_with_fees () = Context.init 2 diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index bf72bd377881..3771fdc54ed6 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -23,11 +23,11 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Boostrap contracts. Delegate registration. +(** Testing + ------- + Component: Protocol (delegation) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Boostrap contracts. Delegate registration. *) open Protocol @@ -57,9 +57,7 @@ let expect_no_change_registered_delegate_pkh pkh = function | _ -> failwith "Delegate can not be deleted and operation should fail." -(* Test. - Bootstrap contracts delegate to themselves -*) +(** Bootstrap contracts delegate to themselves *) let bootstrap_manager_is_bootstrap_delegate () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -69,9 +67,7 @@ let bootstrap_manager_is_bootstrap_delegate () = Context.Contract.manager (B b) bootstrap0 >>=? fun manager0 -> Assert.equal_pkh ~loc:__LOC__ delegate0 manager0.pkh -(* Test. - Bootstrap contracts cannot change their delegate -*) +(** Bootstrap contracts cannot change their delegate. *) let bootstrap_delegate_cannot_change ~fee () = Context.init 2 >>=? fun (b, bootstrap_contracts) -> @@ -114,9 +110,7 @@ let bootstrap_delegate_cannot_change ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (B b) bootstrap0 balance0 fee -(* Test. - Bootstrap contracts cannot delete their delegation -*) +(** Bootstrap contracts cannot delete their delegation. *) let bootstrap_delegate_cannot_be_removed ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -154,8 +148,8 @@ let bootstrap_delegate_cannot_be_removed ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) bootstrap balance fee -(* Test. - Contracts not registered as delegate can change their delegation +(** Contracts not registered as delegate can change their + delegation. *) let delegate_can_be_changed_from_unregistered_contract ~fee () = Context.init 2 @@ -209,8 +203,8 @@ let delegate_can_be_changed_from_unregistered_contract ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) unregistered credit fee -(* Test. - Contracts not registered as delegate can delete their delegation +(** Contracts not registered as delegate can delete their + delegation. *) let delegate_can_be_removed_from_unregistered_contract ~fee () = Context.init 1 @@ -264,9 +258,7 @@ let delegate_can_be_removed_from_unregistered_contract ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) unregistered credit fee -(* Test. - Bootstrap keys are already registered as delegate keys -*) +(** Bootstrap keys are already registered as delegate keys. *) let bootstrap_manager_already_registered_delegate ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -302,9 +294,8 @@ let bootstrap_manager_already_registered_delegate ~fee () = (* fee has been debited *) Assert.balance_was_debited ~loc:__LOC__ (I i) impl_contract balance fee -(* Test. - Bootstrap manager can be set as delegate of an originated contract - (through origination operation) +(** Bootstrap manager can be set as delegate of an originated contract + (through origination operation). *) let delegate_to_bootstrap_by_origination ~fee () = Context.init 1 @@ -503,9 +494,8 @@ let expect_unregistered_key pkh = function No self-delegation *) -(* Test. - No token transfer, no self-delegation. - Originated account. +(** No token transfer, no self-delegation. + Originated account. *) let unregistered_delegate_key_init_origination ~fee () = Context.init 1 @@ -558,9 +548,8 @@ let unregistered_delegate_key_init_origination ~fee () = | _ -> false) -(* Test. - Delegation when delegate key is not assigned. Delegate account is - initialized. +(** Delegation when delegate key is not assigned. Delegate account is + initialized. *) let unregistered_delegate_key_init_delegation ~fee () = Context.init 1 @@ -612,9 +601,7 @@ let unregistered_delegate_key_init_delegation ~fee () = | _ -> false) -(* Test. - Re-delegation when a delegate key was already assigned. -*) +(** Re-delegation when a delegate key was already assigned. *) let unregistered_delegate_key_switch_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -673,9 +660,8 @@ let unregistered_delegate_key_switch_delegation ~fee () = >>=? fun delegate_pkh_after -> Assert.equal_pkh ~loc:__LOC__ delegate_pkh delegate_pkh_after -(* Test. - Same as [unregistered_delegate_key_init_origination] and credits [amount], - no self-delegation. +(** Same as [unregistered_delegate_key_init_origination] and credits + [amount], no self-delegation. *) let unregistered_delegate_key_init_origination_credit ~fee ~amount () = Context.init 1 @@ -728,9 +714,8 @@ let unregistered_delegate_key_init_origination_credit ~fee ~amount () = | _ -> false) -(* Test. - Same as [unregistered_delegate_key_init_delegation] and credits the - amount [amount] of the implicit contract. +(** Same as [unregistered_delegate_key_init_delegation] and credits + the amount [amount] of the implicit contract. *) let unregistered_delegate_key_init_delegation_credit ~fee ~amount () = Context.init 1 @@ -790,9 +775,8 @@ let unregistered_delegate_key_init_delegation_credit ~fee ~amount () = | _ -> false) -(* Test. - Same as in [unregistered_delegate_key_switch_delegation] and credits the - amount [amount] to the implicit contract. +(** Same as in [unregistered_delegate_key_switch_delegation] and + credits the amount [amount] to the implicit contract. *) let unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Context.init 1 @@ -861,9 +845,8 @@ let unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Assert.not_equal_pkh ~loc:__LOC__ delegate unregistered_delegate_pkh >>=? fun () -> Assert.equal_pkh ~loc:__LOC__ delegate bootstrap_pkh -(* Test. - A credit of some amount followed by a debit of the same amount, - no self-delegation +(** A credit of some amount followed by a debit of the same amount, + no self-delegation. *) let unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = Context.init 1 @@ -923,9 +906,8 @@ let unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = | _ -> false) -(* Test. - Same as in [unregistered_delegate_key_init_delegation] but credits then - debits the amount [amount] to the implicit contract. +(** Same as in [unregistered_delegate_key_init_delegation] but credits + then debits the amount [amount] to the implicit contract. *) let unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = Context.init 1 @@ -990,9 +972,8 @@ let unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = | _ -> false) -(* Test. - Same as in [unregistered_delegate_key_switch_delegation] but credits then - debits the amount [amount] to the implicit contract. +(** Same as in [unregistered_delegate_key_switch_delegation] but + credits then debits the amount [amount] to the implicit contract. *) let unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = Context.init 1 @@ -1069,9 +1050,7 @@ let unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = Self-delegation to an empty contract fails *) -(* Test. - Self-delegation with zero-balance contract should fail. -*) +(** Self-delegation with zero-balance contract should fail. *) let failed_self_delegation_no_transaction () = Context.init 1 >>=? fun (b, _) -> @@ -1096,9 +1075,8 @@ let failed_self_delegation_no_transaction () = | _ -> false) -(* Test. - Implicit contract is credited then debited of same amount (i.e., is - emptied). Self-delegation fails. +(** Implicit contract is credited then debited of same amount (i.e., + is emptied). Self-delegation fails. *) let failed_self_delegation_emptied_implicit_contract amount () = (* create an implicit contract *) @@ -1135,10 +1113,9 @@ let failed_self_delegation_emptied_implicit_contract amount () = | _ -> false) -(* Test. - Implicit contract is credited with a non-zero quantity [amount] tz, then it - is delegated. The operation of debit of [amount] tz should fail as the - contract is already delegated. +(** Implicit contract is credited with a non-zero quantity [amount] + tz, then it is delegated. The operation of debit of [amount] tz + should fail as the contract is already delegated. *) let emptying_delegated_implicit_contract_fails amount () = Context.init 1 @@ -1182,8 +1159,8 @@ let emptying_delegated_implicit_contract_fails amount () = - Create delegator implicit contract w first implicit contract as delegate + verification of delegation *) -(* Test. - Initialized account is credited of [amount] tz, then self-delegated. +(** Initialized account is credited of [amount] tz, then + self-delegated. *) let valid_delegate_registration_init_delegation_credit amount () = (* create an implicit contract *) @@ -1238,10 +1215,10 @@ let valid_delegate_registration_init_delegation_credit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh -(* Test. - Creates an implicit contract, credits with [amount] tz. Self-delegates. - Creates another implicit contract with bootstrap as delegate. - Re-delegates it to the first implicit contract. +(** Creates an implicit contract, credits with [amount] + tz. Self-delegates. Creates another implicit contract with + bootstrap as delegate. Re-delegates it to the first implicit + contract. *) let valid_delegate_registration_switch_delegation_credit amount () = (* create an implicit contract *) @@ -1297,9 +1274,7 @@ let valid_delegate_registration_switch_delegation_credit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh -(* Test. - Creates an implicit contract. -*) +(** Creates an implicit contract. *) let valid_delegate_registration_init_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 @@ -1368,12 +1343,11 @@ let valid_delegate_registration_init_delegation_credit_debit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh -(* Test. - A created implicit contract is credited with [amount] tz, then is - self-delegated. It is emptied (funds back into bootstrap), and - should remain existing (as registered as delegate). Another created - implicit contract is delegated to bootstrap, then should be able to - be re-delegated to the latter contract. +(** A created implicit contract is credited with [amount] tz, then is + self-delegated. It is emptied (funds back into bootstrap), and + should remain existing (as registered as delegate). Another created + implicit contract is delegated to bootstrap, then should be able to + be re-delegated to the latter contract. *) let valid_delegate_registration_switch_delegation_credit_debit amount () = (* create an implicit contract *) @@ -1443,8 +1417,8 @@ let valid_delegate_registration_switch_delegation_credit_debit amount () = A second self-delegation should raise an `Active_delegate` error *) -(* Test. - Second self-delegation should fail with implicit contract with some credit. +(** Second self-delegation should fail with implicit contract with + some credit. *) let double_registration () = Context.init 1 @@ -1478,9 +1452,8 @@ let double_registration () = | _ -> false) -(* Test. - Second self-delegation should fail with implicit contract emptied after - first self-delegation. +(** Second self-delegation should fail with implicit contract emptied + after first self-delegation. *) let double_registration_when_empty () = Context.init 1 @@ -1521,9 +1494,8 @@ let double_registration_when_empty () = | _ -> false) -(* Test. - Second self-delegation should fail with implicit contract emptied then - recredited after first self-delegation. +(** Second self-delegation should fail with implicit contract emptied + then recredited after first self-delegation. *) let double_registration_when_recredited () = Context.init 1 @@ -1571,9 +1543,7 @@ let double_registration_when_recredited () = | _ -> false) -(* Test. - Self-delegation on unrevealed contract -*) +(** Self-delegation on unrevealed contract. *) let unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1608,9 +1578,7 @@ let unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = >>=? fun i -> Assert.balance_was_debited ~loc:__LOC__ (I i) contract balance fee -(* Test. - Self-delegation on revealed but not registered contract -*) +(** Self-delegation on revealed but not registered contract. *) let unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1649,9 +1617,7 @@ let unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = >>=? fun i -> Assert.balance_was_debited ~loc:__LOC__ (I i) contract balance fee -(* Test. - Self-delegation on revealed and registered contract -*) +(** Self-delegation on revealed and registered contract. *) let registered_self_delegate_key_init_delegation () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_double_baking.ml b/src/proto_alpha/lib_protocol/test/test_double_baking.ml index 92fb1ec0bc2d..a02716625d07 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_baking.ml @@ -23,12 +23,12 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Double baking evidence operation may happen when a baker - baked two different blocks on the same level. +(** Testing + ------- + Component: Protocol (double baking) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Double baking evidence operation may happen when a baker + baked two different blocks on the same level. *) open Protocol @@ -70,9 +70,8 @@ let block_fork ?policy contracts b = (* Tests *) (****************************************************************) -(* Test. - Simple scenario where two blocks are baked by a same baker and - exposed by a double baking evidence operation +(** Simple scenario where two blocks are baked by a same baker and + exposed by a double baking evidence operation. *) let valid_double_baking_evidence () = Context.init 2 @@ -99,9 +98,8 @@ let valid_double_baking_evidence () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(* Test. - Check that a double baking operation fails if it exposes the same two - blocks +(** Check that a double baking operation fails if it exposes the same two + blocks. *) let same_blocks () = Context.init 2 @@ -119,9 +117,8 @@ let same_blocks () = false) >>=? fun () -> return_unit -(* Test. - Check that a double baking operation exposing two blocks with - different levels fails +(** Check that a double baking operation exposing two blocks with + different levels fails. *) let different_levels () = Context.init 2 @@ -140,9 +137,8 @@ let different_levels () = | _ -> false) -(* Test. - Check that a double baking operation exposing two yet to be baked - blocks fails +(** Check that a double baking operation exposing two yet to be baked + blocks fails. *) let too_early_double_baking_evidence () = Context.init 2 @@ -159,9 +155,8 @@ let too_early_double_baking_evidence () = | _ -> false) -(* Test. - Check that after [preserved_cycles + 1], it is not possible to - create a double baking operation anymore +(** Check that after [preserved_cycles + 1], it is not possible to + create a double baking operation anymore. *) let too_late_double_baking_evidence () = Context.init 2 @@ -185,9 +180,8 @@ let too_late_double_baking_evidence () = | _ -> false) -(* Test. - Check that an invalid double baking evidence that exposes two block - baking with same level made by different bakers fails +(** Check that an invalid double baking evidence that exposes two + block baking with same level made by different bakers fails. *) let different_delegates () = Context.init 2 @@ -208,9 +202,7 @@ let different_delegates () = | _ -> false) -(* Test. - Baker_2 bakes a block but baker signs it -*) +(** Baker_2 bakes a block but baker signs it. *) let wrong_signer () = let header_custom_signer baker baker_2 b = Block.Forge.forge_header ~policy:(By_account baker_2) b diff --git a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml index 3d4799ec7e47..6c79bec145fa 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml @@ -23,12 +23,12 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Double endorsement evidence operation may happen when an - endorser endorsed two different blocks on the same level. +(** Testing + ------- + Component: Protocol (double endorsement) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Double endorsement evidence operation may happen when an + endorser endorsed two different blocks on the same level. *) open Protocol @@ -68,10 +68,9 @@ let block_fork b = (* Tests *) (****************************************************************) -(* Test. - Simple scenario where two endorsements are made from the same - delegate and exposed by a double_endorsement operation. Also verify - that punishment is operated. +(** Simple scenario where two endorsements are made from the same + delegate and exposed by a double_endorsement operation. Also verify + that punishment is operated. *) let valid_double_endorsement_evidence () = Context.init 2 @@ -107,9 +106,8 @@ let valid_double_endorsement_evidence () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(* Test. - Check that an invalid double endorsement operation that exposes a valid - endorsement fails. +(** Check that an invalid double endorsement operation that exposes a + valid endorsement fails. *) let invalid_double_endorsement () = Context.init 10 @@ -130,9 +128,8 @@ let invalid_double_endorsement () = | _ -> false) -(* Test. - Check that a double endorsement added at the same time as a double - endorsement operation fails. +(** Check that a double endorsement added at the same time as a double + endorsement operation fails. *) let too_early_double_endorsement_evidence () = Context.init 2 @@ -155,8 +152,7 @@ let too_early_double_endorsement_evidence () = | _ -> false) -(* Test. - Check that after [preserved_cycles + 1], it is not possible +(** Check that after [preserved_cycles + 1], it is not possible to create a double_endorsement anymore. *) let too_late_double_endorsement_evidence () = @@ -187,9 +183,8 @@ let too_late_double_endorsement_evidence () = | _ -> false) -(* Test. - Check that an invalid double endorsement evidence that expose two - endorsements made by two different endorsers fails. +(** Check that an invalid double endorsement evidence that expose two + endorsements made by two different endorsers fails. *) let different_delegates () = Context.init 2 @@ -223,9 +218,8 @@ let different_delegates () = | _ -> false) -(* Test. - Check that a double endorsement evidence that exposes a ill-formed - endorsement fails. +(** Check that a double endorsement evidence that exposes a ill-formed + endorsement fails. *) let wrong_delegate () = Context.init ~endorsers_per_block:1 2 diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index e6726b856c63..8d287d307712 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -23,17 +23,17 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Endorsing a block adds an extra layer of confidence to the - Tezos' PoS algorithm. The block endorsing operation must be - included in the following block. Each endorser possess a - number of slots corresponding to their priority. After - [preserved_cycles], a reward is given to the endorser. This - reward depends on the priority of the block that contains - the endorsements. +(** Testing + ------- + Component: Protocol (endorsement) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Endorsing a block adds an extra layer of confidence to the + Tezos' PoS algorithm. The block endorsing operation must be + included in the following block. Each endorser possess a + number of slots corresponding to their priority. After + [preserved_cycles], a reward is given to the endorser. This + reward depends on the priority of the block that contains + the endorsements. *) open Protocol @@ -103,9 +103,7 @@ let endorsing_power endorsers = (* Tests *) (****************************************************************) -(* Test. - Apply a single endorsement from the slot 0 endorser -*) +(** Apply a single endorsement from the slot 0 endorser. *) let simple_endorsement () = Context.init 5 >>=? fun (b, _) -> @@ -128,9 +126,8 @@ let simple_endorsement () = delegate initial_balance -(* Test. - Apply a maximum number of endorsements. An endorser can be - selected twice. +(** Apply a maximum number of endorsements. An endorser can be + selected twice. *) let max_endorsement () = let endorsers_per_block = 16 in @@ -177,9 +174,8 @@ let max_endorsement () = delegates previous_balances -(* Test. - Check every that endorsers' balances are consistent with different - priorities +(** Check every that endorsers' balances are consistent with different + priorities. *) let consistent_priorities () = let priorities = 0 -- 64 in @@ -234,8 +230,8 @@ let consistent_priorities () = priorities >>=? fun _b -> return_unit -(* Test. - Check that after [preserved_cycles] cycles the endorser gets his reward +(** Check that after [preserved_cycles] cycles the endorser gets his + reward. *) let reward_retrieval () = Context.init 5 @@ -273,10 +269,9 @@ let reward_retrieval () = balance reward -(* Test. - Check that after [preserved_cycles] cycles endorsers get their - reward. Two endorsers are used and they endorse in different - cycles. +(** Check that after [preserved_cycles] cycles endorsers get their + reward. Two endorsers are used and they endorse in different + cycles. *) let reward_retrieval_two_endorsers () = Context.init 5 @@ -435,9 +430,8 @@ let reward_retrieval_two_endorsers () = (* The following test scenarios are supposed to raise errors. *) (****************************************************************) -(* Test. - Wrong endorsement predecessor : apply an endorsement with an - incorrect block predecessor +(** Wrong endorsement predecessor : apply an endorsement with an + incorrect block predecessor. *) let wrong_endorsement_predecessor () = Context.init 5 @@ -457,9 +451,8 @@ let wrong_endorsement_predecessor () = | _ -> false) -(* Test. - Invalid_endorsement_level : apply an endorsement with an incorrect - level (i.e. the predecessor level) +(** Invalid_endorsement_level: apply an endorsement with an incorrect + level (i.e. the predecessor level). *) let invalid_endorsement_level () = Context.init 5 @@ -479,8 +472,8 @@ let invalid_endorsement_level () = | _ -> false) -(* Test. - Duplicate endorsement : apply an endorsement that has already been done +(** Duplicate endorsement : apply an endorsement that has already been + done. *) let duplicate_endorsement () = Context.init 5 @@ -503,9 +496,7 @@ let duplicate_endorsement () = | _ -> false) -(* Test. - Apply a single endorsement from the slot 0 endorser -*) +(** Apply a single endorsement from the slot 0 endorser. *) let not_enough_for_deposit () = Context.init 5 ~endorsers_per_block:1 >>=? fun (b_init, contracts) -> @@ -556,9 +547,7 @@ let not_enough_for_deposit () = | _ -> false) -(* Test. - Check that a block with not enough endorsement cannot be baked -*) +(** Check that a block with not enough endorsement cannot be baked. *) let endorsement_threshold () = let initial_endorsers = 28 in let num_accounts = 100 in @@ -617,9 +606,7 @@ let endorsement_threshold () = b >>= fun _ -> return_unit -(* Test. - Fitness gap -*) +(** Fitness gap *) let test_fitness_gap () = let num_accounts = 5 in Context.init num_accounts diff --git a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml index 6b0250f71bf0..155f52711d61 100644 --- a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml +++ b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml @@ -23,11 +23,11 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On fixed-point decimal numbers. +(** Testing + ------- + Component: Protocol (fixed-point decimals) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On fixed-point decimal numbers. *) open Protocol @@ -111,9 +111,8 @@ let arith_from_fp : (module Fixed_point_repr.Full) -> (module Arith) = end in (module Arith) -(* Test. - Roundtrips between [integral] and [Z.t] (for fixed-point - decimals). Floor and ceil preserve the integral part. +(** Roundtrips between [integral] and [Z.t] (for fixed-point + decimals). Floor and ceil preserve the integral part. *) let integral_tests decimals () = let module FP = Fixed_point_repr.Make (struct @@ -153,9 +152,7 @@ let integral_tests decimals () = (err "pp_integral(integral) = pp(fp(integral))") >>=? fun () -> basic_arith "integral arith" (arith_from_integral (module FP)) -(* Test. - With zero decimals. -*) +(** With zero decimals. *) let fp_zero () = let decimals = 0 in let module FP = Fixed_point_repr.Make (struct @@ -178,9 +175,7 @@ let fp_zero () = >>=? fun () -> basic_arith "fp (0 decimals) arith" (arith_from_fp (module FP)) -(* Test. - With at one decimal. -*) +(** With at one decimal. *) let fp_nonzero decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals @@ -208,9 +203,8 @@ let fp_nonzero decimals () = FP.(ceil (add (fp (integral x)) (unsafe_fp Z.one)) = integral (Z.succ x)) (err "ceil (x + eps) = x + 1") -(* Test. - Checking the parser [FF.pp] that values are correctly converted - according to the number of decimals. +(** Checking the parser [FF.pp] that values are correctly converted + according to the number of decimals. *) let fp_pp () = let module FP = Fixed_point_repr.Make (struct diff --git a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml index 649a43e9d098..2443a33d428b 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml @@ -23,13 +23,13 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Gas costs - Current limitations: for maps, sets & compare, we only test - integer comparable keys. +(** Testing + ------- + Component: Protocol (gas costs) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Gas costs + Current limitations: for maps, sets & compare, we only test + integer comparable keys. *) open Protocol @@ -233,9 +233,7 @@ let cast_cost_to_z (c : Alpha_context.Gas.cost) : Z.t = Data_encoding.Binary.to_bytes_exn Alpha_context.Gas.cost_encoding c |> Data_encoding.Binary.of_bytes_exn Data_encoding.z -(* Test. - Checks that all costs are positive values. -*) +(** Checks that all costs are positive values. *) let check_cost_reprs_are_all_positive list () = List.iter_es (fun (cost_name, cost) -> @@ -247,9 +245,7 @@ let check_cost_reprs_are_all_positive list () = (Failure (Format.asprintf "Gas cost test \"%s\" failed" cost_name)))) list -(* Test. - Checks that all costs are positive values. -*) +(** Checks that all costs are positive values. *) let check_costs_are_all_positive list () = let list = List.map (fun (cost_name, cost) -> (cost_name, cast_cost_to_z cost)) list diff --git a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml index 9d5c5878dcdd..ebd82552e254 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml @@ -23,11 +23,11 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Arithmetic properties around gas. +(** Testing + ------- + Component: Protocol (gas properties) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Arithmetic properties around gas. *) open Protocol @@ -82,9 +82,7 @@ let random_cost_of_kind (cost_kind : cost_kind) = let random_cost () = random_cost_of_kind (random_cost_kind ()) -(* Test. - Consuming [Gas.free] is equivalent to consuming nothing. -*) +(** Consuming [Gas.free] is equivalent to consuming nothing. *) let free_neutral since = let open Alpha_context in let open Environment.Error_monad in @@ -102,9 +100,8 @@ let free_neutral since = then ok_none else Ok (Some (cost, Gas.free)) -(* Test. - Consuming [cost1] then [cost2] is equivalent to consuming - [Gas.(cost1 +@ cost2)]. +(** Consuming [cost1] then [cost2] is equivalent to consuming + [Gas.(cost1 +@ cost2)]. *) let consume_commutes since = let open Alpha_context in diff --git a/src/proto_alpha/lib_protocol/test/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/test_interpretation.ml index 3ab19d5e2c5f..6ade374e8731 100644 --- a/src/proto_alpha/lib_protocol/test/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/test_interpretation.ml @@ -1,9 +1,9 @@ -(* Testing - ------- - Component: Protocol - Dependencies: src/proto_alpha/lib_protocol/script_interpreter.ml - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Interpretation of Michelson scripts +(** Testing + ------- + Component: Protocol (interpretation) + Dependencies: src/proto_alpha/lib_protocol/script_interpreter.ml + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Interpretation of Michelson scripts *) open Protocol @@ -75,9 +75,8 @@ let run_step ctxt code param = code param -(* Test. - Runs a script with an ill-typed parameter and verifies that a - Bad_contract_parameter error is returned +(** Runs a script with an ill-typed parameter and verifies that a + Bad_contract_parameter error is returned *) let test_bad_contract_parameter () = test_context () @@ -141,9 +140,7 @@ let test_json_roundtrip name testable enc v = v' ; return_unit -(* Test. - Encoding/decoding of script_interpreter.ml specific errors -*) +(** Encoding/decoding of script_interpreter.ml specific errors. *) let test_json_roundtrip_err name e () = test_json_roundtrip name diff --git a/src/proto_alpha/lib_protocol/test/test_origination.ml b/src/proto_alpha/lib_protocol/test/test_origination.ml index 3ae74d0498ef..b2bd7fd73bf1 100644 --- a/src/proto_alpha/lib_protocol/test/test_origination.ml +++ b/src/proto_alpha/lib_protocol/test/test_origination.ml @@ -23,9 +23,9 @@ (* *) (*****************************************************************************) -(* Testing +(** Testing ------- - Component: Protocol + Component: Protocol (origination) Invocation: dune build @src/proto_alpha/lib_protocol/runtest Subject: On originating contracts. *) @@ -132,33 +132,26 @@ let two_nth_of_balance incr contract nth = >>=? fun balance -> Lwt.return (Tez.( /? ) balance nth >>? fun res -> Tez.( *? ) res 2L) -(* Test. - Basic test. A contract is created as well as the newly originated contract - (called from origination operation). The balance before/after are checked. +(** Basic test. A contract is created as well as the newly originated + contract (called from origination operation). The balance + before/after are checked. *) let balances_simple () = test_origination_balances ~loc:__LOC__ () -(* Test. - Same as [balances_simple] but credits 10 tez to the originated contract - (no fees). +(** Same as [balances_simple] but credits 10 tez to the originated + contract (no fees). *) let balances_credit () = test_origination_balances ~loc:__LOC__ ~credit:ten_tez () -(* Test. - Same as [balances_credit] with 10 tez fees. -*) +(** Same as [balances_credit] with 10 tez fees. *) let balances_credit_fee () = test_origination_balances ~loc:__LOC__ ~credit:(Tez.of_int 2) ~fee:ten_tez () -(* Test. - Same as the basic test. -*) +(** Same as the basic test. *) let balances_undelegatable () = test_origination_balances ~loc:__LOC__ () -(* Test. - Ask source contract to pay a fee when originating a contract -*) +(** Ask source contract to pay a fee when originating a contract. *) let pay_fee () = register_origination ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun (_b, _contract, _new_contract) -> return_unit @@ -168,9 +161,8 @@ let pay_fee () = (******************************************************) -(* Test. - Create an originate contract where the contract - does not have enough tez to pay for the fee. +(** Create an originate contract where the contract does not have + enough tez to pay for the fee. *) let not_tez_in_contract_to_pay_fee () = Context.init 2 @@ -227,17 +219,13 @@ let n_originations n ?credit ?fee () = [] (1 -- n) -(* Test. - Creates 100 originations. -*) +(** Creates 100 originations. *) let multiple_originations () = n_originations 100 ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun contracts -> Assert.equal_int ~loc:__LOC__ (List.length contracts) 100 -(* Test. - Cannot originate two contracts with the same context's counter -*) +(** Cannot originate two contracts with the same context's counter. *) let counter () = Context.init 1 >>=? fun (b, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_qty.ml b/src/proto_alpha/lib_protocol/test/test_qty.ml index 95790c82ae40..a4cdecd9874a 100644 --- a/src/proto_alpha/lib_protocol/test/test_qty.ml +++ b/src/proto_alpha/lib_protocol/test/test_qty.ml @@ -23,11 +23,11 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On tez quantities. +(** Testing + ------- + Component: Protocol (quantities) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On tez quantities. *) open Protocol @@ -87,9 +87,7 @@ let is_none ?(msg = "") x = if x <> None then fail "None" "Some _" msg let is_some ?(msg = "") x = if x = None then fail "Some _" "None" msg -(* Test. - Literals which are supposed to be parsed correctly. -*) +(** Literals which are supposed to be parsed correctly. *) let test_known_tez_literals () = List.iter (fun (v, s) -> @@ -126,9 +124,8 @@ let test_known_tez_literals () = known_bad_tez_literals ; return_unit -(* Test. - Randomly generated tez value which is printed into string then parsed again - to test equality. +(** Randomly generated tez value which is printed into string then + parsed again to test equality. *) let test_random_tez_literals () = for _ = 0 to 100_000 do diff --git a/src/proto_alpha/lib_protocol/test/test_rolls.ml b/src/proto_alpha/lib_protocol/test/test_rolls.ml index 9f30f19c4ac5..d09287066e63 100644 --- a/src/proto_alpha/lib_protocol/test/test_rolls.ml +++ b/src/proto_alpha/lib_protocol/test/test_rolls.ml @@ -23,9 +23,9 @@ (* *) (*****************************************************************************) -(* Testing +(** Testing ------- - Component: Protocol + Component: Protocol (rolls) Invocation: dune build @src/proto_alpha/lib_protocol/runtest Subject: On rolls and baking rights. A delegate has baking rights provided that it has at least @@ -101,11 +101,10 @@ let check_no_rolls (b : Block.t) (account : Account.t) = get_rolls ctxt account.pkh >>=? fun rolls -> Assert.equal_int ~loc:__LOC__ (List.length rolls) 0 -(* Test. - Creates a block with two initialized contracts/accounts. Asserts - that the first account has a staking balance which equals to its - own balance, and that its staking rights are consistent - (check_rolls). +(** Creates a block with two initialized contracts/accounts. Asserts + that the first account has a staking balance which equals to its + own balance, and that its staking rights are consistent + (check_rolls). *) let simple_staking_rights () = Context.init 2 @@ -120,11 +119,10 @@ let simple_staking_rights () = Assert.equal_tez ~loc:__LOC__ balance info.staking_balance >>=? fun () -> check_rolls b m1 -(* Test. - Creates a block with two initialized contracts/accounts. Bakes five - blocks. Asserts that the staking balance of the first account - equals to its balance. Then both accounts have consistent staking - rights. +(** Creates a block with two initialized contracts/accounts. Bakes + five blocks. Asserts that the staking balance of the first account + equals to its balance. Then both accounts have consistent staking + rights. *) let simple_staking_rights_after_baking () = Context.init 2 @@ -182,10 +180,9 @@ let run_until_deactivation () = check_activate_staking_balance ~loc:__LOC__ ~deactivated:true b (a1, m1) >|=? fun () -> (b, ((a1, m1), balance_start), (a2, m2)) -(* Test. - From an initialized block with two contracts/accounts, the first - one is active then deactivated. After baking, checks that the - account is active again. Baking rights are ensured. +(** From an initialized block with two contracts/accounts, the first + one is active then deactivated. After baking, checks that the + account is active again. Baking rights are ensured. *) let deactivation_then_bake () = run_until_deactivation () @@ -198,10 +195,9 @@ let deactivation_then_bake () = check_activate_staking_balance ~loc:__LOC__ ~deactivated:false b deactivated >>=? fun () -> check_rolls b deactivated_account -(* Test. - A deactivated account, after baking with self-delegation, is active - again. Preservation of its balance is tested. Baking rights are - ensured. +(** A deactivated account, after baking with self-delegation, is + active again. Preservation of its balance is tested. Baking rights + are ensured. *) let deactivation_then_self_delegation () = run_until_deactivation () @@ -220,10 +216,9 @@ let deactivation_then_self_delegation () = Assert.equal_tez ~loc:__LOC__ start_balance balance >>=? fun () -> check_rolls b deactivated_account -(* Test. - A deactivated account, which is emptied (into a newly created sink - account), then self-delegated, becomes activated. Its balance is - zero. Baking rights are ensured. +(** A deactivated account, which is emptied (into a newly created sink + account), then self-delegated, becomes activated. Its balance is + zero. Baking rights are ensured. *) let deactivation_then_empty_then_self_delegation () = run_until_deactivation () @@ -263,10 +258,9 @@ let deactivation_then_empty_then_self_delegation () = Assert.equal_tez ~loc:__LOC__ Tez.zero balance >>=? fun () -> check_rolls b deactivated_account -(* Test. - A deactivated account, which is emptied, then self-delegated, then - re-credited of the sunk amount, becomes active again. Staking - rights remain consistent. +(** A deactivated account, which is emptied, then self-delegated, then + re-credited of the sunk amount, becomes active again. Staking + rights remain consistent. *) let deactivation_then_empty_then_self_delegation_then_recredit () = run_until_deactivation () @@ -309,13 +303,12 @@ let deactivation_then_empty_then_self_delegation_then_recredit () = Assert.equal_tez ~loc:__LOC__ amount balance >>=? fun () -> check_rolls b deactivated_account -(* Test. - Initializes a block with two contracts/accounts. A third new - account is also created. The first account is self-delegated. First - account sends to third one the amount of 0.5 tez. The third account - has no delegate and is consistent for baking rights. Then, it is - self-delegated and is supposed to be activated. Again, consistency - for baking rights are preserved for the first and third accounts. +(** Initializes a block with two contracts/accounts. A third new + account is also created. The first account is self-delegated. First + account sends to third one the amount of 0.5 tez. The third account + has no delegate and is consistent for baking rights. Then, it is + self-delegated and is supposed to be activated. Again, consistency + for baking rights are preserved for the first and third accounts. *) let delegation () = Context.init 2 diff --git a/src/proto_alpha/lib_protocol/test/test_seed.ml b/src/proto_alpha/lib_protocol/test/test_seed.ml index 2ab19e0d6ee9..c2bee61c860d 100644 --- a/src/proto_alpha/lib_protocol/test/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/test_seed.ml @@ -23,21 +23,20 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: - seed_nonce_hash included in some blocks - - revelation operation of seed_nonce that should correspond - to each seed_nonce_hash +(** Testing + ------- + Component: Protocol (seed) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: - seed_nonce_hash included in some blocks + - revelation operation of seed_nonce that should correspond + to each seed_nonce_hash *) open Protocol open Test_tez -(* Test. - Baking [blocks_per_commitment] blocks without a [seed_nonce_hash] - commitment fails with [Invalid_commitment] +(** Baking [blocks_per_commitment] blocks without a [seed_nonce_hash] + commitment fails with [Invalid_commitment]. *) let no_commitment () = Context.init 5 @@ -68,17 +67,16 @@ let baking_reward ctxt (b : Block.t) = >>=? fun endorsing_power -> Context.get_baking_reward ctxt ~priority ~endorsing_power -(* Test. - Choose a baker, denote it by id. In the first cycle, make id bake only once. - Checks that: - - after id bakes with a commitment the bond is frozen and the reward - allocated - - when id reveals the nonce too early, there's an error - - when id reveals at the right time but the wrong value, there's an error - - when another baker reveals correctly, it receives the tip - - revealing twice produces an error - - after [preserved cycles] a committer that correctly revealed - receives back the bond and the reward +(** Choose a baker, denote it by id. In the first cycle, make id bake only once. + Checks that: + - after id bakes with a commitment the bond is frozen and the reward + allocated + - when id reveals the nonce too early, there's an error + - when id reveals at the right time but the wrong value, there's an error + - when another baker reveals correctly, it receives the tip + - revealing twice produces an error + - after [preserved cycles] a committer that correctly revealed + receives back the bond and the reward *) let revelation_early_wrong_right_twice () = let open Assert in @@ -225,10 +223,9 @@ let revelation_early_wrong_right_twice () = balance_is ~loc:__LOC__ (B b) id ~kind:Deposit Tez.zero >>=? fun () -> balance_is ~loc:__LOC__ (B b) id ~kind:Rewards Tez.zero -(* Test. - - a committer at cycle 0, which doesn't reveal at cycle 1, - at the end of the cycle 1 looses the bond and the reward - - revealing too late produces an error +(** - a committer at cycle 0, which doesn't reveal at cycle 1, + at the end of the cycle 1 looses the bond and the reward + - revealing too late produces an error *) let revelation_missing_and_late () = let open Context in diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index 7fd9baa97010..ff86e72ab9f0 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -23,9 +23,9 @@ (* *) (*****************************************************************************) -(* Testing +(** Testing ------- - Component: Protocol + Component: Protocol (transfer) Invocation: dune build @src/proto_alpha/lib_protocol/runtest Subject: Quantities transfer between contracts. *) @@ -168,20 +168,14 @@ let single_transfer ?fee ?expect_failure amount = amount >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Single transfer without fee -*) +(** Single transfer without fee. *) let block_with_a_single_transfer () = single_transfer Tez.one -(* Test. - Single transfer with fee -*) +(** Single transfer with fee. *) let block_with_a_single_transfer_with_fee () = single_transfer ~fee:Tez.one Tez.one -(* Test. - Single transfer without fee -*) +(** Single transfer without fee. *) let transfer_zero_tez () = single_transfer ~expect_failure:(function @@ -192,9 +186,7 @@ let transfer_zero_tez () = failwith "Empty transaction should fail") Tez.zero -(* Test. - Transfer zero tez from an implicit contract -*) +(** Transfer zero tez from an implicit contract. *) let transfer_zero_implicit () = Context.init 1 >>=? fun (b, contracts) -> @@ -213,9 +205,7 @@ let transfer_zero_implicit () = | _ -> false) -(* Test. - Transfer to originated contract -*) +(** Transfer to originated contract. *) let transfer_to_originate_with_fee () = Context.init 1 >>=? fun (b, contracts) -> @@ -234,9 +224,7 @@ let transfer_to_originate_with_fee () = transfer_and_check_balances ~loc:__LOC__ b ~fee contract new_contract amount >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Transfer from balance -*) +(** Transfer from balance. *) let transfer_amount_of_contract_balance () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -253,9 +241,7 @@ let transfer_amount_of_contract_balance () = transfer_and_check_balances ~loc:__LOC__ b contract_1 contract_2 balance >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Transfer to itself -*) +(** Transfer to oneself. *) let transfers_to_self () = Context.init 1 >>=? fun (b, contracts) -> @@ -271,9 +257,7 @@ let transfers_to_self () = transfer_to_itself_and_check_balances ~loc:__LOC__ b ~fee contract ten_tez >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Forgot to add the valid transaction into the block -*) +(** Forgot to add the valid transaction into the block. *) let missing_transaction () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -302,9 +286,7 @@ let missing_transaction () = (********************) -(* Test. - Implicit to Implicit -*) +(** Implicit to Implicit. *) let transfer_from_implicit_to_implicit_contract () = Context.init 1 >>=? fun (b, contracts) -> @@ -344,9 +326,7 @@ let transfer_from_implicit_to_implicit_contract () = amount2 >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Implicit to originated -*) +(** Implicit to originated. *) let transfer_from_implicit_to_originated_contract () = Context.init 1 >>=? fun (b, contracts) -> @@ -391,25 +371,22 @@ let multiple_transfer n ?fee amount = n_transactions n b ?fee contract_1 contract_2 amount >>=? fun b -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - 1- Create a block with two contracts; - 2- Apply 100 transfers. +(** 1- Create a block with two contracts; + 2- Apply 100 transfers. *) let block_with_multiple_transfers () = multiple_transfer 99 (Tez.of_int 1000) -(* Test. - 1- Create a block with two contracts; - 2- Apply 100 transfers with 10tz fee. +(** 1- Create a block with two contracts; + 2- Apply 100 transfers with 10tz fee. *) let block_with_multiple_transfers_pay_fee () = multiple_transfer 10 ~fee:ten_tez (Tez.of_int 1000) (* TODO : increase the number of operations and add a `Slow tag to it in `tests` *) -(* Test. - 1- Create a block with 8 contracts; - 2- Apply multiple transfers without fees; - 3- Apply multiple transfers with fees. +(** 1- Create a block with 8 contracts; + 2- Apply multiple transfers without fees; + 3- Apply multiple transfers with fees. *) let block_with_multiple_transfers_with_without_fee () = Context.init 8 @@ -449,9 +426,7 @@ let block_with_multiple_transfers_with_without_fee () = n_transactions 20 ~fee:ten b contracts.(1) contracts.(0) twenty >>=? fun b -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Build a chain that has 10 blocks. -*) +(** Build a chain that has 10 blocks. *) let build_a_chain () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -470,9 +445,7 @@ let build_a_chain () = (* Expected error test cases *) (*********************************************************************) -(* Test. - Transfer zero tez is forbidden in implicit contract -*) +(** Transfer zero tez is forbidden in implicit contract. *) let empty_implicit () = Context.init 1 >>=? fun (b, contracts) -> @@ -494,9 +467,7 @@ let empty_implicit () = | _ -> false) -(* Test. - Balance is too low to transfer -*) +(** Balance is too low to transfer. *) let balance_too_low fee () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -529,12 +500,11 @@ let balance_too_low fee () = (* contract_2 is not credited *) Assert.balance_was_credited ~loc:__LOC__ (I i) contract_2 balance2 Tez.zero -(* Test. - 1- Create a block, and three contracts; - 2- Add a transfer that at the end the balance of a contract is - zero into this block; - 3- Add another transfer that send tez from a zero balance contract; - 4- Catch the expected error: Balance_too_low. +(** 1- Create a block, and three contracts; + 2- Add a transfer that at the end the balance of a contract is + zero into this block; + 3- Add another transfer that send tez from a zero balance contract; + 4- Catch the expected error: Balance_too_low. *) let balance_too_low_two_transfers fee () = Context.init 3 @@ -577,9 +547,7 @@ let balance_too_low_two_transfers fee () = (* contract_3 is not credited *) Assert.balance_was_credited ~loc:__LOC__ (I i) contract_3 balance3 Tez.zero -(* Test. - The counter is already used for the previous operation -*) +(** The counter is already used for the previous operation. *) let invalid_counter () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -599,9 +567,7 @@ let invalid_counter () = | _ -> false) -(* Test. - Same as before but different way to perform this error -*) +(** Same as before but different way to perform this error. *) let add_the_same_operation_twice () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -619,9 +585,7 @@ let add_the_same_operation_twice () = | _ -> false) -(* Test. - Check ownership -*) +(** Check ownership. *) let ownership_sender () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -652,9 +616,8 @@ let random_contract contract_array = let i = Random.int (Array.length contract_array) in contract_array.(i) -(* Test. - Transfer by randomly choose amount 10 contracts, and randomly - choose the amount in the source contract +(** Transfer by randomly choose amount 10 contracts, and randomly + choose the amount in the source contract. *) let random_transfer () = Context.init 10 @@ -675,9 +638,7 @@ let random_transfer () = else transfer_and_check_balances ~loc:__LOC__ b source dest amount ) >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit -(* Test. - Transfer random transactions -*) +(** Transfer random transactions. *) let random_multi_transactions () = let n = random_range (1, 100) in multiple_transfer n (Tez.of_int 100) diff --git a/src/proto_alpha/lib_protocol/test/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/test_typechecking.ml index bbe6a6401d89..7bb3e6ff6eca 100644 --- a/src/proto_alpha/lib_protocol/test/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/test_typechecking.ml @@ -1,8 +1,8 @@ -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Type-checking +(** Testing + ------- + Component: Protocol (type-checking) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: Type-checking *) open Protocol @@ -108,9 +108,8 @@ let read_file filename = let s = really_input_string ch (in_channel_length ch) in close_in ch ; s -(* Test. - Check that the custom stack overflow exception is triggered when it - should be. +(** Checks that the custom stack overflow exception is triggered when + it should be. *) let test_typecheck_stack_overflow () = test_context () diff --git a/src/proto_alpha/lib_protocol/test/test_voting.ml b/src/proto_alpha/lib_protocol/test/test_voting.ml index 35f6abf23801..54854d2c7579 100644 --- a/src/proto_alpha/lib_protocol/test/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/test_voting.ml @@ -23,11 +23,11 @@ (* *) (*****************************************************************************) -(* Testing - ------- - Component: Protocol - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On the voting process. +(** Testing + ------- + Component: Protocol (voting) + Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Subject: On the voting process. *) open Protocol @@ -202,9 +202,7 @@ let bake_until_first_block_of_next_period b = Context.Vote.get_current_period (B b) >>=? fun {remaining; _} -> Block.bake_n Int32.(add remaining one |> to_int) b -(* Test. - A normal and successful vote sequence. -*) +(** A normal and successful vote sequence. *) let test_successful_vote num_delegates () = let open Alpha_context in let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in @@ -546,9 +544,9 @@ let get_expected_participation_ema rolls voter_rolls old_participation_ema = in get_updated_participation_ema old_participation_ema participation -(* Test. - If not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- - in testing vote, go back to proposal period +(** If not enough quorum + -- get_updated_participation_ema < pr_ema_weight/den -- + in testing vote, go back to proposal period. *) let test_not_enough_quorum_in_testing_vote num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in @@ -612,9 +610,9 @@ let test_not_enough_quorum_in_testing_vote num_delegates () = (Int32.to_int new_participation_ema) >>=? fun () -> return_unit -(* Test. - If not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- - In promotion vote, go back to proposal period +(** If not enough quorum + -- get_updated_participation_ema < pr_ema_weight/den -- + In promotion vote, go back to proposal period. *) let test_not_enough_quorum_in_promotion_vote num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in @@ -704,9 +702,8 @@ let test_not_enough_quorum_in_promotion_vote num_delegates () = >>=? fun () -> assert_listings_not_empty b ~loc:__LOC__ >>=? fun () -> return_unit -(* Test. - Identical proposals (identified by their hash) must be counted as - one. +(** Identical proposals (identified by their hash) must be counted as + one. *) let test_multiple_identical_proposals_count_as_one () = Context.init 1 @@ -746,9 +743,8 @@ let test_multiple_identical_proposals_count_as_one () = | None -> failwith "%s - Missing proposal" __LOC__ -(* Test. - Assumes the initial balance of allocated by Context.init is at - least 4 time the value of the tokens_per_roll constant +(** Assumes the initial balance of allocated by Context.init is at + least 4 time the value of the tokens_per_roll constant. *) let test_supermajority_in_proposal there_is_a_winner () = let min_proposal_quorum = 0l in @@ -817,10 +813,9 @@ let test_supermajority_in_proposal there_is_a_winner () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit -(* Test. - After one voting period, if [has_quorum] then the period kind must - have been the testing vote. Otherwise, it should have remained in - place in the proposal period. +(** After one voting period, if [has_quorum] then the period kind must + have been the testing vote. Otherwise, it should have remained in + place in the proposal period. *) let test_quorum_in_proposal has_quorum () = let total_tokens = 32_000_000_000_000L in @@ -879,9 +874,8 @@ let test_quorum_in_proposal has_quorum () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit -(* Test. - If a supermajority is reached, then the voting period must be - reached. Otherwise, it remains in proposal period. +(** If a supermajority is reached, then the voting period must be + reached. Otherwise, it remains in proposal period. *) let test_supermajority_in_testing_vote supermajority () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / 100)) in @@ -935,8 +929,8 @@ let test_supermajority_in_testing_vote supermajority () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit -(* Test. - Tests also how the selection scales: all delegates propose max proposals +(** Tests also how the selection scales: all delegates propose max + proposals. *) let test_no_winning_proposal num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in @@ -961,10 +955,9 @@ let test_no_winning_proposal num_delegates () = (* we stay in the same proposal period because no winning proposal *) assert_period ~expected_kind:Proposal b __LOC__ >>=? fun () -> return_unit -(* Test. - Vote to pass with maximum possible participation_ema (100%), it is - sufficient for the vote quorum to be equal or greater than the - maximum quorum cap. +(** Vote to pass with maximum possible participation_ema (100%), it is + sufficient for the vote quorum to be equal or greater than the + maximum quorum cap. *) let test_quorum_capped_maximum num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in @@ -1011,10 +1004,10 @@ let test_quorum_capped_maximum num_delegates () = (* expect to move to testing because we have supermajority and enough quorum *) assert_period ~expected_kind:Testing b __LOC__ -(* Test. - Vote to pass with minimum possible participation_ema (0%), it is - sufficient for the vote quorum to be equal or greater than the - minimum quorum cap. *) +(** Vote to pass with minimum possible participation_ema (0%), it is + sufficient for the vote quorum to be equal or greater than the + minimum quorum cap. +*) let test_quorum_capped_minimum num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates -- GitLab From 14eb772a4ff2ee8608989c2b904ab1888ee86fe2 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Tue, 3 Nov 2020 10:34:02 +0100 Subject: [PATCH 05/17] Testing: Prefixed test function names --- .../lib_protocol/test/test_activation.ml | 44 +++---- .../test/test_combined_operations.ml | 20 +-- .../lib_protocol/test/test_delegation.ml | 114 +++++++++--------- .../lib_protocol/test/test_double_baking.ml | 28 ++--- .../test/test_double_endorsement.ml | 24 ++-- .../lib_protocol/test/test_endorsement.ml | 40 +++--- .../lib_protocol/test/test_fixed_point.ml | 22 ++-- .../lib_protocol/test/test_gas_costs.ml | 16 +-- .../lib_protocol/test/test_gas_properties.ml | 8 +- .../lib_protocol/test/test_origination.ml | 32 ++--- .../lib_protocol/test/test_reveal.ml | 12 +- .../lib_protocol/test/test_rolls.ml | 36 +++--- .../lib_protocol/test/test_seed.ml | 12 +- .../lib_protocol/test/test_transfer.ml | 90 +++++++------- 14 files changed, 249 insertions(+), 249 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index cb43e5a0b1a8..b8fd4f521876 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -312,13 +312,13 @@ let activation_init () = >|=? fun (b, cs) -> secrets () |> fun ss -> (b, cs, ss) (** A simple initialization *) -let simple_init_with_commitments () = +let test_simple_init_with_commitments () = activation_init () >>=? fun (blk, _contracts, _secrets) -> Block.bake blk >>=? fun _ -> return_unit (** A single activation *) -let single_activation () = +let test_single_activation () = activation_init () >>=? fun (blk, _contracts, secrets) -> let ({account; activation_code; amount = expected_amount; _} as _first_one) = @@ -343,7 +343,7 @@ let single_activation () = expected_amount (** 10 activations, one per bake *) -let multi_activation_1 () = +let test_multi_activation_1 () = activation_init () >>=? fun (blk, _contracts, secrets) -> List.fold_left_es @@ -363,7 +363,7 @@ let multi_activation_1 () = >>=? fun _ -> return_unit (** All in one bake *) -let multi_activation_2 () = +let test_multi_activation_2 () = activation_init () >>=? fun (blk, _contracts, secrets) -> List.fold_left_es @@ -385,7 +385,7 @@ let multi_activation_2 () = secrets (** Transfer with activated account *) -let activation_and_transfer () = +let test_activation_and_transfer () = activation_init () >>=? fun (blk, contracts, secrets) -> let ({account; activation_code; _} as _first_one) = @@ -415,7 +415,7 @@ let activation_and_transfer () = half_amount (** Transfer to an unactivated account and then activating it *) -let transfer_to_unactivated_then_activate () = +let test_transfer_to_unactivated_then_activate () = activation_init () >>=? fun (blk, contracts, secrets) -> let ({account; activation_code; amount} as _first_one) = @@ -457,7 +457,7 @@ let transfer_to_unactivated_then_activate () = (** Invalid pkh activation: expected to fail as the context does not contain any commitment. *) -let invalid_activation_with_no_commitments () = +let test_invalid_activation_with_no_commitments () = Context.init 1 >>=? fun (blk, _) -> let secrets = secrets () in @@ -475,7 +475,7 @@ let invalid_activation_with_no_commitments () = false) (** Wrong activation: wrong secret given in the operation. *) -let invalid_activation_wrong_secret () = +let test_invalid_activation_wrong_secret () = activation_init () >>=? fun (blk, _, secrets) -> let ({account; _} as _first_one) = Option.get @@ List.nth secrets 0 in @@ -494,7 +494,7 @@ let invalid_activation_wrong_secret () = (** Invalid pkh activation : expected to fail as the context does not contain an associated commitment. *) -let invalid_activation_inexistent_pkh () = +let test_invalid_activation_inexistent_pkh () = activation_init () >>=? fun (blk, _, secrets) -> let ({activation_code; _} as _first_one) = Option.get @@ List.hd secrets in @@ -515,7 +515,7 @@ let invalid_activation_inexistent_pkh () = (** Invalid pkh activation : expected to fail as the commitment has already been claimed. *) -let invalid_double_activation () = +let test_invalid_double_activation () = activation_init () >>=? fun (blk, _, secrets) -> let ({account; activation_code; _} as _first_one) = @@ -538,7 +538,7 @@ let invalid_double_activation () = false) (** Transfer from an unactivated commitment account. *) -let invalid_transfer_from_unactivated_account () = +let test_invalid_transfer_from_unactivated_account () = activation_init () >>=? fun (blk, contracts, secrets) -> let ({account; _} as _first_one) = Option.get @@ List.hd secrets in @@ -560,26 +560,26 @@ let invalid_transfer_from_unactivated_account () = false) let tests = - [ Test.tztest "init with commitments" `Quick simple_init_with_commitments; - Test.tztest "single activation" `Quick single_activation; - Test.tztest "multi-activation one-by-one" `Quick multi_activation_1; - Test.tztest "multi-activation all at a time" `Quick multi_activation_2; - Test.tztest "activation and transfer" `Quick activation_and_transfer; + [ Test.tztest "init with commitments" `Quick test_simple_init_with_commitments; + Test.tztest "single activation" `Quick test_single_activation; + Test.tztest "multi-activation one-by-one" `Quick test_multi_activation_1; + Test.tztest "multi-activation all at a time" `Quick test_multi_activation_2; + Test.tztest "activation and transfer" `Quick test_activation_and_transfer; Test.tztest "transfer to unactivated account then activate" `Quick - transfer_to_unactivated_then_activate; + test_transfer_to_unactivated_then_activate; Test.tztest "invalid activation with no commitments" `Quick - invalid_activation_with_no_commitments; + test_invalid_activation_with_no_commitments; Test.tztest "invalid activation with commitments" `Quick - invalid_activation_inexistent_pkh; - Test.tztest "invalid double activation" `Quick invalid_double_activation; - Test.tztest "wrong activation code" `Quick invalid_activation_wrong_secret; + test_invalid_activation_inexistent_pkh; + Test.tztest "invalid double activation" `Quick test_invalid_double_activation; + Test.tztest "wrong activation code" `Quick test_invalid_activation_wrong_secret; Test.tztest "invalid transfer from unactivated account" `Quick - invalid_transfer_from_unactivated_account ] + test_invalid_transfer_from_unactivated_account ] diff --git a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml index 42c67458e753..6934c3161032 100644 --- a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml @@ -47,7 +47,7 @@ open Test_tez let ten_tez = Tez.of_int 10 (** Groups ten transactions between the same parties. *) -let multiple_transfers () = +let test_multiple_transfers () = Context.init 3 >>=? fun (blk, contracts) -> let (c1, c2, c3) = @@ -81,7 +81,7 @@ let multiple_transfers () = >>=? fun () -> return_unit (** Groups ten delegated originations. *) -let multiple_origination_and_delegation () = +let test_multiple_origination_and_delegation () = Context.init 2 >>=? fun (blk, contracts) -> let (c1, c2) = @@ -170,7 +170,7 @@ let expect_balance_too_low = function Checks that the receipt is consistent. Variant without fees. *) -let failing_operation_in_the_middle () = +let test_failing_operation_in_the_middle () = Context.init 2 >>=? fun (blk, contracts) -> let (c1, c2) = @@ -228,7 +228,7 @@ let failing_operation_in_the_middle () = Checks that the receipt is consistent. Variant with fees, that should be spent even in case of failure. *) -let failing_operation_in_the_middle_with_fees () = +let test_failing_operation_in_the_middle_with_fees () = Context.init 2 >>=? fun (blk, contracts) -> let (c1, c2) = @@ -303,7 +303,7 @@ let expect_wrong_signature list = "Packed operation has invalid source in the middle : operation expected \ to fail." -let wrong_signature_in_the_middle () = +let test_wrong_signature_in_the_middle () = Context.init 2 >>=? function | (_, []) | (_, [_]) -> @@ -339,20 +339,20 @@ let wrong_signature_in_the_middle () = >>=? fun _inc -> return_unit let tests = - [ Test.tztest "multiple transfers" `Quick multiple_transfers; + [ Test.tztest "multiple transfers" `Quick test_multiple_transfers; Test.tztest "multiple originations and delegations" `Quick - multiple_origination_and_delegation; + test_multiple_origination_and_delegation; Test.tztest "Failing operation in the middle" `Quick - failing_operation_in_the_middle; + test_failing_operation_in_the_middle; Test.tztest "Failing operation in the middle (with fees)" `Quick - failing_operation_in_the_middle_with_fees; + test_failing_operation_in_the_middle_with_fees; Test.tztest "Failing operation (wrong manager in the middle of a pack)" `Quick - wrong_signature_in_the_middle ] + test_wrong_signature_in_the_middle ] diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index 3771fdc54ed6..dc0ca753afdb 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -497,7 +497,7 @@ let expect_unregistered_key pkh = function (** No token transfer, no self-delegation. Originated account. *) -let unregistered_delegate_key_init_origination ~fee () = +let test_unregistered_delegate_key_init_origination ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -551,7 +551,7 @@ let unregistered_delegate_key_init_origination ~fee () = (** Delegation when delegate key is not assigned. Delegate account is initialized. *) -let unregistered_delegate_key_init_delegation ~fee () = +let test_unregistered_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -602,7 +602,7 @@ let unregistered_delegate_key_init_delegation ~fee () = false) (** Re-delegation when a delegate key was already assigned. *) -let unregistered_delegate_key_switch_delegation ~fee () = +let test_unregistered_delegate_key_switch_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -663,7 +663,7 @@ let unregistered_delegate_key_switch_delegation ~fee () = (** Same as [unregistered_delegate_key_init_origination] and credits [amount], no self-delegation. *) -let unregistered_delegate_key_init_origination_credit ~fee ~amount () = +let test_unregistered_delegate_key_init_origination_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -717,7 +717,7 @@ let unregistered_delegate_key_init_origination_credit ~fee ~amount () = (** Same as [unregistered_delegate_key_init_delegation] and credits the amount [amount] of the implicit contract. *) -let unregistered_delegate_key_init_delegation_credit ~fee ~amount () = +let test_unregistered_delegate_key_init_delegation_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -778,7 +778,7 @@ let unregistered_delegate_key_init_delegation_credit ~fee ~amount () = (** Same as in [unregistered_delegate_key_switch_delegation] and credits the amount [amount] to the implicit contract. *) -let unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = +let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -848,7 +848,7 @@ let unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = (** A credit of some amount followed by a debit of the same amount, no self-delegation. *) -let unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = +let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -909,7 +909,7 @@ let unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = (** Same as in [unregistered_delegate_key_init_delegation] but credits then debits the amount [amount] to the implicit contract. *) -let unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = +let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -975,7 +975,7 @@ let unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = (** Same as in [unregistered_delegate_key_switch_delegation] but credits then debits the amount [amount] to the implicit contract. *) -let unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = +let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1051,7 +1051,7 @@ let unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = *) (** Self-delegation with zero-balance contract should fail. *) -let failed_self_delegation_no_transaction () = +let test_failed_self_delegation_no_transaction () = Context.init 1 >>=? fun (b, _) -> Incremental.begin_construction b @@ -1078,7 +1078,7 @@ let failed_self_delegation_no_transaction () = (** Implicit contract is credited then debited of same amount (i.e., is emptied). Self-delegation fails. *) -let failed_self_delegation_emptied_implicit_contract amount () = +let test_failed_self_delegation_emptied_implicit_contract amount () = (* create an implicit contract *) Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1117,7 +1117,7 @@ let failed_self_delegation_emptied_implicit_contract amount () = tz, then it is delegated. The operation of debit of [amount] tz should fail as the contract is already delegated. *) -let emptying_delegated_implicit_contract_fails amount () = +let test_emptying_delegated_implicit_contract_fails amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1162,7 +1162,7 @@ let emptying_delegated_implicit_contract_fails amount () = (** Initialized account is credited of [amount] tz, then self-delegated. *) -let valid_delegate_registration_init_delegation_credit amount () = +let test_valid_delegate_registration_init_delegation_credit amount () = (* create an implicit contract *) Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1220,7 +1220,7 @@ let valid_delegate_registration_init_delegation_credit amount () = bootstrap as delegate. Re-delegates it to the first implicit contract. *) -let valid_delegate_registration_switch_delegation_credit amount () = +let test_valid_delegate_registration_switch_delegation_credit amount () = (* create an implicit contract *) Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1275,7 +1275,7 @@ let valid_delegate_registration_switch_delegation_credit amount () = Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh (** Creates an implicit contract. *) -let valid_delegate_registration_init_delegation_credit_debit amount () = +let test_valid_delegate_registration_init_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1349,7 +1349,7 @@ let valid_delegate_registration_init_delegation_credit_debit amount () = implicit contract is delegated to bootstrap, then should be able to be re-delegated to the latter contract. *) -let valid_delegate_registration_switch_delegation_credit_debit amount () = +let test_valid_delegate_registration_switch_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1420,7 +1420,7 @@ let valid_delegate_registration_switch_delegation_credit_debit amount () = (** Second self-delegation should fail with implicit contract with some credit. *) -let double_registration () = +let test_double_registration () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1455,7 +1455,7 @@ let double_registration () = (** Second self-delegation should fail with implicit contract emptied after first self-delegation. *) -let double_registration_when_empty () = +let test_double_registration_when_empty () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1497,7 +1497,7 @@ let double_registration_when_empty () = (** Second self-delegation should fail with implicit contract emptied then recredited after first self-delegation. *) -let double_registration_when_recredited () = +let test_double_registration_when_recredited () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1544,7 +1544,7 @@ let double_registration_when_recredited () = false) (** Self-delegation on unrevealed contract. *) -let unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = +let test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1579,7 +1579,7 @@ let unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = Assert.balance_was_debited ~loc:__LOC__ (I i) contract balance fee (** Self-delegation on revealed but not registered contract. *) -let unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = +let test_unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1618,7 +1618,7 @@ let unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = Assert.balance_was_debited ~loc:__LOC__ (I i) contract balance fee (** Self-delegation on revealed and registered contract. *) -let registered_self_delegate_key_init_delegation () = +let test_registered_self_delegate_key_init_delegation () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1663,196 +1663,196 @@ let tests_delegate_registration = Test.tztest "unregistered delegate key (origination, small fee)" `Quick - (unregistered_delegate_key_init_origination ~fee:Tez.one_mutez); + (test_unregistered_delegate_key_init_origination ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key (origination, edge case fee)" `Quick - (unregistered_delegate_key_init_origination ~fee:(Tez.of_int 3_999_488)); + (test_unregistered_delegate_key_init_origination ~fee:(Tez.of_int 3_999_488)); Test.tztest "unregistered delegate key (origination, large fee)" `Quick - (unregistered_delegate_key_init_origination ~fee:(Tez.of_int 10_000_000)); + (test_unregistered_delegate_key_init_origination ~fee:(Tez.of_int 10_000_000)); Test.tztest "unregistered delegate key (init with delegation, small fee)" `Quick - (unregistered_delegate_key_init_delegation ~fee:Tez.one_mutez); + (test_unregistered_delegate_key_init_delegation ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key (init with delegation, max fee)" `Quick - (unregistered_delegate_key_init_delegation ~fee:Tez.max_tez); + (test_unregistered_delegate_key_init_delegation ~fee:Tez.max_tez); Test.tztest "unregistered delegate key (switch with delegation, small fee)" `Quick - (unregistered_delegate_key_switch_delegation ~fee:Tez.one_mutez); + (test_unregistered_delegate_key_switch_delegation ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key (switch with delegation, max fee)" `Quick - (unregistered_delegate_key_switch_delegation ~fee:Tez.max_tez); + (test_unregistered_delegate_key_switch_delegation ~fee:Tez.max_tez); (* credit/debit 1μꜩ, no self-delegation *) Test.tztest "unregistered delegate key - credit/debit 1μꜩ (origination, small fee)" `Quick - (unregistered_delegate_key_init_origination_credit_debit + (test_unregistered_delegate_key_init_origination_credit_debit ~fee:Tez.one_mutez ~amount:Tez.one_mutez); Test.tztest "unregistered delegate key - credit/debit 1μꜩ (origination, large fee)" `Quick - (unregistered_delegate_key_init_origination_credit_debit + (test_unregistered_delegate_key_init_origination_credit_debit ~fee:Tez.max_tez ~amount:Tez.one_mutez); Test.tztest "unregistered delegate key - credit/debit 1μꜩ (init with delegation, \ small fee)" `Quick - (unregistered_delegate_key_init_delegation_credit_debit + (test_unregistered_delegate_key_init_delegation_credit_debit ~amount:Tez.one_mutez ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key - credit/debit 1μꜩ (init with delegation, \ large fee)" `Quick - (unregistered_delegate_key_init_delegation_credit_debit + (test_unregistered_delegate_key_init_delegation_credit_debit ~amount:Tez.one_mutez ~fee:Tez.max_tez); Test.tztest "unregistered delegate key - credit/debit 1μꜩ (switch with \ delegation, small fee)" `Quick - (unregistered_delegate_key_switch_delegation_credit_debit + (test_unregistered_delegate_key_switch_delegation_credit_debit ~amount:Tez.one_mutez ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key - credit/debit 1μꜩ (switch with \ delegation, large fee)" `Quick - (unregistered_delegate_key_switch_delegation_credit_debit + (test_unregistered_delegate_key_switch_delegation_credit_debit ~amount:Tez.one_mutez ~fee:Tez.max_tez); (* credit 1μꜩ, no self-delegation *) Test.tztest "unregistered delegate key - credit 1μꜩ (origination, small fee)" `Quick - (unregistered_delegate_key_init_origination_credit + (test_unregistered_delegate_key_init_origination_credit ~fee:Tez.one_mutez ~amount:Tez.one_mutez); Test.tztest "unregistered delegate key - credit 1μꜩ (origination, edge case fee)" `Quick - (unregistered_delegate_key_init_origination_credit + (test_unregistered_delegate_key_init_origination_credit ~fee:(Tez.of_int 3_999_488) ~amount:Tez.one_mutez); Test.tztest "unregistered delegate key - credit 1μꜩ (origination, large fee)" `Quick - (unregistered_delegate_key_init_origination_credit + (test_unregistered_delegate_key_init_origination_credit ~fee:(Tez.of_int 10_000_000) ~amount:Tez.one_mutez); Test.tztest "unregistered delegate key - credit 1μꜩ (init with delegation, small \ fee)" `Quick - (unregistered_delegate_key_init_delegation_credit + (test_unregistered_delegate_key_init_delegation_credit ~amount:Tez.one_mutez ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key - credit 1μꜩ (init with delegation, large \ fee)" `Quick - (unregistered_delegate_key_init_delegation_credit + (test_unregistered_delegate_key_init_delegation_credit ~amount:Tez.one_mutez ~fee:Tez.max_tez); Test.tztest "unregistered delegate key - credit 1μꜩ (switch with delegation, \ small fee)" `Quick - (unregistered_delegate_key_switch_delegation_credit + (test_unregistered_delegate_key_switch_delegation_credit ~amount:Tez.one_mutez ~fee:Tez.one_mutez); Test.tztest "unregistered delegate key - credit 1μꜩ (switch with delegation, \ large fee)" `Quick - (unregistered_delegate_key_switch_delegation_credit + (test_unregistered_delegate_key_switch_delegation_credit ~amount:Tez.one_mutez ~fee:Tez.max_tez); (* self delegation on unrevealed and unregistered contract *) Test.tztest "unregistered and unrevealed self-delegation (small fee)" `Quick - (unregistered_and_unrevealed_self_delegate_key_init_delegation + (test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee:Tez.one_mutez); Test.tztest "unregistered and unrevealed self-delegation (large fee)" `Quick - (unregistered_and_unrevealed_self_delegate_key_init_delegation + (test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee:Tez.max_tez); (* self delegation on unregistered contract *) Test.tztest "unregistered and revealed self-delegation (small fee)" `Quick - (unregistered_and_revealed_self_delegate_key_init_delegation + (test_unregistered_and_revealed_self_delegate_key_init_delegation ~fee:Tez.one_mutez); Test.tztest "unregistered and revealed self-delegation large fee)" `Quick - (unregistered_and_revealed_self_delegate_key_init_delegation + (test_unregistered_and_revealed_self_delegate_key_init_delegation ~fee:Tez.max_tez); (* self delegation on registered contract *) Test.tztest "registered and revealed self-delegation" `Quick - registered_self_delegate_key_init_delegation; + test_registered_self_delegate_key_init_delegation; (*** unregistered delegate key: failed self-delegation ***) (* no token transfer, self-delegation *) Test.tztest "failed self-delegation: no transaction" `Quick - failed_self_delegation_no_transaction; + test_failed_self_delegation_no_transaction; (* credit 1μtz, debit 1μtz, self-delegation *) Test.tztest "failed self-delegation: credit & debit 1μꜩ" `Quick - (failed_self_delegation_emptied_implicit_contract Tez.one_mutez); + (test_failed_self_delegation_emptied_implicit_contract Tez.one_mutez); (* credit 1μtz, delegate, debit 1μtz *) Test.tztest "empty delegated contract is not deleted: credit 1μꜩ, delegate & \ debit 1μꜩ" `Quick - (emptying_delegated_implicit_contract_fails Tez.one_mutez); + (test_emptying_delegated_implicit_contract_fails Tez.one_mutez); (*** valid registration ***) (* valid registration: credit 1 μꜩ, self delegation *) Test.tztest "valid delegate registration: credit 1μꜩ, self delegation (init with \ delegation)" `Quick - (valid_delegate_registration_init_delegation_credit Tez.one_mutez); + (test_valid_delegate_registration_init_delegation_credit Tez.one_mutez); Test.tztest "valid delegate registration: credit 1μꜩ, self delegation (switch \ with delegation)" `Quick - (valid_delegate_registration_switch_delegation_credit Tez.one_mutez); + (test_valid_delegate_registration_switch_delegation_credit Tez.one_mutez); (* valid registration: credit 1 μꜩ, self delegation, debit 1μꜩ *) Test.tztest "valid delegate registration: credit 1μꜩ, self delegation, debit \ 1μꜩ (init with delegation)" `Quick - (valid_delegate_registration_init_delegation_credit_debit Tez.one_mutez); + (test_valid_delegate_registration_init_delegation_credit_debit Tez.one_mutez); Test.tztest "valid delegate registration: credit 1μꜩ, self delegation, debit \ 1μꜩ (switch with delegation)" `Quick - (valid_delegate_registration_switch_delegation_credit_debit Tez.one_mutez); + (test_valid_delegate_registration_switch_delegation_credit_debit Tez.one_mutez); (*** double registration ***) - Test.tztest "double registration" `Quick double_registration; + Test.tztest "double registration" `Quick test_double_registration; Test.tztest "double registration when delegate account is emptied" `Quick - double_registration_when_empty; + test_double_registration_when_empty; Test.tztest "double registration when delegate account is emptied and then recredited" `Quick - double_registration_when_recredited ] + test_double_registration_when_recredited ] (******************************************************************************) (* Main *) diff --git a/src/proto_alpha/lib_protocol/test/test_double_baking.ml b/src/proto_alpha/lib_protocol/test/test_double_baking.ml index a02716625d07..9e8603e8a576 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_baking.ml @@ -73,7 +73,7 @@ let block_fork ?policy contracts b = (** Simple scenario where two blocks are baked by a same baker and exposed by a double baking evidence operation. *) -let valid_double_baking_evidence () = +let test_valid_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> Context.get_bakers (B b) @@ -101,7 +101,7 @@ let valid_double_baking_evidence () = (** Check that a double baking operation fails if it exposes the same two blocks. *) -let same_blocks () = +let test_same_blocks () = Context.init 2 >>=? fun (b, _contracts) -> Block.bake b @@ -120,7 +120,7 @@ let same_blocks () = (** Check that a double baking operation exposing two blocks with different levels fails. *) -let different_levels () = +let test_different_levels () = Context.init 2 >>=? fun (b, contracts) -> block_fork ~policy:(By_priority 0) contracts b @@ -140,7 +140,7 @@ let different_levels () = (** Check that a double baking operation exposing two yet to be baked blocks fails. *) -let too_early_double_baking_evidence () = +let test_too_early_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> block_fork ~policy:(By_priority 0) contracts b @@ -158,7 +158,7 @@ let too_early_double_baking_evidence () = (** Check that after [preserved_cycles + 1], it is not possible to create a double baking operation anymore. *) -let too_late_double_baking_evidence () = +let test_too_late_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> Context.get_constants (B b) @@ -183,7 +183,7 @@ let too_late_double_baking_evidence () = (** Check that an invalid double baking evidence that exposes two block baking with same level made by different bakers fails. *) -let different_delegates () = +let test_different_delegates () = Context.init 2 >>=? fun (b, _) -> get_first_different_bakers (B b) @@ -203,7 +203,7 @@ let different_delegates () = false) (** Baker_2 bakes a block but baker signs it. *) -let wrong_signer () = +let test_wrong_signer () = let header_custom_signer baker baker_2 b = Block.Forge.forge_header ~policy:(By_account baker_2) b >>=? fun header -> @@ -231,17 +231,17 @@ let tests = [ Test.tztest "valid double baking evidence" `Quick - valid_double_baking_evidence; + test_valid_double_baking_evidence; (* Should fail*) - Test.tztest "same blocks" `Quick same_blocks; - Test.tztest "different levels" `Quick different_levels; + Test.tztest "same blocks" `Quick test_same_blocks; + Test.tztest "different levels" `Quick test_different_levels; Test.tztest "too early double baking evidence" `Quick - too_early_double_baking_evidence; + test_too_early_double_baking_evidence; Test.tztest "too late double baking evidence" `Quick - too_late_double_baking_evidence; - Test.tztest "different delegates" `Quick different_delegates; - Test.tztest "wrong delegate" `Quick wrong_signer ] + test_too_late_double_baking_evidence; + Test.tztest "different delegates" `Quick test_different_delegates; + Test.tztest "wrong delegate" `Quick test_wrong_signer ] diff --git a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml index 6c79bec145fa..af58c77a95dc 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml @@ -72,7 +72,7 @@ let block_fork b = delegate and exposed by a double_endorsement operation. Also verify that punishment is operated. *) -let valid_double_endorsement_evidence () = +let test_valid_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> block_fork b @@ -109,7 +109,7 @@ let valid_double_endorsement_evidence () = (** Check that an invalid double endorsement operation that exposes a valid endorsement fails. *) -let invalid_double_endorsement () = +let test_invalid_double_endorsement () = Context.init 10 >>=? fun (b, _) -> Block.bake b @@ -131,7 +131,7 @@ let invalid_double_endorsement () = (** Check that a double endorsement added at the same time as a double endorsement operation fails. *) -let too_early_double_endorsement_evidence () = +let test_too_early_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> block_fork b @@ -155,7 +155,7 @@ let too_early_double_endorsement_evidence () = (** Check that after [preserved_cycles + 1], it is not possible to create a double_endorsement anymore. *) -let too_late_double_endorsement_evidence () = +let test_too_late_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> Context.get_constants (B b) @@ -186,7 +186,7 @@ let too_late_double_endorsement_evidence () = (** Check that an invalid double endorsement evidence that expose two endorsements made by two different endorsers fails. *) -let different_delegates () = +let test_different_delegates () = Context.init 2 >>=? fun (b, _) -> Block.bake b @@ -221,7 +221,7 @@ let different_delegates () = (** Check that a double endorsement evidence that exposes a ill-formed endorsement fails. *) -let wrong_delegate () = +let test_wrong_delegate () = Context.init ~endorsers_per_block:1 2 >>=? fun (b, contracts) -> List.map_es (Context.Contract.manager (B b)) contracts @@ -256,18 +256,18 @@ let tests = [ Test.tztest "valid double endorsement evidence" `Quick - valid_double_endorsement_evidence; + test_valid_double_endorsement_evidence; Test.tztest "invalid double endorsement evidence" `Quick - invalid_double_endorsement; + test_invalid_double_endorsement; Test.tztest "too early double endorsement evidence" `Quick - too_early_double_endorsement_evidence; + test_too_early_double_endorsement_evidence; Test.tztest "too late double endorsement evidence" `Quick - too_late_double_endorsement_evidence; - Test.tztest "different delegates" `Quick different_delegates; - Test.tztest "wrong delegate" `Quick wrong_delegate ] + test_too_late_double_endorsement_evidence; + Test.tztest "different delegates" `Quick test_different_delegates; + Test.tztest "wrong delegate" `Quick test_wrong_delegate ] diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index 8d287d307712..e35806a8140c 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -104,7 +104,7 @@ let endorsing_power endorsers = (****************************************************************) (** Apply a single endorsement from the slot 0 endorser. *) -let simple_endorsement () = +let test_simple_endorsement () = Context.init 5 >>=? fun (b, _) -> Context.get_endorser (B b) @@ -129,7 +129,7 @@ let simple_endorsement () = (** Apply a maximum number of endorsements. An endorser can be selected twice. *) -let max_endorsement () = +let test_max_endorsement () = let endorsers_per_block = 16 in Context.init ~endorsers_per_block 32 >>=? fun (b, _) -> @@ -177,7 +177,7 @@ let max_endorsement () = (** Check every that endorsers' balances are consistent with different priorities. *) -let consistent_priorities () = +let test_consistent_priorities () = let priorities = 0 -- 64 in Context.init 64 >>=? fun (b, _) -> @@ -233,7 +233,7 @@ let consistent_priorities () = (** Check that after [preserved_cycles] cycles the endorser gets his reward. *) -let reward_retrieval () = +let test_reward_retrieval () = Context.init 5 >>=? fun (b, _) -> Context.get_constants (B b) @@ -273,7 +273,7 @@ let reward_retrieval () = reward. Two endorsers are used and they endorse in different cycles. *) -let reward_retrieval_two_endorsers () = +let test_reward_retrieval_two_endorsers () = Context.init 5 >>=? fun (b, _) -> Context.get_constants (B b) @@ -433,7 +433,7 @@ let reward_retrieval_two_endorsers () = (** Wrong endorsement predecessor : apply an endorsement with an incorrect block predecessor. *) -let wrong_endorsement_predecessor () = +let test_wrong_endorsement_predecessor () = Context.init 5 >>=? fun (b, _) -> Context.get_endorser (B b) @@ -454,7 +454,7 @@ let wrong_endorsement_predecessor () = (** Invalid_endorsement_level: apply an endorsement with an incorrect level (i.e. the predecessor level). *) -let invalid_endorsement_level () = +let test_invalid_endorsement_level () = Context.init 5 >>=? fun (b, _) -> Context.get_level (B b) @@ -475,7 +475,7 @@ let invalid_endorsement_level () = (** Duplicate endorsement : apply an endorsement that has already been done. *) -let duplicate_endorsement () = +let test_duplicate_endorsement () = Context.init 5 >>=? fun (b, _) -> Incremental.begin_construction b @@ -497,7 +497,7 @@ let duplicate_endorsement () = false) (** Apply a single endorsement from the slot 0 endorser. *) -let not_enough_for_deposit () = +let test_not_enough_for_deposit () = Context.init 5 ~endorsers_per_block:1 >>=? fun (b_init, contracts) -> List.map_es @@ -548,7 +548,7 @@ let not_enough_for_deposit () = false) (** Check that a block with not enough endorsement cannot be baked. *) -let endorsement_threshold () = +let test_endorsement_threshold () = let initial_endorsers = 28 in let num_accounts = 100 in Context.init ~initial_endorsers num_accounts @@ -636,21 +636,21 @@ let test_fitness_gap () = Assert.equal_int ~loc:__LOC__ res 1 >>=? fun () -> return_unit let tests = - [ Test.tztest "Simple endorsement" `Quick simple_endorsement; - Test.tztest "Maximum endorsement" `Quick max_endorsement; - Test.tztest "Consistent priorities" `Quick consistent_priorities; - Test.tztest "Reward retrieval" `Quick reward_retrieval; + [ Test.tztest "Simple endorsement" `Quick test_simple_endorsement; + Test.tztest "Maximum endorsement" `Quick test_max_endorsement; + Test.tztest "Consistent priorities" `Quick test_consistent_priorities; + Test.tztest "Reward retrieval" `Quick test_reward_retrieval; Test.tztest "Reward retrieval two endorsers" `Quick - reward_retrieval_two_endorsers; - Test.tztest "Endorsement threshold" `Quick endorsement_threshold; + test_reward_retrieval_two_endorsers; + Test.tztest "Endorsement threshold" `Quick test_endorsement_threshold; Test.tztest "Fitness gap" `Quick test_fitness_gap; (* Fail scenarios *) Test.tztest "Wrong endorsement predecessor" `Quick - wrong_endorsement_predecessor; - Test.tztest "Invalid endorsement level" `Quick invalid_endorsement_level; - Test.tztest "Duplicate endorsement" `Quick duplicate_endorsement; - Test.tztest "Not enough for deposit" `Quick not_enough_for_deposit ] + test_wrong_endorsement_predecessor; + Test.tztest "Invalid endorsement level" `Quick test_invalid_endorsement_level; + Test.tztest "Duplicate endorsement" `Quick test_duplicate_endorsement; + Test.tztest "Not enough for deposit" `Quick test_not_enough_for_deposit ] diff --git a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml index 155f52711d61..58ca644f674f 100644 --- a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml +++ b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml @@ -114,7 +114,7 @@ let arith_from_fp : (module Fixed_point_repr.Full) -> (module Arith) = (** Roundtrips between [integral] and [Z.t] (for fixed-point decimals). Floor and ceil preserve the integral part. *) -let integral_tests decimals () = +let test_integral_tests decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals end) in @@ -153,7 +153,7 @@ let integral_tests decimals () = >>=? fun () -> basic_arith "integral arith" (arith_from_integral (module FP)) (** With zero decimals. *) -let fp_zero () = +let test_fp_zero () = let decimals = 0 in let module FP = Fixed_point_repr.Make (struct let decimals = decimals @@ -176,7 +176,7 @@ let fp_zero () = basic_arith "fp (0 decimals) arith" (arith_from_fp (module FP)) (** With at one decimal. *) -let fp_nonzero decimals () = +let test_fp_nonzero decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals end) in @@ -206,7 +206,7 @@ let fp_nonzero decimals () = (** Checking the parser [FF.pp] that values are correctly converted according to the number of decimals. *) -let fp_pp () = +let test_fp_pp () = let module FP = Fixed_point_repr.Make (struct let decimals = 3 end) in @@ -231,10 +231,10 @@ let fp_pp () = >>=? fun () -> fail_unless (FP.zero =:= "0") (err "0") let tests = - [ Test.tztest "Integral tests (0 decimals)" `Quick (integral_tests 0); - Test.tztest "Integral tests (1 decimals)" `Quick (integral_tests 1); - Test.tztest "Integral tests (10 decimals)" `Quick (integral_tests 10); - Test.tztest "FP tests (0 decimals)" `Quick fp_zero; - Test.tztest "FP tests (1 decimals)" `Quick (fp_nonzero 1); - Test.tztest "FP tests (3 decimals)" `Quick (fp_nonzero 3); - Test.tztest "FP pp tests (3 decimals)" `Quick fp_pp ] + [ Test.tztest "Integral tests (0 decimals)" `Quick (test_integral_tests 0); + Test.tztest "Integral tests (1 decimals)" `Quick (test_integral_tests 1); + Test.tztest "Integral tests (10 decimals)" `Quick (test_integral_tests 10); + Test.tztest "FP tests (0 decimals)" `Quick test_fp_zero; + Test.tztest "FP tests (1 decimals)" `Quick (test_fp_nonzero 1); + Test.tztest "FP tests (3 decimals)" `Quick (test_fp_nonzero 3); + Test.tztest "FP pp tests (3 decimals)" `Quick test_fp_pp ] diff --git a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml index 2443a33d428b..cbdb8a430950 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml @@ -234,8 +234,8 @@ let cast_cost_to_z (c : Alpha_context.Gas.cost) : Z.t = |> Data_encoding.Binary.of_bytes_exn Data_encoding.z (** Checks that all costs are positive values. *) -let check_cost_reprs_are_all_positive list () = - List.iter_es +let test_cost_reprs_are_all_positive list () = + iter_s (fun (cost_name, cost) -> if Z.gt cost Z.zero then return_unit else if Z.equal cost Z.zero && List.mem cost_name free then return_unit @@ -246,26 +246,26 @@ let check_cost_reprs_are_all_positive list () = list (** Checks that all costs are positive values. *) -let check_costs_are_all_positive list () = +let test_costs_are_all_positive list () = let list = List.map (fun (cost_name, cost) -> (cost_name, cast_cost_to_z cost)) list in - check_cost_reprs_are_all_positive list () + test_cost_reprs_are_all_positive list () let tests = [ Test.tztest "Positivity of interpreter costs" `Quick - (check_costs_are_all_positive all_interpreter_costs); + (test_costs_are_all_positive all_interpreter_costs); Test.tztest "Positivity of typechecking costs" `Quick - (check_costs_are_all_positive all_parsing_costs); + (test_costs_are_all_positive all_parsing_costs); Test.tztest "Positivity of unparsing costs" `Quick - (check_costs_are_all_positive all_unparsing_costs); + (test_costs_are_all_positive all_unparsing_costs); Test.tztest "Positivity of io costs" `Quick - (check_cost_reprs_are_all_positive all_io_costs) ] + (test_cost_reprs_are_all_positive all_io_costs) ] diff --git a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml index ebd82552e254..1748549f3fcc 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml @@ -83,7 +83,7 @@ let random_cost_of_kind (cost_kind : cost_kind) = let random_cost () = random_cost_of_kind (random_cost_kind ()) (** Consuming [Gas.free] is equivalent to consuming nothing. *) -let free_neutral since = +let test_free_neutral since = let open Alpha_context in let open Environment.Error_monad in let cost = random_cost () in @@ -103,7 +103,7 @@ let free_neutral since = (** Consuming [cost1] then [cost2] is equivalent to consuming [Gas.(cost1 +@ cost2)]. *) -let consume_commutes since = +let test_consume_commutes since = let open Alpha_context in let open Environment.Error_monad in let cost1 = random_cost () in @@ -165,8 +165,8 @@ let tests = [ Test.tztest "Gas.free is a neutral element" `Quick - (check_property (loop_check free_neutral 1000)); + (check_property (loop_check test_free_neutral 1000)); Test.tztest "Gas.consume commutes" `Quick - (check_property (loop_check consume_commutes 1000)) ] + (check_property (loop_check test_consume_commutes 1000)) ] diff --git a/src/proto_alpha/lib_protocol/test/test_origination.ml b/src/proto_alpha/lib_protocol/test/test_origination.ml index b2bd7fd73bf1..3f6c0fea754c 100644 --- a/src/proto_alpha/lib_protocol/test/test_origination.ml +++ b/src/proto_alpha/lib_protocol/test/test_origination.ml @@ -136,23 +136,23 @@ let two_nth_of_balance incr contract nth = contract (called from origination operation). The balance before/after are checked. *) -let balances_simple () = test_origination_balances ~loc:__LOC__ () +let test_balances_simple () = test_origination_balances ~loc:__LOC__ () (** Same as [balances_simple] but credits 10 tez to the originated contract (no fees). *) -let balances_credit () = +let test_balances_credit () = test_origination_balances ~loc:__LOC__ ~credit:ten_tez () (** Same as [balances_credit] with 10 tez fees. *) -let balances_credit_fee () = +let test_balances_credit_fee () = test_origination_balances ~loc:__LOC__ ~credit:(Tez.of_int 2) ~fee:ten_tez () (** Same as the basic test. *) -let balances_undelegatable () = test_origination_balances ~loc:__LOC__ () +let test_balances_undelegatable () = test_origination_balances ~loc:__LOC__ () (** Ask source contract to pay a fee when originating a contract. *) -let pay_fee () = +let test_pay_fee () = register_origination ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun (_b, _contract, _new_contract) -> return_unit @@ -164,7 +164,7 @@ let pay_fee () = (** Create an originate contract where the contract does not have enough tez to pay for the fee. *) -let not_tez_in_contract_to_pay_fee () = +let test_not_tez_in_contract_to_pay_fee () = Context.init 2 >>=? fun (b, contracts) -> let contract_1 = Option.get @@ List.nth contracts 0 in @@ -220,13 +220,13 @@ let n_originations n ?credit ?fee () = (1 -- n) (** Creates 100 originations. *) -let multiple_originations () = +let test_multiple_originations () = n_originations 100 ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun contracts -> Assert.equal_int ~loc:__LOC__ (List.length contracts) 100 (** Cannot originate two contracts with the same context's counter. *) -let counter () = +let test_counter () = Context.init 1 >>=? fun (b, contracts) -> let contract = Option.get @@ List.hd contracts in @@ -249,14 +249,14 @@ let counter () = (******************************************************) let tests = - [ Test.tztest "balances_simple" `Quick balances_simple; - Test.tztest "balances_credit" `Quick balances_credit; - Test.tztest "balances_credit_fee" `Quick balances_credit_fee; - Test.tztest "balances_undelegatable" `Quick balances_undelegatable; - Test.tztest "pay_fee" `Quick pay_fee; + [ Test.tztest "balances_simple" `Quick test_balances_simple; + Test.tztest "balances_credit" `Quick test_balances_credit; + Test.tztest "balances_credit_fee" `Quick test_balances_credit_fee; + Test.tztest "balances_undelegatable" `Quick test_balances_undelegatable; + Test.tztest "pay_fee" `Quick test_pay_fee; Test.tztest "not enough tez in contract to pay fee" `Quick - not_tez_in_contract_to_pay_fee; - Test.tztest "multiple originations" `Quick multiple_originations; - Test.tztest "counter" `Quick counter ] + test_not_tez_in_contract_to_pay_fee; + Test.tztest "multiple originations" `Quick test_multiple_originations; + Test.tztest "counter" `Quick test_counter ] diff --git a/src/proto_alpha/lib_protocol/test/test_reveal.ml b/src/proto_alpha/lib_protocol/test/test_reveal.ml index 5833aa1aa4c3..f780d75de1ad 100644 --- a/src/proto_alpha/lib_protocol/test/test_reveal.ml +++ b/src/proto_alpha/lib_protocol/test/test_reveal.ml @@ -30,7 +30,7 @@ open Test_tez let ten_tez = Tez.of_int 10 -let simple_reveal () = +let test_simple_reveal () = Context.init 1 >>=? fun (blk, contracts) -> let c = Option.get @@ List.hd contracts in @@ -54,7 +54,7 @@ let simple_reveal () = >|=? function | true -> () | false -> Stdlib.failwith "New contract revelation failed." -let empty_account_on_reveal () = +let test_empty_account_on_reveal () = Context.init 1 >>=? fun (blk, contracts) -> let c = Option.get @@ List.hd contracts in @@ -86,7 +86,7 @@ let empty_account_on_reveal () = | true -> Stdlib.failwith "Empty account still exists and is revealed." -let not_enough_found_for_reveal () = +let test_not_enough_found_for_reveal () = Context.init 1 >>=? fun (blk, contracts) -> let c = Option.get @@ List.hd contracts in @@ -113,9 +113,9 @@ let not_enough_found_for_reveal () = false) let tests = - [ Test.tztest "simple reveal" `Quick simple_reveal; - Test.tztest "empty account on reveal" `Quick empty_account_on_reveal; + [ Test.tztest "simple reveal" `Quick test_simple_reveal; + Test.tztest "empty account on reveal" `Quick test_empty_account_on_reveal; Test.tztest "not enough found for reveal" `Quick - not_enough_found_for_reveal ] + test_not_enough_found_for_reveal ] diff --git a/src/proto_alpha/lib_protocol/test/test_rolls.ml b/src/proto_alpha/lib_protocol/test/test_rolls.ml index d09287066e63..68a3e208dd19 100644 --- a/src/proto_alpha/lib_protocol/test/test_rolls.ml +++ b/src/proto_alpha/lib_protocol/test/test_rolls.ml @@ -60,10 +60,10 @@ let get_rolls ctxt delegate = >>=? function | None -> return_nil | Some head_roll -> traverse_rolls ctxt head_roll -(* Baking rights consistency. Asserts that the number of rolls for - [account]'s pkh - equals to the number of expected rolls, i.e., - staking balance of [account] / (token_per_roll). As of protocol - version 007, token_per_roll = 8000. +(** Baking rights consistency. Asserts that the number of rolls for + [account]'s pkh - equals to the number of expected rolls, i.e., + staking balance of [account] / (token_per_roll). As of protocol + version 007, token_per_roll = 8000. *) let check_rolls (b : Block.t) (account : Account.t) = Context.get_constants (B b) @@ -106,7 +106,7 @@ let check_no_rolls (b : Block.t) (account : Account.t) = own balance, and that its staking rights are consistent (check_rolls). *) -let simple_staking_rights () = +let test_simple_staking_rights () = Context.init 2 >>=? fun (b, accounts) -> let (a1, _a2) = account_pair accounts in @@ -124,7 +124,7 @@ let simple_staking_rights () = equals to its balance. Then both accounts have consistent staking rights. *) -let simple_staking_rights_after_baking () = +let test_simple_staking_rights_after_baking () = Context.init 2 >>=? fun (b, accounts) -> let (a1, a2) = account_pair accounts in @@ -184,7 +184,7 @@ let run_until_deactivation () = one is active then deactivated. After baking, checks that the account is active again. Baking rights are ensured. *) -let deactivation_then_bake () = +let test_deactivation_then_bake () = run_until_deactivation () >>=? fun ( b, ( ((_deactivated_contract, deactivated_account) as deactivated), @@ -199,7 +199,7 @@ let deactivation_then_bake () = active again. Preservation of its balance is tested. Baking rights are ensured. *) -let deactivation_then_self_delegation () = +let test_deactivation_then_self_delegation () = run_until_deactivation () >>=? fun ( b, ( ((deactivated_contract, deactivated_account) as deactivated), @@ -220,7 +220,7 @@ let deactivation_then_self_delegation () = account), then self-delegated, becomes activated. Its balance is zero. Baking rights are ensured. *) -let deactivation_then_empty_then_self_delegation () = +let test_deactivation_then_empty_then_self_delegation () = run_until_deactivation () >>=? fun ( b, ( ((deactivated_contract, deactivated_account) as deactivated), @@ -262,7 +262,7 @@ let deactivation_then_empty_then_self_delegation () = re-credited of the sunk amount, becomes active again. Staking rights remain consistent. *) -let deactivation_then_empty_then_self_delegation_then_recredit () = +let test_deactivation_then_empty_then_self_delegation_then_recredit () = run_until_deactivation () >>=? fun ( b, ( ((deactivated_contract, deactivated_account) as deactivated), @@ -310,7 +310,7 @@ let deactivation_then_empty_then_self_delegation_then_recredit () = self-delegated and is supposed to be activated. Again, consistency for baking rights are preserved for the first and third accounts. *) -let delegation () = +let test_delegation () = Context.init 2 >>=? fun (b, accounts) -> let (a1, a2) = account_pair accounts in @@ -352,22 +352,22 @@ let delegation () = >>=? fun () -> check_rolls b m3 >>=? fun () -> check_rolls b m1 let tests = - [ Test.tztest "simple staking rights" `Quick simple_staking_rights; + [ Test.tztest "simple staking rights" `Quick test_simple_staking_rights; Test.tztest "simple staking rights after baking" `Quick - simple_staking_rights_after_baking; - Test.tztest "deactivation then bake" `Quick deactivation_then_bake; + test_simple_staking_rights_after_baking; + Test.tztest "deactivation then bake" `Quick test_deactivation_then_bake; Test.tztest "deactivation then self delegation" `Quick - deactivation_then_self_delegation; + test_deactivation_then_self_delegation; Test.tztest "deactivation then empty then self delegation" `Quick - deactivation_then_empty_then_self_delegation; + test_deactivation_then_empty_then_self_delegation; Test.tztest "deactivation then empty then self delegation then recredit" `Quick - deactivation_then_empty_then_self_delegation_then_recredit; - Test.tztest "delegation" `Quick delegation ] + test_deactivation_then_empty_then_self_delegation_then_recredit; + Test.tztest "delegation" `Quick test_delegation ] diff --git a/src/proto_alpha/lib_protocol/test/test_seed.ml b/src/proto_alpha/lib_protocol/test/test_seed.ml index c2bee61c860d..254aaa088bc3 100644 --- a/src/proto_alpha/lib_protocol/test/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/test_seed.ml @@ -38,7 +38,7 @@ open Test_tez (** Baking [blocks_per_commitment] blocks without a [seed_nonce_hash] commitment fails with [Invalid_commitment]. *) -let no_commitment () = +let test_no_commitment () = Context.init 5 >>=? fun (b, _) -> Context.get_constants (B b) @@ -78,7 +78,7 @@ let baking_reward ctxt (b : Block.t) = - after [preserved cycles] a committer that correctly revealed receives back the bond and the reward *) -let revelation_early_wrong_right_twice () = +let test_revelation_early_wrong_right_twice () = let open Assert in Context.init 5 >>=? fun (b, _) -> @@ -227,7 +227,7 @@ let revelation_early_wrong_right_twice () = at the end of the cycle 1 looses the bond and the reward - revealing too late produces an error *) -let revelation_missing_and_late () = +let test_revelation_missing_and_late () = let open Context in let open Assert in Context.init 5 @@ -288,12 +288,12 @@ let revelation_missing_and_late () = false) let tests = - [ Test.tztest "no commitment" `Quick no_commitment; + [ Test.tztest "no commitment" `Quick test_no_commitment; Test.tztest "revelation_early_wrong_right_twice" `Quick - revelation_early_wrong_right_twice; + test_revelation_early_wrong_right_twice; Test.tztest "revelation_missing_and_late" `Quick - revelation_missing_and_late ] + test_revelation_missing_and_late ] diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index ff86e72ab9f0..5b7f6fef14fb 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -169,14 +169,14 @@ let single_transfer ?fee ?expect_failure amount = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Single transfer without fee. *) -let block_with_a_single_transfer () = single_transfer Tez.one +let test_block_with_a_single_transfer () = single_transfer Tez.one (** Single transfer with fee. *) -let block_with_a_single_transfer_with_fee () = +let test_block_with_a_single_transfer_with_fee () = single_transfer ~fee:Tez.one Tez.one (** Single transfer without fee. *) -let transfer_zero_tez () = +let test_transfer_zero_tez () = single_transfer ~expect_failure:(function | Environment.Ecoproto_error (Contract_storage.Empty_transaction _) :: _ @@ -187,7 +187,7 @@ let transfer_zero_tez () = Tez.zero (** Transfer zero tez from an implicit contract. *) -let transfer_zero_implicit () = +let test_transfer_zero_implicit () = Context.init 1 >>=? fun (b, contracts) -> let dest = Option.get @@ List.nth contracts 0 in @@ -206,7 +206,7 @@ let transfer_zero_implicit () = false) (** Transfer to originated contract. *) -let transfer_to_originate_with_fee () = +let test_transfer_to_originate_with_fee () = Context.init 1 >>=? fun (b, contracts) -> let contract = Option.get @@ List.nth contracts 0 in @@ -225,7 +225,7 @@ let transfer_to_originate_with_fee () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Transfer from balance. *) -let transfer_amount_of_contract_balance () = +let test_transfer_amount_of_contract_balance () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> Context.Contract.pkh contract_1 @@ -242,7 +242,7 @@ let transfer_amount_of_contract_balance () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Transfer to oneself. *) -let transfers_to_self () = +let test_transfers_to_self () = Context.init 1 >>=? fun (b, contracts) -> let contract = Option.get @@ List.nth contracts 0 in @@ -258,7 +258,7 @@ let transfers_to_self () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Forgot to add the valid transaction into the block. *) -let missing_transaction () = +let test_missing_transaction () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> (* given that contract_1 no longer has a sufficient balance to bake, @@ -287,7 +287,7 @@ let missing_transaction () = (********************) (** Implicit to Implicit. *) -let transfer_from_implicit_to_implicit_contract () = +let test_transfer_from_implicit_to_implicit_contract () = Context.init 1 >>=? fun (b, contracts) -> let bootstrap_contract = Option.get @@ List.nth contracts 0 in @@ -327,7 +327,7 @@ let transfer_from_implicit_to_implicit_contract () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Implicit to originated. *) -let transfer_from_implicit_to_originated_contract () = +let test_transfer_from_implicit_to_originated_contract () = Context.init 1 >>=? fun (b, contracts) -> let bootstrap_contract = Option.get @@ List.nth contracts 0 in @@ -374,12 +374,12 @@ let multiple_transfer n ?fee amount = (** 1- Create a block with two contracts; 2- Apply 100 transfers. *) -let block_with_multiple_transfers () = multiple_transfer 99 (Tez.of_int 1000) +let test_block_with_multiple_transfers () = multiple_transfer 99 (Tez.of_int 1000) (** 1- Create a block with two contracts; 2- Apply 100 transfers with 10tz fee. *) -let block_with_multiple_transfers_pay_fee () = +let test_block_with_multiple_transfers_pay_fee () = multiple_transfer 10 ~fee:ten_tez (Tez.of_int 1000) (* TODO : increase the number of operations and add a `Slow tag to it in `tests` *) @@ -388,7 +388,7 @@ let block_with_multiple_transfers_pay_fee () = 2- Apply multiple transfers without fees; 3- Apply multiple transfers with fees. *) -let block_with_multiple_transfers_with_without_fee () = +let test_block_with_multiple_transfers_with_without_fee () = Context.init 8 >>=? fun (b, contracts) -> let contracts = Array.of_list contracts in @@ -427,7 +427,7 @@ let block_with_multiple_transfers_with_without_fee () = >>=? fun b -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Build a chain that has 10 blocks. *) -let build_a_chain () = +let test_build_a_chain () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> let ten = Tez.of_int 10 in @@ -446,7 +446,7 @@ let build_a_chain () = (*********************************************************************) (** Transfer zero tez is forbidden in implicit contract. *) -let empty_implicit () = +let test_empty_implicit () = Context.init 1 >>=? fun (b, contracts) -> let dest = Option.get @@ List.nth contracts 0 in @@ -468,7 +468,7 @@ let empty_implicit () = false) (** Balance is too low to transfer. *) -let balance_too_low fee () = +let test_balance_too_low fee () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> Incremental.begin_construction b @@ -506,7 +506,7 @@ let balance_too_low fee () = 3- Add another transfer that send tez from a zero balance contract; 4- Catch the expected error: Balance_too_low. *) -let balance_too_low_two_transfers fee () = +let test_balance_too_low_two_transfers fee () = Context.init 3 >>=? fun (b, contracts) -> let contract_1 = Option.get @@ List.nth contracts 0 in @@ -568,7 +568,7 @@ let invalid_counter () = false) (** Same as before but different way to perform this error. *) -let add_the_same_operation_twice () = +let test_add_the_same_operation_twice () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> Incremental.begin_construction b @@ -586,7 +586,7 @@ let add_the_same_operation_twice () = false) (** Check ownership. *) -let ownership_sender () = +let test_ownership_sender () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> Incremental.begin_construction b @@ -619,7 +619,7 @@ let random_contract contract_array = (** Transfer by randomly choose amount 10 contracts, and randomly choose the amount in the source contract. *) -let random_transfer () = +let test_random_transfer () = Context.init 10 >>=? fun (b, contracts) -> let contracts = Array.of_list contracts in @@ -639,7 +639,7 @@ let random_transfer () = >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit (** Transfer random transactions. *) -let random_multi_transactions () = +let test_random_multi_transactions () = let n = random_range (1, 100) in multiple_transfer n (Tez.of_int 100) @@ -647,81 +647,81 @@ let random_multi_transactions () = let tests = [ (* single transfer *) - Test.tztest "single transfer" `Quick block_with_a_single_transfer; + Test.tztest "single transfer" `Quick test_block_with_a_single_transfer; Test.tztest "single transfer with fee" `Quick - block_with_a_single_transfer_with_fee; + test_block_with_a_single_transfer_with_fee; (* transfer zero tez *) - Test.tztest "single transfer zero tez" `Quick transfer_zero_tez; + Test.tztest "single transfer zero tez" `Quick test_transfer_zero_tez; Test.tztest "transfer zero tez from implicit contract" `Quick - transfer_zero_implicit; + test_transfer_zero_implicit; (* transfer to originated contract *) Test.tztest "transfer to originated contract paying transaction fee" `Quick - transfer_to_originate_with_fee; + test_transfer_to_originate_with_fee; (* transfer by the balance of contract *) Test.tztest "transfer the amount from source contract balance" `Quick - transfer_amount_of_contract_balance; + test_transfer_amount_of_contract_balance; (* transfer to itself *) - Test.tztest "transfers to itself" `Quick transfers_to_self; + Test.tztest "transfers to itself" `Quick test_transfers_to_self; (* missing operation *) - Test.tztest "missing transaction" `Quick missing_transaction; + Test.tztest "missing transaction" `Quick test_missing_transaction; (* transfer from/to implicit/originated contracts*) Test.tztest "transfer from an implicit to implicit contract " `Quick - transfer_from_implicit_to_implicit_contract; + test_transfer_from_implicit_to_implicit_contract; Test.tztest "transfer from an implicit to an originated contract" `Quick - transfer_from_implicit_to_originated_contract; + test_transfer_from_implicit_to_originated_contract; (* Slow tests *) Test.tztest "block with multiple transfers" `Slow - block_with_multiple_transfers; + test_block_with_multiple_transfers; (* TODO increase the number of transaction times *) Test.tztest "block with multiple transfer paying fee" `Slow - block_with_multiple_transfers_pay_fee; + test_block_with_multiple_transfers_pay_fee; Test.tztest "block with multiple transfer without paying fee" `Slow - block_with_multiple_transfers_with_without_fee; + test_block_with_multiple_transfers_with_without_fee; (* build the chain *) - Test.tztest "build a chain" `Quick build_a_chain; + Test.tztest "build a chain" `Quick test_build_a_chain; (* Erroneous *) - Test.tztest "empty implicit" `Quick empty_implicit; + Test.tztest "empty implicit" `Quick test_empty_implicit; Test.tztest "balance too low - transfer zero" `Quick - (balance_too_low Tez.zero); - Test.tztest "balance too low" `Quick (balance_too_low Tez.one); + (test_balance_too_low Tez.zero); + Test.tztest "balance too low" `Quick (test_balance_too_low Tez.one); Test.tztest "balance too low (max fee)" `Quick - (balance_too_low Tez.max_tez); + (test_balance_too_low Tez.max_tez); Test.tztest "balance too low with two transfers - transfer zero" `Quick - (balance_too_low_two_transfers Tez.zero); + (test_balance_too_low_two_transfers Tez.zero); Test.tztest "balance too low with two transfers" `Quick - (balance_too_low_two_transfers Tez.one); + (test_balance_too_low_two_transfers Tez.one); Test.tztest "invalid_counter" `Quick invalid_counter; Test.tztest "add the same operation twice" `Quick - add_the_same_operation_twice; - Test.tztest "ownership sender" `Quick ownership_sender; + test_add_the_same_operation_twice; + Test.tztest "ownership sender" `Quick test_ownership_sender; (* Random tests *) - Test.tztest "random transfer" `Quick random_transfer; - Test.tztest "random multi transfer" `Quick random_multi_transactions ] + Test.tztest "random transfer" `Quick test_random_transfer; + Test.tztest "random multi transfer" `Quick test_random_multi_transactions ] -- GitLab From 9dd499e8e799ae4ab7162fecfedb4d89526c7c36 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Mon, 16 Nov 2020 10:53:15 +0100 Subject: [PATCH 06/17] Testing: Amended with @yrg's reviews. --- src/proto_alpha/lib_protocol/test/test_activation.ml | 2 +- .../lib_protocol/test/test_combined_operations.ml | 8 ++++---- src/proto_alpha/lib_protocol/test/test_delegation.ml | 10 +++++----- src/proto_alpha/lib_protocol/test/test_endorsement.ml | 2 +- src/proto_alpha/lib_protocol/test/test_origination.ml | 4 ++-- src/proto_alpha/lib_protocol/test/test_qty.ml | 2 +- src/proto_alpha/lib_protocol/test/test_rolls.ml | 10 +++++----- src/proto_alpha/lib_protocol/test/test_seed.ml | 2 +- src/proto_alpha/lib_protocol/test/test_transfer.ml | 4 ++-- src/proto_alpha/lib_protocol/test/test_typechecking.ml | 2 +- src/proto_alpha/lib_protocol/test/test_voting.ml | 4 ++-- 11 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index b8fd4f521876..086c0b06b514 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -36,7 +36,7 @@ - an amount. The commitments and the secrets are generated from - /scripts/create_genesis/create_genenis.py and should be + /scripts/create_genesis/create_genesis.py and should be coherent. *) diff --git a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml index 6934c3161032..64116fdead86 100644 --- a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml @@ -31,10 +31,10 @@ deterministic application. If an invalid operation is present in this group of - operation, the previous applied operations are backtracked - leaving the context unchanged and the following operations - are skipped. Fees attributed to the operations are collected - by the baker nonetheless. + operations, the previously applied operations are + backtracked leaving the context unchanged and the + following operations are skipped. Fees attributed to the + operations are collected by the baker nonetheless. Only manager operations are allowed in multiple transactions. They must all belong to the same manager as there is only one diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index dc0ca753afdb..565acb9a9f6c 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -467,7 +467,7 @@ let tests_bootstrap_contracts = (* Part A. Unregistered delegate keys cannot be used for delegation - Two main series of tests: without self-delegation, and with a failed attempt at self-delegation: + Two main series of tests: without self-delegation and with a failed attempt at self-delegation: 1/ no self-delegation a/ no credit @@ -1215,9 +1215,9 @@ let test_valid_delegate_registration_init_delegation_credit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh -(** Creates an implicit contract, credits with [amount] - tz. Self-delegates. Creates another implicit contract with - bootstrap as delegate. Re-delegates it to the first implicit +(** Create an implicit contract, credits with [amount] + tz. Self-delegates. Create another implicit contract with + bootstrap as delegate. Re-delegate it to the first implicit contract. *) let test_valid_delegate_registration_switch_delegation_credit amount () = @@ -1274,7 +1274,7 @@ let test_valid_delegate_registration_switch_delegation_credit amount () = >>=? fun delegator_delegate -> Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh -(** Creates an implicit contract. *) +(** Create an implicit contract. *) let test_valid_delegate_registration_init_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index e35806a8140c..39a7498b6026 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -29,7 +29,7 @@ Invocation: dune build @src/proto_alpha/lib_protocol/runtest Subject: Endorsing a block adds an extra layer of confidence to the Tezos' PoS algorithm. The block endorsing operation must be - included in the following block. Each endorser possess a + included in the following block. Each endorser possesses a number of slots corresponding to their priority. After [preserved_cycles], a reward is given to the endorser. This reward depends on the priority of the block that contains diff --git a/src/proto_alpha/lib_protocol/test/test_origination.ml b/src/proto_alpha/lib_protocol/test/test_origination.ml index 3f6c0fea754c..8c4aeb5b9975 100644 --- a/src/proto_alpha/lib_protocol/test/test_origination.ml +++ b/src/proto_alpha/lib_protocol/test/test_origination.ml @@ -210,7 +210,7 @@ let register_contract_get_endorser () = Context.get_endorser (I inc) >|=? fun (account_endorser, _slots) -> (inc, contract, account_endorser) -(* Create multiple originated contracts and ask contract to pay the fee *) +(* Create multiple originated contracts and ask contract to pay the fee. *) let n_originations n ?credit ?fee () = List.fold_left_es (fun new_contracts _ -> @@ -219,7 +219,7 @@ let n_originations n ?credit ?fee () = [] (1 -- n) -(** Creates 100 originations. *) +(** Create 100 originations. *) let test_multiple_originations () = n_originations 100 ~credit:(Tez.of_int 2) ~fee:ten_tez () >>=? fun contracts -> diff --git a/src/proto_alpha/lib_protocol/test/test_qty.ml b/src/proto_alpha/lib_protocol/test/test_qty.ml index a4cdecd9874a..9cd6c8e6836c 100644 --- a/src/proto_alpha/lib_protocol/test/test_qty.ml +++ b/src/proto_alpha/lib_protocol/test/test_qty.ml @@ -124,7 +124,7 @@ let test_known_tez_literals () = known_bad_tez_literals ; return_unit -(** Randomly generated tez value which is printed into string then +(** Randomly generated tez value which is printed into a string then parsed again to test equality. *) let test_random_tez_literals () = diff --git a/src/proto_alpha/lib_protocol/test/test_rolls.ml b/src/proto_alpha/lib_protocol/test/test_rolls.ml index 68a3e208dd19..28a6a44be68d 100644 --- a/src/proto_alpha/lib_protocol/test/test_rolls.ml +++ b/src/proto_alpha/lib_protocol/test/test_rolls.ml @@ -60,7 +60,7 @@ let get_rolls ctxt delegate = >>=? function | None -> return_nil | Some head_roll -> traverse_rolls ctxt head_roll -(** Baking rights consistency. Asserts that the number of rolls for +(** Baking rights consistency. Assert that the number of rolls for [account]'s pkh - equals to the number of expected rolls, i.e., staking balance of [account] / (token_per_roll). As of protocol version 007, token_per_roll = 8000. @@ -101,7 +101,7 @@ let check_no_rolls (b : Block.t) (account : Account.t) = get_rolls ctxt account.pkh >>=? fun rolls -> Assert.equal_int ~loc:__LOC__ (List.length rolls) 0 -(** Creates a block with two initialized contracts/accounts. Asserts +(** Create a block with two initialized contracts/accounts. Asserts that the first account has a staking balance which equals to its own balance, and that its staking rights are consistent (check_rolls). @@ -119,7 +119,7 @@ let test_simple_staking_rights () = Assert.equal_tez ~loc:__LOC__ balance info.staking_balance >>=? fun () -> check_rolls b m1 -(** Creates a block with two initialized contracts/accounts. Bakes +(** Create a block with two initialized contracts/accounts. Bakes five blocks. Asserts that the staking balance of the first account equals to its balance. Then both accounts have consistent staking rights. @@ -181,7 +181,7 @@ let run_until_deactivation () = >|=? fun () -> (b, ((a1, m1), balance_start), (a2, m2)) (** From an initialized block with two contracts/accounts, the first - one is active then deactivated. After baking, checks that the + one is active then deactivated. After baking, check that the account is active again. Baking rights are ensured. *) let test_deactivation_then_bake () = @@ -303,7 +303,7 @@ let test_deactivation_then_empty_then_self_delegation_then_recredit () = Assert.equal_tez ~loc:__LOC__ amount balance >>=? fun () -> check_rolls b deactivated_account -(** Initializes a block with two contracts/accounts. A third new +(** Initialize a block with two contracts/accounts. A third new account is also created. The first account is self-delegated. First account sends to third one the amount of 0.5 tez. The third account has no delegate and is consistent for baking rights. Then, it is diff --git a/src/proto_alpha/lib_protocol/test/test_seed.ml b/src/proto_alpha/lib_protocol/test/test_seed.ml index 254aaa088bc3..5446d4d62b07 100644 --- a/src/proto_alpha/lib_protocol/test/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/test_seed.ml @@ -68,7 +68,7 @@ let baking_reward ctxt (b : Block.t) = Context.get_baking_reward ctxt ~priority ~endorsing_power (** Choose a baker, denote it by id. In the first cycle, make id bake only once. - Checks that: + Check that: - after id bakes with a commitment the bond is frozen and the reward allocated - when id reveals the nonce too early, there's an error diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index 5b7f6fef14fb..bf8486a7b6d9 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -445,7 +445,7 @@ let test_build_a_chain () = (* Expected error test cases *) (*********************************************************************) -(** Transfer zero tez is forbidden in implicit contract. *) +(** Transferring zero tez is forbidden in implicit contract. *) let test_empty_implicit () = Context.init 1 >>=? fun (b, contracts) -> @@ -611,7 +611,7 @@ let random_range (min, max) = in init -(* Return a random contract *) +(* Return a random contract. *) let random_contract contract_array = let i = Random.int (Array.length contract_array) in contract_array.(i) diff --git a/src/proto_alpha/lib_protocol/test/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/test_typechecking.ml index 7bb3e6ff6eca..ef99a89b3fdf 100644 --- a/src/proto_alpha/lib_protocol/test/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/test_typechecking.ml @@ -108,7 +108,7 @@ let read_file filename = let s = really_input_string ch (in_channel_length ch) in close_in ch ; s -(** Checks that the custom stack overflow exception is triggered when +(** Check that the custom stack overflow exception is triggered when it should be. *) let test_typecheck_stack_overflow () = diff --git a/src/proto_alpha/lib_protocol/test/test_voting.ml b/src/proto_alpha/lib_protocol/test/test_voting.ml index 54854d2c7579..38413bd20134 100644 --- a/src/proto_alpha/lib_protocol/test/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/test_voting.ml @@ -743,7 +743,7 @@ let test_multiple_identical_proposals_count_as_one () = | None -> failwith "%s - Missing proposal" __LOC__ -(** Assumes the initial balance of allocated by Context.init is at +(** Assume the initial balance of allocated by Context.init is at least 4 time the value of the tokens_per_roll constant. *) let test_supermajority_in_proposal there_is_a_winner () = @@ -929,7 +929,7 @@ let test_supermajority_in_testing_vote supermajority () = else assert_period ~expected_kind:Proposal b __LOC__ ) >>=? fun () -> return_unit -(** Tests also how the selection scales: all delegates propose max +(** Test also how the selection scales: all delegates propose max proposals. *) let test_no_winning_proposal num_delegates () = -- GitLab From 26816ddadcc4cca280631246e6701f2aebac15b1 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Tue, 17 Nov 2020 12:30:45 +0100 Subject: [PATCH 07/17] Testing: Bad function name/comment in test/test_transfer.ml --- .../lib_protocol/test/test_transfer.ml | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index bf8486a7b6d9..407bab563372 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -140,13 +140,11 @@ let register_two_contracts () = | (b, contract_1 :: contract_2 :: _) -> (b, contract_1, contract_2) -(** compute half of the balance and divided by nth - times *) - -let two_nth_of_balance incr contract nth = +(** Computes a fraction of 2/[n] of the balance of [contract] *) +let two_over_n_of_balance incr contract n = Context.Contract.balance (I incr) contract >>=? fun balance -> - Lwt.return (Tez.( /? ) balance nth >>? fun res -> Tez.( *? ) res 2L) + Lwt.return (Tez.( /? ) balance n >>? fun res -> Tez.( *? ) res 2L) (********************) (** Single transfer *) @@ -212,14 +210,14 @@ let test_transfer_to_originate_with_fee () = let contract = Option.get @@ List.nth contracts 0 in Incremental.begin_construction b >>=? fun b -> - two_nth_of_balance b contract 10L + two_over_n_of_balance b contract 10L >>=? fun fee -> (* originated contract, paying a fee to originated this contract *) Op.origination (I b) ~fee:ten_tez contract ~script:Op.dummy_script >>=? fun (operation, new_contract) -> Incremental.add_operation b operation >>=? fun b -> - two_nth_of_balance b contract 3L + two_over_n_of_balance b contract 3L >>=? fun amount -> transfer_and_check_balances ~loc:__LOC__ b ~fee contract new_contract amount >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit @@ -248,11 +246,11 @@ let test_transfers_to_self () = let contract = Option.get @@ List.nth contracts 0 in Incremental.begin_construction b >>=? fun b -> - two_nth_of_balance b contract 3L + two_over_n_of_balance b contract 3L >>=? fun amount -> transfer_to_itself_and_check_balances ~loc:__LOC__ b contract amount >>=? fun (b, _) -> - two_nth_of_balance b contract 5L + two_over_n_of_balance b contract 5L >>=? fun fee -> transfer_to_itself_and_check_balances ~loc:__LOC__ b ~fee contract ten_tez >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit @@ -267,7 +265,7 @@ let test_missing_transaction () = >>=? fun pkh1 -> Incremental.begin_construction b ~policy:(Block.Excluding [pkh1]) >>=? fun b -> - two_nth_of_balance b contract_1 6L + two_over_n_of_balance b contract_1 6L >>=? fun amount -> (* do the transfer 3 times from source contract to destination contract *) n_transactions 3 b contract_1 contract_2 amount @@ -296,9 +294,9 @@ let test_transfer_from_implicit_to_implicit_contract () = Incremental.begin_construction b >>=? fun b -> let src = Contract.implicit_contract account_a.Account.pkh in - two_nth_of_balance b bootstrap_contract 3L + two_over_n_of_balance b bootstrap_contract 3L >>=? fun amount1 -> - two_nth_of_balance b bootstrap_contract 10L + two_over_n_of_balance b bootstrap_contract 10L >>=? fun fee1 -> transfer_and_check_balances ~with_burn:true @@ -311,9 +309,9 @@ let test_transfer_from_implicit_to_implicit_contract () = >>=? fun (b, _) -> (* create an implicit contract as a destination contract *) let dest = Contract.implicit_contract account_b.pkh in - two_nth_of_balance b bootstrap_contract 4L + two_over_n_of_balance b bootstrap_contract 4L >>=? fun amount2 -> - two_nth_of_balance b bootstrap_contract 10L + two_over_n_of_balance b bootstrap_contract 10L >>=? fun fee2 -> (* transfer from implicit contract to another implicit contract *) transfer_and_check_balances @@ -336,7 +334,7 @@ let test_transfer_from_implicit_to_originated_contract () = let src = Contract.implicit_contract account.Account.pkh in Incremental.begin_construction b >>=? fun b -> - two_nth_of_balance b bootstrap_contract 3L + two_over_n_of_balance b bootstrap_contract 3L >>=? fun amount1 -> (* transfer the money to implicit contract *) transfer_and_check_balances @@ -352,7 +350,7 @@ let test_transfer_from_implicit_to_originated_contract () = >>=? fun (operation, new_contract) -> Incremental.add_operation b operation >>=? fun b -> - two_nth_of_balance b bootstrap_contract 4L + two_over_n_of_balance b bootstrap_contract 4L >>=? fun amount2 -> (* transfer from implicit contract to originated contract *) transfer_and_check_balances ~loc:__LOC__ b src new_contract amount2 @@ -454,7 +452,7 @@ let test_empty_implicit () = Incremental.begin_construction b >>=? fun incr -> let src = Contract.implicit_contract account.Account.pkh in - two_nth_of_balance incr dest 3L + two_over_n_of_balance incr dest 3L >>=? fun amount -> (* transfer zero tez from an implicit contract *) Op.transaction (I incr) src dest amount -- GitLab From 74c0018158d568045390f6899a812555f19eee4f Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Tue, 17 Nov 2020 13:31:59 +0100 Subject: [PATCH 08/17] Doc: remove useless spaces --- src/proto_alpha/lib_protocol/test/test_activation.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index 086c0b06b514..0829a08789b9 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -30,11 +30,11 @@ Subject: The activation operation creates an implicit contract from a registered commitment present in the context. It is parametrized by a public key hash (pkh) and a secret. - + The commitments are composed of : - a blinded pkh that can be revealed by the secret ; - an amount. - + The commitments and the secrets are generated from /scripts/create_genesis/create_genesis.py and should be coherent. -- GitLab From e2d4804f5926033c7b2119f0170816eecbf54884 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Wed, 18 Nov 2020 20:00:04 +0100 Subject: [PATCH 09/17] Testing: Linter --- .../lib_protocol/test/test_activation.ml | 10 ++++++-- .../lib_protocol/test/test_delegation.ml | 24 ++++++++++++------- .../lib_protocol/test/test_endorsement.ml | 5 +++- .../lib_protocol/test/test_transfer.ml | 6 +++-- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index 0829a08789b9..9c8a8d5d9a04 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -577,8 +577,14 @@ let tests = "invalid activation with commitments" `Quick test_invalid_activation_inexistent_pkh; - Test.tztest "invalid double activation" `Quick test_invalid_double_activation; - Test.tztest "wrong activation code" `Quick test_invalid_activation_wrong_secret; + Test.tztest + "invalid double activation" + `Quick + test_invalid_double_activation; + Test.tztest + "wrong activation code" + `Quick + test_invalid_activation_wrong_secret; Test.tztest "invalid transfer from unactivated account" `Quick diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index 565acb9a9f6c..e49ae66da6e5 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -848,7 +848,8 @@ let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = (** A credit of some amount followed by a debit of the same amount, no self-delegation. *) -let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = +let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount + () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -909,7 +910,8 @@ let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () (** Same as in [unregistered_delegate_key_init_delegation] but credits then debits the amount [amount] to the implicit contract. *) -let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = +let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () + = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -975,7 +977,8 @@ let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () (** Same as in [unregistered_delegate_key_switch_delegation] but credits then debits the amount [amount] to the implicit contract. *) -let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = +let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount + () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1544,7 +1547,8 @@ let test_double_registration_when_recredited () = false) (** Self-delegation on unrevealed contract. *) -let test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = +let test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () + = Context.init 1 >>=? fun (b, bootstrap_contracts) -> Incremental.begin_construction b @@ -1667,11 +1671,13 @@ let tests_delegate_registration = Test.tztest "unregistered delegate key (origination, edge case fee)" `Quick - (test_unregistered_delegate_key_init_origination ~fee:(Tez.of_int 3_999_488)); + (test_unregistered_delegate_key_init_origination + ~fee:(Tez.of_int 3_999_488)); Test.tztest "unregistered delegate key (origination, large fee)" `Quick - (test_unregistered_delegate_key_init_origination ~fee:(Tez.of_int 10_000_000)); + (test_unregistered_delegate_key_init_origination + ~fee:(Tez.of_int 10_000_000)); Test.tztest "unregistered delegate key (init with delegation, small fee)" `Quick @@ -1837,12 +1843,14 @@ let tests_delegate_registration = "valid delegate registration: credit 1μꜩ, self delegation, debit \ 1μꜩ (init with delegation)" `Quick - (test_valid_delegate_registration_init_delegation_credit_debit Tez.one_mutez); + (test_valid_delegate_registration_init_delegation_credit_debit + Tez.one_mutez); Test.tztest "valid delegate registration: credit 1μꜩ, self delegation, debit \ 1μꜩ (switch with delegation)" `Quick - (test_valid_delegate_registration_switch_delegation_credit_debit Tez.one_mutez); + (test_valid_delegate_registration_switch_delegation_credit_debit + Tez.one_mutez); (*** double registration ***) Test.tztest "double registration" `Quick test_double_registration; Test.tztest diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index 39a7498b6026..0e113b3adc41 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -651,6 +651,9 @@ let tests = "Wrong endorsement predecessor" `Quick test_wrong_endorsement_predecessor; - Test.tztest "Invalid endorsement level" `Quick test_invalid_endorsement_level; + Test.tztest + "Invalid endorsement level" + `Quick + test_invalid_endorsement_level; Test.tztest "Duplicate endorsement" `Quick test_duplicate_endorsement; Test.tztest "Not enough for deposit" `Quick test_not_enough_for_deposit ] diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index 407bab563372..85f92faeb87c 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -372,7 +372,8 @@ let multiple_transfer n ?fee amount = (** 1- Create a block with two contracts; 2- Apply 100 transfers. *) -let test_block_with_multiple_transfers () = multiple_transfer 99 (Tez.of_int 1000) +let test_block_with_multiple_transfers () = + multiple_transfer 99 (Tez.of_int 1000) (** 1- Create a block with two contracts; 2- Apply 100 transfers with 10tz fee. @@ -722,4 +723,5 @@ let tests = Test.tztest "ownership sender" `Quick test_ownership_sender; (* Random tests *) Test.tztest "random transfer" `Quick test_random_transfer; - Test.tztest "random multi transfer" `Quick test_random_multi_transactions ] + Test.tztest "random multi transfer" `Quick test_random_multi_transactions + ] -- GitLab From bb5e1105d653187df009ecbbe0c6d5702867f503 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Wed, 18 Nov 2020 20:03:39 +0100 Subject: [PATCH 10/17] Testing: Bad filename for test/lazy_storage_diff.ml --- src/proto_alpha/lib_protocol/test/main.ml | 2 +- .../test/{lazy_storage_diff.ml => test_lazy_storage_diff.ml} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/proto_alpha/lib_protocol/test/{lazy_storage_diff.ml => test_lazy_storage_diff.ml} (100%) diff --git a/src/proto_alpha/lib_protocol/test/main.ml b/src/proto_alpha/lib_protocol/test/main.ml index e2b734458d73..3dc8010fccf5 100644 --- a/src/proto_alpha/lib_protocol/test/main.ml +++ b/src/proto_alpha/lib_protocol/test/main.ml @@ -53,7 +53,7 @@ let () = ("fixed point computation", Test_fixed_point.tests); ("gas levels", Gas_levels.tests); ("gas cost functions", Test_gas_costs.tests); - ("lazy storage diff", Lazy_storage_diff.tests); + ("lazy storage diff", Test_lazy_storage_diff.tests); ("sapling", Test_sapling.tests); ("helpers rpcs", Test_helpers_rpcs.tests); ("script deserialize gas", Script_gas.tests) ] diff --git a/src/proto_alpha/lib_protocol/test/lazy_storage_diff.ml b/src/proto_alpha/lib_protocol/test/test_lazy_storage_diff.ml similarity index 100% rename from src/proto_alpha/lib_protocol/test/lazy_storage_diff.ml rename to src/proto_alpha/lib_protocol/test/test_lazy_storage_diff.ml -- GitLab From b0ac91b6116055a2ee43da8c6cc501a19b517000 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Thu, 17 Dec 2020 09:03:42 +0100 Subject: [PATCH 11/17] Testing: Amended with @dannywillems' reviews. --- .../lib_protocol/test/test_activation.ml | 27 ++++++++------- .../lib_protocol/test/test_baking.ml | 29 ++++++++++------ .../test/test_combined_operations.ml | 28 +++++++-------- .../lib_protocol/test/test_delegation.ml | 34 ++++++++++++------- .../lib_protocol/test/test_double_baking.ml | 2 +- .../test/test_double_endorsement.ml | 2 +- .../lib_protocol/test/test_endorsement.ml | 18 +++++----- .../lib_protocol/test/test_fixed_point.ml | 8 ++--- .../lib_protocol/test/test_gas_costs.ml | 10 +++--- .../lib_protocol/test/test_gas_properties.ml | 6 ++-- .../lib_protocol/test/test_interpretation.ml | 2 +- .../lib_protocol/test/test_origination.ml | 10 ++---- src/proto_alpha/lib_protocol/test/test_qty.ml | 29 ++++++---------- .../lib_protocol/test/test_reveal.ml | 7 ++++ .../lib_protocol/test/test_rolls.ml | 24 +++++++------ .../lib_protocol/test/test_seed.ml | 2 +- .../lib_protocol/test/test_transfer.ml | 6 ++-- .../lib_protocol/test/test_typechecking.ml | 2 +- .../lib_protocol/test/test_voting.ml | 6 ++-- 19 files changed, 135 insertions(+), 117 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index 9c8a8d5d9a04..8d9296e875fe 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -25,19 +25,19 @@ (** Testing ------- - Component: Protocol (activation) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: The activation operation creates an implicit contract from a - registered commitment present in the context. It is - parametrized by a public key hash (pkh) and a secret. + Component: Protocol (activation) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^activation$" + Subject: The activation operation creates an implicit contract from a + registered commitment present in the context. It is + parametrized by a public key hash (pkh) and a secret. - The commitments are composed of : - - a blinded pkh that can be revealed by the secret ; - - an amount. + The commitments are composed of : + - a blinded pkh that can be revealed by the secret ; + - an amount. - The commitments and the secrets are generated from - /scripts/create_genesis/create_genesis.py and should be - coherent. + The commitments and the secrets are generated from + /scripts/create_genesis/create_genesis.py and should be + coherent. *) open Protocol @@ -307,11 +307,14 @@ let secrets () = "zknAl3lrX2", "ettilrvh.zsrqrbud@tezos.example.org" ) ] +(** Helper: Create a genesis block with predefined commitments, + accounts and balances. *) let activation_init () = Context.init ~with_commitments:true 1 >|=? fun (b, cs) -> secrets () |> fun ss -> (b, cs, ss) -(** A simple initialization *) +(** Verify the genesis block created by [activation_init] can be + baked. *) let test_simple_init_with_commitments () = activation_init () >>=? fun (blk, _contracts, _secrets) -> diff --git a/src/proto_alpha/lib_protocol/test/test_baking.ml b/src/proto_alpha/lib_protocol/test/test_baking.ml index 116ebcac1c5d..eee390e33610 100644 --- a/src/proto_alpha/lib_protocol/test/test_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_baking.ml @@ -27,15 +27,25 @@ (** Testing ------- Component: Protocol (baking) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Rewards and bakers. + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^baking$" + Subject: Rewards and bakers. Tests based on RPCs. *) open Protocol open Alpha_context -(** In a cycle, [bake_until_cycle_end] returns a block at level - [blocks_per_cycle]. Then, [bake_n n] bakes [n] blocks. +(** Verify the level is correctly computed when the first cycle is + passed and after baking a certain fixed number of blocks (10 for + the moment). The result should be `blocks_per_cycle + 10` where + `blocks_per_cycle` comes from the constants of the selected + protocol. + + IMPROVEMENTS: + - Randomize the number of cycle. + - Randomize the number of accounts created at the beginning + - Randomize the blocks per cycle. + - Randomize the number of blocks baked after the n cycles baked + previously *) let test_cycle () = Context.init 5 @@ -246,6 +256,7 @@ let test_rewards_formulas_equivalence () = >>=? fun reward2 -> Assert.equal_tez ~loc:__LOC__ reward1 reward2) ranges +(** Test baking [n] cycles in a raw works smoothly. *) let test_bake_n_cycles n () = let open Block in let policy = By_priority 0 in @@ -253,11 +264,8 @@ let test_bake_n_cycles n () = >>=? fun (block, _contracts) -> Block.bake_until_n_cycle_end ~policy n block >>=? fun _block -> return () -(* gets the voting power *) -let get_voting_power block pkhash = - let ctxt = Context.B block in - Context.get_voting_power ctxt pkhash - +(** Check the voting power is constant between cycles when number of + rolls are constant and in presence of one account. *) let test_voting_power_cache () = let open Block in let policy = By_priority 0 in @@ -267,7 +275,8 @@ let test_voting_power_cache () = >>=? fun bakers -> let baker = Option.get @@ List.hd bakers in let assert_voting_power n block = - get_voting_power block baker + let ctxt = Context.B block in + Context.get_voting_power ctxt baker >>=? fun voting_power -> Assert.equal_int ~loc:__LOC__ n (Int32.to_int voting_power) in diff --git a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml index 64116fdead86..8549597ff3fd 100644 --- a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml @@ -25,20 +25,20 @@ (** Testing ------- - Component: Protocol (combined operations) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Multiple operations can be grouped in one ensuring their - deterministic application. - - If an invalid operation is present in this group of - operations, the previously applied operations are - backtracked leaving the context unchanged and the - following operations are skipped. Fees attributed to the - operations are collected by the baker nonetheless. - - Only manager operations are allowed in multiple transactions. - They must all belong to the same manager as there is only one - signature. + Component: Protocol (combined operations) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^combined$" + Subject: Multiple operations can be grouped in one ensuring their + deterministic application. + + If an invalid operation is present in this group of + operations, the previously applied operations are + backtracked leaving the context unchanged and the + following operations are skipped. Fees attributed to the + operations are collected by the baker nonetheless. + + Only manager operations are allowed in multiple transactions. + They must all belong to the same manager as there is only one + signature. *) open Protocol diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index e49ae66da6e5..3d9d8776007d 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (delegation) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Boostrap contracts. Delegate registration. + Component: Protocol (delegation) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^delegation$" + Subject: Boostrap contracts. Delegate registration. *) open Protocol @@ -438,27 +438,27 @@ let tests_bootstrap_contracts = to the pkh. The implicit contract must be credited when the self-delegation is done. Furthermore, trying to register an already registered key raises an error. - + In this series of tests, we verify that 1- unregistered delegate keys cannot be delegated to, 2- registered keys can be delegated to, 3- registering an already registered key raises an error. - + We consider three scenarios for setting a delegate: - through origination, - through delegation when the implicit contract has no delegate yet, - through delegation when the implicit contract already has a delegate. - + We also test that emptying the implicit contract linked to a registered delegate key does not unregister the delegate key. - + Valid registration ------------------ Unregistered key: - contract not credited and no self-delegation - contract credited but no self-delegation - contract not credited and self-delegation - + Not credited: - no credit operation - credit operation of 1μꜩ and then debit operation of 1μꜩ *) @@ -494,8 +494,11 @@ let expect_unregistered_key pkh = function No self-delegation *) -(** No token transfer, no self-delegation. - Originated account. +(** No token transfer, no self-delegation. Originated account. If + fees are higher than balance, [Balance_too_low] is + raised. Otherwise, it checks the correct exception is raised + (unregistered key), and the fees are still debited. Using RPCs, we + verify the contract has not been originated. *) let test_unregistered_delegate_key_init_origination ~fee () = Context.init 1 @@ -549,8 +552,9 @@ let test_unregistered_delegate_key_init_origination ~fee () = false) (** Delegation when delegate key is not assigned. Delegate account is - initialized. -*) + initialized. If fees are higher than initial credit (10 tez), + [Balance_too_low] is raised. Otherwise, fees are still debited. The + implicit contract has no delegate. *) let test_unregistered_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -601,7 +605,11 @@ let test_unregistered_delegate_key_init_delegation ~fee () = | _ -> false) -(** Re-delegation when a delegate key was already assigned. *) +(** Re-delegation when a delegate key was already assigned. If fees + are higher than initial credit (10 tez), [Balance_too_low] is + raised. Otherwise, fees are not debited and the implicit contract + delegate remains unchanged. +*) let test_unregistered_delegate_key_switch_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_double_baking.ml b/src/proto_alpha/lib_protocol/test/test_double_baking.ml index 9e8603e8a576..07920b9c64fc 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_baking.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: Protocol (double baking) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^double baking$" Subject: Double baking evidence operation may happen when a baker baked two different blocks on the same level. *) diff --git a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml index af58c77a95dc..dacdd1ea8492 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: Protocol (double endorsement) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^double endorsement$" Subject: Double endorsement evidence operation may happen when an endorser endorsed two different blocks on the same level. *) diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index 0e113b3adc41..f56388b07266 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -25,15 +25,15 @@ (** Testing ------- - Component: Protocol (endorsement) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Endorsing a block adds an extra layer of confidence to the - Tezos' PoS algorithm. The block endorsing operation must be - included in the following block. Each endorser possesses a - number of slots corresponding to their priority. After - [preserved_cycles], a reward is given to the endorser. This - reward depends on the priority of the block that contains - the endorsements. + Component: Protocol (endorsement) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^endorsement$" + Subject: Endorsing a block adds an extra layer of confidence to the + Tezos' PoS algorithm. The block endorsing operation must be + included in the following block. Each endorser possesses a + number of slots corresponding to their priority. After + [preserved_cycles], a reward is given to the endorser. This + reward depends on the priority of the block that contains + the endorsements. *) open Protocol diff --git a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml index 58ca644f674f..37a301622ec5 100644 --- a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml +++ b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (fixed-point decimals) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On fixed-point decimal numbers. + Component: Protocol (fixed-point decimals) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^fixed point computation$" + Subject: On fixed-point decimal numbers. *) open Protocol @@ -175,7 +175,7 @@ let test_fp_zero () = >>=? fun () -> basic_arith "fp (0 decimals) arith" (arith_from_fp (module FP)) -(** With at one decimal. *) +(** With [decimals] decimal. *) let test_fp_nonzero decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals diff --git a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml index cbdb8a430950..805bfe3552e4 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml @@ -25,11 +25,11 @@ (** Testing ------- - Component: Protocol (gas costs) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Gas costs - Current limitations: for maps, sets & compare, we only test - integer comparable keys. + Component: Protocol (gas costs) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^gas cost functions$" + Subject: Gas costs + Current limitations: for maps, sets & compare, we only test + integer comparable keys. *) open Protocol diff --git a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml index 1748549f3fcc..6581ba799768 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (gas properties) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Arithmetic properties around gas. + Component: Protocol (gas properties) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^gas properties$" + Subject: Arithmetic properties around gas. *) open Protocol diff --git a/src/proto_alpha/lib_protocol/test/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/test_interpretation.ml index 6ade374e8731..fd4d106061a7 100644 --- a/src/proto_alpha/lib_protocol/test/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/test_interpretation.ml @@ -2,7 +2,7 @@ ------- Component: Protocol (interpretation) Dependencies: src/proto_alpha/lib_protocol/script_interpreter.ml - Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^interpretation$" Subject: Interpretation of Michelson scripts *) diff --git a/src/proto_alpha/lib_protocol/test/test_origination.ml b/src/proto_alpha/lib_protocol/test/test_origination.ml index 8c4aeb5b9975..b69ea73df2ec 100644 --- a/src/proto_alpha/lib_protocol/test/test_origination.ml +++ b/src/proto_alpha/lib_protocol/test/test_origination.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (origination) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On originating contracts. + Component: Protocol (origination) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^origination$" + Subject: On originating contracts. *) open Protocol @@ -148,9 +148,6 @@ let test_balances_credit () = let test_balances_credit_fee () = test_origination_balances ~loc:__LOC__ ~credit:(Tez.of_int 2) ~fee:ten_tez () -(** Same as the basic test. *) -let test_balances_undelegatable () = test_origination_balances ~loc:__LOC__ () - (** Ask source contract to pay a fee when originating a contract. *) let test_pay_fee () = register_origination ~credit:(Tez.of_int 2) ~fee:ten_tez () @@ -252,7 +249,6 @@ let tests = [ Test.tztest "balances_simple" `Quick test_balances_simple; Test.tztest "balances_credit" `Quick test_balances_credit; Test.tztest "balances_credit_fee" `Quick test_balances_credit_fee; - Test.tztest "balances_undelegatable" `Quick test_balances_undelegatable; Test.tztest "pay_fee" `Quick test_pay_fee; Test.tztest "not enough tez in contract to pay fee" diff --git a/src/proto_alpha/lib_protocol/test/test_qty.ml b/src/proto_alpha/lib_protocol/test/test_qty.ml index 9cd6c8e6836c..aa5caa056821 100644 --- a/src/proto_alpha/lib_protocol/test/test_qty.ml +++ b/src/proto_alpha/lib_protocol/test/test_qty.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (quantities) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On tez quantities. + Component: Protocol (quantities) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^qty$" + Subject: On tez quantities. *) open Protocol @@ -80,13 +80,6 @@ let fail_msg fmt = Format.kasprintf (fail "" "") fmt let default_printer _ = "" -let equal ?(eq = ( = )) ?(prn = default_printer) ?(msg = "") x y = - if not (eq x y) then fail (prn x) (prn y) msg - -let is_none ?(msg = "") x = if x <> None then fail "None" "Some _" msg - -let is_some ?(msg = "") x = if x = None then fail "Some _" "None" msg - (** Literals which are supposed to be parsed correctly. *) let test_known_tez_literals () = List.iter @@ -113,14 +106,14 @@ let test_known_tez_literals () = | Some vs' -> vs' in - equal ~prn:Tez_repr.to_string vv vs ; - equal ~prn:Tez_repr.to_string vv vs' ; - equal ~prn:(fun s -> s) (Tez_repr.to_string vv) s) + assert (vv = vs) ; + assert (vv = vs') ; + assert (Tez_repr.to_string vv = s)) known_ok_tez_literals ; List.iter (fun s -> let vs = Tez_repr.of_string s in - is_none ~msg:("Unexpected successful parsing of " ^ s) vs) + assert (vs = None)) known_bad_tez_literals ; return_unit @@ -138,20 +131,20 @@ let test_random_tez_literals () = let vs = Tez_repr.of_string s in let s' = String.concat "" (String.split_on_char ',' s) in let vs' = Tez_repr.of_string s' in - is_some ~msg:("Could not parse " ^ s ^ " back") vs ; - is_some ~msg:("Could not parse " ^ s ^ " back") vs' ; + assert (vs <> None) ; + assert (vs' <> None) ; ( match vs with | None -> assert false | Some vs -> let rev = Tez_repr.to_int64 vs in - equal ~prn:Int64.to_string ~msg:(Tez_repr.to_string vv) v rev ) ; + assert (v = rev) ) ; match vs' with | None -> assert false | Some vs' -> let rev = Tez_repr.to_int64 vs' in - equal ~prn:Int64.to_string ~msg:(Tez_repr.to_string vv) v rev + assert (v = rev) done ; return_unit diff --git a/src/proto_alpha/lib_protocol/test/test_reveal.ml b/src/proto_alpha/lib_protocol/test/test_reveal.ml index f780d75de1ad..b972f7276a4e 100644 --- a/src/proto_alpha/lib_protocol/test/test_reveal.ml +++ b/src/proto_alpha/lib_protocol/test/test_reveal.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(** Testing + ------- + Component: Protocol (revelation) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^revelation$" + Subject: For the reveal operation. +*) + (** Test for the [Reveal] operation. *) open Protocol diff --git a/src/proto_alpha/lib_protocol/test/test_rolls.ml b/src/proto_alpha/lib_protocol/test/test_rolls.ml index 28a6a44be68d..3aec4f6dd395 100644 --- a/src/proto_alpha/lib_protocol/test/test_rolls.ml +++ b/src/proto_alpha/lib_protocol/test/test_rolls.ml @@ -25,16 +25,16 @@ (** Testing ------- - Component: Protocol (rolls) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On rolls and baking rights. - A delegate has baking rights provided that it has at least - more than [token_per_rolls] tz of staking balance. This - balance corresponds to the quantity of tez that have been - delegated to it for baking rights. After a given number of - cycles where it has not made use of its baking rights, its - account will be deactivated for baker selection. To bake - again, it will have to re-activate its account. + Component: Protocol (rolls) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^rolls$" + Subject: On rolls and baking rights. + A delegate has baking rights provided that it has at least + more than [token_per_rolls] tz of staking balance. This + balance corresponds to the quantity of tez that have been + delegated to it for baking rights. After a given number of + cycles where it has not made use of its baking rights, its + account will be deactivated for baker selection. To bake + again, it will have to re-activate its account. *) open Protocol @@ -63,7 +63,9 @@ let get_rolls ctxt delegate = (** Baking rights consistency. Assert that the number of rolls for [account]'s pkh - equals to the number of expected rolls, i.e., staking balance of [account] / (token_per_roll). As of protocol - version 007, token_per_roll = 8000. + version 007, token_per_roll = 8000. Note that the consistency is + verified against the value in the context, i.e. we are testing + Storage.Roll.Delegate_roll_list. We do not use RPCs here. *) let check_rolls (b : Block.t) (account : Account.t) = Context.get_constants (B b) diff --git a/src/proto_alpha/lib_protocol/test/test_seed.ml b/src/proto_alpha/lib_protocol/test/test_seed.ml index 5446d4d62b07..6036d5babb51 100644 --- a/src/proto_alpha/lib_protocol/test/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/test_seed.ml @@ -26,7 +26,7 @@ (** Testing ------- Component: Protocol (seed) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^seed$" Subject: - seed_nonce_hash included in some blocks - revelation operation of seed_nonce that should correspond to each seed_nonce_hash diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index 85f92faeb87c..546243fd1f3f 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (transfer) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: Quantities transfer between contracts. + Component: Protocol (transfer) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^transfer$" + Subject: Quantities transfer between contracts. *) open Protocol diff --git a/src/proto_alpha/lib_protocol/test/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/test_typechecking.ml index ef99a89b3fdf..c0dab75d2f5c 100644 --- a/src/proto_alpha/lib_protocol/test/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/test_typechecking.ml @@ -1,7 +1,7 @@ (** Testing ------- Component: Protocol (type-checking) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^typechecking$" Subject: Type-checking *) diff --git a/src/proto_alpha/lib_protocol/test/test_voting.ml b/src/proto_alpha/lib_protocol/test/test_voting.ml index 38413bd20134..72a8cc4b08ee 100644 --- a/src/proto_alpha/lib_protocol/test/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/test_voting.ml @@ -25,9 +25,9 @@ (** Testing ------- - Component: Protocol (voting) - Invocation: dune build @src/proto_alpha/lib_protocol/runtest - Subject: On the voting process. + Component: Protocol (voting) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^voting$" + Subject: On the voting process. *) open Protocol -- GitLab From 4f4f5c4796b0c77c8c04bc163810f970b02d9ec1 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Thu, 17 Dec 2020 09:32:54 +0100 Subject: [PATCH 12/17] Testing: Fixed rebase/merge issues. --- src/proto_alpha/lib_protocol/test/test_gas_costs.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml index 805bfe3552e4..a61923572d78 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_costs.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_costs.ml @@ -235,7 +235,7 @@ let cast_cost_to_z (c : Alpha_context.Gas.cost) : Z.t = (** Checks that all costs are positive values. *) let test_cost_reprs_are_all_positive list () = - iter_s + List.iter_es (fun (cost_name, cost) -> if Z.gt cost Z.zero then return_unit else if Z.equal cost Z.zero && List.mem cost_name free then return_unit -- GitLab From 86cf8b3ba734441b8fe5b61c504227db9f9ca14d Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Mon, 21 Dec 2020 10:40:23 +0100 Subject: [PATCH 13/17] Testing: Normalize new untracked tests in lib_protocol. --- src/proto_alpha/lib_protocol/test/main.ml | 4 +-- .../{gas_levels.ml => test_gas_levels.ml} | 35 +++++++++++-------- .../lib_protocol/test/test_helpers_rpcs.ml | 7 ++++ .../lib_protocol/test/test_sapling.ml | 7 ++++ .../{script_gas.ml => test_script_gas.ml} | 15 +++++--- 5 files changed, 47 insertions(+), 21 deletions(-) rename src/proto_alpha/lib_protocol/test/{gas_levels.ml => test_gas_levels.ml} (82%) rename src/proto_alpha/lib_protocol/test/{script_gas.ml => test_script_gas.ml} (92%) diff --git a/src/proto_alpha/lib_protocol/test/main.ml b/src/proto_alpha/lib_protocol/test/main.ml index 3dc8010fccf5..ff5c62e2cc7d 100644 --- a/src/proto_alpha/lib_protocol/test/main.ml +++ b/src/proto_alpha/lib_protocol/test/main.ml @@ -51,10 +51,10 @@ let () = ("typechecking", Test_typechecking.tests); ("gas properties", Test_gas_properties.tests); ("fixed point computation", Test_fixed_point.tests); - ("gas levels", Gas_levels.tests); + ("gas levels", Test_gas_levels.tests); ("gas cost functions", Test_gas_costs.tests); ("lazy storage diff", Test_lazy_storage_diff.tests); ("sapling", Test_sapling.tests); ("helpers rpcs", Test_helpers_rpcs.tests); - ("script deserialize gas", Script_gas.tests) ] + ("script deserialize gas", Test_script_gas.tests) ] |> Lwt_main.run diff --git a/src/proto_alpha/lib_protocol/test/gas_levels.ml b/src/proto_alpha/lib_protocol/test/test_gas_levels.ml similarity index 82% rename from src/proto_alpha/lib_protocol/test/gas_levels.ml rename to src/proto_alpha/lib_protocol/test/test_gas_levels.ml index 7cfef33cb085..e5afb14bfec7 100644 --- a/src/proto_alpha/lib_protocol/test/gas_levels.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_levels.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(** Testing + ------- + Component: Protocol (Gas levels) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^gas levels$" + Subject: On gas consumption and exhaustion. +*) + open Test open Protocol open Raw_context @@ -46,7 +53,7 @@ let dummy_context () = (block.context : Environment_context.Context.t) >|= Environment.wrap_error -let detect_gas_exhaustion_in_fresh_context () = +let test_detect_gas_exhaustion_in_fresh_context () = dummy_context () >>=? fun context -> fail_unless @@ -60,14 +67,14 @@ let make_context initial_operation_gas = ( Gas_limit_repr.Arith.integral_of_int initial_operation_gas |> set_gas_limit context ) -let detect_gas_exhaustion_when_operation_gas_hits_zero () = +let test_detect_gas_exhaustion_when_operation_gas_hits_zero () = make_context 10 >>=? fun context -> fail_unless (consume_gas context (Z.of_int max_int) |> failed) (err "Fail when consuming more than the remaining operation gas.") -let detect_gas_exhaustion_when_block_gas_hits_zero () = +let test_detect_gas_exhaustion_when_block_gas_hits_zero () = make_context max_int >>=? fun context -> fail_unless @@ -102,14 +109,14 @@ let operation_gas_level context = in both situations, the gas levels are correctly reported. *) -let monitor_operation_gas_level = monitor 100 operation_gas_level 90 +let test_monitor_operation_gas_level = monitor 100 operation_gas_level 90 -let monitor_operation_gas_level' = +let test_monitor_operation_gas_level' = monitor max_int operation_gas_level (max_int - 10) -let monitor_block_gas_level = monitor 100 block_gas_level 10399990 +let test_monitor_block_gas_level = monitor 100 block_gas_level 10399990 -let monitor_block_gas_level' = monitor max_int block_gas_level 10399990 +let test_monitor_block_gas_level' = monitor max_int block_gas_level 10399990 let quick (what, how) = tztest what `Quick how @@ -117,18 +124,18 @@ let tests = List.map quick [ ( "Detect gas exhaustion in fresh context", - detect_gas_exhaustion_in_fresh_context ); + test_detect_gas_exhaustion_in_fresh_context ); ( "Detect gas exhaustion when operation gas as hits zero", - detect_gas_exhaustion_when_operation_gas_hits_zero ); + test_detect_gas_exhaustion_when_operation_gas_hits_zero ); ( "Detect gas exhaustion when block gas as hits zero", - detect_gas_exhaustion_when_block_gas_hits_zero ); + test_detect_gas_exhaustion_when_block_gas_hits_zero ); ( "Each gas consumption impacts operation gas level (operation < block)", - monitor_operation_gas_level ); + test_monitor_operation_gas_level ); ( "Each gas consumption impacts operation gas level (block < operation)", - monitor_operation_gas_level' ); + test_monitor_operation_gas_level' ); ( "Each gas consumption has an impact on block gas level (operation < \ block)", - monitor_block_gas_level ); + test_monitor_block_gas_level ); ( "Each gas consumption has an impact on block gas level (block < \ operation)", - monitor_block_gas_level' ) ] + test_monitor_block_gas_level' ) ] diff --git a/src/proto_alpha/lib_protocol/test/test_helpers_rpcs.ml b/src/proto_alpha/lib_protocol/test/test_helpers_rpcs.ml index 11bf1dbb0dab..bcb017481254 100644 --- a/src/proto_alpha/lib_protocol/test/test_helpers_rpcs.ml +++ b/src/proto_alpha/lib_protocol/test/test_helpers_rpcs.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(** Testing + ------- + Component: Protocol (Helpers RPCs) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^helpers rpcs$" + Subject: On RPCs. +*) + open Protocol open Alpha_context diff --git a/src/proto_alpha/lib_protocol/test/test_sapling.ml b/src/proto_alpha/lib_protocol/test/test_sapling.ml index dbc3db59ddd4..727c532737e6 100644 --- a/src/proto_alpha/lib_protocol/test/test_sapling.ml +++ b/src/proto_alpha/lib_protocol/test/test_sapling.ml @@ -23,6 +23,13 @@ (* *) (*****************************************************************************) +(** Testing + ------- + Component: Protocol (Sapling) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^sapling$" + Subject: On the privacy-preserving library Sapling +*) + open Protocol module Raw_context_tests = struct diff --git a/src/proto_alpha/lib_protocol/test/script_gas.ml b/src/proto_alpha/lib_protocol/test/test_script_gas.ml similarity index 92% rename from src/proto_alpha/lib_protocol/test/script_gas.ml rename to src/proto_alpha/lib_protocol/test/test_script_gas.ml index 3bbd175040bd..aae948676c30 100644 --- a/src/proto_alpha/lib_protocol/test/script_gas.ml +++ b/src/proto_alpha/lib_protocol/test/test_script_gas.ml @@ -23,10 +23,15 @@ (* *) (*****************************************************************************) -open Protocol +(** Testing + ------- + Component: Protocol (Michelson serialization gas) + Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^script deserialize gas$" + Subject: Unit tests pertaining to the computation of serialization + and deserialization gas of Michelson terms. +*) -(* This file contains unit tests pertaining to the computation of - serialization and deserialization gas of Michelson terms. *) +open Protocol module Tested_terms () = struct open Micheline @@ -116,7 +121,7 @@ module Tested_terms () = struct let check_correctness () = Lwt.return @@ check_correctness () end -let check_property () = +let test_check_property () = let module T = Tested_terms () in T.check_correctness () @@ -125,4 +130,4 @@ let tests = "Script_repr.minimal_deserialize_cost is a lower bound for full \ deserialization cost" `Quick - check_property ] + test_check_property ] -- GitLab From 1e60d96e01984775107d89e1d2d63a047e216c61 Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Mon, 28 Dec 2020 17:29:39 +0100 Subject: [PATCH 14/17] Testing: Amended with @yrg's reviews. --- .../lib_protocol/test/test_activation.ml | 12 +-- .../lib_protocol/test/test_baking.ml | 12 +-- .../test/test_combined_operations.ml | 6 +- .../lib_protocol/test/test_delegation.ml | 91 ++++++++----------- .../lib_protocol/test/test_double_baking.ml | 22 ++--- .../test/test_double_endorsement.ml | 20 ++-- .../lib_protocol/test/test_endorsement.ml | 29 +++--- .../lib_protocol/test/test_fixed_point.ml | 10 +- .../lib_protocol/test/test_gas_levels.ml | 8 +- .../lib_protocol/test/test_gas_properties.ml | 3 +- .../lib_protocol/test/test_interpretation.ml | 3 +- .../lib_protocol/test/test_origination.ml | 12 +-- src/proto_alpha/lib_protocol/test/test_qty.ml | 3 +- .../lib_protocol/test/test_reveal.ml | 2 +- .../lib_protocol/test/test_rolls.ml | 32 +++---- .../lib_protocol/test/test_seed.ml | 9 +- .../lib_protocol/test/test_transfer.ml | 39 ++++---- .../lib_protocol/test/test_typechecking.ml | 3 +- .../lib_protocol/test/test_voting.ml | 27 ++---- 19 files changed, 128 insertions(+), 215 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index 8d9296e875fe..4c7744221785 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -365,7 +365,7 @@ let test_multi_activation_1 () = secrets >>=? fun _ -> return_unit -(** All in one bake *) +(** All of the 10 activations occur in one bake. *) let test_multi_activation_2 () = activation_init () >>=? fun (blk, _contracts, secrets) -> @@ -387,7 +387,7 @@ let test_multi_activation_2 () = expected_amount) secrets -(** Transfer with activated account *) +(** Transfer with activated account. *) let test_activation_and_transfer () = activation_init () >>=? fun (blk, contracts, secrets) -> @@ -417,7 +417,7 @@ let test_activation_and_transfer () = activated_amount_before half_amount -(** Transfer to an unactivated account and then activating it *) +(** Transfer to an unactivated account and then activating it. *) let test_transfer_to_unactivated_then_activate () = activation_init () >>=? fun (blk, contracts, secrets) -> @@ -458,8 +458,7 @@ let test_transfer_to_unactivated_then_activate () = (****************************************************************) (** Invalid pkh activation: expected to fail as the context does not - contain any commitment. -*) + contain any commitment. *) let test_invalid_activation_with_no_commitments () = Context.init 1 >>=? fun (blk, _) -> @@ -516,8 +515,7 @@ let test_invalid_activation_inexistent_pkh () = false) (** Invalid pkh activation : expected to fail as the commitment has - already been claimed. -*) + already been claimed. *) let test_invalid_double_activation () = activation_init () >>=? fun (blk, _, secrets) -> diff --git a/src/proto_alpha/lib_protocol/test/test_baking.ml b/src/proto_alpha/lib_protocol/test/test_baking.ml index eee390e33610..534f8d6ea73f 100644 --- a/src/proto_alpha/lib_protocol/test/test_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_baking.ml @@ -45,8 +45,7 @@ open Alpha_context - Randomize the number of accounts created at the beginning - Randomize the blocks per cycle. - Randomize the number of blocks baked after the n cycles baked - previously -*) + previously. *) let test_cycle () = Context.init 5 >>=? fun (b, _) -> @@ -83,8 +82,7 @@ let test_cycle () = (Int32.add (Alpha_context.Raw_level.to_int32 l) 10l) (** After baking and/or endorsing a block, the baker and the endorsers - get their reward. -*) + get their reward. *) let test_rewards_retrieval () = Context.init 256 >>=? fun (b, _) -> @@ -183,8 +181,7 @@ let test_rewards_retrieval () = ranges (** Checks the baking and endorsing rewards formulas against a precomputed - table. -*) + table. *) let test_rewards_formulas () = Context.init 1 >>=? fun (b, _) -> @@ -216,8 +213,7 @@ let test_rewards_formulas () = let wrap e = Lwt.return (Environment.wrap_error e) (** Check that the rewards formulas from Context are equivalent with - the ones from Baking. -*) + the ones from Baking. *) let test_rewards_formulas_equivalence () = Context.init 1 >>=? fun (b, _) -> diff --git a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml index 8549597ff3fd..415eb6ec843e 100644 --- a/src/proto_alpha/lib_protocol/test/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/test_combined_operations.ml @@ -168,8 +168,7 @@ let expect_balance_too_low = function (** Groups three operations, the middle one failing. Checks that the receipt is consistent. - Variant without fees. -*) + Variant without fees. *) let test_failing_operation_in_the_middle () = Context.init 2 >>=? fun (blk, contracts) -> @@ -226,8 +225,7 @@ let test_failing_operation_in_the_middle () = (** Groups three operations, the middle one failing. Checks that the receipt is consistent. - Variant with fees, that should be spent even in case of failure. -*) + Variant with fees, that should be spent even in case of failure. *) let test_failing_operation_in_the_middle_with_fees () = Context.init 2 >>=? fun (blk, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index 3d9d8776007d..a3feb54df20a 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -27,7 +27,12 @@ ------- Component: Protocol (delegation) Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^delegation$" - Subject: Boostrap contracts. Delegate registration. + Subject: - Properties on bootstrap contracts (self-delegation, + cannot delete/change their delegate (as opposed to contracts + not-being-delegate which can do these), bootstrap manager + as delegate during origination). + - Properties on delegation depending on whether delegate + keys registration, through origination and delegation. *) open Protocol @@ -57,7 +62,7 @@ let expect_no_change_registered_delegate_pkh pkh = function | _ -> failwith "Delegate can not be deleted and operation should fail." -(** Bootstrap contracts delegate to themselves *) +(** Bootstrap contracts delegate to themselves. *) let bootstrap_manager_is_bootstrap_delegate () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -149,8 +154,7 @@ let bootstrap_delegate_cannot_be_removed ~fee () = Assert.balance_was_debited ~loc:__LOC__ (I i) bootstrap balance fee (** Contracts not registered as delegate can change their - delegation. -*) + delegation. *) let delegate_can_be_changed_from_unregistered_contract ~fee () = Context.init 2 >>=? fun (b, bootstrap_contracts) -> @@ -204,8 +208,7 @@ let delegate_can_be_changed_from_unregistered_contract ~fee () = Assert.balance_was_debited ~loc:__LOC__ (I i) unregistered credit fee (** Contracts not registered as delegate can delete their - delegation. -*) + delegation. *) let delegate_can_be_removed_from_unregistered_contract ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -295,8 +298,7 @@ let bootstrap_manager_already_registered_delegate ~fee () = Assert.balance_was_debited ~loc:__LOC__ (I i) impl_contract balance fee (** Bootstrap manager can be set as delegate of an originated contract - (through origination operation). -*) + (through origination operation). *) let delegate_to_bootstrap_by_origination ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -455,9 +457,9 @@ let tests_bootstrap_contracts = Valid registration ------------------ Unregistered key: - - contract not credited and no self-delegation - - contract credited but no self-delegation - - contract not credited and self-delegation + - contract not credited and no self-delegation, + - contract credited but no self-delegation, + - contract not credited and self-delegation. Not credited: - no credit operation @@ -480,8 +482,7 @@ let tests_bootstrap_contracts = - through delegation when a delegate was assigned (switch delegation). 2/ Self-delegation fails if the contract has no credit. We try the - two possibilities of 1a for non-credited contracts. -*) + two possibilities of 1a for non-credited contracts. *) let expect_unregistered_key pkh = function | Environment.Ecoproto_error (Roll_storage.Unregistered_delegate pkh0) :: _ @@ -491,15 +492,13 @@ let expect_unregistered_key pkh = function failwith "Delegate key is not registered: operation should fail." (* Part A. Section 1. - No self-delegation -*) + No self-delegation. *) (** No token transfer, no self-delegation. Originated account. If fees are higher than balance, [Balance_too_low] is raised. Otherwise, it checks the correct exception is raised (unregistered key), and the fees are still debited. Using RPCs, we - verify the contract has not been originated. -*) + verify the contract has not been originated. *) let test_unregistered_delegate_key_init_origination ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -554,7 +553,7 @@ let test_unregistered_delegate_key_init_origination ~fee () = (** Delegation when delegate key is not assigned. Delegate account is initialized. If fees are higher than initial credit (10 tez), [Balance_too_low] is raised. Otherwise, fees are still debited. The - implicit contract has no delegate. *) + implicit contract has no delegate. *) let test_unregistered_delegate_key_init_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -608,8 +607,7 @@ let test_unregistered_delegate_key_init_delegation ~fee () = (** Re-delegation when a delegate key was already assigned. If fees are higher than initial credit (10 tez), [Balance_too_low] is raised. Otherwise, fees are not debited and the implicit contract - delegate remains unchanged. -*) + delegate remains unchanged. *) let test_unregistered_delegate_key_switch_delegation ~fee () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -669,8 +667,7 @@ let test_unregistered_delegate_key_switch_delegation ~fee () = Assert.equal_pkh ~loc:__LOC__ delegate_pkh delegate_pkh_after (** Same as [unregistered_delegate_key_init_origination] and credits - [amount], no self-delegation. -*) + [amount], no self-delegation. *) let test_unregistered_delegate_key_init_origination_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -723,8 +720,7 @@ let test_unregistered_delegate_key_init_origination_credit ~fee ~amount () = false) (** Same as [unregistered_delegate_key_init_delegation] and credits - the amount [amount] of the implicit contract. -*) + the amount [amount] of the implicit contract. *) let test_unregistered_delegate_key_init_delegation_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -784,8 +780,7 @@ let test_unregistered_delegate_key_init_delegation_credit ~fee ~amount () = false) (** Same as in [unregistered_delegate_key_switch_delegation] and - credits the amount [amount] to the implicit contract. -*) + credits the amount [amount] to the implicit contract. *) let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -854,8 +849,7 @@ let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = >>=? fun () -> Assert.equal_pkh ~loc:__LOC__ delegate bootstrap_pkh (** A credit of some amount followed by a debit of the same amount, - no self-delegation. -*) + no self-delegation. *) let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () = Context.init 1 @@ -916,8 +910,7 @@ let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount false) (** Same as in [unregistered_delegate_key_init_delegation] but credits - then debits the amount [amount] to the implicit contract. -*) + then debits the amount [amount] to the implicit contract. *) let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () = Context.init 1 @@ -983,8 +976,7 @@ let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () false) (** Same as in [unregistered_delegate_key_switch_delegation] but - credits then debits the amount [amount] to the implicit contract. -*) + credits then debits the amount [amount] to the implicit contract. *) let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount () = Context.init 1 @@ -1058,8 +1050,7 @@ let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount Assert.not_equal_pkh ~loc:__LOC__ delegate unregistered_delegate_pkh (* Part A. Section 2. - Self-delegation to an empty contract fails -*) + Self-delegation to an empty contract fails. *) (** Self-delegation with zero-balance contract should fail. *) let test_failed_self_delegation_no_transaction () = @@ -1087,8 +1078,7 @@ let test_failed_self_delegation_no_transaction () = false) (** Implicit contract is credited then debited of same amount (i.e., - is emptied). Self-delegation fails. -*) + is emptied). Self-delegation fails. *) let test_failed_self_delegation_emptied_implicit_contract amount () = (* create an implicit contract *) Context.init 1 @@ -1126,8 +1116,7 @@ let test_failed_self_delegation_emptied_implicit_contract amount () = (** Implicit contract is credited with a non-zero quantity [amount] tz, then it is delegated. The operation of debit of [amount] tz - should fail as the contract is already delegated. -*) + should fail as the contract is already delegated. *) let test_emptying_delegated_implicit_contract_fails amount () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1167,12 +1156,10 @@ let test_emptying_delegated_implicit_contract_fails amount () = - Credit implicit contract with some ꜩ + verification of balance - Self delegation + verification - Empty contract + verification of balance + verification of not being erased / self-delegation - - Create delegator implicit contract w first implicit contract as delegate + verification of delegation -*) + - Create delegator implicit contract w first implicit contract as delegate + verification of delegation. *) (** Initialized account is credited of [amount] tz, then - self-delegated. -*) + self-delegated. *) let test_valid_delegate_registration_init_delegation_credit amount () = (* create an implicit contract *) Context.init 1 @@ -1229,8 +1216,7 @@ let test_valid_delegate_registration_init_delegation_credit amount () = (** Create an implicit contract, credits with [amount] tz. Self-delegates. Create another implicit contract with bootstrap as delegate. Re-delegate it to the first implicit - contract. -*) + contract. *) let test_valid_delegate_registration_switch_delegation_credit amount () = (* create an implicit contract *) Context.init 1 @@ -1355,11 +1341,10 @@ let test_valid_delegate_registration_init_delegation_credit_debit amount () = Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh (** A created implicit contract is credited with [amount] tz, then is - self-delegated. It is emptied (funds back into bootstrap), and + self-delegated. It is emptied (fund back into bootstrap), and should remain existing (as registered as delegate). Another created implicit contract is delegated to bootstrap, then should be able to - be re-delegated to the latter contract. -*) + be re-delegated to the latter contract. *) let test_valid_delegate_registration_switch_delegation_credit_debit amount () = (* create an implicit contract *) Context.init 1 @@ -1425,12 +1410,10 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh (* Part C. - A second self-delegation should raise an `Active_delegate` error -*) + A second self-delegation should raise an `Active_delegate` error. *) (** Second self-delegation should fail with implicit contract with - some credit. -*) + some credit. *) let test_double_registration () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1464,8 +1447,7 @@ let test_double_registration () = false) (** Second self-delegation should fail with implicit contract emptied - after first self-delegation. -*) + after first self-delegation. *) let test_double_registration_when_empty () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> @@ -1506,8 +1488,7 @@ let test_double_registration_when_empty () = false) (** Second self-delegation should fail with implicit contract emptied - then recredited after first self-delegation. -*) + then credited back after first self-delegation. *) let test_double_registration_when_recredited () = Context.init 1 >>=? fun (b, bootstrap_contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_double_baking.ml b/src/proto_alpha/lib_protocol/test/test_double_baking.ml index 07920b9c64fc..ec7b4ad6ab09 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_baking.ml @@ -58,7 +58,7 @@ let get_first_different_endorsers ctxt = Context.get_endorsers ctxt >|=? fun endorsers -> get_hd_hd endorsers (** Bake two block at the same level using the same policy (i.e. same - baker) *) + baker). *) let block_fork ?policy contracts b = let (contract_a, contract_b) = get_hd_hd contracts in Op.transaction (B b) contract_a contract_b Alpha_context.Tez.one_cent @@ -71,8 +71,7 @@ let block_fork ?policy contracts b = (****************************************************************) (** Simple scenario where two blocks are baked by a same baker and - exposed by a double baking evidence operation. -*) + exposed by a double baking evidence operation. *) let test_valid_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> @@ -99,8 +98,7 @@ let test_valid_double_baking_evidence () = (****************************************************************) (** Check that a double baking operation fails if it exposes the same two - blocks. -*) + blocks. *) let test_same_blocks () = Context.init 2 >>=? fun (b, _contracts) -> @@ -118,8 +116,7 @@ let test_same_blocks () = >>=? fun () -> return_unit (** Check that a double baking operation exposing two blocks with - different levels fails. -*) + different levels fails. *) let test_different_levels () = Context.init 2 >>=? fun (b, contracts) -> @@ -137,9 +134,8 @@ let test_different_levels () = | _ -> false) -(** Check that a double baking operation exposing two yet to be baked - blocks fails. -*) +(** Check that a double baking operation exposing two yet-to-be-baked + blocks fails. *) let test_too_early_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> @@ -156,8 +152,7 @@ let test_too_early_double_baking_evidence () = false) (** Check that after [preserved_cycles + 1], it is not possible to - create a double baking operation anymore. -*) + create a double baking operation anymore. *) let test_too_late_double_baking_evidence () = Context.init 2 >>=? fun (b, contracts) -> @@ -181,8 +176,7 @@ let test_too_late_double_baking_evidence () = false) (** Check that an invalid double baking evidence that exposes two - block baking with same level made by different bakers fails. -*) + block baking with same level made by different bakers fails. *) let test_different_delegates () = Context.init 2 >>=? fun (b, _) -> diff --git a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml index dacdd1ea8492..a009f9522a66 100644 --- a/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_double_endorsement.ml @@ -70,8 +70,7 @@ let block_fork b = (** Simple scenario where two endorsements are made from the same delegate and exposed by a double_endorsement operation. Also verify - that punishment is operated. -*) + that punishment is operated. *) let test_valid_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> @@ -107,8 +106,7 @@ let test_valid_double_endorsement_evidence () = (****************************************************************) (** Check that an invalid double endorsement operation that exposes a - valid endorsement fails. -*) + valid endorsement fails. *) let test_invalid_double_endorsement () = Context.init 10 >>=? fun (b, _) -> @@ -129,8 +127,7 @@ let test_invalid_double_endorsement () = false) (** Check that a double endorsement added at the same time as a double - endorsement operation fails. -*) + endorsement operation fails. *) let test_too_early_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> @@ -153,8 +150,7 @@ let test_too_early_double_endorsement_evidence () = false) (** Check that after [preserved_cycles + 1], it is not possible - to create a double_endorsement anymore. -*) + to create a double_endorsement anymore. *) let test_too_late_double_endorsement_evidence () = Context.init 2 >>=? fun (b, _) -> @@ -183,9 +179,8 @@ let test_too_late_double_endorsement_evidence () = | _ -> false) -(** Check that an invalid double endorsement evidence that expose two - endorsements made by two different endorsers fails. -*) +(** Check that an invalid double endorsement evidence that exposes two + endorsements made by two different endorsers fails. *) let test_different_delegates () = Context.init 2 >>=? fun (b, _) -> @@ -219,8 +214,7 @@ let test_different_delegates () = false) (** Check that a double endorsement evidence that exposes a ill-formed - endorsement fails. -*) + endorsement fails. *) let test_wrong_delegate () = Context.init ~endorsers_per_block:1 2 >>=? fun (b, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index f56388b07266..8de9320926d6 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -127,8 +127,7 @@ let test_simple_endorsement () = initial_balance (** Apply a maximum number of endorsements. An endorser can be - selected twice. -*) + selected twice. *) let test_max_endorsement () = let endorsers_per_block = 16 in Context.init ~endorsers_per_block 32 @@ -175,8 +174,7 @@ let test_max_endorsement () = previous_balances (** Check every that endorsers' balances are consistent with different - priorities. -*) + priorities. *) let test_consistent_priorities () = let priorities = 0 -- 64 in Context.init 64 @@ -230,9 +228,8 @@ let test_consistent_priorities () = priorities >>=? fun _b -> return_unit -(** Check that after [preserved_cycles] cycles the endorser gets his - reward. -*) +(** Check that after [preserved_cycles] number of cycles the endorser + gets his reward. *) let test_reward_retrieval () = Context.init 5 >>=? fun (b, _) -> @@ -269,10 +266,9 @@ let test_reward_retrieval () = balance reward -(** Check that after [preserved_cycles] cycles endorsers get their - reward. Two endorsers are used and they endorse in different - cycles. -*) +(** Check that after [preserved_cycles] number of cycles endorsers get + their reward. Two endorsers are used and they endorse in different + cycles. *) let test_reward_retrieval_two_endorsers () = Context.init 5 >>=? fun (b, _) -> @@ -375,7 +371,7 @@ let test_reward_retrieval_two_endorsers () = balance2 security_deposit2 >>=? fun () -> - (* bake [preserved_cycles] cycles *) + (* bake [preserved_cycles] number of cycles *) List.fold_left_es (fun b _ -> Assert.balance_was_debited @@ -431,8 +427,7 @@ let test_reward_retrieval_two_endorsers () = (****************************************************************) (** Wrong endorsement predecessor : apply an endorsement with an - incorrect block predecessor. -*) + incorrect block predecessor. *) let test_wrong_endorsement_predecessor () = Context.init 5 >>=? fun (b, _) -> @@ -452,8 +447,7 @@ let test_wrong_endorsement_predecessor () = false) (** Invalid_endorsement_level: apply an endorsement with an incorrect - level (i.e. the predecessor level). -*) + level (i.e. the predecessor level). *) let test_invalid_endorsement_level () = Context.init 5 >>=? fun (b, _) -> @@ -473,8 +467,7 @@ let test_invalid_endorsement_level () = false) (** Duplicate endorsement : apply an endorsement that has already been - done. -*) + done. *) let test_duplicate_endorsement () = Context.init 5 >>=? fun (b, _) -> diff --git a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml index 37a301622ec5..3b8782bd9370 100644 --- a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml +++ b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml @@ -112,8 +112,7 @@ let arith_from_fp : (module Fixed_point_repr.Full) -> (module Arith) = (module Arith) (** Roundtrips between [integral] and [Z.t] (for fixed-point - decimals). Floor and ceil preserve the integral part. -*) + decimals). Floor and ceil preserve the integral part. *) let test_integral_tests decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals @@ -152,7 +151,7 @@ let test_integral_tests decimals () = (err "pp_integral(integral) = pp(fp(integral))") >>=? fun () -> basic_arith "integral arith" (arith_from_integral (module FP)) -(** With zero decimals. *) +(** With zero decimal. *) let test_fp_zero () = let decimals = 0 in let module FP = Fixed_point_repr.Make (struct @@ -175,7 +174,7 @@ let test_fp_zero () = >>=? fun () -> basic_arith "fp (0 decimals) arith" (arith_from_fp (module FP)) -(** With [decimals] decimal. *) +(** With [decimals] decimal(s). *) let test_fp_nonzero decimals () = let module FP = Fixed_point_repr.Make (struct let decimals = decimals @@ -204,8 +203,7 @@ let test_fp_nonzero decimals () = (err "ceil (x + eps) = x + 1") (** Checking the parser [FF.pp] that values are correctly converted - according to the number of decimals. -*) + according to the number of decimals. *) let test_fp_pp () = let module FP = Fixed_point_repr.Make (struct let decimals = 3 diff --git a/src/proto_alpha/lib_protocol/test/test_gas_levels.ml b/src/proto_alpha/lib_protocol/test/test_gas_levels.ml index e5afb14bfec7..09ee74b21d60 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_levels.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_levels.ml @@ -102,13 +102,9 @@ let operation_gas_level context = (* because this function is called after [set_gas_limit]. *) assert false -(* - - Monitoring runs differently depending on the minimum between the +(* Monitoring runs differently depending on the minimum between the operation gas level and the block gas level. Hence, we check that - in both situations, the gas levels are correctly reported. - -*) + in both situations, the gas levels are correctly reported. *) let test_monitor_operation_gas_level = monitor 100 operation_gas_level 90 let test_monitor_operation_gas_level' = diff --git a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml index 6581ba799768..aa0b229af16a 100644 --- a/src/proto_alpha/lib_protocol/test/test_gas_properties.ml +++ b/src/proto_alpha/lib_protocol/test/test_gas_properties.ml @@ -101,8 +101,7 @@ let test_free_neutral since = else Ok (Some (cost, Gas.free)) (** Consuming [cost1] then [cost2] is equivalent to consuming - [Gas.(cost1 +@ cost2)]. -*) + [Gas.(cost1 +@ cost2)]. *) let test_consume_commutes since = let open Alpha_context in let open Environment.Error_monad in diff --git a/src/proto_alpha/lib_protocol/test/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/test_interpretation.ml index fd4d106061a7..323100349eb1 100644 --- a/src/proto_alpha/lib_protocol/test/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/test_interpretation.ml @@ -76,8 +76,7 @@ let run_step ctxt code param = param (** Runs a script with an ill-typed parameter and verifies that a - Bad_contract_parameter error is returned -*) + Bad_contract_parameter error is returned. *) let test_bad_contract_parameter () = test_context () >>=? fun ctx -> diff --git a/src/proto_alpha/lib_protocol/test/test_origination.ml b/src/proto_alpha/lib_protocol/test/test_origination.ml index b69ea73df2ec..c782e4b9801f 100644 --- a/src/proto_alpha/lib_protocol/test/test_origination.ml +++ b/src/proto_alpha/lib_protocol/test/test_origination.ml @@ -122,7 +122,6 @@ let test_origination_balances ~loc:_ ?(fee = Tez.zero) ?(credit = Tez.zero) () (******************************************************) (* Tests *) - (******************************************************) (** compute half of the balance and divided it by nth times *) @@ -134,13 +133,11 @@ let two_nth_of_balance incr contract nth = (** Basic test. A contract is created as well as the newly originated contract (called from origination operation). The balance - before/after are checked. -*) + before/after are checked. *) let test_balances_simple () = test_origination_balances ~loc:__LOC__ () (** Same as [balances_simple] but credits 10 tez to the originated - contract (no fees). -*) + contract (no fees). *) let test_balances_credit () = test_origination_balances ~loc:__LOC__ ~credit:ten_tez () @@ -159,8 +156,7 @@ let test_pay_fee () = (******************************************************) (** Create an originate contract where the contract does not have - enough tez to pay for the fee. -*) + enough tez to pay for the fee. *) let test_not_tez_in_contract_to_pay_fee () = Context.init 2 >>=? fun (b, contracts) -> @@ -197,7 +193,7 @@ let test_not_tez_in_contract_to_pay_fee () = false) (* Set the endorser of the block as manager/delegate of the originated - account *) + account. *) let register_contract_get_endorser () = Context.init 1 >>=? fun (b, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_qty.ml b/src/proto_alpha/lib_protocol/test/test_qty.ml index aa5caa056821..94567cae4376 100644 --- a/src/proto_alpha/lib_protocol/test/test_qty.ml +++ b/src/proto_alpha/lib_protocol/test/test_qty.ml @@ -118,8 +118,7 @@ let test_known_tez_literals () = return_unit (** Randomly generated tez value which is printed into a string then - parsed again to test equality. -*) + parsed again for their equality. *) let test_random_tez_literals () = for _ = 0 to 100_000 do let v = Random.int64 12L in diff --git a/src/proto_alpha/lib_protocol/test/test_reveal.ml b/src/proto_alpha/lib_protocol/test/test_reveal.ml index b972f7276a4e..9579c9ad00da 100644 --- a/src/proto_alpha/lib_protocol/test/test_reveal.ml +++ b/src/proto_alpha/lib_protocol/test/test_reveal.ml @@ -27,7 +27,7 @@ ------- Component: Protocol (revelation) Invocation: dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "^revelation$" - Subject: For the reveal operation. + Subject: On the reveal operation. *) (** Test for the [Reveal] operation. *) diff --git a/src/proto_alpha/lib_protocol/test/test_rolls.ml b/src/proto_alpha/lib_protocol/test/test_rolls.ml index 3aec4f6dd395..98f5b223fa45 100644 --- a/src/proto_alpha/lib_protocol/test/test_rolls.ml +++ b/src/proto_alpha/lib_protocol/test/test_rolls.ml @@ -65,8 +65,7 @@ let get_rolls ctxt delegate = staking balance of [account] / (token_per_roll). As of protocol version 007, token_per_roll = 8000. Note that the consistency is verified against the value in the context, i.e. we are testing - Storage.Roll.Delegate_roll_list. We do not use RPCs here. -*) + Storage.Roll.Delegate_roll_list. We do not use RPCs here. *) let check_rolls (b : Block.t) (account : Account.t) = Context.get_constants (B b) >>=? fun constants -> @@ -103,11 +102,10 @@ let check_no_rolls (b : Block.t) (account : Account.t) = get_rolls ctxt account.pkh >>=? fun rolls -> Assert.equal_int ~loc:__LOC__ (List.length rolls) 0 -(** Create a block with two initialized contracts/accounts. Asserts - that the first account has a staking balance which equals to its +(** Create a block with two initialized contracts/accounts. Assert + that the first account has a staking balance that is equal to its own balance, and that its staking rights are consistent - (check_rolls). -*) + (check_rolls). *) let test_simple_staking_rights () = Context.init 2 >>=? fun (b, accounts) -> @@ -121,11 +119,10 @@ let test_simple_staking_rights () = Assert.equal_tez ~loc:__LOC__ balance info.staking_balance >>=? fun () -> check_rolls b m1 -(** Create a block with two initialized contracts/accounts. Bakes - five blocks. Asserts that the staking balance of the first account +(** Create a block with two initialized contracts/accounts. Bake + five blocks. Assert that the staking balance of the first account equals to its balance. Then both accounts have consistent staking - rights. -*) + rights. *) let test_simple_staking_rights_after_baking () = Context.init 2 >>=? fun (b, accounts) -> @@ -184,8 +181,7 @@ let run_until_deactivation () = (** From an initialized block with two contracts/accounts, the first one is active then deactivated. After baking, check that the - account is active again. Baking rights are ensured. -*) + account is active again. Baking rights are ensured. *) let test_deactivation_then_bake () = run_until_deactivation () >>=? fun ( b, @@ -199,8 +195,7 @@ let test_deactivation_then_bake () = (** A deactivated account, after baking with self-delegation, is active again. Preservation of its balance is tested. Baking rights - are ensured. -*) + are ensured. *) let test_deactivation_then_self_delegation () = run_until_deactivation () >>=? fun ( b, @@ -220,8 +215,7 @@ let test_deactivation_then_self_delegation () = (** A deactivated account, which is emptied (into a newly created sink account), then self-delegated, becomes activated. Its balance is - zero. Baking rights are ensured. -*) + zero. Baking rights are ensured. *) let test_deactivation_then_empty_then_self_delegation () = run_until_deactivation () >>=? fun ( b, @@ -262,8 +256,7 @@ let test_deactivation_then_empty_then_self_delegation () = (** A deactivated account, which is emptied, then self-delegated, then re-credited of the sunk amount, becomes active again. Staking - rights remain consistent. -*) + rights remain consistent. *) let test_deactivation_then_empty_then_self_delegation_then_recredit () = run_until_deactivation () >>=? fun ( b, @@ -310,8 +303,7 @@ let test_deactivation_then_empty_then_self_delegation_then_recredit () = account sends to third one the amount of 0.5 tez. The third account has no delegate and is consistent for baking rights. Then, it is self-delegated and is supposed to be activated. Again, consistency - for baking rights are preserved for the first and third accounts. -*) + for baking rights are preserved for the first and third accounts. *) let test_delegation () = Context.init 2 >>=? fun (b, accounts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_seed.ml b/src/proto_alpha/lib_protocol/test/test_seed.ml index 6036d5babb51..bf04ca8923de 100644 --- a/src/proto_alpha/lib_protocol/test/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/test_seed.ml @@ -36,8 +36,7 @@ open Protocol open Test_tez (** Baking [blocks_per_commitment] blocks without a [seed_nonce_hash] - commitment fails with [Invalid_commitment]. -*) + commitment fails with [Invalid_commitment]. *) let test_no_commitment () = Context.init 5 >>=? fun (b, _) -> @@ -76,8 +75,7 @@ let baking_reward ctxt (b : Block.t) = - when another baker reveals correctly, it receives the tip - revealing twice produces an error - after [preserved cycles] a committer that correctly revealed - receives back the bond and the reward -*) + receives back the bond and the reward. *) let test_revelation_early_wrong_right_twice () = let open Assert in Context.init 5 @@ -225,8 +223,7 @@ let test_revelation_early_wrong_right_twice () = (** - a committer at cycle 0, which doesn't reveal at cycle 1, at the end of the cycle 1 looses the bond and the reward - - revealing too late produces an error -*) + - revealing too late produces an error *) let test_revelation_missing_and_late () = let open Context in let open Assert in diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index 546243fd1f3f..59421e337080 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -52,8 +52,7 @@ open Test_tez This function returns a pair: - A block that added a valid operation - - a valid operation -*) + - a valid operation *) let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee = Tez.zero) ?expect_failure src dst amount = Tez.( +? ) fee amount @@ -97,8 +96,7 @@ let transfer_and_check_balances ?(with_burn = false) ~loc b ?(fee = Tez.zero) This function returns a pair: - a block that added the valid transaction - - an valid transaction -*) + - an valid transaction *) let transfer_to_itself_and_check_balances ~loc b ?(fee = Tez.zero) contract amount = Context.Contract.balance (I b) contract @@ -116,8 +114,7 @@ let transfer_to_itself_and_check_balances ~loc b ?(fee = Tez.zero) contract a destination contract and an amount one wants to transfer. This function will do a transaction from a source contract to - a destination contract with the amount "n" times. -*) + a destination contract with the amount "n" times. *) let n_transactions n b ?fee source dest amount = List.fold_left_es (fun b _ -> @@ -140,7 +137,7 @@ let register_two_contracts () = | (b, contract_1 :: contract_2 :: _) -> (b, contract_1, contract_2) -(** Computes a fraction of 2/[n] of the balance of [contract] *) +(** Compute a fraction of 2/[n] of the balance of [contract] *) let two_over_n_of_balance incr contract n = Context.Contract.balance (I incr) contract >>=? fun balance -> @@ -267,7 +264,7 @@ let test_missing_transaction () = >>=? fun b -> two_over_n_of_balance b contract_1 6L >>=? fun amount -> - (* do the transfer 3 times from source contract to destination contract *) + (* Do the transfer 3 times from source contract to destination contract *) n_transactions 3 b contract_1 contract_2 amount >>=? fun b -> (* do the fourth transfer from source contract to destination contract *) @@ -275,12 +272,11 @@ let test_missing_transaction () = >>=? fun _ -> Incremental.finalize_block b >>=? fun _ -> return_unit (********************) -(* These following tests are for different kind of contracts: +(* The following tests are for different kind of contracts: - implicit to implicit - implicit to originated - originated to implicit - - originated to originated -*) + - originated to originated *) (********************) @@ -307,13 +303,13 @@ let test_transfer_from_implicit_to_implicit_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 two_over_n_of_balance b bootstrap_contract 4L >>=? fun amount2 -> two_over_n_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 ~with_burn:true ~loc:__LOC__ @@ -376,8 +372,7 @@ let test_block_with_multiple_transfers () = multiple_transfer 99 (Tez.of_int 1000) (** 1- Create a block with two contracts; - 2- Apply 100 transfers with 10tz fee. -*) + 2- Apply 100 transfers with 10tz fee. *) let test_block_with_multiple_transfers_pay_fee () = multiple_transfer 10 ~fee:ten_tez (Tez.of_int 1000) @@ -385,8 +380,7 @@ let test_block_with_multiple_transfers_pay_fee () = (** 1- Create a block with 8 contracts; 2- Apply multiple transfers without fees; - 3- Apply multiple transfers with fees. -*) + 3- Apply multiple transfers with fees. *) let test_block_with_multiple_transfers_with_without_fee () = Context.init 8 >>=? fun (b, contracts) -> @@ -503,8 +497,7 @@ let test_balance_too_low fee () = 2- Add a transfer that at the end the balance of a contract is zero into this block; 3- Add another transfer that send tez from a zero balance contract; - 4- Catch the expected error: Balance_too_low. -*) + 4- Catch the expected error: Balance_too_low. *) let test_balance_too_low_two_transfers fee () = Context.init 3 >>=? fun (b, contracts) -> @@ -566,7 +559,8 @@ let invalid_counter () = | _ -> false) -(** Same as before but different way to perform this error. *) +(** Same as before but through a different way to perform this + error. *) let test_add_the_same_operation_twice () = register_two_contracts () >>=? fun (b, contract_1, contract_2) -> @@ -601,7 +595,7 @@ let test_ownership_sender () = (*********************************************************************) (* Random transfer *) -(* Return a pair of minimum and maximum random number *) +(* Return a pair of minimum and maximum random number. *) let random_range (min, max) = let interv = max - min + 1 in let init = @@ -616,8 +610,7 @@ let random_contract contract_array = contract_array.(i) (** Transfer by randomly choose amount 10 contracts, and randomly - choose the amount in the source contract. -*) + choose the amount in the source contract. *) let test_random_transfer () = Context.init 10 >>=? fun (b, contracts) -> diff --git a/src/proto_alpha/lib_protocol/test/test_typechecking.ml b/src/proto_alpha/lib_protocol/test/test_typechecking.ml index c0dab75d2f5c..6a8d461044ad 100644 --- a/src/proto_alpha/lib_protocol/test/test_typechecking.ml +++ b/src/proto_alpha/lib_protocol/test/test_typechecking.ml @@ -109,8 +109,7 @@ let read_file filename = close_in ch ; s (** Check that the custom stack overflow exception is triggered when - it should be. -*) + it should be. *) let test_typecheck_stack_overflow () = test_context () >>=? fun ctxt -> diff --git a/src/proto_alpha/lib_protocol/test/test_voting.ml b/src/proto_alpha/lib_protocol/test/test_voting.ml index 72a8cc4b08ee..8364d1a786c1 100644 --- a/src/proto_alpha/lib_protocol/test/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/test_voting.ml @@ -546,8 +546,7 @@ let get_expected_participation_ema rolls voter_rolls old_participation_ema = (** If not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- - in testing vote, go back to proposal period. -*) + in testing vote, go back to proposal period. *) let test_not_enough_quorum_in_testing_vote num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -612,8 +611,7 @@ let test_not_enough_quorum_in_testing_vote num_delegates () = (** If not enough quorum -- get_updated_participation_ema < pr_ema_weight/den -- - In promotion vote, go back to proposal period. -*) + In promotion vote, go back to proposal period. *) let test_not_enough_quorum_in_promotion_vote num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -703,8 +701,7 @@ let test_not_enough_quorum_in_promotion_vote num_delegates () = assert_listings_not_empty b ~loc:__LOC__ >>=? fun () -> return_unit (** Identical proposals (identified by their hash) must be counted as - one. -*) + one. *) let test_multiple_identical_proposals_count_as_one () = Context.init 1 >>=? fun (b, delegates) -> @@ -744,8 +741,7 @@ let test_multiple_identical_proposals_count_as_one () = failwith "%s - Missing proposal" __LOC__ (** Assume the initial balance of allocated by Context.init is at - least 4 time the value of the tokens_per_roll constant. -*) + least 4 times the value of the tokens_per_roll constant. *) let test_supermajority_in_proposal there_is_a_winner () = let min_proposal_quorum = 0l in Context.init ~min_proposal_quorum ~initial_balances:[1L; 1L; 1L] 10 @@ -815,8 +811,7 @@ let test_supermajority_in_proposal there_is_a_winner () = (** After one voting period, if [has_quorum] then the period kind must have been the testing vote. Otherwise, it should have remained in - place in the proposal period. -*) + place in the proposal period. *) let test_quorum_in_proposal has_quorum () = let total_tokens = 32_000_000_000_000L in let half_tokens = Int64.div total_tokens 2L in @@ -875,8 +870,7 @@ let test_quorum_in_proposal has_quorum () = >>=? fun () -> return_unit (** If a supermajority is reached, then the voting period must be - reached. Otherwise, it remains in proposal period. -*) + reached. Otherwise, it remains in proposal period. *) let test_supermajority_in_testing_vote supermajority () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / 100)) in Context.init ~min_proposal_quorum 100 @@ -930,8 +924,7 @@ let test_supermajority_in_testing_vote supermajority () = >>=? fun () -> return_unit (** Test also how the selection scales: all delegates propose max - proposals. -*) + proposals. *) let test_no_winning_proposal num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -957,8 +950,7 @@ let test_no_winning_proposal num_delegates () = (** Vote to pass with maximum possible participation_ema (100%), it is sufficient for the vote quorum to be equal or greater than the - maximum quorum cap. -*) + maximum quorum cap. *) let test_quorum_capped_maximum num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates @@ -1006,8 +998,7 @@ let test_quorum_capped_maximum num_delegates () = (** Vote to pass with minimum possible participation_ema (0%), it is sufficient for the vote quorum to be equal or greater than the - minimum quorum cap. -*) + minimum quorum cap. *) let test_quorum_capped_minimum num_delegates () = let min_proposal_quorum = Int32.(of_int @@ (100_00 / num_delegates)) in Context.init ~min_proposal_quorum num_delegates -- GitLab From f5d974149eeb21d23f835d9accfa2f063a26a544 Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas <946787-yrg@users.noreply.gitlab.com> Date: Mon, 28 Dec 2020 16:33:19 +0000 Subject: [PATCH 15/17] Apply 1 suggestion(s) to 1 file(s) --- src/proto_alpha/lib_protocol/test/test_activation.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/test_activation.ml b/src/proto_alpha/lib_protocol/test/test_activation.ml index 4c7744221785..8c73151e9a8a 100644 --- a/src/proto_alpha/lib_protocol/test/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/test_activation.ml @@ -345,7 +345,7 @@ let test_single_activation () = (Contract.implicit_contract account) expected_amount -(** 10 activations, one per bake *) +(** 10 activations, one per bake. *) let test_multi_activation_1 () = activation_init () >>=? fun (blk, _contracts, secrets) -> -- GitLab From 9e5a88c5c05a19c1e30bfa42b086c941c45a1165 Mon Sep 17 00:00:00 2001 From: Yann Regis-Gianas <946787-yrg@users.noreply.gitlab.com> Date: Mon, 28 Dec 2020 16:42:03 +0000 Subject: [PATCH 16/17] Apply 1 suggestion(s) to 1 file(s) --- src/proto_alpha/lib_protocol/test/test_transfer.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/test/test_transfer.ml b/src/proto_alpha/lib_protocol/test/test_transfer.ml index 59421e337080..cd8a87420a9c 100644 --- a/src/proto_alpha/lib_protocol/test/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/test_transfer.ml @@ -449,7 +449,7 @@ let test_empty_implicit () = let src = Contract.implicit_contract account.Account.pkh in two_over_n_of_balance incr dest 3L >>=? fun amount -> - (* transfer zero tez from an implicit contract *) + (* Transfer zero tez from an implicit contract. *) Op.transaction (I incr) src dest amount >>=? fun op -> Incremental.add_operation incr op -- GitLab From 005fa6434abf900d60439d58724ce1a4bb07ed0e Mon Sep 17 00:00:00 2001 From: Hai Nguyen Van Date: Mon, 28 Dec 2020 18:02:32 +0100 Subject: [PATCH 17/17] Testing: Amended with @yrg's reviews. --- src/proto_alpha/lib_protocol/test/test_baking.ml | 4 ++-- src/proto_alpha/lib_protocol/test/test_delegation.ml | 2 +- src/proto_alpha/lib_protocol/test/test_endorsement.ml | 2 +- src/proto_alpha/lib_protocol/test/test_fixed_point.ml | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/proto_alpha/lib_protocol/test/test_baking.ml b/src/proto_alpha/lib_protocol/test/test_baking.ml index 534f8d6ea73f..29ac3327c67a 100644 --- a/src/proto_alpha/lib_protocol/test/test_baking.ml +++ b/src/proto_alpha/lib_protocol/test/test_baking.ml @@ -36,8 +36,8 @@ open Alpha_context (** Verify the level is correctly computed when the first cycle is passed and after baking a certain fixed number of blocks (10 for - the moment). The result should be `blocks_per_cycle + 10` where - `blocks_per_cycle` comes from the constants of the selected + the moment). The result should be [blocks_per_cycle + 10] where + [blocks_per_cycle] comes from the constants of the selected protocol. IMPROVEMENTS: diff --git a/src/proto_alpha/lib_protocol/test/test_delegation.ml b/src/proto_alpha/lib_protocol/test/test_delegation.ml index a3feb54df20a..34a349036a5e 100644 --- a/src/proto_alpha/lib_protocol/test/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/test_delegation.ml @@ -1410,7 +1410,7 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = Assert.equal_pkh ~loc:__LOC__ delegator_delegate delegate_pkh (* Part C. - A second self-delegation should raise an `Active_delegate` error. *) + A second self-delegation should raise an [Active_delegate] error. *) (** Second self-delegation should fail with implicit contract with some credit. *) diff --git a/src/proto_alpha/lib_protocol/test/test_endorsement.ml b/src/proto_alpha/lib_protocol/test/test_endorsement.ml index 8de9320926d6..54546503e2ab 100644 --- a/src/proto_alpha/lib_protocol/test/test_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/test_endorsement.ml @@ -173,7 +173,7 @@ let test_max_endorsement () = delegates previous_balances -(** Check every that endorsers' balances are consistent with different +(** Check that every endorsers' balances are consistent with different priorities. *) let test_consistent_priorities () = let priorities = 0 -- 64 in diff --git a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml index 3b8782bd9370..60cb8f18f400 100644 --- a/src/proto_alpha/lib_protocol/test/test_fixed_point.ml +++ b/src/proto_alpha/lib_protocol/test/test_fixed_point.ml @@ -202,8 +202,9 @@ let test_fp_nonzero decimals () = FP.(ceil (add (fp (integral x)) (unsafe_fp Z.one)) = integral (Z.succ x)) (err "ceil (x + eps) = x + 1") -(** Checking the parser [FF.pp] that values are correctly converted - according to the number of decimals. *) +(** Checking the output of the pretty-printer [FF.pp] such that + fixed-point decimal values are converted to their correct string + output according to the number of decimals. *) let test_fp_pp () = let module FP = Fixed_point_repr.Make (struct let decimals = 3 -- GitLab