-
Notifications
You must be signed in to change notification settings - Fork 296
Integration tests for GetPendingTransactions() #1661
Conversation
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]>
There was a problem hiding this 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
719d6d4
to
eb2436e
Compare
There was a problem hiding this 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ... & subject
?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a ledger
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | ||
*/ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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]>
Signed-off-by: Akvinikym <[email protected]>
@@ -32,6 +32,13 @@ namespace iroha { | |||
}); | |||
} | |||
} | |||
void shareState( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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]>
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not look consistent with https://github.com/hyperledger/iroha/blob/7ebc34ed3379a1a99253d453ac18f823b5701402/irohad/multi_sig_transactions/impl/mst_processor_impl.cpp#L48-L49
Maybe refactor it, so that updated_state_
is used?
StateUpdateResult MstState::operator+=(const DataType &rhs) { | ||
auto completed_state = MstState::empty(completer_); | ||
auto updated_state = MstState::empty(completer_); | ||
insertOne(completed_state, updated_state, rhs); |
There was a problem hiding this comment.
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?
test/module/irohad/multi_sig_transactions/mst_processor_test.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
Signed-off-by: Akvinikym <[email protected]>
6ac4763
to
2e21944
Compare
Signed-off-by: Akvinikym <[email protected]>
2e21944
to
dcf06c3
Compare
Signed-off-by: Akvinikym <[email protected]>
SonarQube analysis reported 3 issues
|
Signed-off-by: Akvinikym <[email protected]>
Description of the Change
This PR does two things:
getPendingTransactions
queryBenefits
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