Draft: Cnt: adding a counter
What
This is a study project. I added a simple internal counter in the Context which can be increased by 1 in 2 ways:
- from octez-client:
octez-client increase counter from bootstrap4
- from a contract in Michelson with
CNT
primitive:
parameter unit ;
storage int ;
code { # This contract pushes counter and the counter is increased and pushed to the stack
DROP ; CNT ; NIL operation ; PAIR} ;
Why
This is a study project. Do not merge it.
How
I added a new command in the octez-client: increase counter
.
It sends a request to the tezos node to increase the global counter in the context.
The counter is saved when the new block is forged.
The counter can be alternatively increased with a CNT
primitive.
This primitive increases the counter in the context by 1 and puts the new counter
value on top of the stack.
Manually testing the MR
run in console 1
./src/bin_node/octez-sandboxed-node.sh 1 --connections 1
run in console 2
./src/bin_node/octez-sandboxed-node.sh 9 --connections 1
run in console 3
eval `./src/bin_client/octez-init-sandboxed-client.sh 1`
octez-autocomplete
octez-activate-alpha
octez-client increase counter from bootstrap4 &
octez-client bake for --minimal-timestamp
Updated counter: 1
octez-client increase counter from bootstrap4 &
octez-client bake for --minimal-timestamp
Updated counter: 2
octez-client originate contract mycnt1 transferring 10 from bootstrap1 running cnt.tz --init 1 --burn-cap 0.07425 &
octez-client bake for --minimal-timestamp
octez-client transfer 0 from bootstrap3 to mycnt1 &
octez-client bake for --minimal-timestamp
Updated counter: 3
octez-client transfer 0 from bootstrap2 to mycnt1 &
octez-client bake for --minimal-timestamp
Updated counter: 4
unit tests
> dune exec src/proto_alpha/lib_protocol/test/unit/main.exe \
-- --file test_cnt_repr.ml
qcheck random seed: 305030579
[13:35:42.078] [SUCCESS] (1/2) alpha: Cnt_storage.ml (Test counter init for internal count)
[13:35:42.080] [SUCCESS] (2/2) alpha: Cnt_storage.ml (Test counter increase for internal count)
integration tests
> dune exec tezt/tests/main.exe -- --file cnt.ml
qcheck random seed: 412981918
[13:26:18.749] [SUCCESS] (1/1) Alpha: Increasing intrernal counter with RPC
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rst
for the protocol and the environment,CHANGES.rst
at the root of the repository for everything else). -
Select suitable reviewers using the Reviewers
field below. -
Select as Assignee
the next person who should take action on that MR
Edited by Diana Savvatina