diff --git a/src/proto_alpha/lib_protocol/test/baking.ml b/src/proto_alpha/lib_protocol/test/baking.ml new file mode 100644 index 000000000..d609727c4 --- /dev/null +++ b/src/proto_alpha/lib_protocol/test/baking.ml @@ -0,0 +1,37 @@ +(**************************************************************************) +(* *) +(* Copyright (c) 2014 - 2018. *) +(* Dynamic Ledger Solutions, Inc. *) +(* *) +(* All rights reserved. No warranty, explicit or implicit, provided. *) +(* *) +(**************************************************************************) + +open Proto_alpha + +(** Tests for [bake_n] and [bake_until_end_cycle]. *) +let test_cycle () = + Context.init 5 >>=? fun (b,_) -> + Context.get_constants (B b) >>=? fun csts -> + let blocks_per_cycle = csts.parametric.blocks_per_cycle in + + let pp = fun fmt x -> Format.fprintf fmt "%ld" x in + + (* Tests that [bake_n n] bakes [n] blocks. *) + Block.bake_n 10 b >>=? fun b -> + Context.get_level (B b) >>=? fun curr_level -> + Assert.equal ~loc:__LOC__ Int32.equal "not the right level" pp + (Alpha_context.Raw_level.to_int32 curr_level) + 10l >>=? fun () -> + + (* Tests that [bake_until_cycle_end] returns a block at + level [blocks_per_cycle]. *) + Block.bake_until_cycle_end b >>=? fun b -> + Context.get_level (B b) >>=? fun curr_level -> + Assert.equal ~loc:__LOC__ Int32.equal "not the right level" pp + (Alpha_context.Raw_level.to_int32 curr_level) + blocks_per_cycle + +let tests = [ + Test.tztest "cycle" `Quick (test_cycle) ; +] diff --git a/src/proto_alpha/lib_protocol/test/main.ml b/src/proto_alpha/lib_protocol/test/main.ml index 58dc30fb5..7f8ffa959 100644 --- a/src/proto_alpha/lib_protocol/test/main.ml +++ b/src/proto_alpha/lib_protocol/test/main.ml @@ -16,4 +16,5 @@ let () = "double endorsement", Double_endorsement.tests ; "double baking", Double_baking.tests ; "seed", Seed.tests ; + "baking", Baking.tests ; ]