diff --git a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java index b346ad51952..6a1988911d5 100644 --- a/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java +++ b/core/src/main/java/bisq/core/payment/payload/PaymentMethod.java @@ -42,8 +42,6 @@ import org.jetbrains.annotations.NotNull; -import static com.google.common.base.Preconditions.checkNotNull; - @EqualsAndHashCode(exclude = {"maxTradePeriod", "maxTradeLimit"}) @ToString @Slf4j @@ -381,14 +379,18 @@ public static Optional getActivePaymentMethod(String id) { // We leave currencyCode as param for being flexible if we need custom handling of a currency in future // again (as we had in the past) public Coin getMaxTradeLimitAsCoin(String currencyCode) { + // We adjust the custom trade limits with the factor of the change of the DAO param. Initially it was set to 2 BTC. + long initialTradeLimit = 200000000; TradeLimits tradeLimits = TradeLimits.getINSTANCE(); - checkNotNull(tradeLimits, "tradeLimits must not be null"); + if (tradeLimits == null) { + // is null in some tests... + log.warn("tradeLimits was null"); + return Coin.valueOf(initialTradeLimit); + } long maxTradeLimitFromDaoParam = tradeLimits.getMaxTradeLimitFromDaoParam().value; // Payment methods which define their own trade limits if (id.equals(NEFT_ID) || id.equals(UPI_ID) || id.equals(PAYTM_ID) || id.equals(BIZUM_ID) || id.equals(TIKKIE_ID)) { - // We adjust the custom trade limits with the factor of the change of the DAO param. Initially it was set to 2 BTC. - long initialTradeLimit = 200000000; double factor = maxTradeLimitFromDaoParam / (double) initialTradeLimit; long value = MathUtils.roundDoubleToLong(Coin.valueOf(maxTradeLimit).getValue() * factor); return Coin.valueOf(value); diff --git a/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java b/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java index 4ad75198916..68692801c88 100644 --- a/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java +++ b/core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java @@ -69,7 +69,8 @@ public void testStartEditOfferForActiveOffer() { null, null, null, - persistenceManager + persistenceManager, + null ); AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false); @@ -118,7 +119,8 @@ public void testStartEditOfferForDeactivatedOffer() { null, null, null, - persistenceManager + persistenceManager, + null ); AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false); @@ -159,7 +161,8 @@ public void testStartEditOfferForOfferThatIsCurrentlyEdited() { null, null, null, - persistenceManager + persistenceManager, + null ); AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false); diff --git a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java index 28e98312fe4..e03f47e87d4 100644 --- a/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java +++ b/desktop/src/test/java/bisq/desktop/main/offer/offerbook/OfferBookViewModelTest.java @@ -17,6 +17,7 @@ package bisq.desktop.main.offer.offerbook; +import bisq.core.dao.state.DaoStateService; import bisq.core.locale.Country; import bisq.core.locale.CryptoCurrency; import bisq.core.locale.FiatCurrency; @@ -85,6 +86,7 @@ public class OfferBookViewModelTest { private final CoinFormatter coinFormatter = new ImmutableCoinFormatter(Config.baseCurrencyNetworkParameters().getMonetaryFormat()); private User user; + private final DaoStateService daoStateService = new DaoStateService(null, null, null); @BeforeEach public void setUp() { @@ -241,7 +243,7 @@ public void testMaxCharactersForAmountWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); assertEquals(0, model.maxPlacesForAmount.intValue()); } @@ -255,12 +257,13 @@ public void testMaxCharactersForAmount() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), + null, coinFormatter, new BsqFormatter(), null, null, daoStateService); model.activate(); assertEquals(6, model.maxPlacesForAmount.intValue()); - offerBookListItems.addAll(make(btcBuyItem.but(with(amount, 2000000000L)))); - assertEquals(7, model.maxPlacesForAmount.intValue()); + offerBookListItems.addAll(make(btcBuyItem.but(with(amount, 200000000L)))); + assertEquals(6, model.maxPlacesForAmount.intValue()); } @Test @@ -273,15 +276,12 @@ public void testMaxCharactersForAmountRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); model.activate(); assertEquals(15, model.maxPlacesForAmount.intValue()); - offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L)))); - assertEquals(16, model.maxPlacesForAmount.intValue()); - offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L), - with(amount, 30000000000L)))); - assertEquals(19, model.maxPlacesForAmount.intValue()); + offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 200000000L)))); + assertEquals(15, model.maxPlacesForAmount.intValue()); } @Test @@ -292,7 +292,7 @@ public void testMaxCharactersForVolumeWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); assertEquals(0, model.maxPlacesForVolume.intValue()); } @@ -306,12 +306,13 @@ public void testMaxCharactersForVolume() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, + coinFormatter, new BsqFormatter(), null, null, daoStateService); model.activate(); assertEquals(5, model.maxPlacesForVolume.intValue()); - offerBookListItems.addAll(make(btcBuyItem.but(with(amount, 2000000000L)))); - assertEquals(7, model.maxPlacesForVolume.intValue()); + offerBookListItems.addAll(make(btcBuyItem.but(with(amount, 200000000L)))); + assertEquals(6, model.maxPlacesForVolume.intValue()); } @Test @@ -324,15 +325,12 @@ public void testMaxCharactersForVolumeRange() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); model.activate(); assertEquals(9, model.maxPlacesForVolume.intValue()); - offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 2000000000L)))); - assertEquals(11, model.maxPlacesForVolume.intValue()); - offerBookListItems.addAll(make(btcItemWithRange.but(with(minAmount, 30000000000L), - with(amount, 30000000000L)))); - assertEquals(19, model.maxPlacesForVolume.intValue()); + offerBookListItems.addAll(make(btcItemWithRange.but(with(amount, 200000000L)))); + assertEquals(10, model.maxPlacesForVolume.intValue()); } @Test @@ -343,7 +341,7 @@ public void testMaxCharactersForPriceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); assertEquals(0, model.maxPlacesForPrice.intValue()); } @@ -357,7 +355,7 @@ public void testMaxCharactersForPrice() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); model.activate(); assertEquals(7, model.maxPlacesForPrice.intValue()); @@ -375,7 +373,7 @@ public void testMaxCharactersForPriceDistanceWithNoOffers() { when(offerBook.getOfferBookListItems()).thenReturn(offerBookListItems); final OfferBookViewModel model = new BtcOfferBookViewModel(null, null, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); assertEquals(0, model.maxPlacesForMarketPriceMargin.intValue()); } @@ -410,7 +408,7 @@ public void testMaxCharactersForPriceDistance() { offerBookListItems.addAll(item1, item2); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, priceFeedService, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); model.activate(); assertEquals(8, model.maxPlacesForMarketPriceMargin.intValue()); //" (1.97%)" @@ -431,7 +429,7 @@ public void testGetPrice() { when(priceFeedService.getMarketPrice(anyString())).thenReturn(new MarketPrice("USD", 12684.0450, Instant.now().getEpochSecond(), true)); final OfferBookViewModel model = new BtcOfferBookViewModel(user, openOfferManager, offerBook, empty, null, null, null, - null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null); + null, null, null, null, getPriceUtil(), null, coinFormatter, new BsqFormatter(), null, null, daoStateService); final OfferBookListItem item = make(btcBuyItem.but( with(useMarketBasedPrice, true),