Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Integration tests for GetPendingTransactions() #1661

Merged
merged 25 commits into from
Sep 11, 2018

Conversation

Akvinikym
Copy link
Contributor

@Akvinikym Akvinikym commented Aug 21, 2018

Description of the Change

This PR does two things:

  1. Fixes MST - before it did not send batches, which were inserted or updated with new signatures, to the pending storage, which lead to inability to retrieve them
  2. Implements a couple of tests for getPendingTransactions query

Benefits

Tests for a new query.

Possible Drawbacks

None.

Usage of tests

All tests, which are added, are located inside test/integration/pipeline/multisig_tx_pipeline_test.cpp. They can be executed by building and running the corresponding target, multisig_tx_pipeline_test

@l4l l4l added needs-review pr awaits review from maintainers tests pr aimed at the code coverage increase or test refactorings query All that relates to the iroha querying labels Aug 27, 2018
@Akvinikym Akvinikym changed the base branch from develop to dev August 31, 2018 12:31
Copy link
Contributor

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

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

the build is broken on both platforms

Copy link
Contributor

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

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

Since there are notable changes in MST part, I request the review from @muratovv .

@@ -32,6 +32,13 @@ namespace iroha {
});
}
}
void shareState(
ConstRefState state,
rxcpp::subjects::subject<std::shared_ptr<MstState>> &subject) {
Copy link
Contributor

Choose a reason for hiding this comment

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

const ... & subject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Compile error, if you try to do it :(

@@ -120,3 +140,102 @@ TEST_F(MstPipelineTest, OnePeerSendsTest) {
ASSERT_EQ(proposal->transactions().size(), 1);
});
}

