Skip to content

Commit

Permalink
Add test for receiving existing tx
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Lebedev <[email protected]>
  • Loading branch information
lebdron committed Jun 24, 2019
1 parent 74c8ac2 commit 865799e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions test/framework/test_subscriber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace framework {
subscription_.unsubscribe();
}

auto reason() {
return strategy_->invalidate_reason_;
}

private:
Observable unwrapped_;
std::unique_ptr<VerificationStrategy<T>> strategy_;
Expand Down
34 changes: 31 additions & 3 deletions test/module/irohad/multi_sig_transactions/mst_processor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ auto initObservers(std::shared_ptr<FairMstProcessor> mst_processor,
*/
template <typename T>
void check(T &t) {
ASSERT_TRUE(std::get<0>(t).validate());
ASSERT_TRUE(std::get<1>(t).validate());
ASSERT_TRUE(std::get<2>(t).validate());
ASSERT_TRUE(std::get<0>(t).validate())
<< "onStateUpdate" << std::get<0>(t).reason();
ASSERT_TRUE(std::get<1>(t).validate())
<< "onPreparedBatches" << std::get<1>(t).reason();
ASSERT_TRUE(std::get<2>(t).validate())
<< "onExpiredBatches" << std::get<2>(t).reason();
}

/**
Expand Down Expand Up @@ -346,3 +349,28 @@ TEST_F(MstProcessorTest, receivedOutdatedState) {
EXPECT_FALSE(storage->batchInStorage(expired_batch));
check(observers);
}

/**
* @given initialized mst processor with two incomplete transactions in the
* state
*
* @when one of them is received from another peer
*
* @then no observables are triggered
*/
TEST_F(MstProcessorTest, receivedOneOfExistingTxs) {
const auto batch = addSignaturesFromKeyPairs(
makeTestBatch(txBuilder(1, time_now, 2)), 0, makeKey());
mst_processor->propagateBatch(batch);
mst_processor->propagateBatch(addSignaturesFromKeyPairs(
makeTestBatch(txBuilder(2, time_now, 2)), 0, makeKey()));

auto received_state = MstState::empty(getTestLogger("MstState"),
std::make_shared<TestCompleter>());
received_state += batch;
auto observers = initObservers(mst_processor, 0, 0, 0);
shared_model::crypto::PublicKey another_peer_key("another_pubkey");
mst_processor->onNewState(another_peer_key, received_state);

check(observers);
}

0 comments on commit 865799e

Please sign in to comment.