Skip to content

Commit

Permalink
use exceptions also in inflation tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rafał Malinowski <[email protected]>
  • Loading branch information
vogel committed May 23, 2017
1 parent a4e2eaf commit 9290e1b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/test/TestExceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ throwIf(InflationResult const& result)
{
switch (result.code())
{
case INFLATION_NOT_TIME:
throw ex_INFLATION_NOT_TIME{};
case INFLATION_SUCCESS:
break;
default:
Expand Down
4 changes: 4 additions & 0 deletions src/test/TestExceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,9 @@ class ex_SET_OPTIONS_BAD_SIGNER
class ex_SET_OPTIONS_INVALID_HOME_DOMAIN
{
};

class ex_INFLATION_NOT_TIME
{
};
}
}
7 changes: 2 additions & 5 deletions src/test/TxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,19 +843,16 @@ createInflation(Hash const& networkID, SecretKey const& from,
}

OperationResult
applyInflation(Application& app, SecretKey const& from, SequenceNumber seq,
InflationResultCode result)
applyInflation(Application& app, SecretKey const& from, SequenceNumber seq)
{
TransactionFramePtr txFrame =
createInflation(app.getNetworkID(), from, seq);

LedgerDelta delta(app.getLedgerManager().getCurrentLedgerHeader(),
app.getDatabase());
bool res = applyCheck(txFrame, delta, app);

throwIf(txFrame->getResult());
checkTransaction(*txFrame);
REQUIRE(InflationOpFrame::getInnerCode(
txFrame->getResult().result.results()[0]) == result);
if (res)
{
delta.commit();
Expand Down
3 changes: 1 addition & 2 deletions src/test/TxTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ Operation createInflationOp();
TransactionFramePtr createInflation(Hash const& networkID,
SecretKey const& from, SequenceNumber seq);
OperationResult
applyInflation(Application& app, SecretKey const& from, SequenceNumber seq,
InflationResultCode targetResult = INFLATION_SUCCESS);
applyInflation(Application& app, SecretKey const& from, SequenceNumber seq);

Operation createMergeOp(SecretKey const* from, PublicKey const& dest);

Expand Down
21 changes: 11 additions & 10 deletions src/transactions/InflationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "main/Application.h"
#include "main/Config.h"
#include "test/TestAccount.h"
#include "test/TestExceptions.h"
#include "test/TestUtils.h"
#include "test/TxTests.h"
#include "test/test.h"
Expand Down Expand Up @@ -295,8 +296,8 @@ TEST_CASE("inflation", "[tx][inflation]")
{
for_all_versions(app, [&]{
closeLedgerOn(app, 2, 30, 6, 2014);
applyInflation(app, root, root.nextSequenceNumber(),
INFLATION_NOT_TIME);
REQUIRE_THROWS_AS(applyInflation(app, root, root.nextSequenceNumber()),
ex_INFLATION_NOT_TIME);

REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
0);
Expand All @@ -310,30 +311,30 @@ TEST_CASE("inflation", "[tx][inflation]")
REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
1);

applyInflation(app, root, root.nextSequenceNumber(),
INFLATION_NOT_TIME);
REQUIRE_THROWS_AS(applyInflation(app, root, root.nextSequenceNumber()),
ex_INFLATION_NOT_TIME);
REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
1);

closeLedgerOn(app, 5, 8, 7, 2014);
applyInflation(app, root, root.nextSequenceNumber(), INFLATION_SUCCESS);
applyInflation(app, root, root.nextSequenceNumber());
REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
2);

closeLedgerOn(app, 6, 14, 7, 2014);
applyInflation(app, root, root.nextSequenceNumber(),
INFLATION_NOT_TIME);
REQUIRE_THROWS_AS(applyInflation(app, root, root.nextSequenceNumber()),
ex_INFLATION_NOT_TIME);
REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
2);

closeLedgerOn(app, 7, 15, 7, 2014);
applyInflation(app, root, root.nextSequenceNumber(), INFLATION_SUCCESS);
applyInflation(app, root, root.nextSequenceNumber());
REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
3);

closeLedgerOn(app, 8, 21, 7, 2014);
applyInflation(app, root, root.nextSequenceNumber(),
INFLATION_NOT_TIME);
REQUIRE_THROWS_AS(applyInflation(app, root, root.nextSequenceNumber()),
ex_INFLATION_NOT_TIME);
REQUIRE(app.getLedgerManager().getCurrentLedgerHeader().inflationSeq ==
3);
});
Expand Down

0 comments on commit 9290e1b

Please sign in to comment.