/**
* @given ledger with pending transactions
Copy link
Contributor

Choose a reason for hiding this comment

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

a ledger

Copy link
Contributor

Choose a reason for hiding this comment

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

not clear the ledger can be given with pending transactions


/**
* @given ledger with pending transactions
* @when get pending transactions is executed by peer, which is to sign those
Copy link
Contributor

Choose a reason for hiding this comment

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

a user is not a peer

* @when get pending transactions is executed by peer, which is to sign those
* transactions
* @then those transactions is returned
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

given a user that has sent a semi-signed transaction to a ledger
when the user requests pending transactions
then user's semi-signed transaction is returned

.setAccountDetail(kUserId, "fav_meme", "doge")
.quorum(kSignatories + 1);

// prepare itf
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move preparation steps to some fixture method that returns a reference to an initialized instance of ITF?
An ITF can be stored inside boost::optional fixture field.

Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
@@ -32,6 +32,13 @@ namespace iroha {
});
}
}
void shareState(
Copy link
Contributor

Choose a reason for hiding this comment

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

Add documentation for the function and maybe rename it or previous shareState. Now it isn't obvious that they are doing the not same job.

@@ -32,6 +32,13 @@ namespace iroha {
});
}
}
void shareState(
ConstRefState state,
rxcpp::subjects::subject<std::shared_ptr<MstState>> &subject) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use alias for DataType instead

@@ -56,7 +63,12 @@ namespace iroha {

auto FairMstProcessor::propagateBatchImpl(const iroha::DataType &batch)
-> decltype(propagateBatch(batch)) {
shareState(storage_->updateOwnState(batch), batches_subject_);
auto state_update = storage_->updateOwnState(batch);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a reason to introduce pair with bool response here. Method isEmpty is already implemented in MstState.
Also, the current interface of updateOwnState is totally misleading - for one situation it returns one value, for another situation - another value.

UpdateOwnState possibly may return pair of two states: state with completed transactions and state with new signatures.

Copy link
Contributor

@igor-egorov igor-egorov Sep 6, 2018

Choose a reason for hiding this comment

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

AFAIK the second parameter reflects the state of a batch - completed or just updated.
Nevertheless, the current implementation with std::pair is unclear and misleading.
My vote is for the simplicity.

Copy link
Contributor

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

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

I am approving, but the mentioned unclarities should be fixed. Also, the type StateAndCompleteStatus looks redundant. Please consider removing it and making the code simpler.

@@ -92,7 +92,7 @@ namespace iroha {
* @param rhs - batch for insertion
* @return State with completed batches
*/
MstState operator+=(const DataType &rhs);
StateAndCompleteStatus operator+=(const DataType &rhs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Method's docstring (at least return part) is to be updated.

@@ -166,8 +166,9 @@ namespace iroha {
* Insert batch in own state and push it in out_state if required
* @param out_state - state for inserting completed batches
* @param rhs_tx - batch for insert
* @return if batch is complete after that insertion
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the method returns bool instead of void, it cannot just "return if". Probably, true or false is missing.

@@ -13,6 +13,9 @@ using namespace std;
using namespace iroha;
using namespace iroha::model;

// state with tx with A sig, receive with B, only B should be shared among
// others
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems that this floating comment was forgotten to be removed.
Otherwise, it is not clear what is the thing it relates to.

@igor-egorov igor-egorov self-requested a review September 6, 2018 08:22
Copy link
Contributor

@igor-egorov igor-egorov left a comment

Choose a reason for hiding this comment

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

Please fix my previous review comments.
Please edit pr description and fill in the Usage examples and Tests section. At least the name of test target should be mentioned. Thanks.

Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
*/
void insertOne(MstState &out_state, const DataType &rhs_tx);
bool insertOne(MstState &out_state, const DataType &rhs_tx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems, that we can avoid this bool with two passed states

const std::shared_ptr<shared_model::interface::Peer> &target_peer,
const MstState &new_state);

/**
* Provide updating state of current peer with new transaction
* @param tx - new transaction for insertion in state
* @return State with completed transaction
* @return completed or updated mst state
Copy link
Contributor

Choose a reason for hiding this comment

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

s/or/and

}

/**
* @given a ledger with pending transactions
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems that ledger initially empty or at least doesn't contains pending transactions.

Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
@@ -77,6 +66,35 @@ namespace iroha {
return expired_subject_.get_observable();
}

void FairMstProcessor::completedBatchesNotify(ConstRefState state) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

completedBatchesNotify and expiredBatchesNotify look identical, the only difference is the subject used. Maybe make a single method with two parameters?


// expired batches
auto expired_batches = storage_->getDiffState(from, current_time);
shareState(expired_batches, this->expired_subject_);
completedBatchesNotify(storage_->getDiffState(from, current_time));
Copy link
Contributor

Choose a reason for hiding this comment

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

-> expiredBatchesNotify
Please verify that this is covered by tests.

std::make_shared<MstState>(storage_->whatsNew(new_state));
state_subject_.get_subscriber().on_next(new_batches);
auto new_batches = storage_->whatsNew(new_state);
updatedBatchesNotify(new_batches);
Copy link
Contributor

Choose a reason for hiding this comment

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

StateUpdateResult MstState::operator+=(const DataType &rhs) {
auto completed_state = MstState::empty(completer_);
auto updated_state = MstState::empty(completer_);
insertOne(completed_state, updated_state, rhs);
Copy link
Contributor

Choose a reason for hiding this comment

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

It is quite easy to accidently swap completed state and updated state when calling insertOne. Maybe pass StateUpdateResult instead?

Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
@sorabot
Copy link

sorabot commented Sep 10, 2018

SonarQube analysis reported 3 issues

  1. MINOR mst_processor_impl.hpp#L84: Unused private function: 'FairMstProcessor::completedBatchesNotify' rule
  2. MINOR mst_processor_impl.hpp#L91: Unused private function: 'FairMstProcessor::updatedBatchesNotify' rule
  3. MINOR mst_processor_impl.hpp#L97: Unused private function: 'FairMstProcessor::expiredBatchesNotify' rule

@Akvinikym Akvinikym merged commit be1dc33 into dev Sep 11, 2018
@Akvinikym Akvinikym deleted the feature/itf-get-pending-txs branch September 11, 2018 05:07
bakhtin pushed a commit that referenced this pull request Nov 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-review pr awaits review from maintainers query All that relates to the iroha querying tests pr aimed at the code coverage increase or test refactorings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants