Fix potentially overflowing multiply in Block reward processing.

Change BlockChain config to use AmountTypeAdapter instead of
creating duplicated long versions of BigDecimal values.

Some tidying to Amounts class.
This commit is contained in:
catbref
2020-05-01 08:57:15 +01:00
parent a309f8de9e
commit e86143426b
6 changed files with 43 additions and 74 deletions

View File

@@ -13,7 +13,7 @@ public abstract class TestTransaction {
protected static final Random random = new Random();
public static BaseTransactionData generateBase(PrivateKeyAccount account) throws DataException {
return new BaseTransactionData(System.currentTimeMillis(), Group.NO_GROUP, account.getLastReference(), account.getPublicKey(), BlockChain.getInstance().getUnscaledUnitFee(), null);
return new BaseTransactionData(System.currentTimeMillis(), Group.NO_GROUP, account.getLastReference(), account.getPublicKey(), BlockChain.getInstance().getUnitFee(), null);
}
}

View File

@@ -71,7 +71,7 @@ public class RewardTests extends Common {
BlockUtils.mintBlock(repository);
expectedBalance += rewardInfo.unscaledReward;
expectedBalance += rewardInfo.reward;
}
AccountUtils.assertBalance(repository, "alice", Asset.QORT, expectedBalance);
@@ -106,8 +106,8 @@ public class RewardTests extends Common {
public void testLegacyQoraReward() throws DataException {
Common.useSettings("test-settings-v2-qora-holder.json");
long qoraHoldersShare = BlockChain.getInstance().getQoraHoldersUnscaledShare();
long qoraPerQort = BlockChain.getInstance().getUnscaledQoraPerQortReward();
long qoraHoldersShare = BlockChain.getInstance().getQoraHoldersShare();
long qoraPerQort = BlockChain.getInstance().getQoraPerQortReward();
try (final Repository repository = RepositoryManager.getRepository()) {
Map<String, Map<Long, Long>> initialBalances = AccountUtils.getBalances(repository, Asset.QORT, Asset.LEGACY_QORA, Asset.QORT_FROM_QORA);
@@ -161,7 +161,7 @@ public class RewardTests extends Common {
public void testMaxLegacyQoraReward() throws DataException {
Common.useSettings("test-settings-v2-qora-holder.json");
long qoraPerQort = BlockChain.getInstance().getUnscaledQoraPerQortReward();
long qoraPerQort = BlockChain.getInstance().getQoraPerQortReward();
try (final Repository repository = RepositoryManager.getRepository()) {
Map<String, Map<Long, Long>> initialBalances = AccountUtils.getBalances(repository, Asset.QORT, Asset.LEGACY_QORA, Asset.QORT_FROM_QORA);