Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unit tests, mutation tests, other tests #29

Open
wants to merge 7 commits into
base: next
Choose a base branch
from

Conversation

dhsorens
Copy link

These add unit tests and mutation tests (both in the unit_tests.mligo).
See comments on the mutation tests for how the output should be interpreted.

A current bug in Ligo is giving problems for test.mligo.

@@ -0,0 +1,98 @@
(* This is a unit testing framework for ctez *)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the different between test.mligo and unit_test.mligo? Please indicate in file comments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed a commit that:

  • Adds comments at the head of each file explaining exactly what is tested and how
  • Adds the .py file that generates the data and expected values
  • Updates the test_params file with the parameters generated by the .py file

… This necesstiated changing test_params for reproducibility.
@dhsorens
Copy link
Author

dhsorens commented Sep 23, 2021

Have just found some bugs in test.mligo that should get resolved before merging this. Working on it now.

…nd the special cases induced by the unit tests themselves.
…out the commands in the main function. This is a ligo bug that should hopefully be fixed soon. Tests on the drift functionality will come after some ligo bug fixes.
@dhsorens
Copy link
Author

The tests here should run and pass with the current codebase, with the following caveats:

  1. The unit tests return a list of mutations that still passed the tests. In the comments in unit_test.mligo you can find justification for each of these.
  2. Due to a ligo bug, the tests in test.mligo will run only if you comment out the update_consumer command in the main function, which is triggered before each of the trade functions.
  3. I removed testing on the drift function, as that still requires some bug fixes from ligo to work. Once those bug fixes are in I can write the test and add it to the testing suite.

In case the comments in test.mligo and unit_test.mligo were not clear enough:

  1. test.mligo ensures that when a swap actually happens, the amount traded can be calculated by a simple formula with the trade_dtez_for_dcash and trade_dcash_for_dtez functions, as was planned and expected.
  2. The tests in unit_test.mligo compares the actual calculation of these trade functions to the known calculation, derived mathematically from the isoutility curve. There is a slight loss of accuracy with the current implementation so it checks within a small margin of error (0.01%).

x = random.randint(0,100000000000000) # between 0 and 100_000_000 XTZ
y = random.randint(0,100000000000000) # between 0 and 100_000_000 CTEZ
dx = random.randint(0, min(x,y)) # so as to not exceed the supply
target = random.randint(0, 28147497671065600) # betweeen 0 and 100
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 * 2**48 is more readable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Changed and pushed.

# Generate the following vector:
# (x, y, dx, target, rounds, const_fee)
for i in range(n):
x = random.randint(0,100000000000000) # between 0 and 100_000_000 XTZ
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10**8

Do you mutez though?

Copy link
Author

@dhsorens dhsorens Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the parameter x varies between 0 and 100_000_000_000_000 mutez, or 100_000_000 tez (did I understand your question right?)

for i in range(len(rand_data)):
if switch:
(x,y,dy,a,rounds,const_fee) = rand_data[i]
b = 281474976710656
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2**48

Copy link
Author

@dhsorens dhsorens Sep 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Changed and pushed.

couillardcharles pushed a commit to bender-labs/ctez that referenced this pull request Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants