Skip to content

Commit

Permalink
Update unit test for crowdsale calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dexX7 committed Sep 22, 2015
1 parent 301b23e commit a4d3e9c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/omnicore/sp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,10 @@ void mastercore::calculateFundraiser(bool inflateAmount, int64_t amtTransfer, ui
uint256 percentage_precision = ConvertTo256(100);

// Calculate the bonus seconds
uint256 bonusSeconds_ = ConvertTo256(fundraiserSecs) - ConvertTo256(currentSecs);
uint256 bonusSeconds_ = 0;
if (currentSecs < fundraiserSecs) {
bonusSeconds_ = ConvertTo256(fundraiserSecs) - ConvertTo256(currentSecs);
}

// Calculate the whole number of weeks to apply bonus
uint256 weeks_ = (bonusSeconds_ / weeks_sec_) * precision_;
Expand Down Expand Up @@ -715,7 +718,6 @@ void mastercore::calculateFundraiser(bool inflateAmount, int64_t amtTransfer, ui
assert(issuerTokens_int <= maxCreatable);

// The tokens for the user
//createdTokens_int = ConvertTo256(MAX_INT_8_BYTES) - issuerTokens_int;
createdTokens_int = maxCreatable - issuerTokens_int;

// Close the crowdsale after assigning all tokens
Expand Down
50 changes: 48 additions & 2 deletions src/omnicore/test/crowdsale_participation_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "omnicore/sp.h"

#include <stdint.h>
#include <limits>
#include <utility>

#include <boost/test/unit_test.hpp>
Expand All @@ -20,8 +21,8 @@ BOOST_AUTO_TEST_CASE(overpayment_close)
//
int64_t amountPerUnitInvested = 3133700000000LL;
int64_t deadline = 1407064860000LL;
int8_t earlyBirdBonus = 6;
int8_t issuerBonus = 10;
uint8_t earlyBirdBonus = 6;
uint8_t issuerBonus = 10;

//
// txid: 8fbd96005aba5671daf8288f89df8026a7ce4782a0bb411937537933956b827b
Expand All @@ -42,5 +43,50 @@ BOOST_AUTO_TEST_CASE(overpayment_close)
BOOST_CHECK_EQUAL(838488366986797800LL, tokensCreated.second); // issuer
}

BOOST_AUTO_TEST_CASE(max_limits)
{
int64_t amountPerUnitInvested = std::numeric_limits<int64_t>::max();
int64_t deadline = std::numeric_limits<int64_t>::max();
uint8_t earlyBirdBonus = std::numeric_limits<uint8_t>::max();
uint8_t issuerBonus = std::numeric_limits<uint8_t>::max();

int64_t timestamp = 0;
int64_t amountInvested = std::numeric_limits<int64_t>::max();

int64_t totalTokens = std::numeric_limits<int64_t>::max() - 1LL;
std::pair<int64_t, int64_t> tokensCreated;
bool fClosed = false;

mastercore::calculateFundraiser(true, amountInvested, earlyBirdBonus, deadline,
timestamp, amountPerUnitInvested, issuerBonus, totalTokens,
tokensCreated, fClosed);

BOOST_CHECK(fClosed);
BOOST_CHECK_EQUAL(1, tokensCreated.first); // user
BOOST_CHECK_EQUAL(0, tokensCreated.second); // issuer
}

BOOST_AUTO_TEST_CASE(negative_time)
{
int64_t amountPerUnitInvested = 50;
int64_t deadline = 500000000;
uint8_t earlyBirdBonus = 255;
uint8_t issuerBonus = 19;

int64_t timestamp = 500007119;
int64_t amountInvested = 1000000000L;

int64_t totalTokens = 0;
std::pair<int64_t, int64_t> tokensCreated;
bool fClosed = false;

mastercore::calculateFundraiser(false, amountInvested, earlyBirdBonus, deadline,
timestamp, amountPerUnitInvested, issuerBonus, totalTokens,
tokensCreated, fClosed);

BOOST_CHECK(!fClosed);
BOOST_CHECK_EQUAL(500, tokensCreated.first); // user
BOOST_CHECK_EQUAL(95, tokensCreated.second); // issuer
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit a4d3e9c

Please sign in to comment.