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

ZK-559: (part 2) unit tests for shielder-sdk #90

Merged
merged 59 commits into from
Jan 16, 2025
Merged

Conversation

kroist
Copy link
Collaborator

@kroist kroist commented Jan 15, 2025

No description provided.

@kroist kroist changed the title Unit tests part 2 ZK-559: (part 2) unit tests for shielder-sdk Jan 15, 2025
Copy link

github-actions bot commented Jan 15, 2025

Transaction NameMainCurrentDifference (%)
NewAccountNative20004192000407-0.00060%
DepositNative18279181827834-0.00460%
WithdrawNative18981621898150-0.00063%

@kroist kroist changed the base branch from main to sdk-unit-tests January 15, 2025 02:18
Copy link

github-actions bot commented Jan 15, 2025

📊 Coverage Report

📈 Total Coverage Summary

Type Covered Total Coverage
📝 Lines 148 411 ❌ 36%
📄 Statements 149 414 ❌ 35.99%
⚡ Functions 38 105 ❌ 36.19%
🔀 Branches 14 66 ❌ 21.21%

Coverage Legend

  • ✅ 100% Coverage
  • 🟡 80-99% Coverage
  • 🟠 50-79% Coverage
  • ❌ 0-49% Coverage

📁 File Coverage

📋 Detailed Coverage Report
File Lines Statements Functions Branches
zkOS-monorepo/ts/shielder-sdk/src/chain/contract.ts 4.76% 4.76% 7.14% 0%
zkOS-monorepo/ts/shielder-sdk/src/chain/relayer.ts 8.57% 8.57% 14.28% 0%
zkOS-monorepo/ts/shielder-sdk/src/constants.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/shielder/actions/deposit.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/shielder/actions/newAccount.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/shielder/actions/utils.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/shielder/actions/withdraw.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/shielder/client.ts 0% 0% 0% 0%
zkOS-monorepo/ts/shielder-sdk/src/shielder/state/events.ts 0% 0% 0% 0%
zkOS-monorepo/ts/shielder-sdk/src/shielder/state/index.ts 0% 0% 0% 0%
zkOS-monorepo/ts/shielder-sdk/src/shielder/state/storageSchema.ts 0% 0% 0% 0%
zkOS-monorepo/ts/shielder-sdk/src/shielder/state/sync.ts 0% 0% 0% 0%
zkOS-monorepo/ts/shielder-sdk/src/utils.ts 100% 100% 100% 100%

@kroist kroist marked this pull request as ready for review January 15, 2025 04:03
Copy link
Contributor

@guspiel guspiel left a comment

Choose a reason for hiding this comment

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

Haven't finished reading but left a few comments, will get back to it tomorrow.

@@ -107,11 +109,11 @@ class MockedConverter implements Converter {

class MockedNoteTreeConfig implements NoteTreeConfig {
treeHeight(): Promise<number> {
return Promise.resolve(13);
return Promise.resolve(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

nice that we have control over this and get short test values

)
).toBe(true);

// merkleRoot should be equal to input merkleRoot
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: These 3 lines are self-explanatory and don't really need comments, do they?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe they don't need comments, but my goal was to comment as much as I can

Copy link
Contributor

Choose a reason for hiding this comment

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

I claim that code with more comments is not always better. A comment helps if reading it is faster than reading the code being commented, or if it provides extra information, and this is not the case here.

So that it is not just me: https://medium.com/@bpnorlander/stop-writing-code-comments-28fef5272752

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm also a proponent of "good code doesn't have to be commented"

BUT

in such complex unit tests I really believe commenting is good.

Copy link
Contributor

Choose a reason for hiding this comment

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

disagreeing here but it's not a big deal, feel free to merge

@@ -1,7 +1,9 @@
import {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be really cool to see not only coverage percentage but also which lines are covered. Do you know if it's easy to do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you run pnpm coverage locally, you can see which lines are uncovered, however it's tricky to add that to report.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, it works for me. We probably can also use some vs code extension to overlay this on editor view, but it seems to take some time to configure.

ts/shielder-sdk/__tests/shielder/actions/deposit.test.ts Outdated Show resolved Hide resolved
ts/shielder-sdk/__tests/helpers.ts Show resolved Hide resolved
ts/shielder-sdk/__tests/shielder/actions/deposit.test.ts Outdated Show resolved Hide resolved
);
expect(isValid).toBe(true);

// Amount should be equal to input amount
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I suggest removing the 3 comments as the commented code is self-explanatory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

want to comment as much as it possible

)
).toBe(true);

// merkleRoot should be equal to input merkleRoot
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these 2 lines are self-explanatory, consider removing the 2 comments

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

want to comment as much as it possible

Copy link
Contributor

@guspiel guspiel left a comment

Choose a reason for hiding this comment

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

Nice coverage. Just a few comments.

ts/shielder-sdk/__tests/shielder/actions/deposit.test.ts Outdated Show resolved Hide resolved
ts/shielder-sdk/__tests/shielder/actions/deposit.test.ts Outdated Show resolved Hide resolved
);
expect(isValid).toBe(true);

// Amount should be equal to input amount
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the 3 comments below do not add value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

want to keep as commented as possible

ts/shielder-sdk/__tests/shielder/actions/withdraw.test.ts Outdated Show resolved Hide resolved
ts/shielder-sdk/__tests/shielder/actions/withdraw.test.ts Outdated Show resolved Hide resolved
ts/shielder-sdk/src/shielder/client.ts Show resolved Hide resolved
Base automatically changed from sdk-unit-tests to main January 16, 2025 13:11
@kroist kroist merged commit 70c5b53 into main Jan 16, 2025
9 checks passed
@kroist kroist deleted the unit-tests-part-2 branch January 16, 2025 14:04
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