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

[trello.com/c/QSbUdocE]: KlyWalletService tests #666

Open
wants to merge 1 commit into
base: trello.com/c/dmJg0inY
Choose a base branch
from

Conversation

ChrisBenua
Copy link
Collaborator

KlyWalletService test.

For testing purposes KlyNodeApiServiceProtocol and KlyTransactionFactoryProtocol were introduced.

For testing URL-request inside sendTransaction RpcRequestBody was used. To return real response body, I've used KlyTransactionSubmitModel.

Because LiskKit inside uses private URLSession, default practice using MockURLProtocol won't work, because it requires to instantiate URLSession with custom URLSessionConfiguration. So I've used swizzling for mocking URLSession.init. Because internally URLSession.init is actually class method, so for swizzling we should exchange two class methods implementations:

guard let originalMethod = class_getClassMethod(URLSession.self, originalSelector),
           let swizzledMethod = class_getClassMethod(URLSession.self, swizzledSelector) else { return }

Inside swizzled method we change actual URLConfiguration with custom URLConfiguration with mocking using MockURLProtocol

@ChrisBenua ChrisBenua self-assigned this Jan 22, 2025
@ChrisBenua ChrisBenua force-pushed the trello.com/c/dmJg0inY branch from a3e5e2f to 8dbf57e Compare January 24, 2025 20:48
@ChrisBenua ChrisBenua force-pushed the trello.com/c/QSbUdocE branch from 54ceb4c to 0efad12 Compare January 24, 2025 21:05
@ChrisBenua ChrisBenua force-pushed the trello.com/c/QSbUdocE branch from 0efad12 to 6966ddc Compare January 24, 2025 21:18
@ChrisBenua ChrisBenua marked this pull request as ready for review January 24, 2025 21:21
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.

1 participant