Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Updater unit tests#6913

Closed
lght wants to merge 29 commits into
openethereum:masterfrom
lght:updater-unit-tests
Closed

Updater unit tests#6913
lght wants to merge 29 commits into
openethereum:masterfrom
lght:updater-unit-tests

Conversation

@lght
Copy link
Copy Markdown

@lght lght commented Oct 27, 2017

Updater Unit Tests

The main point of this PR is to provide basic unit tests, covering all members of the Updater.

Through the process of writing tests, TestBlockChainClient is also undergoing some pretty heavy refactoring. The test client will now use an in-memory blockchain instead of the current HashMap.

The Operations contract is the central feature of Updater. Contracts are executed locally using Parity's EVM interpreter. I still need to write unit tests exercising the smart contract functionality.

Integration tests will target the Kovan test network. One cool possibility would be to make the tests generic across all available testnets. Pluggable consensus and spec configuration should make this pretty straightforward. Integration tests will likely go in their own PR.

Victories

All tests pass!

Shortcomings

Current tests are stupid simple, and test the setup of Updater more than anything else
Complex tests for the Operations contract are needed

TODO

Unit tests are still needed for:

  • deploying Operations contract to in-memory blockchain
  • pushing/executing transactions for relevant parts of the Operations contract

TestBlockChainClient needs to be refactored to use its in-memory blockchain for all block operations, instead of relying on the current HashMap-based mock blockchain.

There are a couple other things I want to do, but fall outside the scope of this pull request.

Write integration tests targeting Kovan (eventually all testnets)

Create a standalone test crate:

  • There are a number of test helpers useful across crates
  • Rust doesn't enable sharing structs directly from another crate's tests module
  • devtools started (in-part?) to address this issue
    • fairly bare-bones, needs feature enhancement, additional structs and restructuring
    • may be able to lower (re)compilation overhead by messing w/ file structure
  • The current method for using test helpers in other crates is to:
    • split them into their own module
    • export with pub use/mod in the lib.rs of the crate
  • Splitting off useful test helpers may turn out to be the best way to go
    • less fighting with Rust build tools
    • test docs could include a readme for how test helpers are structured
    • the current method is definitely more modular
    • naming and structuring idiosyncracies could become an issue
  • A standalone test crate would be a powerful tool unto itself
    • similar to ethrun using parity-ethabi, a fully-featured devtools could be utilized by 3rd-party projects

A hybrid of the current approach and a standalone crate may be possible. I'm thinking this might look like each Parity crate having its own publicly accessible test helper crate. To save on compilation overhead, the crates could be hidden behind feature flags. Then a separate, root-level crate (devtools?) could import all the public test crates from each Parity component.

Not sure if this hybrid approach would actually work, or is a total pipedream. Thoughts?


This change is Reviewable

@parity-cla-bot
Copy link
Copy Markdown

It looks like @lght hasn'signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.parity.io

Once you've signed, plesae reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@lght lght added P5-sometimesoon 🌲 Issue is worth doing soon. A0-pleasereview 🤓 Pull request needs code review. labels Oct 27, 2017
@NikVolf NikVolf added M4-core ⛓ Core client code / Rust. and removed P5-sometimesoon 🌲 Issue is worth doing soon. labels Oct 27, 2017
@NikVolf
Copy link
Copy Markdown
Contributor

NikVolf commented Oct 27, 2017

why commits from @arkpar are included in this pr?
rebase to master probably?

@lght
Copy link
Copy Markdown
Author

lght commented Oct 27, 2017

[clabot:check]

@parity-cla-bot
Copy link
Copy Markdown

It looks like @lght signed our Contributor License Agreement. 👍

Many thanks,

Parity Technologies CLA Bot

@lght
Copy link
Copy Markdown
Author

lght commented Oct 27, 2017

@NikVolf I know, I tried to roll back to master before that contribution. Still not sure how the two commits got rolled up together.

Any recs to detangle that commit?

@NikVolf
Copy link
Copy Markdown
Contributor

NikVolf commented Oct 27, 2017

just merge latest master, reset soft to it, then add, commit and force push
something like this, just make sure you backup the branch though :)

git fetch
git merge origin/master
git reset --soft origin/master
git commit -a -m "Updater unit tests"
git push origin HEAD --force

@NikVolf
Copy link
Copy Markdown
Contributor

NikVolf commented Oct 27, 2017

oh a since it's a fork, make sure your master is the same as paritytech::master

Signed-off-by: lght <cole@parity.io>
@lght lght force-pushed the updater-unit-tests branch from 95a19f1 to 0083982 Compare October 27, 2017 17:48
@lght
Copy link
Copy Markdown
Author

lght commented Oct 27, 2017

woot! that worked, thanks so much :) 👍

