Combined account balance fixes needed for unit tests

This commit is contained in:
catbref 2020-04-27 15:33:09 +01:00
parent 48de33fe24
commit 136188339d
3 changed files with 12 additions and 1 deletions

View File

@ -77,6 +77,12 @@ public class Account {
throw new DataException(message); throw new DataException(message);
} }
// Delete account balance record instead of setting balance to zero
if (balance.signum() == 0) {
this.repository.getAccountRepository().delete(this.address, assetId);
return;
}
// Can't have a balance without an account - make sure it exists! // Can't have a balance without an account - make sure it exists!
this.repository.getAccountRepository().ensureAccount(this.buildAccountData()); this.repository.getAccountRepository().ensureAccount(this.buildAccountData());

View File

@ -250,8 +250,10 @@ public class Payment {
* For QORT amounts only: If recipient's last reference is this transaction's signature, then they can't have made any transactions of their own * For QORT amounts only: If recipient's last reference is this transaction's signature, then they can't have made any transactions of their own
* (which would have changed their last reference) thus this is their first reference so remove it. * (which would have changed their last reference) thus this is their first reference so remove it.
*/ */
if ((alwaysUninitializeRecipientReference || assetId == Asset.QORT) && Arrays.equals(recipient.getLastReference(), signature)) if ((alwaysUninitializeRecipientReference || assetId == Asset.QORT) && Arrays.equals(recipient.getLastReference(), signature)) {
recipient.setLastReference(null); recipient.setLastReference(null);
this.repository.getAccountRepository().delete(recipient.getAddress(), assetId);
}
} }
} }

View File

@ -188,6 +188,9 @@ public class HSQLDBAssetRepository implements AssetRepository {
public void delete(long assetId) throws DataException { public void delete(long assetId) throws DataException {
try { try {
this.repository.delete("Assets", "asset_id = ?", assetId); this.repository.delete("Assets", "asset_id = ?", assetId);
// Also delete account balances that refer to asset
this.repository.delete("AccountBalances", "asset_id = ?", assetId);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Unable to delete asset from repository", e); throw new DataException("Unable to delete asset from repository", e);
} }