From 130398bd54c48c114884ab96ab3b4e0c2a7f884c Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 01/24] Add tests for Stack --- .../mina_transaction_logic.ml | 15 ++++++++++++- .../test/transaction_logic.ml | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index 00815fe43f4..cb4b2a28ea5 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,7 +546,17 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig + module For_tests : sig + module Stack (Elt : sig type t end) : sig + type t = Elt.t list + val if_ : bool -> then_:'a -> else_:'a -> 'a + val empty : unit -> 'a list + val is_empty : 'a list -> bool + val pop_exn : t -> Elt.t * t + val pop : t -> (Elt.t * t) option + val push : Elt.t -> onto:Elt.t list -> t + end + val validate_timing_with_min_balance : account:Account.t -> txn_amount:Amount.t @@ -2548,6 +2558,9 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct + + module Stack = Inputs.Stack + let validate_timing_with_min_balance = validate_timing_with_min_balance let validate_timing = validate_timing diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index fc822d5e8fd..2e69cc790da 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -239,3 +239,25 @@ let%test_module "Test transaction logic." = Transaction_status.equal txn.command.status Applied ) ) (run_zkapp_cmd ~fee_payer ~fee ~accounts txns) ) end ) + +(* This module tests Inputs.Stack *) +let%test_module "Test stack module" = + ( module struct + module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = + let s = [1;2;3] in + match (Stack.pop s) with + | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) + | None -> assert(false) + + let%test_unit "Ensure pop works on empty list." = + match (Stack.pop (Stack.empty ())) with + | Some _ -> assert(false) + | None -> assert(true) + + let%test_unit "Ensure push functionality works." = + let s = [1;2;3] in + let pushed = Stack.push 0 ~onto:s in + assert(List.equal Int.equal pushed [0;1;2;3]) + end ) + From e474254e0d756b9c2716356835976f37c4d5c269 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 02/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 2e69cc790da..b6e6e690a41 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -244,11 +244,19 @@ let%test_module "Test transaction logic." = let%test_module "Test stack module" = ( module struct module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = - let s = [1;2;3] in - match (Stack.pop s) with - | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) - | None -> assert(false) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack,top,tail)) + ~f:(fun (stack,top,tail) -> + match (Stack.pop stack) with + | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) + | None -> assert(false)) let%test_unit "Ensure pop works on empty list." = match (Stack.pop (Stack.empty ())) with @@ -256,8 +264,16 @@ let%test_module "Test stack module" = | None -> assert(true) let%test_unit "Ensure push functionality works." = - let s = [1;2;3] in - let pushed = Stack.push 0 ~onto:s in - assert(List.equal Int.equal pushed [0;1;2;3]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in + let pushed' = List.append stack' stack in + return (pushed,pushed')) + ~f:(fun (pushed,pushed') -> + assert(List.equal Int.equal pushed pushed')) end ) + From 02b8b867c660c114871de79bda2dc2344e3e7d49 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Tue, 14 Mar 2023 19:51:32 -0400 Subject: [PATCH 03/24] Run make reformat to correct formatting --- .../mina_transaction_logic.ml | 29 ++++++---- .../test/transaction_logic.ml | 57 ++++++++++--------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index cb4b2a28ea5..c498ef56540 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,16 +546,24 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig - module Stack (Elt : sig type t end) : sig - type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a - val empty : unit -> 'a list - val is_empty : 'a list -> bool - val pop_exn : t -> Elt.t * t - val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t - end + module For_tests : sig + module Stack (Elt : sig + type t + end) : sig + type t = Elt.t list + + val if_ : bool -> then_:'a -> else_:'a -> 'a + + val empty : unit -> 'a list + + val is_empty : 'a list -> bool + + val pop_exn : t -> Elt.t * t + + val pop : t -> (Elt.t * t) option + + val push : Elt.t -> onto:Elt.t list -> t + end val validate_timing_with_min_balance : account:Account.t @@ -2558,7 +2566,6 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct - module Stack = Inputs.Stack let validate_timing_with_min_balance = validate_timing_with_min_balance diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index b6e6e690a41..8a0d62a1f56 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -246,34 +246,39 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack,top,tail)) - ~f:(fun (stack,top,tail) -> - match (Stack.pop stack) with - | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) - | None -> assert(false)) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = - match (Stack.pop (Stack.empty ())) with - | Some _ -> assert(false) - | None -> assert(true) + match Stack.pop (Stack.empty ()) with + | Some _ -> + assert false + | None -> + assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in - let pushed' = List.append stack' stack in - return (pushed,pushed')) - ~f:(fun (pushed,pushed') -> - assert(List.equal Int.equal pushed pushed')) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) - - From 0c9350a43f6f981a66aca7626ee88780c2d3a7e1 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 04/24] Add tests for Stack --- .../mina_transaction_logic.ml | 15 ++++++++++++- .../test/transaction_logic.ml | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index 00815fe43f4..cb4b2a28ea5 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,7 +546,17 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig + module For_tests : sig + module Stack (Elt : sig type t end) : sig + type t = Elt.t list + val if_ : bool -> then_:'a -> else_:'a -> 'a + val empty : unit -> 'a list + val is_empty : 'a list -> bool + val pop_exn : t -> Elt.t * t + val pop : t -> (Elt.t * t) option + val push : Elt.t -> onto:Elt.t list -> t + end + val validate_timing_with_min_balance : account:Account.t -> txn_amount:Amount.t @@ -2548,6 +2558,9 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct + + module Stack = Inputs.Stack + let validate_timing_with_min_balance = validate_timing_with_min_balance let validate_timing = validate_timing diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index fc822d5e8fd..2e69cc790da 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -239,3 +239,25 @@ let%test_module "Test transaction logic." = Transaction_status.equal txn.command.status Applied ) ) (run_zkapp_cmd ~fee_payer ~fee ~accounts txns) ) end ) + +(* This module tests Inputs.Stack *) +let%test_module "Test stack module" = + ( module struct + module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = + let s = [1;2;3] in + match (Stack.pop s) with + | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) + | None -> assert(false) + + let%test_unit "Ensure pop works on empty list." = + match (Stack.pop (Stack.empty ())) with + | Some _ -> assert(false) + | None -> assert(true) + + let%test_unit "Ensure push functionality works." = + let s = [1;2;3] in + let pushed = Stack.push 0 ~onto:s in + assert(List.equal Int.equal pushed [0;1;2;3]) + end ) + From fe0cce8ce0080cb883bacb0e097cb25c8cb7d291 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 05/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 2e69cc790da..b6e6e690a41 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -244,11 +244,19 @@ let%test_module "Test transaction logic." = let%test_module "Test stack module" = ( module struct module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = - let s = [1;2;3] in - match (Stack.pop s) with - | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) - | None -> assert(false) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack,top,tail)) + ~f:(fun (stack,top,tail) -> + match (Stack.pop stack) with + | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) + | None -> assert(false)) let%test_unit "Ensure pop works on empty list." = match (Stack.pop (Stack.empty ())) with @@ -256,8 +264,16 @@ let%test_module "Test stack module" = | None -> assert(true) let%test_unit "Ensure push functionality works." = - let s = [1;2;3] in - let pushed = Stack.push 0 ~onto:s in - assert(List.equal Int.equal pushed [0;1;2;3]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in + let pushed' = List.append stack' stack in + return (pushed,pushed')) + ~f:(fun (pushed,pushed') -> + assert(List.equal Int.equal pushed pushed')) end ) + From 61a5567a8a8fd198399e925633829ec39c2ca698 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Tue, 14 Mar 2023 19:51:32 -0400 Subject: [PATCH 06/24] Run make reformat to correct formatting --- .../mina_transaction_logic.ml | 29 ++++++---- .../test/transaction_logic.ml | 57 ++++++++++--------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index cb4b2a28ea5..c498ef56540 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,16 +546,24 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig - module Stack (Elt : sig type t end) : sig - type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a - val empty : unit -> 'a list - val is_empty : 'a list -> bool - val pop_exn : t -> Elt.t * t - val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t - end + module For_tests : sig + module Stack (Elt : sig + type t + end) : sig + type t = Elt.t list + + val if_ : bool -> then_:'a -> else_:'a -> 'a + + val empty : unit -> 'a list + + val is_empty : 'a list -> bool + + val pop_exn : t -> Elt.t * t + + val pop : t -> (Elt.t * t) option + + val push : Elt.t -> onto:Elt.t list -> t + end val validate_timing_with_min_balance : account:Account.t @@ -2558,7 +2566,6 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct - module Stack = Inputs.Stack let validate_timing_with_min_balance = validate_timing_with_min_balance diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index b6e6e690a41..8a0d62a1f56 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -246,34 +246,39 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack,top,tail)) - ~f:(fun (stack,top,tail) -> - match (Stack.pop stack) with - | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) - | None -> assert(false)) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = - match (Stack.pop (Stack.empty ())) with - | Some _ -> assert(false) - | None -> assert(true) + match Stack.pop (Stack.empty ()) with + | Some _ -> + assert false + | None -> + assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in - let pushed' = List.append stack' stack in - return (pushed,pushed')) - ~f:(fun (pushed,pushed') -> - assert(List.equal Int.equal pushed pushed')) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) - - From 9103b44dffae591f1190cc9d457dffc25b7fab88 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Mon, 3 Apr 2023 13:50:35 -0400 Subject: [PATCH 07/24] Remove polymorphic types in module For_tests.Stack --- src/lib/transaction_logic/mina_transaction_logic.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index c498ef56540..93e9c2f0599 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -552,17 +552,17 @@ module type S = sig end) : sig type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a + val if_ : bool -> then_:t -> else_:t -> t - val empty : unit -> 'a list + val empty : unit -> t - val is_empty : 'a list -> bool + val is_empty : t -> bool val pop_exn : t -> Elt.t * t val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t + val push : Elt.t -> onto:t -> t end val validate_timing_with_min_balance : From f8c2edcff81eb17b84fa0857010951f055a61a6c Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 08/24] Add tests for Stack --- .../mina_transaction_logic.ml | 15 ++++++++++++- .../test/transaction_logic.ml | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index 00815fe43f4..cb4b2a28ea5 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,7 +546,17 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig + module For_tests : sig + module Stack (Elt : sig type t end) : sig + type t = Elt.t list + val if_ : bool -> then_:'a -> else_:'a -> 'a + val empty : unit -> 'a list + val is_empty : 'a list -> bool + val pop_exn : t -> Elt.t * t + val pop : t -> (Elt.t * t) option + val push : Elt.t -> onto:Elt.t list -> t + end + val validate_timing_with_min_balance : account:Account.t -> txn_amount:Amount.t @@ -2548,6 +2558,9 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct + + module Stack = Inputs.Stack + let validate_timing_with_min_balance = validate_timing_with_min_balance let validate_timing = validate_timing diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index fc822d5e8fd..2e69cc790da 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -239,3 +239,25 @@ let%test_module "Test transaction logic." = Transaction_status.equal txn.command.status Applied ) ) (run_zkapp_cmd ~fee_payer ~fee ~accounts txns) ) end ) + +(* This module tests Inputs.Stack *) +let%test_module "Test stack module" = + ( module struct + module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = + let s = [1;2;3] in + match (Stack.pop s) with + | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) + | None -> assert(false) + + let%test_unit "Ensure pop works on empty list." = + match (Stack.pop (Stack.empty ())) with + | Some _ -> assert(false) + | None -> assert(true) + + let%test_unit "Ensure push functionality works." = + let s = [1;2;3] in + let pushed = Stack.push 0 ~onto:s in + assert(List.equal Int.equal pushed [0;1;2;3]) + end ) + From 9f7462502206743be40fb13138a467348e609d75 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 09/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 2e69cc790da..b6e6e690a41 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -244,11 +244,19 @@ let%test_module "Test transaction logic." = let%test_module "Test stack module" = ( module struct module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = - let s = [1;2;3] in - match (Stack.pop s) with - | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) - | None -> assert(false) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack,top,tail)) + ~f:(fun (stack,top,tail) -> + match (Stack.pop stack) with + | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) + | None -> assert(false)) let%test_unit "Ensure pop works on empty list." = match (Stack.pop (Stack.empty ())) with @@ -256,8 +264,16 @@ let%test_module "Test stack module" = | None -> assert(true) let%test_unit "Ensure push functionality works." = - let s = [1;2;3] in - let pushed = Stack.push 0 ~onto:s in - assert(List.equal Int.equal pushed [0;1;2;3]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in + let pushed' = List.append stack' stack in + return (pushed,pushed')) + ~f:(fun (pushed,pushed') -> + assert(List.equal Int.equal pushed pushed')) end ) + From 5e7edef8c3557570f63b0cc013665ea4d04a9ca4 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Tue, 14 Mar 2023 19:51:32 -0400 Subject: [PATCH 10/24] Run make reformat to correct formatting --- .../mina_transaction_logic.ml | 29 ++++++---- .../test/transaction_logic.ml | 57 ++++++++++--------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index cb4b2a28ea5..c498ef56540 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,16 +546,24 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig - module Stack (Elt : sig type t end) : sig - type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a - val empty : unit -> 'a list - val is_empty : 'a list -> bool - val pop_exn : t -> Elt.t * t - val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t - end + module For_tests : sig + module Stack (Elt : sig + type t + end) : sig + type t = Elt.t list + + val if_ : bool -> then_:'a -> else_:'a -> 'a + + val empty : unit -> 'a list + + val is_empty : 'a list -> bool + + val pop_exn : t -> Elt.t * t + + val pop : t -> (Elt.t * t) option + + val push : Elt.t -> onto:Elt.t list -> t + end val validate_timing_with_min_balance : account:Account.t @@ -2558,7 +2566,6 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct - module Stack = Inputs.Stack let validate_timing_with_min_balance = validate_timing_with_min_balance diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index b6e6e690a41..8a0d62a1f56 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -246,34 +246,39 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack,top,tail)) - ~f:(fun (stack,top,tail) -> - match (Stack.pop stack) with - | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) - | None -> assert(false)) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = - match (Stack.pop (Stack.empty ())) with - | Some _ -> assert(false) - | None -> assert(true) + match Stack.pop (Stack.empty ()) with + | Some _ -> + assert false + | None -> + assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in - let pushed' = List.append stack' stack in - return (pushed,pushed')) - ~f:(fun (pushed,pushed') -> - assert(List.equal Int.equal pushed pushed')) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) - - From ceacdd815718d084bfe624f7bbbfd34388cd9437 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 11/24] Add tests for Stack --- .../test/transaction_logic.ml | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 8a0d62a1f56..2ebc281e97d 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -246,19 +246,12 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack, top, tail)) - ~f:(fun (stack, top, tail) -> - match Stack.pop stack with - | Some (x, xs) -> - assert (Int.equal x top && List.equal Int.equal xs tail) - | None -> - assert false ) + let s = [ 1; 2; 3 ] in + match Stack.pop s with + | Some (x, xs) -> + assert (Int.equal x 1 && List.equal Int.equal xs [ 2; 3 ]) + | None -> + assert false let%test_unit "Ensure pop works on empty list." = match Stack.pop (Stack.empty ()) with @@ -268,17 +261,7 @@ let%test_module "Test stack module" = assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = - List.fold_right stack' ~init:stack ~f:(fun x s -> - Stack.push x ~onto:s ) - in - let pushed' = List.append stack' stack in - return (pushed, pushed')) - ~f:(fun (pushed, pushed') -> - assert (List.equal Int.equal pushed pushed') ) + let s = [ 1; 2; 3 ] in + let pushed = Stack.push 0 ~onto:s in + assert (List.equal Int.equal pushed [ 0; 1; 2; 3 ]) end ) From 5d67098d4cb82761ec29f9dd6851737092c4a01b Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 12/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 2ebc281e97d..8a0d62a1f56 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -246,12 +246,19 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - let s = [ 1; 2; 3 ] in - match Stack.pop s with - | Some (x, xs) -> - assert (Int.equal x 1 && List.equal Int.equal xs [ 2; 3 ]) - | None -> - assert false + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = match Stack.pop (Stack.empty ()) with @@ -261,7 +268,17 @@ let%test_module "Test stack module" = assert true let%test_unit "Ensure push functionality works." = - let s = [ 1; 2; 3 ] in - let pushed = Stack.push 0 ~onto:s in - assert (List.equal Int.equal pushed [ 0; 1; 2; 3 ]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) From 551d8017ad2233c7016a94e6e582fe36cb0bdbb0 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Mon, 3 Apr 2023 13:50:35 -0400 Subject: [PATCH 13/24] Remove polymorphic types in module For_tests.Stack --- src/lib/transaction_logic/mina_transaction_logic.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index c498ef56540..93e9c2f0599 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -552,17 +552,17 @@ module type S = sig end) : sig type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a + val if_ : bool -> then_:t -> else_:t -> t - val empty : unit -> 'a list + val empty : unit -> t - val is_empty : 'a list -> bool + val is_empty : t -> bool val pop_exn : t -> Elt.t * t val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t + val push : Elt.t -> onto:t -> t end val validate_timing_with_min_balance : From 55c65eacb7077a3f452a0c443e361f75af908fd8 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 14/24] Add tests for Stack --- .../mina_transaction_logic.ml | 15 ++++++++++++- .../test/transaction_logic.ml | 22 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index 00815fe43f4..cb4b2a28ea5 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,7 +546,17 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig + module For_tests : sig + module Stack (Elt : sig type t end) : sig + type t = Elt.t list + val if_ : bool -> then_:'a -> else_:'a -> 'a + val empty : unit -> 'a list + val is_empty : 'a list -> bool + val pop_exn : t -> Elt.t * t + val pop : t -> (Elt.t * t) option + val push : Elt.t -> onto:Elt.t list -> t + end + val validate_timing_with_min_balance : account:Account.t -> txn_amount:Amount.t @@ -2548,6 +2558,9 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct + + module Stack = Inputs.Stack + let validate_timing_with_min_balance = validate_timing_with_min_balance let validate_timing = validate_timing diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 9509fcbf886..6f50d925ccb 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -821,3 +821,25 @@ let%test_module "Test transaction logic." = ) (run_zkapp_cmd ~fee_payer ~fee ~accounts txns) ) end ) + +(* This module tests Inputs.Stack *) +let%test_module "Test stack module" = + ( module struct + module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = + let s = [1;2;3] in + match (Stack.pop s) with + | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) + | None -> assert(false) + + let%test_unit "Ensure pop works on empty list." = + match (Stack.pop (Stack.empty ())) with + | Some _ -> assert(false) + | None -> assert(true) + + let%test_unit "Ensure push functionality works." = + let s = [1;2;3] in + let pushed = Stack.push 0 ~onto:s in + assert(List.equal Int.equal pushed [0;1;2;3]) + end ) + From e112c29ec71854c14e9beb004d8dc7f10c5d083f Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 15/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 6f50d925ccb..393d35dd990 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -826,11 +826,19 @@ let%test_module "Test transaction logic." = let%test_module "Test stack module" = ( module struct module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = - let s = [1;2;3] in - match (Stack.pop s) with - | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) - | None -> assert(false) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack,top,tail)) + ~f:(fun (stack,top,tail) -> + match (Stack.pop stack) with + | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) + | None -> assert(false)) let%test_unit "Ensure pop works on empty list." = match (Stack.pop (Stack.empty ())) with @@ -838,8 +846,16 @@ let%test_module "Test stack module" = | None -> assert(true) let%test_unit "Ensure push functionality works." = - let s = [1;2;3] in - let pushed = Stack.push 0 ~onto:s in - assert(List.equal Int.equal pushed [0;1;2;3]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in + let pushed' = List.append stack' stack in + return (pushed,pushed')) + ~f:(fun (pushed,pushed') -> + assert(List.equal Int.equal pushed pushed')) end ) + From 4c206a2126aa1d8f54f939a18d3764312087cc17 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Tue, 14 Mar 2023 19:51:32 -0400 Subject: [PATCH 16/24] Run make reformat to correct formatting --- .../mina_transaction_logic.ml | 29 ++++++---- .../test/transaction_logic.ml | 57 ++++++++++--------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index cb4b2a28ea5..c498ef56540 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -546,16 +546,24 @@ module type S = sig -> ledger -> bool Or_error.t - module For_tests : sig - module Stack (Elt : sig type t end) : sig - type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a - val empty : unit -> 'a list - val is_empty : 'a list -> bool - val pop_exn : t -> Elt.t * t - val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t - end + module For_tests : sig + module Stack (Elt : sig + type t + end) : sig + type t = Elt.t list + + val if_ : bool -> then_:'a -> else_:'a -> 'a + + val empty : unit -> 'a list + + val is_empty : 'a list -> bool + + val pop_exn : t -> Elt.t * t + + val pop : t -> (Elt.t * t) option + + val push : Elt.t -> onto:Elt.t list -> t + end val validate_timing_with_min_balance : account:Account.t @@ -2558,7 +2566,6 @@ module Make (L : Ledger_intf.S) : >>= Mina_stdlib.Result.List.map ~f:(apply_transaction_second_pass ledger) module For_tests = struct - module Stack = Inputs.Stack let validate_timing_with_min_balance = validate_timing_with_min_balance diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 393d35dd990..5d0871b923a 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -828,34 +828,39 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack,top,tail)) - ~f:(fun (stack,top,tail) -> - match (Stack.pop stack) with - | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) - | None -> assert(false)) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = - match (Stack.pop (Stack.empty ())) with - | Some _ -> assert(false) - | None -> assert(true) + match Stack.pop (Stack.empty ()) with + | Some _ -> + assert false + | None -> + assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in - let pushed' = List.append stack' stack in - return (pushed,pushed')) - ~f:(fun (pushed,pushed') -> - assert(List.equal Int.equal pushed pushed')) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) - - From 624aeaf552a4e613327f590f0932d94e92b1d85b Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 17/24] Add tests for Stack --- .../test/transaction_logic.ml | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 5d0871b923a..5f37e61380f 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -828,19 +828,12 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack, top, tail)) - ~f:(fun (stack, top, tail) -> - match Stack.pop stack with - | Some (x, xs) -> - assert (Int.equal x top && List.equal Int.equal xs tail) - | None -> - assert false ) + let s = [ 1; 2; 3 ] in + match Stack.pop s with + | Some (x, xs) -> + assert (Int.equal x 1 && List.equal Int.equal xs [ 2; 3 ]) + | None -> + assert false let%test_unit "Ensure pop works on empty list." = match Stack.pop (Stack.empty ()) with @@ -850,17 +843,7 @@ let%test_module "Test stack module" = assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = - List.fold_right stack' ~init:stack ~f:(fun x s -> - Stack.push x ~onto:s ) - in - let pushed' = List.append stack' stack in - return (pushed, pushed')) - ~f:(fun (pushed, pushed') -> - assert (List.equal Int.equal pushed pushed') ) + let s = [ 1; 2; 3 ] in + let pushed = Stack.push 0 ~onto:s in + assert (List.equal Int.equal pushed [ 0; 1; 2; 3 ]) end ) From 334882d740984c1394f6cf8085c99f1d1ce0d7bb Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 18/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 5f37e61380f..5d0871b923a 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -828,12 +828,19 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - let s = [ 1; 2; 3 ] in - match Stack.pop s with - | Some (x, xs) -> - assert (Int.equal x 1 && List.equal Int.equal xs [ 2; 3 ]) - | None -> - assert false + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = match Stack.pop (Stack.empty ()) with @@ -843,7 +850,17 @@ let%test_module "Test stack module" = assert true let%test_unit "Ensure push functionality works." = - let s = [ 1; 2; 3 ] in - let pushed = Stack.push 0 ~onto:s in - assert (List.equal Int.equal pushed [ 0; 1; 2; 3 ]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) From 0ff36947a90046aa6eb82fbe0678ccd7f995fea4 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Mon, 3 Apr 2023 13:50:35 -0400 Subject: [PATCH 19/24] Remove polymorphic types in module For_tests.Stack --- src/lib/transaction_logic/mina_transaction_logic.ml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/transaction_logic/mina_transaction_logic.ml b/src/lib/transaction_logic/mina_transaction_logic.ml index c498ef56540..93e9c2f0599 100644 --- a/src/lib/transaction_logic/mina_transaction_logic.ml +++ b/src/lib/transaction_logic/mina_transaction_logic.ml @@ -552,17 +552,17 @@ module type S = sig end) : sig type t = Elt.t list - val if_ : bool -> then_:'a -> else_:'a -> 'a + val if_ : bool -> then_:t -> else_:t -> t - val empty : unit -> 'a list + val empty : unit -> t - val is_empty : 'a list -> bool + val is_empty : t -> bool val pop_exn : t -> Elt.t * t val pop : t -> (Elt.t * t) option - val push : Elt.t -> onto:Elt.t list -> t + val push : Elt.t -> onto:t -> t end val validate_timing_with_min_balance : From 8d26f7ced461e0860cfb56986e26d2c513a8fed7 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 20/24] Add tests for Stack --- .../test/transaction_logic.ml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 5d0871b923a..3554389afce 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -864,3 +864,25 @@ let%test_module "Test stack module" = ~f:(fun (pushed, pushed') -> assert (List.equal Int.equal pushed pushed') ) end ) + +(* This module tests Inputs.Stack *) +let%test_module "Test stack module" = + ( module struct + module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = + let s = [1;2;3] in + match (Stack.pop s) with + | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) + | None -> assert(false) + + let%test_unit "Ensure pop works on empty list." = + match (Stack.pop (Stack.empty ())) with + | Some _ -> assert(false) + | None -> assert(true) + + let%test_unit "Ensure push functionality works." = + let s = [1;2;3] in + let pushed = Stack.push 0 ~onto:s in + assert(List.equal Int.equal pushed [0;1;2;3]) + end ) + From ca433ee5ed40f9f6e0885c3dbc1b85a49d345dc0 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 21/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 3554389afce..b2a09d22256 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -869,11 +869,19 @@ let%test_module "Test stack module" = let%test_module "Test stack module" = ( module struct module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = - let s = [1;2;3] in - match (Stack.pop s) with - | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) - | None -> assert(false) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack,top,tail)) + ~f:(fun (stack,top,tail) -> + match (Stack.pop stack) with + | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) + | None -> assert(false)) let%test_unit "Ensure pop works on empty list." = match (Stack.pop (Stack.empty ())) with @@ -881,8 +889,16 @@ let%test_module "Test stack module" = | None -> assert(true) let%test_unit "Ensure push functionality works." = - let s = [1;2;3] in - let pushed = Stack.push 0 ~onto:s in - assert(List.equal Int.equal pushed [0;1;2;3]) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in + let pushed' = List.append stack' stack in + return (pushed,pushed')) + ~f:(fun (pushed,pushed') -> + assert(List.equal Int.equal pushed pushed')) end ) + From 6ea93ced81778c296481a7c697fb6cb7dcd1a558 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Tue, 14 Mar 2023 19:51:32 -0400 Subject: [PATCH 22/24] Run make reformat to correct formatting --- .../test/transaction_logic.ml | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index b2a09d22256..5cf4ae64e2c 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -871,34 +871,39 @@ let%test_module "Test stack module" = module Stack = Transaction_logic.For_tests.Stack (Int) let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack,top,tail)) - ~f:(fun (stack,top,tail) -> - match (Stack.pop stack) with - | Some (x,xs) -> assert(Int.equal x top && (List.equal (Int.equal) xs tail)) - | None -> assert(false)) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%map stack = Generator.list_non_empty Generator.size in + let top = List.hd_exn stack in + let tail = List.tl_exn stack in + (stack, top, tail)) + ~f:(fun (stack, top, tail) -> + match Stack.pop stack with + | Some (x, xs) -> + assert (Int.equal x top && List.equal Int.equal xs tail) + | None -> + assert false ) let%test_unit "Ensure pop works on empty list." = - match (Stack.pop (Stack.empty ())) with - | Some _ -> assert(false) - | None -> assert(true) + match Stack.pop (Stack.empty ()) with + | Some _ -> + assert false + | None -> + assert true let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = List.fold_right stack' ~init:stack ~f:(fun x s -> Stack.push x ~onto:s) in - let pushed' = List.append stack' stack in - return (pushed,pushed')) - ~f:(fun (pushed,pushed') -> - assert(List.equal Int.equal pushed pushed')) + Quickcheck.test ~trials + (let open Quickcheck in + let open Generator.Let_syntax in + let%bind stack = Generator.list_non_empty Generator.size in + let%bind stack' = Generator.list_non_empty Generator.size in + let pushed = + List.fold_right stack' ~init:stack ~f:(fun x s -> + Stack.push x ~onto:s ) + in + let pushed' = List.append stack' stack in + return (pushed, pushed')) + ~f:(fun (pushed, pushed') -> + assert (List.equal Int.equal pushed pushed') ) end ) - - From 6283ae1313663c211bba93b485c3f64b4711b71a Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 16:46:59 -0500 Subject: [PATCH 23/24] Add tests for Stack --- .../test/transaction_logic.ml | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 5cf4ae64e2c..2217e07b018 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -907,3 +907,25 @@ let%test_module "Test stack module" = ~f:(fun (pushed, pushed') -> assert (List.equal Int.equal pushed pushed') ) end ) + +(* This module tests Inputs.Stack *) +let%test_module "Test stack module" = + ( module struct + module Stack = Transaction_logic.For_tests.Stack (Int) + let%test_unit "Ensure pop works on non-empty list." = + let s = [1;2;3] in + match (Stack.pop s) with + | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) + | None -> assert(false) + + let%test_unit "Ensure pop works on empty list." = + match (Stack.pop (Stack.empty ())) with + | Some _ -> assert(false) + | None -> assert(true) + + let%test_unit "Ensure push functionality works." = + let s = [1;2;3] in + let pushed = Stack.push 0 ~onto:s in + assert(List.equal Int.equal pushed [0;1;2;3]) + end ) + From fb95e90ff72aa7a5ca0b0fa8d139a1bbacc0ca04 Mon Sep 17 00:00:00 2001 From: Greg Trost Date: Wed, 8 Mar 2023 17:09:41 -0500 Subject: [PATCH 24/24] Use Generator library in Inputs.Stack tests --- .../test/transaction_logic.ml | 65 ------------------- 1 file changed, 65 deletions(-) diff --git a/src/lib/transaction_logic/test/transaction_logic.ml b/src/lib/transaction_logic/test/transaction_logic.ml index 2217e07b018..5d0871b923a 100644 --- a/src/lib/transaction_logic/test/transaction_logic.ml +++ b/src/lib/transaction_logic/test/transaction_logic.ml @@ -864,68 +864,3 @@ let%test_module "Test stack module" = ~f:(fun (pushed, pushed') -> assert (List.equal Int.equal pushed pushed') ) end ) - -(* This module tests Inputs.Stack *) -let%test_module "Test stack module" = - ( module struct - module Stack = Transaction_logic.For_tests.Stack (Int) - - let%test_unit "Ensure pop works on non-empty list." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%map stack = Generator.list_non_empty Generator.size in - let top = List.hd_exn stack in - let tail = List.tl_exn stack in - (stack, top, tail)) - ~f:(fun (stack, top, tail) -> - match Stack.pop stack with - | Some (x, xs) -> - assert (Int.equal x top && List.equal Int.equal xs tail) - | None -> - assert false ) - - let%test_unit "Ensure pop works on empty list." = - match Stack.pop (Stack.empty ()) with - | Some _ -> - assert false - | None -> - assert true - - let%test_unit "Ensure push functionality works." = - Quickcheck.test ~trials - (let open Quickcheck in - let open Generator.Let_syntax in - let%bind stack = Generator.list_non_empty Generator.size in - let%bind stack' = Generator.list_non_empty Generator.size in - let pushed = - List.fold_right stack' ~init:stack ~f:(fun x s -> - Stack.push x ~onto:s ) - in - let pushed' = List.append stack' stack in - return (pushed, pushed')) - ~f:(fun (pushed, pushed') -> - assert (List.equal Int.equal pushed pushed') ) - end ) - -(* This module tests Inputs.Stack *) -let%test_module "Test stack module" = - ( module struct - module Stack = Transaction_logic.For_tests.Stack (Int) - let%test_unit "Ensure pop works on non-empty list." = - let s = [1;2;3] in - match (Stack.pop s) with - | Some (x,xs) -> assert(Int.equal x 1 && (List.equal (Int.equal) xs [2;3])) - | None -> assert(false) - - let%test_unit "Ensure pop works on empty list." = - match (Stack.pop (Stack.empty ())) with - | Some _ -> assert(false) - | None -> assert(true) - - let%test_unit "Ensure push functionality works." = - let s = [1;2;3] in - let pushed = Stack.push 0 ~onto:s in - assert(List.equal Int.equal pushed [0;1;2;3]) - end ) -