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

refactor: mock interval in transaction success step #475

Merged
merged 64 commits into from
May 1, 2024

Conversation

goga-m
Copy link
Contributor

@goga-m goga-m commented Apr 19, 2024

Summary

All the server mocks & fixtures are in place, so it shouldn't affect the tests.

Checklist

  • My changes look good in both light AND dark mode
  • The change is not hardcoded to a single network, but has multi-asset in mind
  • I checked my changes for obvious issues, debug statements and commented code
  • Documentation (if necessary)
  • Tests (if necessary)
  • Ready to be merged

"https://ark-test.arkvault.io/api/transactions/ea63bf9a4b3eaf75a1dfff721967c45dce64eb7facf1aef29461868681b5c79b",
transactionsFixture,
),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned earlier, this will bite us later, arkvault should not be aware of PSDK internals, PSDK should be free to change implementation details and when that happens this change either will be obsolete or make tests fail which is far from ideal.

Copy link
Contributor Author

@goga-m goga-m Apr 19, 2024

Choose a reason for hiding this comment

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

@shahin-hq by adding a server mock, we are also ensuring that psdk functions properly and we are not muting a potential problem when signing or broadcasting. This is the approach that has been taken in vault, and it has indeed caught a lot of issues with sdk. By mocking the useTransactionConfirmation we are practically muting the problem, and would not be able to spot those issues, as we assume that psdk works fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not responsibility of arkvault to ensure PSDK functions properly, it is a unit test and should be limited to the SUT, it will introduce more breaking changes when we change stuff in PSDK, at the end of the day PSDK is a library and it has own tests, it is not up to consumer to ensure its behavior..
Also mocking it is not muting problem it is called isolating side factors, you have to rule out some factors when doing unit tests otherwise changing a single function implementation would cause hundreds of tests fail

Copy link
Contributor Author

@goga-m goga-m Apr 19, 2024

Choose a reason for hiding this comment

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

@shahin-hq in theory I agree with you, but practically in the case of arkvault, psdk was always tested through arkvault as it's the only consumer, although it's technically another package.

In arkvault we cover numerous cases that have been thoroughly tested and proven by time, and we have full unit coverage as well as e2e tests that cover a lot more (in terms of flows & edge cases) that are not handled in psdk. The approach from the beginning was to mock only the api requests (both for unit & e2e) so that psdk changes that are breaking could be foreseen or caught in arkvault as final protection layer before they go to production.

It would be fine to mock useTransactionConfirmation if there were tests that were handling all the transaction types. But if you look at the file there aren't any, there are just a couple of tests that check isConfirmed state

. So by mocking it, we are going blind on what's happening for the various tx types that the mentioned tests cover.

To give you another important example. There were recent breaking changes in psdk beta (develop branch) to support CSP, and have precompiled standalone tx schema validators, which is a breaking change. Arkvault is the only app that this can be tested, both in terms of QA but also in tests. If we mock psdk, we are losing the ability to catch important edge cases in transaction schema validations in arkvault that were probably missed in psdk. Something that I think we are going to see it in tests still because they are not fixed in feat/mainsail branch that uses psdk beta.

Copy link
Contributor Author

@goga-m goga-m Apr 24, 2024

Choose a reason for hiding this comment

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

As a matter of fact, it indeed happened with CSP as mentioned. https://github.com/ArdentHQ/arkvault/actions/runs/8801725477/job/24155794355?pr=472#step:9:10428 arkvault caught this validation error in transactions, which was due to a bug in psdk.

vitest.setup.ts Outdated
@@ -15,6 +15,10 @@ vi.mock("@/utils/debounce", () => ({
debounceAsync: (promise) => promise,
}));

vi.mock("@/utils/interval", () => ({
interval: (callback: () => void) => callback(),
}));
Copy link
Contributor

@shahin-hq shahin-hq Apr 19, 2024

Choose a reason for hiding this comment

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

I think adding this has a few implications:

  • This leaks implementation details of useConfirmedTransaction, when implementation of hook changes this will provide no value; besides having this along HTTP call mock makes stuff even worse
  • Makes tests hard to reason, if I had to work on the SendTransfer tests having this hidden configs/overrides would take time to discover
  • Having interval over setInterval for the sake of tests doesn't make sense to me..

Copy link
Contributor Author

@goga-m goga-m Apr 24, 2024

Choose a reason for hiding this comment

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

I see what you mean. The reason I moved it to a dedicated utility function was to have it centrally for better control instead of calling them here n there, it's not only for tests (think of debounce et.al). Plus that it makes it very easy to mock them in tests, instead of using fake timers. We do the same with "setTimeout" in ./src/utils/delay.ts, but I'll remove it, sure, and add fake timers. it's not an issue.

@ItsANameToo ItsANameToo merged commit abc2ab9 into develop May 1, 2024
57 checks passed
@ItsANameToo ItsANameToo deleted the refactor/reduce-tx-confirmation-interval branch May 1, 2024 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants