mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Adjust tests, remove tests which do not make sense anymore
This commit is contained in:
parent
52be126667
commit
0e70a99c42
@ -42,6 +42,7 @@ import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.ExchangeRate;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import java.util.Date;
|
||||
@ -173,15 +174,16 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private TradeStatistics3(String currency,
|
||||
long price,
|
||||
long amount,
|
||||
String paymentMethod,
|
||||
long date,
|
||||
@Nullable String mediator,
|
||||
@Nullable String refundAgent,
|
||||
@Nullable Map<String, String> extraDataMap,
|
||||
@Nullable byte[] hash) {
|
||||
@VisibleForTesting
|
||||
public TradeStatistics3(String currency,
|
||||
long price,
|
||||
long amount,
|
||||
String paymentMethod,
|
||||
long date,
|
||||
@Nullable String mediator,
|
||||
@Nullable String refundAgent,
|
||||
@Nullable Map<String, String> extraDataMap,
|
||||
@Nullable byte[] hash) {
|
||||
this.currency = currency;
|
||||
this.price = price;
|
||||
this.amount = amount;
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.trade.statistics;
|
||||
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import com.natpryce.makeiteasy.Instantiator;
|
||||
import com.natpryce.makeiteasy.Maker;
|
||||
import com.natpryce.makeiteasy.Property;
|
||||
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
|
||||
public class TradeStatistics2Maker {
|
||||
|
||||
public static final Property<TradeStatistics2, Date> date = new Property<>();
|
||||
public static final Property<TradeStatistics2, String> depositTxId = new Property<>();
|
||||
public static final Property<TradeStatistics2, Coin> tradeAmount = new Property<>();
|
||||
|
||||
public static final Instantiator<TradeStatistics2> TradeStatistic2 = lookup -> {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.set(2016, 3, 19);
|
||||
|
||||
return new TradeStatistics2(
|
||||
new OfferPayload("1234",
|
||||
0L,
|
||||
null,
|
||||
null,
|
||||
OfferPayload.Direction.BUY,
|
||||
100000L,
|
||||
0.0,
|
||||
false,
|
||||
100000L,
|
||||
100000L,
|
||||
"BTC",
|
||||
"USD",
|
||||
null,
|
||||
null,
|
||||
"SEPA",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"",
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
false,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
false,
|
||||
false,
|
||||
0L,
|
||||
0L,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
0),
|
||||
Price.valueOf("BTC", 100000L),
|
||||
lookup.valueOf(tradeAmount, Coin.SATOSHI),
|
||||
lookup.valueOf(date, new Date(calendar.getTimeInMillis())),
|
||||
lookup.valueOf(depositTxId, "123456"),
|
||||
Collections.emptyMap());
|
||||
};
|
||||
public static final Maker<TradeStatistics2> dayZeroTrade = a(TradeStatistic2);
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.trade.statistics;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.core.trade.statistics.TradeStatistics2Maker.dayZeroTrade;
|
||||
import static bisq.core.trade.statistics.TradeStatistics2Maker.depositTxId;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.withNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class TradeStatistics2Test {
|
||||
|
||||
@Test
|
||||
public void isValid_WithDepositTxId() {
|
||||
|
||||
TradeStatistics2 tradeStatistic = make(dayZeroTrade);
|
||||
|
||||
assertTrue(tradeStatistic.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isValid_WithEmptyDepositTxId() {
|
||||
TradeStatistics2 tradeStatistic = make(dayZeroTrade.but(withNull(depositTxId)));
|
||||
|
||||
assertTrue(tradeStatistic.isValid());
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* This file is part of Bisq.
|
||||
*
|
||||
* Bisq is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package bisq.core.trade.statistics;
|
||||
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
|
||||
import bisq.network.p2p.P2PService;
|
||||
import bisq.network.p2p.storage.P2PDataStorage;
|
||||
import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreListener;
|
||||
import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.core.trade.statistics.TradeStatistics2Maker.dayZeroTrade;
|
||||
import static bisq.core.trade.statistics.TradeStatistics2Maker.depositTxId;
|
||||
import static bisq.core.trade.statistics.TradeStatistics2Maker.tradeAmount;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.withNull;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TradeStatisticsManagerTest {
|
||||
|
||||
private TradeStatisticsManager manager;
|
||||
private TradeStatistics2 tradeWithNullDepositTxId;
|
||||
private ArgumentCaptor<AppendOnlyDataStoreListener> listenerArgumentCaptor;
|
||||
|
||||
@Before
|
||||
public void prepareMocksAndObjects() {
|
||||
P2PService p2PService = mock(P2PService.class);
|
||||
P2PDataStorage p2PDataStorage = mock(P2PDataStorage.class);
|
||||
File storageDir = mock(File.class);
|
||||
TradeStatistics2StorageService tradeStatistics2StorageService = mock(TradeStatistics2StorageService.class);
|
||||
PriceFeedService priceFeedService = mock(PriceFeedService.class);
|
||||
|
||||
AppendOnlyDataStoreService appendOnlyDataStoreService = mock(AppendOnlyDataStoreService.class);
|
||||
when(p2PService.getP2PDataStorage()).thenReturn(p2PDataStorage);
|
||||
|
||||
manager = new TradeStatisticsManager(p2PService, priceFeedService,
|
||||
tradeStatistics2StorageService, appendOnlyDataStoreService, storageDir, false);
|
||||
|
||||
tradeWithNullDepositTxId = make(dayZeroTrade.but(withNull(depositTxId)));
|
||||
|
||||
manager.onAllServicesInitialized();
|
||||
listenerArgumentCaptor = ArgumentCaptor.forClass(AppendOnlyDataStoreListener.class);
|
||||
verify(p2PDataStorage).addAppendOnlyDataStoreListener(listenerArgumentCaptor.capture());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addToSet_ObjectWithNullDepositTxId() {
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithNullDepositTxId);
|
||||
assertTrue(manager.getObservableTradeStatisticsSet().contains(tradeWithNullDepositTxId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addToSet_RemoveExistingObjectIfObjectWithNullDepositTxIdIsAdded() {
|
||||
TradeStatistics2 tradeWithDepositTxId = make(dayZeroTrade);
|
||||
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithDepositTxId);
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithNullDepositTxId);
|
||||
|
||||
assertFalse(manager.getObservableTradeStatisticsSet().contains(tradeWithDepositTxId));
|
||||
assertTrue(manager.getObservableTradeStatisticsSet().contains(tradeWithNullDepositTxId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addToSet_NotRemoveExistingObjectIfObjectsNotEqual() {
|
||||
TradeStatistics2 tradeWithDepositTxId = make(dayZeroTrade.but(with(tradeAmount, Coin.FIFTY_COINS)));
|
||||
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithDepositTxId);
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithNullDepositTxId);
|
||||
|
||||
assertTrue(manager.getObservableTradeStatisticsSet().contains(tradeWithDepositTxId));
|
||||
assertFalse(manager.getObservableTradeStatisticsSet().contains(tradeWithNullDepositTxId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addToSet_IgnoreObjectIfObjectWithNullDepositTxIdAlreadyExists() {
|
||||
TradeStatistics2 tradeWithDepositTxId = make(dayZeroTrade);
|
||||
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithNullDepositTxId);
|
||||
listenerArgumentCaptor.getValue().onAdded(tradeWithDepositTxId);
|
||||
|
||||
assertTrue(manager.getObservableTradeStatisticsSet().contains(tradeWithNullDepositTxId));
|
||||
assertFalse(manager.getObservableTradeStatisticsSet().contains(tradeWithDepositTxId));
|
||||
}
|
||||
}
|
@ -23,8 +23,9 @@ import bisq.desktop.main.market.trades.charts.CandleData;
|
||||
import bisq.core.locale.FiatCurrency;
|
||||
import bisq.core.monetary.Price;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.payment.payload.PaymentMethod;
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
import bisq.core.trade.statistics.TradeStatistics2;
|
||||
import bisq.core.trade.statistics.TradeStatistics3;
|
||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
@ -106,6 +107,7 @@ public class TradesChartsViewModelTest {
|
||||
null,
|
||||
1
|
||||
);
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
tradeStatisticsManager = mock(TradeStatisticsManager.class);
|
||||
@ -134,13 +136,45 @@ public class TradesChartsViewModelTest {
|
||||
long volume = Fiat.parseFiat("EUR", "2200").value;
|
||||
boolean isBullish = true;
|
||||
|
||||
Set<TradeStatistics2> set = new HashSet<>();
|
||||
Set<TradeStatistics3> set = new HashSet<>();
|
||||
final Date now = new Date();
|
||||
|
||||
set.add(new TradeStatistics2(offer, Price.parse("EUR", "520"), Coin.parseCoin("1"), new Date(now.getTime()), null, null));
|
||||
set.add(new TradeStatistics2(offer, Price.parse("EUR", "500"), Coin.parseCoin("1"), new Date(now.getTime() + 100), null, null));
|
||||
set.add(new TradeStatistics2(offer, Price.parse("EUR", "600"), Coin.parseCoin("1"), new Date(now.getTime() + 200), null, null));
|
||||
set.add(new TradeStatistics2(offer, Price.parse("EUR", "580"), Coin.parseCoin("1"), new Date(now.getTime() + 300), null, null));
|
||||
set.add(new TradeStatistics3(offer.getCurrencyCode(),
|
||||
Price.parse("EUR", "520").getValue(),
|
||||
Coin.parseCoin("1").getValue(),
|
||||
PaymentMethod.BLOCK_CHAINS_ID,
|
||||
now.getTime(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
set.add(new TradeStatistics3(offer.getCurrencyCode(),
|
||||
Price.parse("EUR", "500").getValue(),
|
||||
Coin.parseCoin("1").getValue(),
|
||||
PaymentMethod.BLOCK_CHAINS_ID,
|
||||
now.getTime() + 100,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
set.add(new TradeStatistics3(offer.getCurrencyCode(),
|
||||
Price.parse("EUR", "600").getValue(),
|
||||
Coin.parseCoin("1").getValue(),
|
||||
PaymentMethod.BLOCK_CHAINS_ID,
|
||||
now.getTime() + 200,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
set.add(new TradeStatistics3(offer.getCurrencyCode(),
|
||||
Price.parse("EUR", "580").getValue(),
|
||||
Coin.parseCoin("1").getValue(),
|
||||
PaymentMethod.BLOCK_CHAINS_ID,
|
||||
now.getTime() + 300,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
|
||||
CandleData candleData = model.getCandleData(model.roundToTick(now, TradesChartsViewModel.TickUnit.DAY).getTime(), set);
|
||||
assertEquals(open, candleData.open);
|
||||
@ -194,11 +228,19 @@ public class TradesChartsViewModelTest {
|
||||
// Two trades 10 seconds apart, different YEAR, MONTH, WEEK, DAY, HOUR, MINUTE_10
|
||||
trades.add(new Trade("2017-12-31T23:59:52", "1", "100", "EUR"));
|
||||
trades.add(new Trade("2018-01-01T00:00:02", "1", "110", "EUR"));
|
||||
Set<TradeStatistics2> set = new HashSet<>();
|
||||
Set<TradeStatistics3> set = new HashSet<>();
|
||||
trades.forEach(t ->
|
||||
set.add(new TradeStatistics2(offer, Price.parse(t.cc, t.price), Coin.parseCoin(t.size), t.date, null, null))
|
||||
set.add(new TradeStatistics3(offer.getCurrencyCode(),
|
||||
Price.parse(t.cc, t.price).getValue(),
|
||||
Coin.parseCoin(t.size).getValue(),
|
||||
PaymentMethod.BLOCK_CHAINS_ID,
|
||||
t.date.getTime(),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null))
|
||||
);
|
||||
ObservableSet<TradeStatistics2> tradeStats = FXCollections.observableSet(set);
|
||||
ObservableSet<TradeStatistics3> tradeStats = FXCollections.observableSet(set);
|
||||
|
||||
// Run test for each tick type
|
||||
for (TradesChartsViewModel.TickUnit tick : TradesChartsViewModel.TickUnit.values()) {
|
||||
@ -209,7 +251,7 @@ public class TradesChartsViewModelTest {
|
||||
|
||||
// Trigger chart update
|
||||
model.setTickUnit(tick);
|
||||
assertEquals(model.selectedTradeCurrencyProperty.get().getCode(), tradeStats.iterator().next().getCurrencyCode());
|
||||
assertEquals(model.selectedTradeCurrencyProperty.get().getCode(), tradeStats.iterator().next().getCurrency());
|
||||
assertEquals(2, model.priceItems.size());
|
||||
assertEquals(2, model.volumeItems.size());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user