Skip to content

Commit 134b42a

Browse files
author
MarcoFalke
committed
Merge #14244: amount: Move CAmount CENT to unit test header
fa84723 amount: Move CAmount CENT to unit test header (MarcoFalke) Pull request description: `CAmount` is currently not type-safe. Exporting a constant (`CENT`) that is commonly not referred to by that name might be confusing. `CENT` is only used in two places prior to this commit (`ParseMoney` and `MIN_CHANGE`). So replace these with constants relative to `COIN` and move `CENT` to the unit test header. Tree-SHA512: 5273e96d8664ced6ae211abde2e20bc763e6e99f89404eec02c621f29e1d235e5f9b1ade933743843fae16fc24b643f883deda9221e3d9fd31229d2ab63a914f
2 parents 01211ce + fa84723 commit 134b42a

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

src/amount.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
typedef int64_t CAmount;
1313

1414
static const CAmount COIN = 100000000;
15-
static const CAmount CENT = 1000000;
1615

1716
/** No amount larger than this (in satoshi) is valid.
1817
*

src/bench/ccoins_caching.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// FIXME: Dedup with SetupDummyInputs in test/transaction_tests.cpp.
1313
//
1414
// Helper: create two dummy transactions, each with
15-
// two outputs. The first has 11 and 50 CENT outputs
16-
// paid to a TX_PUBKEY, the second 21 and 22 CENT outputs
15+
// two outputs. The first has 11 and 50 COIN outputs
16+
// paid to a TX_PUBKEY, the second 21 and 22 COIN outputs
1717
// paid to a TX_PUBKEYHASH.
1818
//
1919
static std::vector<CMutableTransaction>
@@ -31,16 +31,16 @@ SetupDummyInputs(CBasicKeyStore& keystoreRet, CCoinsViewCache& coinsRet)
3131

3232
// Create some dummy input transactions
3333
dummyTransactions[0].vout.resize(2);
34-
dummyTransactions[0].vout[0].nValue = 11 * CENT;
34+
dummyTransactions[0].vout[0].nValue = 11 * COIN;
3535
dummyTransactions[0].vout[0].scriptPubKey << ToByteVector(key[0].GetPubKey()) << OP_CHECKSIG;
36-
dummyTransactions[0].vout[1].nValue = 50 * CENT;
36+
dummyTransactions[0].vout[1].nValue = 50 * COIN;
3737
dummyTransactions[0].vout[1].scriptPubKey << ToByteVector(key[1].GetPubKey()) << OP_CHECKSIG;
3838
AddCoins(coinsRet, dummyTransactions[0], 0);
3939

4040
dummyTransactions[1].vout.resize(2);
41-
dummyTransactions[1].vout[0].nValue = 21 * CENT;
41+
dummyTransactions[1].vout[0].nValue = 21 * COIN;
4242
dummyTransactions[1].vout[0].scriptPubKey = GetScriptForDestination(key[2].GetPubKey().GetID());
43-
dummyTransactions[1].vout[1].nValue = 22 * CENT;
43+
dummyTransactions[1].vout[1].nValue = 22 * COIN;
4444
dummyTransactions[1].vout[1].scriptPubKey = GetScriptForDestination(key[3].GetPubKey().GetID());
4545
AddCoins(coinsRet, dummyTransactions[1], 0);
4646

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

7878
// Benchmark.
7979
while (state.KeepRunning()) {
8080
bool success = AreInputsStandard(t1, coins);
8181
assert(success);
8282
CAmount value = coins.GetValueIn(t1);
83-
assert(value == (50 + 21 + 22) * CENT);
83+
assert(value == (50 + 21 + 22) * COIN);
8484
}
8585
}
8686

src/test/test_bitcoin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ static inline uint64_t InsecureRandBits(int bits) { return insecure_rand_ctx.ran
3737
static inline uint64_t InsecureRandRange(uint64_t range) { return insecure_rand_ctx.randrange(range); }
3838
static inline bool InsecureRandBool() { return insecure_rand_ctx.randbool(); }
3939

40+
static constexpr CAmount CENT{1000000};
41+
4042
/** Basic testing setup.
4143
* This just configures logging and chain parameters.
4244
*/

src/utilmoneystr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ bool ParseMoney(const char* pszIn, CAmount& nRet)
4848
if (*p == '.')
4949
{
5050
p++;
51-
int64_t nMult = CENT*10;
51+
int64_t nMult = COIN / 10;
5252
while (isdigit(*p) && (nMult > 0))
5353
{
5454
nUnits += nMult * (*p++ - '0');

src/wallet/coinselection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <random.h>
1111

1212
//! target minimum change amount
13-
static const CAmount MIN_CHANGE = CENT;
13+
static constexpr CAmount MIN_CHANGE{COIN / 100};
1414
//! final minimum change amount after paying for fees
1515
static const CAmount MIN_FINAL_CHANGE = MIN_CHANGE/2;
1616

0 commit comments

Comments
 (0)