Skip to content

Commit fd40b46

Browse files
Merge pull request #14472 from MinaProtocol/fix/zero-vesting-period-alcotest
Fix zero vesting period test
2 parents ceca156 + 78a9047 commit fd40b46

File tree

3 files changed

+91
-35
lines changed

3 files changed

+91
-35
lines changed

src/lib/mina_base/test/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
fields_derivers.zkapps
1818
fields_derivers.json
1919
fields_derivers.graphql
20+
genesis_constants
2021
kimchi_backend.pasta
2122
kimchi_backend.pasta.basic
2223
mina_base
@@ -25,6 +26,7 @@
2526
pickles
2627
pickles.backend
2728
pickles_types
29+
ppx_deriving_yojson.runtime
2830
ppx_version.runtime
2931
run_in_thread
3032
signature_lib

src/lib/mina_base/test/main.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,17 @@ let () =
140140
] )
141141
; Signature_test.
142142
( "signatures"
143-
, [ test_case "Signature decode after encode i identity" `Quick
143+
, [ test_case "Signature decode after encode is identity" `Quick
144144
signature_decode_after_encode_is_identity
145145
; test_case "Base58check is stable" `Quick base58Check_stable
146146
] )
147+
; Zero_vesting_period.
148+
( "zero vesting period"
149+
, [ test_case "Zero vesting period is error" `Quick
150+
zero_vesting_period_is_error
151+
; test_case "Nonzero vesting period is OK" `Quick
152+
nonzero_vesting_period_ok
153+
] )
147154
; Zkapp_command_test.
148155
( "zkApp commands"
149156
, [ test_case "Account_update_or_stack.of_zkapp_command_list." `Quick

src/lib/mina_base/test/zero_vesting_period.ml

Lines changed: 81 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
(** Testing
2+
-------
3+
Component: Mina base
4+
Invocation: dune exec src/lib/mina_base/test/main.exe -- \
5+
test '^zero vesting period$'
6+
Subject: Test zero vesting period detection
7+
*)
8+
19
open Core_kernel
210
open Mina_base
311

4-
let%test_module "zero_vesting" =
5-
( module struct
6-
let mk_zkapp_with_vesting_period n =
7-
sprintf
8-
{json|
12+
let mk_zkapp_with_vesting_period n =
13+
let res =
14+
sprintf
15+
{json|
916
{
1017
"fee_payer": {
1118
"body": {
1219
"public_key": "B62qkb7Sed1VVsogq7qXzi79JNx9MkcbRihwwuSphUtBiEFPNTQfzNR",
13-
"fee": "0.01",
20+
"fee": "2.0",
1421
"valid_until": null,
1522
"nonce": "0"
1623
},
@@ -112,7 +119,25 @@ let%test_module "zero_vesting" =
112119
"epoch_length": [ "Ignore" ]
113120
}
114121
},
115-
"account": [ "Accept" ],
122+
"account": {
123+
"balance": [ "Ignore" ],
124+
"nonce": [ "Ignore" ],
125+
"receipt_chain_hash": [ "Ignore" ],
126+
"delegate": [ "Ignore" ],
127+
"state": [
128+
[ "Ignore" ],
129+
[ "Ignore" ],
130+
[ "Ignore" ],
131+
[ "Ignore" ],
132+
[ "Ignore" ],
133+
[ "Ignore" ],
134+
[ "Ignore" ],
135+
[ "Ignore" ]
136+
],
137+
"action_state": [ "Ignore" ],
138+
"proved_state": [ "Ignore" ],
139+
"is_new": [ "Ignore" ]
140+
},
116141
"valid_while": [ "Ignore" ]
117142
},
118143
"use_full_commitment": true,
@@ -202,7 +227,25 @@ let%test_module "zero_vesting" =
202227
"epoch_length": [ "Ignore" ]
203228
}
204229
},
205-
"account": [ "Accept" ],
230+
"account": {
231+
"balance": [ "Ignore" ],
232+
"nonce": [ "Ignore" ],
233+
"receipt_chain_hash": [ "Ignore" ],
234+
"delegate": [ "Ignore" ],
235+
"state": [
236+
[ "Ignore" ],
237+
[ "Ignore" ],
238+
[ "Ignore" ],
239+
[ "Ignore" ],
240+
[ "Ignore" ],
241+
[ "Ignore" ],
242+
[ "Ignore" ],
243+
[ "Ignore" ]
244+
],
245+
"action_state": [ "Ignore" ],
246+
"proved_state": [ "Ignore" ],
247+
"is_new": [ "Ignore" ]
248+
},
206249
"valid_while": [ "Ignore" ]
207250
},
208251
"use_full_commitment": false,
@@ -224,33 +267,37 @@ let%test_module "zero_vesting" =
224267
}
225268

226269
|json}
227-
n
228-
|> Yojson.Safe.from_string |> Zkapp_command.of_yojson
229-
|> Result.ok_or_failwith
270+
n
271+
|> Yojson.Safe.from_string |> Zkapp_command.of_yojson
272+
in
273+
match res with
274+
| Ppx_deriving_yojson_runtime.Result.Ok zkapp ->
275+
zkapp
276+
| Ppx_deriving_yojson_runtime.Result.Error err ->
277+
failwith err
230278

231-
let zkapp_zero_vesting_period = mk_zkapp_with_vesting_period 0
279+
let zkapp_zero_vesting_period = mk_zkapp_with_vesting_period 0
232280

233-
let%test "zero vesting period is error" =
234-
match
235-
User_command.check_well_formedness
236-
~genesis_constants:Genesis_constants.for_unit_tests
237-
(Zkapp_command zkapp_zero_vesting_period)
238-
with
239-
| Error [ Zero_vesting_period ] ->
240-
true
241-
| Ok _ | Error _ ->
242-
false
281+
let zero_vesting_period_is_error () =
282+
match
283+
User_command.check_well_formedness
284+
~genesis_constants:Genesis_constants.for_unit_tests
285+
(Zkapp_command zkapp_zero_vesting_period)
286+
with
287+
| Error [ Zero_vesting_period ] ->
288+
()
289+
| Ok _ | Error _ ->
290+
assert false
243291

244-
let zkapp_nonzero_vesting_period = mk_zkapp_with_vesting_period 1
292+
let zkapp_nonzero_vesting_period = mk_zkapp_with_vesting_period 1
245293

246-
let%test "nonzero vesting period is ok" =
247-
match
248-
User_command.check_well_formedness
249-
~genesis_constants:Genesis_constants.for_unit_tests
250-
(Zkapp_command zkapp_nonzero_vesting_period)
251-
with
252-
| Ok () ->
253-
true
254-
| Error errs ->
255-
false
256-
end )
294+
let nonzero_vesting_period_ok () =
295+
match
296+
User_command.check_well_formedness
297+
~genesis_constants:Genesis_constants.for_unit_tests
298+
(Zkapp_command zkapp_nonzero_vesting_period)
299+
with
300+
| Ok () ->
301+
()
302+
| Error _ ->
303+
assert false

0 commit comments

Comments
 (0)