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

Multi: unit test the backend #9

Merged
merged 25 commits into from
Nov 10, 2020
Merged

Multi: unit test the backend #9

merged 25 commits into from
Nov 10, 2020

Conversation

matheusd
Copy link
Member

@matheusd matheusd commented Oct 30, 2020

Not ready for review yet

This 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.

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 matheusd force-pushed the testing branch 2 times, most recently from 150e38f to e130eb5 Compare November 5, 2020 20:55
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.
@matheusd matheusd marked this pull request as ready for review November 6, 2020 14:36
@matheusd
Copy link
Member Author

matheusd commented Nov 6, 2020

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.

@matheusd matheusd merged commit 9eb159e into decred:master Nov 10, 2020
@matheusd matheusd deleted the testing branch November 10, 2020 13:00
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