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

Framework for improved RPC unit tests #1141

Merged
merged 13 commits into from
May 28, 2016
Merged

Conversation

rphmeier
Copy link
Contributor

@rphmeier rphmeier commented May 25, 2016

This lays the framework for RPC unit tests which use parity's actual BlockChainClient and Miner. The Miner has not been integrated yet, since the changes were growing pretty large.


let res_after_pending = r#"{"jsonrpc":"2.0","result":"0x01","id":18}"#;

assert_eq!(&tester.handler.handle_request(&req_after_pending).unwrap(), res_after_pending);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, this really only tests the TestMinerService's ability to update transactions.
It would probably be useful to integrate this with the actual Miner, although I worry that this could lead to race conditions in tests like these, where we want to send the "pending" RPC request after the miner has placed the transaction in a pending block, but before the block is sealed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I spoke to @tomusdrw about this in person, apparently this is not an issue.

@rphmeier rphmeier added A0-pleasereview 🤓 Pull request needs code review. A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. and removed A0-pleasereview 🤓 Pull request needs code review. labels May 25, 2016
Vec<Result<TransactionImportResult, Error>>
where T: Fn(&Address) -> AccountDetails {
// lets assume that all txs are valid
self.imported_transactions.lock().unwrap().extend_from_slice(&transactions);

for transaction in &transactions {
Copy link
Collaborator

Choose a reason for hiding this comment

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

transactions.filter_map(|t| t.sender()) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is better

for transaction in &transactions {
if let Ok(ref sender) = transaction.sender() {
let nonce = self.last_nonce(sender).unwrap_or(fetch_account(sender).nonce);
self.last_nonces.write().unwrap().insert(sender.clone(), nonce + U256::from(1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

let nonce = self.last_nonce(sender).map(|n| n + U256::from(1)).unwrap_or(fetch_account(sender).nonce);

In state next valid nonce is stored, last_nonce returns last used nonce afair - so you should increment only in the first case.

Same thing in L144

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(resolved in person, not an issue with TestMinerService)

@rphmeier rphmeier changed the title [WIP] Rpc integration tests Improved RPC unit tests May 26, 2016
@rphmeier
Copy link
Contributor Author

After some discussion with @arkpar and @tomusdrw earlier today, I decided that the tests in this PR do not amount to proper integration tests. Those will be implemented in another PR by interacting with parity completely as an outsider.

@rphmeier
Copy link
Contributor Author

rphmeier commented May 26, 2016

@NikVolf has warned me that this PR is getting too big -- once #1149 is merged I will work on splitting this up into smaller pieces. A lot of the large diff size is due to moving around the previous tests into a serialization submodule, so that is mostly unavoidable. (moved into separate PR)

@rphmeier rphmeier changed the title Improved RPC unit tests Framework for improved RPC unit tests May 27, 2016
@rphmeier rphmeier added A0-pleasereview 🤓 Pull request needs code review. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels May 27, 2016
@gavofyork gavofyork added the A8-looksgood 🦄 Pull request is reviewed well. label May 28, 2016
@gavofyork gavofyork removed the A0-pleasereview 🤓 Pull request needs code review. label May 28, 2016
@arkpar arkpar merged commit b9f7ed9 into openethereum:master May 28, 2016
@rphmeier rphmeier deleted the rpc-tests branch May 29, 2016 13:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants