Fix incorrect orphaning of BUY_NAME transactions.

Orphaning a BUY_NAME transaction would not reinstate the
sale price. Sale price could be nullified by (e.g.) orphaning
a SELL_NAME transaction.

Also added test case to cover above and other test-related support,
e.g. test-mode in NTP.
This commit is contained in:
catbref
2019-08-16 11:48:30 +01:00
parent f83dc26ae0
commit 2889d04633
7 changed files with 273 additions and 4 deletions

View File

@@ -179,6 +179,7 @@ public class Name {
public void unbuy(BuyNameTransactionData buyNameTransactionData) throws DataException {
// Mark as for-sale using existing price
this.nameData.setIsForSale(true);
this.nameData.setSalePrice(buyNameTransactionData.getAmount());
// Previous name reference is taken from this transaction's cached copy
this.nameData.setReference(buyNameTransactionData.getNameReference());

View File

@@ -127,6 +127,7 @@ public class NTP implements Runnable {
if (isStarted)
return;
isStarted = true;
instanceExecutor = Executors.newSingleThreadExecutor();
instance = new NTP();
instanceExecutor.execute(instance);
@@ -136,16 +137,21 @@ public class NTP implements Runnable {
instanceExecutor.shutdownNow();
}
public static synchronized void testMode() {
// Fix offset to match system time
NTP.offset = 0L;
}
/**
* Returns our estimate of internet time.
*
* @return internet time (ms), or null if unsynchronized.
*/
public static Long getTime() {
if (offset == null)
if (NTP.offset == null)
return null;
return System.currentTimeMillis() + offset;
return System.currentTimeMillis() + NTP.offset;
}
public void run() {