-
Notifications
You must be signed in to change notification settings - Fork 285
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
test(core-state): increase coverage to 100% #3543
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…egisterIndexers function for use in Sandbox
… by address and indexers
…y and addresses, using indexers
…s, addresses and usernames
…ex, hasByUsername and hasByPublicKey
…into test/core-state
… search paramtere doesnt exist in set
…ecipient ID doesnt exist in the repository
… address params present
…function as iteratee
…attribute doesn't exist
… args in only place
faustbrian
approved these changes
Mar 11, 2020
ghost
deleted the
test/core-state
branch
March 11, 2020 04:35
ghost
mentioned this pull request
Mar 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adding tests for the
core-state
package.Some refactor work to support the tests.
I chose to reuse a
Sandbox
environment for each test, which sets up and injects every class needed. However, because of the way classes are tagged (and different classes need access to different tagged versions) this may create complications (see discussion below).Checklist
I've left some
TODO
s in the code to highlight areas where I was unsure what the intended behaviour was.Most of these issues occur in
WalletRepository
andTempWalletRepository
- since the latter inherits from the former. Inheritance can be useful for small classes to extend some simple base functionality, but if the two classes are designed to behave differently or become complex - it can become quite difficult to maintain. One problem is that a method in the extended class can call into a method in the base class, which itself calls a method back in the extended class. This can make it harder to reason about the code, it has the potential to cause subtle bugs and makes the code more difficult to maintain. I note here too that there is a 3rdPoolWalletRepository
which extends from this class and lives in a different package. It might be worth thinking about whether a shared common interface might be a better approach here?I found that I lost a lot of time setting up tests because of issues with tagging. When two versions of a class (using the same identifier) are bound via tags - if this identifier is then consumed by a third class which does not specify a tag - which tagged class should it fall back to? Is this an intended consequence, or are we using this "fallback" as a feature? I'd suggest that code should be explicit in its intentions, rather than implicit. In the
ServiceProvider
, theWalletRepository
andTempWalletRepository
classes are bound to the same identifier via tags. However,BlockState
consumes an untagged version of this identifier - what should this default to - or will it only ever exist in an environment where one tagged version could be injected? (If this is true, it would mean we cannot share the same initialisedSandbox
for all tests). Despite initialising the tests by binging the two classes as they are done in theServiceProvider
- inversify fails with:Ambiguous match found for serviceIdentifier
(suggesting that this would happen at runtime). In order to get the tests running, I’ve added a tag to theWalletRepository
consumed byBlockState
for now, but this isn’t the correct solution (since presumably we wantBlockState
to be able to work with both tagged versions), do let me know if anyone has suggestions on how to fix this, or whether I'm misunderstanding something...Finally, two tests are intentionally left failing in
StateBuilder.test.ts
as the code implementation here needs review.