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

feat: unit improvements #13

Merged
merged 33 commits into from
Apr 10, 2024
Merged

Conversation

gomesalexandre
Copy link
Contributor

@gomesalexandre gomesalexandre commented Apr 9, 2024

Description

This PR:

  • adds full coverage including all branches
  • runs CI on PRs and pushes targeted to develop/main
  • uses OZ safeTransfer / safeTransferFrom for transfers

As the current last PR of the stack, also adds some improvements to the contract as noted by @0xean in #2, namely:

Not sure on this one, but do we want to also emit the oldRuneAddress if we are changing it. (#2 (comment))

can we do better than this? I would imagine rune addresses are specific length / number of bytes so we might be able to (#2 (comment))

Issue

Screenshots

image

@gomesalexandre gomesalexandre marked this pull request as draft April 9, 2024 14:15
@gomesalexandre gomesalexandre self-assigned this Apr 9, 2024
@gomesalexandre gomesalexandre marked this pull request as ready for review April 9, 2024 18:42
@gomesalexandre gomesalexandre force-pushed the feat_pausable_contract branch from 7ec7e1f to 1994426 Compare April 9, 2024 18:44
@gomesalexandre gomesalexandre force-pushed the feat_unit_tests_full_coverage branch from c678d8f to a4c9a78 Compare April 9, 2024 18:44
@gomesalexandre gomesalexandre removed their assignment Apr 9, 2024
Comment on lines +42 to +45
- name: Generate coverage report
run: |
forge coverage --report summary
id: coverage
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note this doesn't exit 1 on non-100% coverage unfortunately. Since the output:

Compiling 39 files with 0.8.25
Solc 0.8.25 finished in 2.42s
Compiler run �[32msuccessful!�[0m
Analysing contracts...
Running tests...
| File                  | % Lines         | % Statements    | % Branches      | % Funcs         |
|-----------------------|-----------------|-----------------|-----------------|-----------------|
| src/FoxStaking.sol    | 100.00% (37/37) | 100.00% (38/38) | 100.00% (14/14) | 100.00% (14/14) |
| test/FoxStaking.t.sol | 100.00% (1/1)   | 100.00% (1/1)   | 100.00% (0/0)   | 100.00% (1/1)   |
| Total                 | 100.00% (38/38) | 100.00% (39/39) | 100.00% (14/14) | 100.00% (15/15) |

is more than likely to stay pretty much the same as we're not going to add more contract files/test files, do we want to have some smallish awk/sed/grep script here to exit 1 on non-100% coverage so that CI can fail? e.g something like this (ChatGPT-generated, untested but the idea is to rely on the output being consistent, filter out the irrelevant lines, and ensure both FoxStaking, FoxStaking.t and Total lines are 100.00%.

- name: Check coverage for 100%
  run: |
    forge coverage --report summary | tee coverage.txt
    # Assuming the coverage summary always starts at a known line after "Running tests..."
    tail -n +10 coverage.txt > trimmed_coverage.txt
    if grep -v '100.00%' trimmed_coverage.txt; then
      echo "Not all coverage metrics are 100%"
      exit 1
    else
      echo "All coverage metrics are 100%"
    fi

Alternatively, forge coverage can output lcov which we may be able to use instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re: Using lcov to fail CI on non-100% :sad: :

image

Copy link
Member

Choose a reason for hiding this comment

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

We'll likely have more files as our test suites expand, but simply checking the total should be totally sufficient.

Could easily have a brute force check of the test with a regex to assert that any number preceding a % symbol is the string 100.00, which would cover all files regardless of how many we add in the future

@gomesalexandre gomesalexandre force-pushed the feat_pausable_contract branch from 1994426 to 968cac1 Compare April 9, 2024 22:10
@gomesalexandre gomesalexandre force-pushed the feat_unit_tests_full_coverage branch 2 times, most recently from ab8e855 to 0e80a13 Compare April 10, 2024 06:44
@gomesalexandre gomesalexandre changed the base branch from feat_pausable_contract to main April 10, 2024 06:45
@woodenfurniture woodenfurniture force-pushed the feat_unit_tests_full_coverage branch from 1b21631 to 476030f Compare April 10, 2024 23:17
Copy link
Member

@woodenfurniture woodenfurniture left a comment

Choose a reason for hiding this comment

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

Getting this in to keep things unblocked, will follow up on coverage assertion for CI re this comment
#13 (comment)

@woodenfurniture woodenfurniture merged commit 1f7b013 into main Apr 10, 2024
1 check passed
@0xean 0xean deleted the feat_unit_tests_full_coverage branch May 29, 2024 17:59
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.

smart contract unit tests
2 participants