Search in sources :

Example 26 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method testGetPrice.

@Test
public void testGetPrice() {
    OfferBook offerBook = mock(OfferBook.class);
    OpenOfferManager openOfferManager = mock(OpenOfferManager.class);
    PriceFeedService priceFeedService = mock(PriceFeedService.class);
    final ObservableList<OfferBookListItem> offerBookListItems = FXCollections.observableArrayList();
    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, null, new BSFormatter());
    final OfferBookListItem item = make(btcItem.but(with(useMarketBasedPrice, true), with(marketPriceMargin, -0.12)));
    final OfferBookListItem lowItem = make(btcItem.but(with(useMarketBasedPrice, true), with(marketPriceMargin, 0.01)));
    final OfferBookListItem fixedItem = make(btcItem);
    item.getOffer().setPriceFeedService(priceFeedService);
    lowItem.getOffer().setPriceFeedService(priceFeedService);
    offerBookListItems.addAll(lowItem, fixedItem);
    model.activate();
    assertEquals("12557.2046 (1.00%)", model.getPrice(lowItem));
    assertEquals("   10.0000        ", model.getPrice(fixedItem));
    offerBookListItems.addAll(item);
    assertEquals("14206.1304 (-12.00%)", model.getPrice(item));
    assertEquals("12557.2046   (1.00%)", model.getPrice(lowItem));
}
Also used : OpenOfferManager(bisq.core.offer.OpenOfferManager) MarketPrice(bisq.core.provider.price.MarketPrice) PriceFeedService(bisq.core.provider.price.PriceFeedService) BSFormatter(bisq.desktop.util.BSFormatter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with BSFormatter

use of bisq.desktop.util.BSFormatter in project bisq-desktop by bisq-network.

the class BtcValidatorTest method testIsValid.

@Test
public void testIsValid() {
    BtcValidator validator = new BtcValidator(new BSFormatter());
    assertTrue(validator.validate("1").isValid);
    assertTrue(validator.validate("0,1").isValid);
    assertTrue(validator.validate("0.1").isValid);
    assertTrue(validator.validate(",1").isValid);
    assertTrue(validator.validate(".1").isValid);
    assertTrue(validator.validate("0.12345678").isValid);
    // below dust
    assertFalse(validator.validate(Coin.SATOSHI.toPlainString()).isValid);
    assertFalse(validator.validate(null).isValid);
    assertFalse(validator.validate("").isValid);
    assertFalse(validator.validate("0").isValid);
    assertFalse(validator.validate("0.0").isValid);
    assertFalse(validator.validate("0,1,1").isValid);
    assertFalse(validator.validate("0.1.1").isValid);
    assertFalse(validator.validate("0,000.1").isValid);
    assertFalse(validator.validate("0.000,1").isValid);
    assertFalse(validator.validate("0.123456789").isValid);
    assertFalse(validator.validate("-1").isValid);
// assertFalse(validator.validate(NetworkParameters.MAX_MONEY.toPlainString()).isValid);
}
Also used : BSFormatter(bisq.desktop.util.BSFormatter) Test(org.junit.Test)

Aggregations

BSFormatter (bisq.desktop.util.BSFormatter)27 Test (org.junit.Test)24 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 OfferBook (bisq.desktop.main.offer.offerbook.OfferBook)12 OfferBookListItem (bisq.desktop.main.offer.offerbook.OfferBookListItem)12 PriceFeedService (bisq.core.provider.price.PriceFeedService)9 OpenOfferManager (bisq.core.offer.OpenOfferManager)7 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)4 AddressEntry (bisq.core.btc.AddressEntry)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 MarketPrice (bisq.core.provider.price.MarketPrice)2 Popup (bisq.desktop.main.overlays.popups.Popup)2 Coin (org.bitcoinj.core.Coin)2 Transaction (org.bitcoinj.core.Transaction)2 AddressEntryException (bisq.core.btc.AddressEntryException)1 InsufficientFundsException (bisq.core.btc.InsufficientFundsException)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 BsqWalletService (bisq.core.btc.wallet.BsqWalletService)1 ChangeBelowDustException (bisq.core.btc.wallet.ChangeBelowDustException)1