mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-21 21:19:36 -04:00
general rebase in order to update payment methods and desktop app
Co-authored-by: Alva Swanson <alvasw@protonmail.com> Co-authored-by: andyheko <haoen.ko@gmail.com> Co-authored-by: Bisq GitHub Admin <51445974+bisq-github-admin-3@users.noreply.github.com> Co-authored-by: BtcContributor <79100296+BtcContributor@users.noreply.github.com> Co-authored-by: cd2357 <cd2357@users.noreply.github.com> Co-authored-by: chimp1984 <chimp1984@gmx.com> Co-authored-by: Chris Beams <chris@beams.io> Co-authored-by: Christoph Atteneder <christoph.atteneder@gmail.com> Co-authored-by: Devin Bileck <603793+devinbileck@users.noreply.github.com> Co-authored-by: ghubstan <36207203+ghubstan@users.noreply.github.com> Co-authored-by: Huey <hueydane@gmail.com> Co-authored-by: Jakub Loucký <jakub.loucky@outlook.cz> Co-authored-by: jmacxx <47253594+jmacxx@users.noreply.github.com> Co-authored-by: KanoczTomas <tomas.kanocz@cnl.sk> Co-authored-by: m52go <735155+m52go@users.noreply.github.com> Co-authored-by: Marcus0x <marcus0x@xrhodium.org> Co-authored-by: MarnixCroes <93143998+MarnixCroes@users.noreply.github.com> Co-authored-by: Martin Harrigan <martinharrigan@gmail.com> Co-authored-by: MwithM <50149324+MwithM@users.noreply.github.com> Co-authored-by: sqrrm <sqrrm@users.noreply.github.com> Co-authored-by: Stan <36207203+ghubstan@users.noreply.github.com> Co-authored-by: Stephan Oeste <emzy@emzy.de> Co-authored-by: Steven Barclay <stejbac@gmail.com> Co-authored-by: WAT <shiido.it@gmail.com> Co-authored-by: wiz <j@wiz.biz> Co-authored-by: xyzmaker123 <84982606+xyzmaker123@users.noreply.github.com>
This commit is contained in:
parent
15a1fe8a36
commit
88578bed10
539 changed files with 27629 additions and 8178 deletions
|
@ -99,7 +99,7 @@ public class GuiceSetupTest {
|
|||
assertSingleton(DisplayedTransactionsFactory.class);
|
||||
|
||||
// core module
|
||||
// assertSingleton(HavenoSetup.class); // this is a can of worms
|
||||
// assertSingleton(BisqSetup.class); // this is a can of worms
|
||||
// assertSingleton(DisputeMsgEvents.class);
|
||||
assertSingleton(TorSetup.class);
|
||||
assertSingleton(P2PNetworkSetup.class);
|
||||
|
|
|
@ -32,8 +32,8 @@ import javafx.collections.ObservableList;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcBuyItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcSellItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrBuyItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrSellItem;
|
||||
import static bisq.desktop.maker.PreferenceMakers.empty;
|
||||
import static bisq.desktop.maker.TradeCurrencyMakers.usd;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
|
@ -57,7 +57,7 @@ public class OfferBookChartViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, null, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, null, null, null);
|
||||
assertEquals(0, model.maxPlacesForBuyPrice.intValue());
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class OfferBookChartViewModelTest {
|
|||
|
||||
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
final OfferBookListItem item = make(OfferBookListItemMaker.btcBuyItem.but(with(OfferBookListItemMaker.useMarketBasedPrice, true)));
|
||||
final OfferBookListItem item = make(OfferBookListItemMaker.xmrBuyItem.but(with(OfferBookListItemMaker.useMarketBasedPrice, true)));
|
||||
item.getOffer().setPriceFeedService(priceFeedService);
|
||||
offerBookListItems.addAll(item);
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class OfferBookChartViewModelTest {
|
|||
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, priceFeedService, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, priceFeedService, null, null);
|
||||
model.activate();
|
||||
assertEquals(0, model.maxPlacesForBuyPrice.intValue());
|
||||
}
|
||||
|
@ -86,16 +86,16 @@ public class OfferBookChartViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
PriceFeedService service = mock(PriceFeedService.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcBuyItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, service, null, null);
|
||||
model.activate();
|
||||
assertEquals(7, model.maxPlacesForBuyPrice.intValue());
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(OfferBookListItemMaker.price, 94016475L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.price, 94016475L))));
|
||||
assertEquals(9, model.maxPlacesForBuyPrice.intValue()); // 9401.6475
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(OfferBookListItemMaker.price, 101016475L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.price, 101016475L))));
|
||||
assertEquals(10, model.maxPlacesForBuyPrice.intValue()); //10101.6475
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ public class OfferBookChartViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, null, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, null, null, null);
|
||||
assertEquals(0, model.maxPlacesForBuyVolume.intValue());
|
||||
}
|
||||
|
||||
|
@ -115,16 +115,16 @@ public class OfferBookChartViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
PriceFeedService service = mock(PriceFeedService.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcBuyItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, service, null, null);
|
||||
model.activate();
|
||||
assertEquals(1, model.maxPlacesForBuyVolume.intValue()); //0
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(OfferBookListItemMaker.amount, 100000000L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.amount, 100000000L))));
|
||||
assertEquals(2, model.maxPlacesForBuyVolume.intValue()); //10
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(OfferBookListItemMaker.amount, 22128600000L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.amount, 22128600000L))));
|
||||
assertEquals(4, model.maxPlacesForBuyVolume.intValue()); //2213
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class OfferBookChartViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, null, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, null, null, null);
|
||||
assertEquals(0, model.maxPlacesForSellPrice.intValue());
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class OfferBookChartViewModelTest {
|
|||
|
||||
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
final OfferBookListItem item = make(OfferBookListItemMaker.btcSellItem.but(with(OfferBookListItemMaker.useMarketBasedPrice, true)));
|
||||
final OfferBookListItem item = make(OfferBookListItemMaker.xmrSellItem.but(with(OfferBookListItemMaker.useMarketBasedPrice, true)));
|
||||
item.getOffer().setPriceFeedService(priceFeedService);
|
||||
offerBookListItems.addAll(item);
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class OfferBookChartViewModelTest {
|
|||
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, priceFeedService, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, priceFeedService, null, null);
|
||||
model.activate();
|
||||
assertEquals(0, model.maxPlacesForSellPrice.intValue());
|
||||
}
|
||||
|
@ -164,16 +164,16 @@ public class OfferBookChartViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
PriceFeedService service = mock(PriceFeedService.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcSellItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrSellItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, service, null, null);
|
||||
model.activate();
|
||||
assertEquals(7, model.maxPlacesForSellPrice.intValue()); // 10.0000 default price
|
||||
offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.price, 94016475L))));
|
||||
offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.price, 94016475L))));
|
||||
assertEquals(9, model.maxPlacesForSellPrice.intValue()); // 9401.6475
|
||||
offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.price, 101016475L))));
|
||||
offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.price, 101016475L))));
|
||||
assertEquals(10, model.maxPlacesForSellPrice.intValue()); // 10101.6475
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ public class OfferBookChartViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, null, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, null, null, null);
|
||||
assertEquals(0, model.maxPlacesForSellVolume.intValue());
|
||||
}
|
||||
|
||||
|
@ -193,16 +193,16 @@ public class OfferBookChartViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
PriceFeedService service = mock(PriceFeedService.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcSellItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrSellItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, empty, service, null, null);
|
||||
final OfferBookChartViewModel model = new OfferBookChartViewModel(offerBook, null, empty, service, null, null);
|
||||
model.activate();
|
||||
assertEquals(1, model.maxPlacesForSellVolume.intValue()); //0
|
||||
offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.amount, 100000000L))));
|
||||
offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.amount, 100000000L))));
|
||||
assertEquals(2, model.maxPlacesForSellVolume.intValue()); //10
|
||||
offerBookListItems.addAll(make(btcSellItem.but(with(OfferBookListItemMaker.amount, 22128600000L))));
|
||||
offerBookListItems.addAll(make(xmrSellItem.but(with(OfferBookListItemMaker.amount, 22128600000L))));
|
||||
assertEquals(4, model.maxPlacesForSellVolume.intValue()); //2213
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ import javafx.collections.ObservableList;
|
|||
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcBuyItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.btcSellItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrBuyItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.xmrSellItem;
|
||||
import static bisq.desktop.main.offer.offerbook.OfferBookListItemMaker.id;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
|
@ -61,14 +61,14 @@ public class SpreadViewModelTest {
|
|||
public void testMaxCharactersForAmount() {
|
||||
OfferBook offerBook = mock(OfferBook.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(btcBuyItem));
|
||||
offerBookListItems.addAll(make(xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
SpreadViewModel model = new SpreadViewModel(offerBook, null, coinFormatter);
|
||||
model.activate();
|
||||
assertEquals(6, model.maxPlacesForAmount.intValue()); // 0.001
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(OfferBookListItemMaker.amount, 1403000000L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(OfferBookListItemMaker.amount, 1403000000L))));
|
||||
assertEquals(7, model.maxPlacesForAmount.intValue()); //14.0300
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class SpreadViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
PriceFeedService priceFeedService = mock(PriceFeedService.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(btcBuyItem));
|
||||
offerBookListItems.addAll(make(xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
|
@ -86,10 +86,10 @@ public class SpreadViewModelTest {
|
|||
|
||||
assertEquals(1, model.spreadItems.get(0).numberOfOffers);
|
||||
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(id, "2345"))),
|
||||
make(btcBuyItem.but(with(id, "2345"))),
|
||||
make(btcSellItem.but(with(id, "3456"))),
|
||||
make(btcSellItem.but(with(id, "3456"))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(id, "2345"))),
|
||||
make(xmrBuyItem.but(with(id, "2345"))),
|
||||
make(xmrSellItem.but(with(id, "3456"))),
|
||||
make(xmrSellItem.but(with(id, "3456"))));
|
||||
|
||||
assertEquals(2, model.spreadItems.get(0).numberOfBuyOffers);
|
||||
assertEquals(1, model.spreadItems.get(0).numberOfSellOffers);
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.bitcoinj.utils.Fiat;
|
|||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableSet;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -45,6 +47,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -94,11 +97,10 @@ public class TradesChartsViewModelTest {
|
|||
false,
|
||||
null,
|
||||
null,
|
||||
1,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
null);
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException {
|
||||
|
@ -115,7 +117,8 @@ public class TradesChartsViewModelTest {
|
|||
@SuppressWarnings("ConstantConditions")
|
||||
@Test
|
||||
public void testGetCandleData() {
|
||||
model.selectedTradeCurrencyProperty.setValue(new FiatCurrency("EUR"));
|
||||
String currencyCode = "EUR";
|
||||
model.selectedTradeCurrencyProperty.setValue(new FiatCurrency(currencyCode));
|
||||
|
||||
long low = Fiat.parseFiat("EUR", "500").value;
|
||||
long open = Fiat.parseFiat("EUR", "520").value;
|
||||
|
@ -163,7 +166,13 @@ public class TradesChartsViewModelTest {
|
|||
null,
|
||||
null));
|
||||
|
||||
CandleData candleData = model.getCandleData(model.roundToTick(now, TradesChartsViewModel.TickUnit.DAY).getTime(), set, 0);
|
||||
Map<Long, Pair<Date, Set<TradeStatistics3>>> itemsPerInterval = null;
|
||||
long tick = ChartCalculations.roundToTick(now, TradesChartsViewModel.TickUnit.DAY).getTime();
|
||||
CandleData candleData = ChartCalculations.getCandleData(tick,
|
||||
set,
|
||||
0,
|
||||
TradesChartsViewModel.TickUnit.DAY, currencyCode,
|
||||
itemsPerInterval);
|
||||
assertEquals(open, candleData.open);
|
||||
assertEquals(close, candleData.close);
|
||||
assertEquals(high, candleData.high);
|
||||
|
|
|
@ -7,6 +7,7 @@ import bisq.core.locale.FiatCurrency;
|
|||
import bisq.core.locale.GlobalSettings;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.CreateOfferService;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.payment.ClearXchangeAccount;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
|
@ -27,7 +28,6 @@ import java.util.UUID;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.core.offer.OfferPayload.Direction;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
@ -96,7 +96,7 @@ public class CreateOfferDataModelTest {
|
|||
when(preferences.getSelectedPaymentAccountForCreateOffer()).thenReturn(revolutAccount);
|
||||
when(offerUtil.getMakerFee(any())).thenReturn(Coin.ZERO);
|
||||
|
||||
model.initWithData(Direction.BUY, new FiatCurrency("USD"));
|
||||
model.initWithData(OfferDirection.BUY, new FiatCurrency("USD"));
|
||||
assertEquals("USD", model.getTradeCurrencyCode().get());
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class CreateOfferDataModelTest {
|
|||
when(preferences.getSelectedPaymentAccountForCreateOffer()).thenReturn(revolutAccount);
|
||||
when(offerUtil.getMakerFee(any())).thenReturn(Coin.ZERO);
|
||||
|
||||
model.initWithData(Direction.BUY, new FiatCurrency("USD"));
|
||||
model.initWithData(OfferDirection.BUY, new FiatCurrency("USD"));
|
||||
assertEquals("USD", model.getTradeCurrencyCode().get());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import bisq.core.locale.CryptoCurrency;
|
|||
import bisq.core.locale.GlobalSettings;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.CreateOfferService;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
|
@ -128,7 +129,7 @@ public class CreateOfferViewModelTest {
|
|||
coinFormatter,
|
||||
tradeStats,
|
||||
null);
|
||||
dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("XMR", "monero"));
|
||||
dataModel.initWithData(OfferDirection.BUY, new CryptoCurrency("XMR", "monero"));
|
||||
dataModel.activate();
|
||||
|
||||
model = new CreateOfferViewModel(dataModel,
|
||||
|
|
|
@ -19,14 +19,14 @@ package bisq.desktop.main.offer.offerbook;
|
|||
|
||||
import bisq.desktop.maker.OfferMaker;
|
||||
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
|
||||
import com.natpryce.makeiteasy.Instantiator;
|
||||
import com.natpryce.makeiteasy.MakeItEasy;
|
||||
import com.natpryce.makeiteasy.Maker;
|
||||
import com.natpryce.makeiteasy.Property;
|
||||
|
||||
import static bisq.desktop.maker.OfferMaker.btcUsdOffer;
|
||||
import static bisq.desktop.maker.OfferMaker.xmrUsdOffer;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
|
@ -37,18 +37,18 @@ public class OfferBookListItemMaker {
|
|||
public static final Property<OfferBookListItem, Long> price = new Property<>();
|
||||
public static final Property<OfferBookListItem, Long> amount = new Property<>();
|
||||
public static final Property<OfferBookListItem, Long> minAmount = new Property<>();
|
||||
public static final Property<OfferBookListItem, OfferPayload.Direction> direction = new Property<>();
|
||||
public static final Property<OfferBookListItem, OfferDirection> direction = new Property<>();
|
||||
public static final Property<OfferBookListItem, Boolean> useMarketBasedPrice = new Property<>();
|
||||
public static final Property<OfferBookListItem, Double> marketPriceMargin = new Property<>();
|
||||
public static final Property<OfferBookListItem, String> baseCurrencyCode = new Property<>();
|
||||
public static final Property<OfferBookListItem, String> counterCurrencyCode = new Property<>();
|
||||
|
||||
public static final Instantiator<OfferBookListItem> OfferBookListItem = lookup ->
|
||||
new OfferBookListItem(make(btcUsdOffer.but(
|
||||
new OfferBookListItem(make(xmrUsdOffer.but(
|
||||
MakeItEasy.with(OfferMaker.price, lookup.valueOf(price, 100000L)),
|
||||
with(OfferMaker.amount, lookup.valueOf(amount, 100000L)),
|
||||
with(OfferMaker.minAmount, lookup.valueOf(amount, 100000L)),
|
||||
with(OfferMaker.direction, lookup.valueOf(direction, OfferPayload.Direction.BUY)),
|
||||
with(OfferMaker.direction, lookup.valueOf(direction, OfferDirection.BUY)),
|
||||
with(OfferMaker.useMarketBasedPrice, lookup.valueOf(useMarketBasedPrice, false)),
|
||||
with(OfferMaker.marketPriceMargin, lookup.valueOf(marketPriceMargin, 0.0)),
|
||||
with(OfferMaker.baseCurrencyCode, lookup.valueOf(baseCurrencyCode, "XMR")),
|
||||
|
@ -57,13 +57,13 @@ public class OfferBookListItemMaker {
|
|||
)));
|
||||
|
||||
public static final Instantiator<OfferBookListItem> OfferBookListItemWithRange = lookup ->
|
||||
new OfferBookListItem(make(btcUsdOffer.but(
|
||||
new OfferBookListItem(make(xmrUsdOffer.but(
|
||||
MakeItEasy.with(OfferMaker.price, lookup.valueOf(price, 100000L)),
|
||||
with(OfferMaker.minAmount, lookup.valueOf(minAmount, 100000L)),
|
||||
with(OfferMaker.amount, lookup.valueOf(amount, 200000L)))));
|
||||
|
||||
public static final Maker<OfferBookListItem> btcBuyItem = a(OfferBookListItem);
|
||||
public static final Maker<OfferBookListItem> btcSellItem = a(OfferBookListItem, with(direction, OfferPayload.Direction.SELL));
|
||||
public static final Maker<OfferBookListItem> xmrBuyItem = a(OfferBookListItem);
|
||||
public static final Maker<OfferBookListItem> xmrSellItem = a(OfferBookListItem, with(direction, OfferDirection.SELL));
|
||||
|
||||
public static final Maker<OfferBookListItem> btcItemWithRange = a(OfferBookListItemWithRange);
|
||||
public static final Maker<OfferBookListItem> xmrItemWithRange = a(OfferBookListItemWithRange);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ import bisq.core.locale.FiatCurrency;
|
|||
import bisq.core.locale.GlobalSettings;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.offer.OpenOfferManager;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.payment.AliPayAccount;
|
||||
import bisq.core.payment.CountryBasedPaymentAccount;
|
||||
import bisq.core.payment.CryptoCurrencyAccount;
|
||||
|
@ -42,6 +42,7 @@ import bisq.core.payment.payload.SpecificBanksAccountPayload;
|
|||
import bisq.core.provider.price.MarketPrice;
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import bisq.core.user.User;
|
||||
import bisq.core.util.PriceUtil;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
import bisq.core.util.coin.ImmutableCoinFormatter;
|
||||
|
@ -75,7 +76,9 @@ import static com.natpryce.makeiteasy.MakeItEasy.make;
|
|||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -83,12 +86,15 @@ import static org.mockito.Mockito.when;
|
|||
public class OfferBookViewModelTest {
|
||||
private final CoinFormatter coinFormatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat());
|
||||
private static final Logger log = LoggerFactory.getLogger(OfferBookViewModelTest.class);
|
||||
private User user;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
GlobalSettings.setDefaultTradeCurrency(usd);
|
||||
Res.setBaseCurrencyCode(usd.getCode());
|
||||
Res.setBaseCurrencyName(usd.getName());
|
||||
user = mock(User.class);
|
||||
when(user.hasPaymentAccountForCurrency(any())).thenReturn(true);
|
||||
}
|
||||
|
||||
private PriceUtil getPriceUtil() {
|
||||
|
@ -236,8 +242,8 @@ public class OfferBookViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
assertEquals(0, model.maxPlacesForAmount.intValue());
|
||||
}
|
||||
|
||||
|
@ -246,16 +252,16 @@ public class OfferBookViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcBuyItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
model.activate();
|
||||
|
||||
assertEquals(6, model.maxPlacesForAmount.intValue());
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(amount, 2000000000L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(amount, 2000000000L))));
|
||||
assertEquals(7, model.maxPlacesForAmount.intValue());
|
||||
}
|
||||
|
||||
|
@ -264,18 +270,18 @@ public class OfferBookViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcItemWithRange));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrItemWithRange));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
model.activate();
|
||||
|
||||
assertEquals(15, model.maxPlacesForAmount.intValue());
|
||||
offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L))));
|
||||
offerBookListItems.addAll(make(xmrItemWithRange.but(with(amount, 2000000000L))));
|
||||
assertEquals(16, model.maxPlacesForAmount.intValue());
|
||||
offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L),
|
||||
offerBookListItems.addAll(make(xmrItemWithRange.but(with(minAmount, 30000000000L),
|
||||
with(amount, 30000000000L))));
|
||||
assertEquals(19, model.maxPlacesForAmount.intValue());
|
||||
}
|
||||
|
@ -287,8 +293,8 @@ public class OfferBookViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
assertEquals(0, model.maxPlacesForVolume.intValue());
|
||||
}
|
||||
|
||||
|
@ -297,16 +303,16 @@ public class OfferBookViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcBuyItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
model.activate();
|
||||
|
||||
assertEquals(5, model.maxPlacesForVolume.intValue());
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(amount, 2000000000L))));
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(amount, 2000000000L))));
|
||||
assertEquals(7, model.maxPlacesForVolume.intValue());
|
||||
}
|
||||
|
||||
|
@ -315,18 +321,18 @@ public class OfferBookViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcItemWithRange));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrItemWithRange));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
model.activate();
|
||||
|
||||
assertEquals(9, model.maxPlacesForVolume.intValue());
|
||||
offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L))));
|
||||
offerBookListItems.addAll(make(xmrItemWithRange.but(with(amount, 2000000000L))));
|
||||
assertEquals(11, model.maxPlacesForVolume.intValue());
|
||||
offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L),
|
||||
offerBookListItems.addAll(make(xmrItemWithRange.but(with(minAmount, 30000000000L),
|
||||
with(amount, 30000000000L))));
|
||||
assertEquals(19, model.maxPlacesForVolume.intValue());
|
||||
}
|
||||
|
@ -338,8 +344,8 @@ public class OfferBookViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
assertEquals(0, model.maxPlacesForPrice.intValue());
|
||||
}
|
||||
|
||||
|
@ -348,18 +354,18 @@ public class OfferBookViewModelTest {
|
|||
OfferBook offerBook = mock(OfferBook.class);
|
||||
OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.btcBuyItem));
|
||||
offerBookListItems.addAll(make(OfferBookListItemMaker.xmrBuyItem));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
model.activate();
|
||||
|
||||
assertEquals(7, model.maxPlacesForPrice.intValue());
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(price, 149558240L)))); //14955.8240
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(price, 149558240L)))); //14955.8240
|
||||
assertEquals(10, model.maxPlacesForPrice.intValue());
|
||||
offerBookListItems.addAll(make(btcBuyItem.but(with(price, 14955824L)))); //1495.58240
|
||||
offerBookListItems.addAll(make(xmrBuyItem.but(with(price, 14955824L)))); //1495.58240
|
||||
assertEquals(10, model.maxPlacesForPrice.intValue());
|
||||
}
|
||||
|
||||
|
@ -370,8 +376,8 @@ public class OfferBookViewModelTest {
|
|||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue());
|
||||
}
|
||||
|
||||
|
@ -382,24 +388,31 @@ public class OfferBookViewModelTest {
|
|||
PriceFeedService priceFeedService = mock(PriceFeedService.class);
|
||||
|
||||
final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
|
||||
final Maker<OfferBookListItem> item = btcBuyItem.but(with(useMarketBasedPrice, true));
|
||||
final Maker<OfferBookListItem> item = xmrBuyItem.but(with(useMarketBasedPrice, true));
|
||||
|
||||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
when(priceFeedService.getMarketPrice(anyString())).thenReturn(null);
|
||||
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
|
||||
|
||||
final OfferBookListItem item1 = make(item);
|
||||
assertNotNull(item1.getHashOfPayload());
|
||||
item1.getOffer().setPriceFeedService(priceFeedService);
|
||||
|
||||
final OfferBookListItem item2 = make(item.but(with(marketPriceMargin, 0.0197)));
|
||||
assertNotNull(item2.getHashOfPayload());
|
||||
item2.getOffer().setPriceFeedService(priceFeedService);
|
||||
|
||||
final OfferBookListItem item3 = make(item.but(with(marketPriceMargin, 0.1)));
|
||||
assertNotNull(item3.getHashOfPayload());
|
||||
item3.getOffer().setPriceFeedService(priceFeedService);
|
||||
|
||||
final OfferBookListItem item4 = make(item.but(with(marketPriceMargin, -0.1)));
|
||||
assertNotNull(item4.getHashOfPayload());
|
||||
item4.getOffer().setPriceFeedService(priceFeedService);
|
||||
offerBookListItems.addAll(item1, item2);
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, priceFeedService,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, priceFeedService,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
model.activate();
|
||||
|
||||
assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)"
|
||||
|
@ -419,18 +432,21 @@ public class OfferBookViewModelTest {
|
|||
when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems);
|
||||
when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true));
|
||||
|
||||
final OfferBookViewModel model = new OfferBookViewModel(null, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter);
|
||||
final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null,
|
||||
null, null, null, getPriceUtil(), null, coinFormatter, null);
|
||||
|
||||
final OfferBookListItem item = make(btcBuyItem.but(
|
||||
final OfferBookListItem item = make(xmrBuyItem.but(
|
||||
with(useMarketBasedPrice, true),
|
||||
with(marketPriceMargin, -0.12)));
|
||||
assertNotNull(item.getHashOfPayload());
|
||||
|
||||
final OfferBookListItem lowItem = make(btcBuyItem.but(
|
||||
final OfferBookListItem lowItem = make(xmrBuyItem.but(
|
||||
with(useMarketBasedPrice, true),
|
||||
with(marketPriceMargin, 0.01)));
|
||||
assertNotNull(lowItem.getHashOfPayload());
|
||||
|
||||
final OfferBookListItem fixedItem = make(btcBuyItem);
|
||||
final OfferBookListItem fixedItem = make(xmrBuyItem);
|
||||
assertNotNull(fixedItem.getHashOfPayload());
|
||||
|
||||
item.getOffer().setPriceFeedService(priceFeedService);
|
||||
lowItem.getOffer().setPriceFeedService(priceFeedService);
|
||||
|
@ -592,7 +608,7 @@ public class OfferBookViewModelTest {
|
|||
false,
|
||||
0,
|
||||
0,
|
||||
"XMR",
|
||||
"BTC",
|
||||
tradeCurrencyCode,
|
||||
paymentMethodId,
|
||||
null,
|
||||
|
@ -616,9 +632,10 @@ public class OfferBookViewModelTest {
|
|||
false,
|
||||
null,
|
||||
null,
|
||||
1,
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
null));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
package bisq.desktop.main.portfolio.editoffer;
|
||||
|
||||
import bisq.desktop.util.validation.SecurityDepositValidator;
|
||||
|
||||
import bisq.core.account.witness.AccountAgeWitnessService;
|
||||
import bisq.core.btc.model.XmrAddressEntry;
|
||||
import bisq.core.btc.wallet.XmrWalletService;
|
||||
import bisq.core.locale.Country;
|
||||
import bisq.core.locale.CryptoCurrency;
|
||||
import bisq.core.locale.GlobalSettings;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.offer.CreateOfferService;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.offer.OfferUtil;
|
||||
import bisq.core.offer.OpenOffer;
|
||||
import bisq.core.payment.CryptoCurrencyAccount;
|
||||
import bisq.core.payment.PaymentAccount;
|
||||
import bisq.core.provider.fee.FeeService;
|
||||
import bisq.core.provider.price.MarketPrice;
|
||||
import bisq.core.provider.price.PriceFeedService;
|
||||
import bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import bisq.core.user.Preferences;
|
||||
import bisq.core.user.User;
|
||||
import bisq.core.util.validation.InputValidator;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static bisq.desktop.maker.OfferMaker.btcBCHCOffer;
|
||||
import static bisq.desktop.maker.PreferenceMakers.empty;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class EditOfferDataModelTest {
|
||||
|
||||
private EditOfferDataModel model;
|
||||
private User user;
|
||||
|
||||
@Rule
|
||||
public final ExpectedException exception = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
final CryptoCurrency xmr = new CryptoCurrency("XMR", "monero");
|
||||
GlobalSettings.setDefaultTradeCurrency(xmr);
|
||||
Res.setup();
|
||||
|
||||
FeeService feeService = mock(FeeService.class);
|
||||
XmrAddressEntry addressEntry = mock(XmrAddressEntry.class);
|
||||
XmrWalletService xmrWalletService = mock(XmrWalletService.class);
|
||||
PriceFeedService priceFeedService = mock(PriceFeedService.class);
|
||||
user = mock(User.class);
|
||||
PaymentAccount paymentAccount = mock(PaymentAccount.class);
|
||||
Preferences preferences = mock(Preferences.class);
|
||||
SecurityDepositValidator securityDepositValidator = mock(SecurityDepositValidator.class);
|
||||
AccountAgeWitnessService accountAgeWitnessService = mock(AccountAgeWitnessService.class);
|
||||
CreateOfferService createOfferService = mock(CreateOfferService.class);
|
||||
OfferUtil offerUtil = mock(OfferUtil.class);
|
||||
|
||||
when(xmrWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
|
||||
when(xmrWalletService.getBalanceForSubaddress(any(Integer.class))).thenReturn(Coin.valueOf(1000L));
|
||||
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
|
||||
when(priceFeedService.getMarketPrice(anyString())).thenReturn(
|
||||
new MarketPrice("USD",
|
||||
12684.0450,
|
||||
Instant.now().getEpochSecond(),
|
||||
true));
|
||||
when(feeService.getTxFee(anyInt())).thenReturn(Coin.valueOf(1000L));
|
||||
when(user.findFirstPaymentAccountWithCurrency(any())).thenReturn(paymentAccount);
|
||||
when(user.getPaymentAccountsAsObservable()).thenReturn(FXCollections.observableSet());
|
||||
when(securityDepositValidator.validate(any())).thenReturn(new InputValidator.ValidationResult(false));
|
||||
when(accountAgeWitnessService.getMyTradeLimit(any(), any(), any())).thenReturn(100000000L);
|
||||
when(preferences.getUserCountry()).thenReturn(new Country("US", "United States", null));
|
||||
when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString());
|
||||
|
||||
model = new EditOfferDataModel(createOfferService,
|
||||
null,
|
||||
offerUtil,
|
||||
xmrWalletService,
|
||||
empty,
|
||||
user,
|
||||
null,
|
||||
priceFeedService,
|
||||
accountAgeWitnessService,
|
||||
feeService,
|
||||
null,
|
||||
null,
|
||||
mock(TradeStatisticsManager.class),
|
||||
null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEditOfferOfRemovedAsset() {
|
||||
|
||||
final CryptoCurrencyAccount bitcoinClashicAccount = new CryptoCurrencyAccount();
|
||||
bitcoinClashicAccount.setId("BCHC");
|
||||
|
||||
when(user.getPaymentAccount(anyString())).thenReturn(bitcoinClashicAccount);
|
||||
|
||||
model.applyOpenOffer(new OpenOffer(make(btcBCHCOffer)));
|
||||
assertNull(model.getPreselectedPaymentAccount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitializeEditOfferWithRemovedAsset() {
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
model.initWithData(OfferPayload.Direction.BUY, null);
|
||||
}
|
||||
}
|
|
@ -18,33 +18,68 @@
|
|||
package bisq.desktop.maker;
|
||||
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferDirection;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
|
||||
import bisq.network.p2p.NodeAddress;
|
||||
|
||||
import bisq.common.crypto.Encryption;
|
||||
import bisq.common.crypto.PubKeyRing;
|
||||
import bisq.common.crypto.Sig;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.natpryce.makeiteasy.Instantiator;
|
||||
import com.natpryce.makeiteasy.Maker;
|
||||
import com.natpryce.makeiteasy.Property;
|
||||
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.a;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
import static com.natpryce.makeiteasy.Property.newProperty;
|
||||
import static java.lang.System.currentTimeMillis;
|
||||
import static java.net.InetAddress.getLocalHost;
|
||||
|
||||
@SuppressWarnings("InstantiationOfUtilityClass")
|
||||
public class OfferMaker {
|
||||
|
||||
public static final Property<Offer, Long> price = new Property<>();
|
||||
public static final Property<Offer, Long> minAmount = new Property<>();
|
||||
public static final Property<Offer, Long> amount = new Property<>();
|
||||
public static final Property<Offer, String> baseCurrencyCode = new Property<>();
|
||||
public static final Property<Offer, String> counterCurrencyCode = new Property<>();
|
||||
public static final Property<Offer, OfferPayload.Direction> direction = new Property<>();
|
||||
public static final Property<Offer, Boolean> useMarketBasedPrice = new Property<>();
|
||||
public static final Property<Offer, Double> marketPriceMargin = new Property<>();
|
||||
public static final Property<Offer, String> id = new Property<>();
|
||||
public static final Property<Offer, String> id = newProperty();
|
||||
public static final Property<Offer, String> paymentMethodId = newProperty();
|
||||
public static final Property<Offer, String> paymentAccountId = newProperty();
|
||||
public static final Property<Offer, String> offerFeePaymentTxId = newProperty();
|
||||
public static final Property<Offer, String> countryCode = newProperty();
|
||||
public static final Property<Offer, List<String>> countryCodes = newProperty();
|
||||
public static final Property<Offer, Long> date = newProperty();
|
||||
public static final Property<Offer, Long> price = newProperty();
|
||||
public static final Property<Offer, Long> minAmount = newProperty();
|
||||
public static final Property<Offer, Long> amount = newProperty();
|
||||
public static final Property<Offer, String> baseCurrencyCode = newProperty();
|
||||
public static final Property<Offer, String> counterCurrencyCode = newProperty();
|
||||
public static final Property<Offer, OfferDirection> direction = newProperty();
|
||||
public static final Property<Offer, Boolean> useMarketBasedPrice = newProperty();
|
||||
public static final Property<Offer, Double> marketPriceMargin = newProperty();
|
||||
public static final Property<Offer, NodeAddress> nodeAddress = newProperty();
|
||||
public static final Property<Offer, List<NodeAddress>> nodeAddresses = newProperty();
|
||||
public static final Property<Offer, PubKeyRing> pubKeyRing = newProperty();
|
||||
public static final Property<Offer, Long> blockHeight = newProperty();
|
||||
public static final Property<Offer, Long> txFee = newProperty();
|
||||
public static final Property<Offer, Long> makerFee = newProperty();
|
||||
public static final Property<Offer, Long> buyerSecurityDeposit = newProperty();
|
||||
public static final Property<Offer, Long> sellerSecurityDeposit = newProperty();
|
||||
public static final Property<Offer, Long> tradeLimit = newProperty();
|
||||
public static final Property<Offer, Long> maxTradePeriod = newProperty();
|
||||
public static final Property<Offer, Long> lowerClosePrice = newProperty();
|
||||
public static final Property<Offer, Long> upperClosePrice = newProperty();
|
||||
public static final Property<Offer, Integer> protocolVersion = newProperty();
|
||||
|
||||
public static final Instantiator<Offer> Offer = lookup -> new Offer(
|
||||
new OfferPayload(lookup.valueOf(id, "1234"),
|
||||
0L,
|
||||
null,
|
||||
null,
|
||||
lookup.valueOf(direction, OfferPayload.Direction.BUY),
|
||||
lookup.valueOf(date, currentTimeMillis()),
|
||||
lookup.valueOf(nodeAddress, getLocalHostNodeWithPort(10000)),
|
||||
lookup.valueOf(pubKeyRing, genPubKeyRing()),
|
||||
lookup.valueOf(direction, OfferDirection.BUY),
|
||||
lookup.valueOf(price, 100000L),
|
||||
lookup.valueOf(marketPriceMargin, 0.0),
|
||||
lookup.valueOf(useMarketBasedPrice, false),
|
||||
|
@ -52,33 +87,47 @@ public class OfferMaker {
|
|||
lookup.valueOf(minAmount, 100000L),
|
||||
lookup.valueOf(baseCurrencyCode, "XMR"),
|
||||
lookup.valueOf(counterCurrencyCode, "USD"),
|
||||
"SEPA",
|
||||
"",
|
||||
lookup.valueOf(paymentMethodId, "SEPA"),
|
||||
lookup.valueOf(paymentAccountId, "00002c4d-1ffc-4208-8ff3-e669817b0000"),
|
||||
lookup.valueOf(offerFeePaymentTxId, "0000dcd1d388b95714c96ce13f5cb000090c41a1faf89e4ce7680938cc170000"),
|
||||
lookup.valueOf(countryCode, "FR"),
|
||||
lookup.valueOf(countryCodes, new ArrayList<>() {{
|
||||
add("FR");
|
||||
}}),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
"",
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
0L,
|
||||
"2",
|
||||
lookup.valueOf(blockHeight, 700000L),
|
||||
lookup.valueOf(txFee, 250L),
|
||||
lookup.valueOf(makerFee, 1000L),
|
||||
lookup.valueOf(buyerSecurityDeposit, 10000L),
|
||||
lookup.valueOf(sellerSecurityDeposit, 10000L),
|
||||
lookup.valueOf(tradeLimit, 0L),
|
||||
lookup.valueOf(maxTradePeriod, 0L),
|
||||
false,
|
||||
false,
|
||||
0L,
|
||||
0L,
|
||||
lookup.valueOf(lowerClosePrice, 0L),
|
||||
lookup.valueOf(upperClosePrice, 0L),
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
null,
|
||||
lookup.valueOf(protocolVersion, 0),
|
||||
getLocalHostNodeWithPort(99999),
|
||||
null,
|
||||
null));
|
||||
|
||||
public static final Maker<Offer> btcUsdOffer = a(Offer);
|
||||
public static final Maker<Offer> xmrUsdOffer = a(Offer);
|
||||
public static final Maker<Offer> btcBCHCOffer = a(Offer).but(with(counterCurrencyCode, "BCHC"));
|
||||
|
||||
static NodeAddress getLocalHostNodeWithPort(int port) {
|
||||
try {
|
||||
return new NodeAddress(getLocalHost().getHostAddress(), port);
|
||||
} catch (UnknownHostException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static PubKeyRing genPubKeyRing() {
|
||||
return new PubKeyRing(Sig.generateKeyPair().getPublic(), Encryption.generateKeyPair().getPublic());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ public class PreferenceMakers {
|
|||
lookup.valueOf(config, new SameValueDonor<Config>(null)),
|
||||
lookup.valueOf(feeService, new SameValueDonor<FeeService>(null)),
|
||||
lookup.valueOf(localBitcoinNode, new SameValueDonor<LocalBitcoinNode>(null)),
|
||||
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<String>(null)));
|
||||
lookup.valueOf(useTorFlagFromOptions, new SameValueDonor<String>(null))
|
||||
);
|
||||
|
||||
public static final Preferences empty = make(a(Preferences));
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package bisq.desktop.util;
|
||||
|
||||
import bisq.core.locale.GlobalSettings;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.monetary.Volume;
|
||||
import bisq.core.offer.Offer;
|
||||
import bisq.core.offer.OfferPayload;
|
||||
import bisq.core.util.coin.ImmutableCoinFormatter;
|
||||
import bisq.core.util.VolumeUtil;
|
||||
import bisq.core.util.coin.CoinFormatter;
|
||||
import bisq.core.util.coin.ImmutableCoinFormatter;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
|
||||
|
@ -17,7 +19,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.desktop.maker.OfferMaker.btcUsdOffer;
|
||||
import static bisq.desktop.maker.OfferMaker.xmrUsdOffer;
|
||||
import static bisq.desktop.maker.VolumeMaker.usdVolume;
|
||||
import static bisq.desktop.maker.VolumeMaker.volumeString;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
|
@ -31,7 +33,8 @@ public class DisplayUtilsTest {
|
|||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Locale.setDefault(new Locale("en", "US"));
|
||||
Locale.setDefault(Locale.US);
|
||||
GlobalSettings.setLocale(Locale.US);
|
||||
Res.setBaseCurrencyCode("XMR");
|
||||
Res.setBaseCurrencyName("Monero");
|
||||
}
|
||||
|
@ -49,9 +52,9 @@ public class DisplayUtilsTest {
|
|||
|
||||
@Test
|
||||
public void testFormatVolume() {
|
||||
assertEquals("1", DisplayUtils.formatVolume(make(btcUsdOffer), true, 4));
|
||||
assertEquals("100", DisplayUtils.formatVolume(make(usdVolume)));
|
||||
assertEquals("1775", DisplayUtils.formatVolume(make(usdVolume.but(with(volumeString, "1774.62")))));
|
||||
assertEquals("1", VolumeUtil.formatVolume(make(xmrUsdOffer), true, 4));
|
||||
assertEquals("100", VolumeUtil.formatVolume(make(usdVolume)));
|
||||
assertEquals("1775", VolumeUtil.formatVolume(make(usdVolume.but(with(volumeString, "1774.62")))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -61,7 +64,7 @@ public class DisplayUtilsTest {
|
|||
when(offer.getMinVolume()).thenReturn(xmr);
|
||||
when(offer.getVolume()).thenReturn(xmr);
|
||||
|
||||
assertEquals("0.10000000", DisplayUtils.formatVolume(offer.getVolume()));
|
||||
assertEquals("0.10000000", VolumeUtil.formatVolume(offer.getVolume()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,7 +76,7 @@ public class DisplayUtilsTest {
|
|||
when(offer.getMinVolume()).thenReturn(xmrMin);
|
||||
when(offer.getVolume()).thenReturn(xmrMax);
|
||||
|
||||
assertEquals("0.10000000 - 0.25000000", DisplayUtils.formatVolume(offer, false, 0));
|
||||
assertEquals("0.10000000 - 0.25000000", VolumeUtil.formatVolume(offer, false, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -82,7 +85,7 @@ public class DisplayUtilsTest {
|
|||
when(offer.getMinVolume()).thenReturn(null);
|
||||
when(offer.getVolume()).thenReturn(null);
|
||||
|
||||
assertEquals("", DisplayUtils.formatVolume(offer.getVolume()));
|
||||
assertEquals("", VolumeUtil.formatVolume(offer.getVolume()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -56,8 +56,8 @@ public class GUIUtilTest {
|
|||
public void setup() {
|
||||
Locale.setDefault(new Locale("en", "US"));
|
||||
GlobalSettings.setLocale(new Locale("en", "US"));
|
||||
Res.setBaseCurrencyCode("XMR");
|
||||
Res.setBaseCurrencyName("Monero");
|
||||
Res.setBaseCurrencyCode("BTC");
|
||||
Res.setBaseCurrencyName("Bitcoin");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package bisq.desktop.util.validation;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
import bisq.core.locale.Res;
|
||||
import bisq.core.util.validation.RegexValidator;
|
||||
|
||||
import bisq.common.config.BaseCurrencyNetwork;
|
||||
import bisq.common.config.Config;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class CapitualValidatorTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
final BaseCurrencyNetwork baseCurrencyNetwork = Config.baseCurrencyNetwork();
|
||||
final String currencyCode = baseCurrencyNetwork.getCurrencyCode();
|
||||
Res.setBaseCurrencyCode(currencyCode);
|
||||
Res.setBaseCurrencyName(baseCurrencyNetwork.getCurrencyName());
|
||||
CurrencyUtil.setBaseCurrencyCode(currencyCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validate() {
|
||||
CapitualValidator validator = new CapitualValidator(
|
||||
new RegexValidator()
|
||||
);
|
||||
|
||||
assertTrue(validator.validate("CAP-123456").isValid);
|
||||
assertTrue(validator.validate("CAP-XXXXXX").isValid);
|
||||
assertTrue(validator.validate("CAP-123XXX").isValid);
|
||||
|
||||
assertFalse(validator.validate("").isValid);
|
||||
assertFalse(validator.validate(null).isValid);
|
||||
assertFalse(validator.validate("123456").isValid);
|
||||
assertFalse(validator.validate("XXXXXX").isValid);
|
||||
assertFalse(validator.validate("123XXX").isValid);
|
||||
assertFalse(validator.validate("12XXX").isValid);
|
||||
assertFalse(validator.validate("CAP-12XXX").isValid);
|
||||
assertFalse(validator.validate("CA-12XXXx").isValid);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue