Skip to content

Commit 865799e

Browse files
committed
Add test for receiving existing tx
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
1 parent 74c8ac2 commit 865799e

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

test/framework/test_subscriber.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ namespace framework {
138138
subscription_.unsubscribe();
139139
}
140140

141+
auto reason() {
142+
return strategy_->invalidate_reason_;
143+
}
144+
141145
private:
142146
Observable unwrapped_;
143147
std::unique_ptr<VerificationStrategy<T>> strategy_;

test/module/irohad/multi_sig_transactions/mst_processor_test.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ auto initObservers(std::shared_ptr<FairMstProcessor> mst_processor,
9393
*/
9494
template <typename T>
9595
void check(T &t) {
96-
ASSERT_TRUE(std::get<0>(t).validate());
97-
ASSERT_TRUE(std::get<1>(t).validate());
98-
ASSERT_TRUE(std::get<2>(t).validate());
96+
ASSERT_TRUE(std::get<0>(t).validate())
97+
<< "onStateUpdate" << std::get<0>(t).reason();
98+
ASSERT_TRUE(std::get<1>(t).validate())
99+
<< "onPreparedBatches" << std::get<1>(t).reason();
100+
ASSERT_TRUE(std::get<2>(t).validate())
101+
<< "onExpiredBatches" << std::get<2>(t).reason();
99102
}
100103

101104
/**
@@ -346,3 +349,28 @@ TEST_F(MstProcessorTest, receivedOutdatedState) {
346349
EXPECT_FALSE(storage->batchInStorage(expired_batch));
347350
check(observers);
348351
}
352+
353+
/**
354+
* @given initialized mst processor with two incomplete transactions in the
355+
* state
356+
*
357+
* @when one of them is received from another peer
358+
*
359+
* @then no observables are triggered
360+
*/
361+
TEST_F(MstProcessorTest, receivedOneOfExistingTxs) {
362+
const auto batch = addSignaturesFromKeyPairs(
363+
makeTestBatch(txBuilder(1, time_now, 2)), 0, makeKey());
364+
mst_processor->propagateBatch(batch);
365+
mst_processor->propagateBatch(addSignaturesFromKeyPairs(
366+
makeTestBatch(txBuilder(2, time_now, 2)), 0, makeKey()));
367+
368+
auto received_state = MstState::empty(getTestLogger("MstState"),
369+
std::make_shared<TestCompleter>());
370+
received_state += batch;
371+
auto observers = initObservers(mst_processor, 0, 0, 0);
372+
shared_model::crypto::PublicKey another_peer_key("another_pubkey");
373+
mst_processor->onNewState(another_peer_key, received_state);
374+
375+
check(observers);
376+
}

0 commit comments

Comments
 (0)