lght added 3 commits October 27, 2017 12:23
Signed-off-by: lght <cole@parity.io>
Signed-off-by: lght <cole@parity.io>
Signed-off-by: lght <cole@parity.io>
}
}

pub struct NoopDBRestore;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add a doc comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

just saw this. added doc comments to that struct and the following trait.

was planning to move the split-out test classes shared across crates to a central parity-test crate. think this would be a worthwhile change, but wanted to consult the team before starting in on the work. what are your thoughts on taking this approach?

lght added 2 commits October 27, 2017 18:01
Signed-off-by: lght <cole@parity.io>
Signed-off-by: lght <cole@parity.io>
@5chdn 5chdn added this to the 1.9 milestone Oct 29, 2017
lght added 2 commits October 31, 2017 15:28
First steps to implementing calling into the local Operations contract
from TestBlockChainClient

Signed-off-by: lght <cole@parity.io>
Signed-off-by: lght <cole@parity.io>

[fix] UpdaterState set in test constructor, tests::info passes

Signed-off-by: lght <cole@parity.io>

[fix] All unit tests passing, using kvdb_memory-backed blockchain

Signed-off-by: lght <cole@parity.io>

[minor fix] corrected path to test helper

Signed-off-by: lght <cole@parity.io>

[minor fixes] dependency refactors and new Spec::new_test_kovan()

Signed-off-by: lght <cole@parity.io>

[minor fix] ethcore::snapshot::account test dependency fix

Signed-off-by: lght <cole@parity.io>

[fix] Dependency issue finally fixed

Signed-off-by: lght <cole@parity.io>
@lght lght force-pushed the updater-unit-tests branch from 967399c to eb9da9b Compare November 2, 2017 02:39
@lght lght removed the A0-pleasereview 🤓 Pull request needs code review. label Nov 2, 2017
@5chdn 5chdn added the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Nov 2, 2017
@lght lght force-pushed the updater-unit-tests branch from b2ff878 to b55d5c5 Compare November 3, 2017 01:52
@lght lght added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Nov 9, 2017
Operations.sol and derived files under updater/res were added
accidentally, and only used for local analysis purposes.

Signed-off-by: lght <cole@parity.io>
@5chdn
Copy link
Copy Markdown
Contributor

5chdn commented Nov 28, 2017

9 tests failed.

@lght
Copy link
Copy Markdown
Author

lght commented Nov 28, 2017

Yeah, I noticed that too. 👎

Those are all tests for rpc, which are not part of this PR. Think those errors came over from a merge with master. ~~~If those tests are fixed in main, I can pull down the changes and merge with this PR.~~~

Pulled down the latest master, and this problem still exists.

From latest CI run:

failures:
    v1::tests::mocked::eth::rpc_eth_call
    v1::tests::mocked::eth::rpc_eth_call_default_block
    v1::tests::mocked::eth::rpc_eth_call_latest
    v1::tests::mocked::parity::rpc_parity_call
    v1::tests::mocked::traces::rpc_trace_call
    v1::tests::mocked::traces::rpc_trace_call_state_pruned
    v1::tests::mocked::traces::rpc_trace_multi_call
    v1::tests::mocked::traces::rpc_trace_raw_transaction
    v1::tests::mocked::traces::rpc_trace_raw_transaction_state_pruned

test result: FAILED. 264 passed; 9 failed; 4 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--lib'
ERROR: Job failed: exit code 1

Copy link
Copy Markdown
Collaborator

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Grumbles

Comment thread updater/src/updater.rs Outdated
// against a real testnet.

//#[test]
//fn operations_call_clients_required() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Commented code?

Comment thread updater/src/updater.rs Outdated
return;
}
}
if self.operations.lock().is_none() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Indentation issues.

Comment thread sync/src/test_snapshot.rs
manifest: Option<ManifestData>,
chunks: HashMap<H256, Bytes>,

restoration_manifest: Mutex<Option<ManifestData>>,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be simple to have a:

struct Wrapped(Mutex<TestSnapshotService>);
impl SnapshotService for Wrapped {

}

instead of maintaining all those Mutexes/locks here.

Copy link
Copy Markdown
Author

@lght lght Jan 15, 2018

Choose a reason for hiding this comment

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

That would be simpler. ~~~Since this PR is already fairly large, can we save that change for another PR to refactor TestSnapshotSevice?~~~ Going to put my focus into refactoring TestSnapshotService to merge this PR as quickly as possible since it is holding #6896.

There are a number of refactors that will need to happen after #6896 is merged. I would prefer to save further refactors for TestSnapshotService until after #6896 and #7038 are merged.

Update: Problems with jsonrpc tests brought up another issue with TestSnapshotService. I'll try to resolve the issues for the RPC API, and see how much refactoring will be necessary to replace all instances of TestSnapshotService with Wrapped(Mutex<TestSnapshotService>).

