Skip to content

Commit

Permalink
amount: Move CAmount CENT to unit test header
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Sep 17, 2018
1 parent 4901c00 commit fa84723
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
typedef int64_t CAmount;

static const CAmount COIN = 100000000;
static const CAmount CENT = 1000000;

/** No amount larger than this (in satoshi) is valid.
*
Expand Down
16 changes: 8 additions & 8 deletions src/bench/ccoins_caching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// FIXME: Dedup with SetupDummyInputs in test/transaction_tests.cpp.
//
// Helper: create two dummy transactions, each with
// two outputs. The first has 11 and 50 CENT outputs
// paid to a TX_PUBKEY, the second 21 and 22 CENT outputs
// two outputs. The first has 11 and 50 COIN outputs
// paid to a TX_PUBKEY, the second 21 and 22 COIN outputs
// paid to a TX_PUBKEYHASH.
//
static std::vector<CMutableTransaction>
Expand All @@ -31,16 +31,16 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)

// Create some dummy input transactions
dummyTransactions[0].vout.resize(2);
dummyTransactions[0].vout[0].nValue = 11 * CENT;
dummyTransactions[0].vout[0].nValue = 11 * COIN;
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
dummyTransactions[0].vout[1].nValue = 50 * CENT;
dummyTransactions[0].vout[1].nValue = 50 * COIN;
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
AddCoins(coinsRet, dummyTransactions[0], 0);

dummyTransactions[1].vout.resize(2);
dummyTransactions[1].vout[0].nValue = 21 * CENT;
dummyTransactions[1].vout[0].nValue = 21 * COIN;
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(key[2].GetPubKey().GetID());
dummyTransactions[1].vout[1].nValue = 22 * CENT;
dummyTransactions[1].vout[1].nValue = 22 * COIN;
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(key[3].GetPubKey().GetID());
AddCoins(coinsRet, dummyTransactions[1], 0);

Expand Down Expand Up @@ -72,15 +72,15 @@ static void CCoinsCaching(benchmark::State& state)
t1.vin[2].prevout.n = 1;
t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);
t1.vout.resize(2);
t1.vout[0].nValue = 90 * CENT;
t1.vout[0].nValue = 90 * COIN;
t1.vout[0].scriptPubKey << OP_1;

// Benchmark.
while (state.KeepRunning()) {
bool success = AreInputsStandard(t1, coins);
assert(success);
CAmount value = coins.GetValueIn(t1);
assert(value == (50 + 21 + 22) * CENT);
assert(value == (50 + 21 + 22) * COIN);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/test_bitcoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.ran
static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); }
static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); }

static constexpr CAmount CENT{1000000};

/** Basic testing setup.
* This just configures logging and chain parameters.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/utilmoneystr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool ParseMoney(const char* pszIn, CAmount& nRet)
if (*p == '.')
{
p++;
int64_t nMult = CENT*10;
int64_t nMult = COIN / 10;
while (isdigit(*p) && (nMult > 0))
{
nUnits += nMult * (*p++ - '0');
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/coinselection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <random.h>

//! target minimum change amount
static const CAmount MIN_CHANGE = CENT;
static constexpr CAmount MIN_CHANGE{COIN / 100};
//! final minimum change amount after paying for fees
static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2;

Expand Down

0 comments on commit fa84723

Please sign in to comment.