-
Notifications
You must be signed in to change notification settings - Fork 4
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
Multi: unit test the backend #9
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
This updates the rosetta-sdk library to v0.5.0 and the backend server implementation in order to support v1.4.5 of the Rosetta specs. The sample rosetta-cli config files have been updated for the corresponding version v0.5.8 of the tool.
matheusd
force-pushed
the
testing
branch
2 times, most recently
from
November 5, 2020 20:55
150e38f
to
e130eb5
Compare
This adds tests to the current existing backenddb implementations. The tests are done in a closed-box format, only using the interface-defined functions. This helps to ensure the correct behavior of the implementations according to the current usage pattern of the functions within the backend. We also restrict implementations to only extending the tip with new blocks and to not overwrite already processed blocks to ensure block idempotency and prevent possible bugs that slip through to not put the database in an invalid state.
This changes the check done in /account/balance to use an exported function from the types package (CheckRosettaAccount) instead of dcrutil.DecodeAddress. Some Rosetta accounts aren't represented by standard Decred addresses. For example, pkscripts with a version > 0 or that are not standard P2PKH/P2SH addresses. These have a particular format that is not decodable by dcrutil.DecodeAddress. Previously this could cause calls to account/balance to fail for such addresses.
This fixes a bug where an amount specified without a currency field could trigger a panic.
This makes the RosettaOpsToTx function handle clients that specify negative debit amounts. Debits are supposed to be subtractions from an account (i.e. a transaction input) so clients may specify them in the same notation as that generated by block processing.
This changes the CombineTxSigs function ensure that all passed public keys and signatures are valid while combining inputs. This makes this function safer to use in situations where some of the pubkeys or signatures come from untrusted sources. It also helps to dected any signing problems earlier. Test cases were updated to account for the added restrictions.
This function will allow external callers to easily verify whether some RosettaError value corresponds to a given ErrorCode.
This allows more easily mocking or replacing the source of chain data during tests.
This allows testing specific concurrency values.
This adds a structure that can regularly report on block connected counts by the server. This will be used in a future commit to improve reporting of connected blocks.
This allows specifying the db instance directly, which will be used during tests.
This allows configuring the server to use a custom chain implementation. This will be used in tests to provide a mock backing chain.
This moves code related to chain syncing and reorging to a separate file to ease maintenance.
Previously, processing the chain was largely based on fetching blocks by height during pre-processing. While notifications are disabled during preprocessing, a reorg could happen while preprocessing blocks very close to the tip, potentially causing the DB data to be incorrectly stored. This changes the chain sync logic to exclusively follow valid branches by consulting the appropriate block headers instead of requesting blocks by height, thus making every chain switch deterministic.
This adds tests to assert the behavior of chain preprocessing, which generates the underlying data used for the Account service.
This adds tests that ensure the correct behavior when block notifications are received from the underlying chain.
This adds tests for basic server behavior, including the basic Run() function and block notifications.
This adds a special case for the genesis block on uninitialized databases to avoid an empty server failing certain calls.
This fixes an off-by-one error in size estimation, which was double counting the size varint in standard P2PKH scripts.
This fixes an issue in the ConstructionPreprocess function that was not correctly returning early in case of certain errors in the underlying chain.
There are still a couple of refactorings, tests and improvements possible but I'll leave those for a new PR, given this one is already very large. In any case, this provides unit tests for every service call of the backend and for the majority of the code paths. |
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.
Not ready for review yetThis updates the dcrros implementation to Rosetta's v1.4.5.
It also adds unit testing for the backend package, which houses the main Rosetta services.
While writing the tests, a few bugs were surfaced and corrected.