Comment thread ethcore/src/spec/spec.rs Outdated
load_bundled!("ethereum/olympic")
}

/// Create a new spec for Operations contract
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Indentation.

Comment thread ethcore/src/spec/spec.rs Outdated
}

/// Create a new Spec with Kovan testnet using the AuthorityRound consensuse engine (not requiring work).
pub fn new_test_kovan() -> Self {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Indentation.

Comment thread ethcore/src/client/test_client.rs Outdated

/// Convenience method to retrieve current state from a given state_db
pub fn get_in_memory_state(&self) -> Result<State<StateDB>, EvmTestError> {
{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Additional block unnecessary.

Comment thread ethcore/src/client/test_client.rs Outdated

/// Convenience method to retrieve state from a fresh state_db
pub fn get_new_state(&self) -> Result<State<StateDB>, EvmTestError> {
let (_, state_db) = get_in_memory_db(&self.spec).unwrap();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why unwrap and not ? seems that the error type is the same.

Comment thread ethcore/src/client/test_client.rs Outdated
}

/// Convenience method to retrieve current state from a given state_db
pub fn get_in_memory_state(&self) -> Result<State<StateDB>, EvmTestError> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Avoid get in function names use in_memory_state is it's a getter or new_/create_ if you are creating something.

Comment thread .gitlab-ci.yml Outdated
script:
- set RUST_BACKTRACE=1
- echo cargo test --features json-tests -p rlp -p ethash -p ethcore -p ethcore-bigint -p parity-dapps -p parity-rpc -p ethcore-util -p ethcore-network -p ethcore-io -p ethkey -p ethstore -p ethsync -p ethcore-ipc -p ethcore-ipc-tests -p ethcore-ipc-nano -p parity-rpc-client -p parity %CARGOFLAGS% --verbose --release
- echo cargo test --features json-tests -p rlp -p ethash -p ethcore -p ethcore-bigint -p parity-dapps -p parity-rpc -p ethcore-util -p ethcore-network -p ethcore-io -p ethkey -p ethstore -p ethsync -p ethcore-ipc -p ethcore-ipc-tests -p ethcore-ipc-nano -p parity-rpc-client -p parity -p parity-updater %CARGOFLAGS% --verbose --release
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should go to workspace members, Why does .gitlab-ci-.yml list packages names here? CC @paritytech/ui-devs
Should only run cargo test --all

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll change it to cargo test --all, and revert to original if there are merge issues.

// Write DB
{
let mut batch = kvdb::DBTransaction::new();
state_db.journal_under(&mut batch, 0, &genesis.hash())?;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

state_db is empty at this point, no? I don't think there is a need to write anything to the DB.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Unsure, I took this from the existing code, and modified it to use the new state_db setup.

I don't think there is a need to write anything to the DB.

Why wouldn't we need to add the genesis hash to the DB when it is created?

@tomusdrw tomusdrw added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 30, 2017
@tomusdrw
Copy link
Copy Markdown
Collaborator

@lght any progress on this one?

@5chdn 5chdn added the A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. label Dec 30, 2017
@5chdn 5chdn modified the milestones: 1.9, 1.10 Dec 30, 2017
@5chdn 5chdn removed the A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. label Jan 9, 2018
@lght
Copy link
Copy Markdown
Author

lght commented Jan 15, 2018


Will also write up the auto-updater Truffle tests, and remove the commented tests from this PR. Will separate the Truffle/Operations.sol-specific tests into their own PR.

lght added a commit to lght/parity that referenced this pull request Jan 15, 2018
Formatting changes for openethereum#6913
Formatting changes for openethereum#6913
@lght lght force-pushed the updater-unit-tests branch from 87be7e5 to 842ef40 Compare January 15, 2018 20:04
lght added 2 commits January 15, 2018 20:09
Part of an attempt to get updater unit tests running on automated builds
for openethereum#6913.
Removed commented tests from `updater/src/updater.rs`, and will migrate
them to a separate PR dedicated to unit tests for Operations.sol.

Changed `test_client::get_in_memory_db` to
`test_client::create_in_memory_db` to be more semantically correction,
and follow better naming convention.
@lght
Copy link
Copy Markdown
Author

lght commented Jan 15, 2018

RPC tests are causing this PR's builds to fail. Changes to RPC originated from a merge with past master. Looks like the tests use a snapshot_service() that returns a wrapped TestSnapshotService. Debugging the failures now.

lght added 2 commits January 15, 2018 21:37
Part of openethereum#6913, JSON RPC tests from a merge with previous master were
causing CI builds to fail.
@5chdn 5chdn modified the milestones: 1.10, 1.11 Jan 23, 2018
@debris
Copy link
Copy Markdown
Collaborator

debris commented Feb 6, 2018

please reopen if/when the pr is ready

@debris debris closed this Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. M4-core ⛓ Core client code / Rust.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants