Refactor test to clarify expectations

This commit is contained in:
Jack Grigg 2016-10-14 09:31:26 -05:00
parent 82c2d97c60
commit 6da46b692a
No known key found for this signature in database
GPG Key ID: 6A6914DAFBEA00DA
1 changed files with 34 additions and 18 deletions

View File

@ -707,36 +707,52 @@ TEST(wallet_tests, WriteWitnessCache) {
auto wtx = GetValidReceive(sk, 10, true);
wallet.AddToWallet(wtx, true, NULL);
EXPECT_CALL(walletdb, TxnBegin())
.WillOnce(Return(false))
.WillRepeatedly(Return(true));
EXPECT_CALL(walletdb, TxnCommit())
.WillOnce(Return(false))
.WillRepeatedly(Return(true));
EXPECT_CALL(walletdb, TxnAbort())
.Times(4);
EXPECT_CALL(walletdb, WriteTx(wtx.GetHash(), wtx))
.WillOnce(Return(false))
.WillOnce(ThrowLogicError())
.WillRepeatedly(Return(true));
EXPECT_CALL(walletdb, WriteWitnessCacheSize(0))
.WillOnce(Return(false))
.WillOnce(ThrowLogicError())
.WillRepeatedly(Return(true));
// TxnBegin fails
EXPECT_CALL(walletdb, TxnBegin())
.WillOnce(Return(false));
wallet.WriteWitnessCache(walletdb);
EXPECT_CALL(walletdb, TxnBegin())
.WillRepeatedly(Return(true));
// WriteTx fails
EXPECT_CALL(walletdb, WriteTx(wtx.GetHash(), wtx))
.WillOnce(Return(false));
EXPECT_CALL(walletdb, TxnAbort())
.Times(1);
wallet.WriteWitnessCache(walletdb);
// WriteTx throws
EXPECT_CALL(walletdb, WriteTx(wtx.GetHash(), wtx))
.WillOnce(ThrowLogicError());
EXPECT_CALL(walletdb, TxnAbort())
.Times(1);
wallet.WriteWitnessCache(walletdb);
EXPECT_CALL(walletdb, WriteTx(wtx.GetHash(), wtx))
.WillRepeatedly(Return(true));
// WriteWitnessCacheSize fails
EXPECT_CALL(walletdb, WriteWitnessCacheSize(0))
.WillOnce(Return(false));
EXPECT_CALL(walletdb, TxnAbort())
.Times(1);
wallet.WriteWitnessCache(walletdb);
// WriteWitnessCacheSize throws
EXPECT_CALL(walletdb, WriteWitnessCacheSize(0))
.WillOnce(ThrowLogicError());
EXPECT_CALL(walletdb, TxnAbort())
.Times(1);
wallet.WriteWitnessCache(walletdb);
EXPECT_CALL(walletdb, WriteWitnessCacheSize(0))
.WillRepeatedly(Return(true));
// TxCommit fails
EXPECT_CALL(walletdb, TxnCommit())
.WillOnce(Return(false));
wallet.WriteWitnessCache(walletdb);
EXPECT_CALL(walletdb, TxnCommit())
.WillRepeatedly(Return(true));
// Everything succeeds
wallet.WriteWitnessCache(walletdb);
}