Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Don't use 20 BTC amount as we limit to 2 BTC
Remove 30 BTC amounts
  • Loading branch information
HenrikJannsen committed May 26, 2024
1 parent bb191fa commit 8c07c11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
12 changes: 7 additions & 5 deletions core/src/main/java/bisq/core/payment/payload/PaymentMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@

import org.jetbrains.annotations.NotNull;

import static com.google.common.base.Preconditions.checkNotNull;

@EqualsAndHashCode(exclude = {"maxTradePeriod", "maxTradeLimit"})
@ToString
@Slf4j
Expand Down Expand Up @@ -381,14 +379,18 @@ public static Optional<PaymentMethod> 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);
Expand Down
9 changes: 6 additions & 3 deletions core/src/test/java/bisq/core/offer/OpenOfferManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void testStartEditOfferForActiveOffer() {
null,
null,
null,
persistenceManager
persistenceManager,
null
);

AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false);
Expand Down Expand Up @@ -118,7 +119,8 @@ public void testStartEditOfferForDeactivatedOffer() {
null,
null,
null,
persistenceManager
persistenceManager,
null
);

AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false);
Expand Down Expand Up @@ -159,7 +161,8 @@ public void testStartEditOfferForOfferThatIsCurrentlyEdited() {
null,
null,
null,
persistenceManager
persistenceManager,
null
);

AtomicBoolean startEditOfferSuccessful = new AtomicBoolean(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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());
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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());
}

Expand All @@ -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());
Expand All @@ -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());
}

Expand Down Expand Up @@ -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%)"
Expand All @@ -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),
Expand Down

0 comments on commit 8c07c11

Please sign in to comment.