This commit is contained in:
woodser 2021-05-04 20:20:30 -04:00
parent 8a38081c04
commit a22edd60f8
241 changed files with 10631 additions and 4905 deletions

View file

@ -17,28 +17,35 @@
package bisq.desktop.main.funds.transactions;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.XmrWalletService;
import org.bitcoinj.core.Transaction;
import com.google.common.collect.Sets;
import com.google.common.collect.Lists;
import javafx.collections.FXCollections;
import java.util.Collections;
import java.util.Set;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import monero.wallet.model.MoneroTxWallet;
public class DisplayedTransactionsTest {
@Test
public void testUpdate() {
Set<Transaction> transactions = Sets.newHashSet(mock(Transaction.class), mock(Transaction.class));
List<MoneroTxWallet> transactions = Lists.newArrayList(mock(MoneroTxWallet.class), mock(MoneroTxWallet.class));
BtcWalletService walletService = mock(BtcWalletService.class);
XmrWalletService walletService = mock(XmrWalletService.class);
when(walletService.getTransactions(false)).thenReturn(transactions);
TransactionListItemFactory transactionListItemFactory = mock(TransactionListItemFactory.class,
@ -58,9 +65,9 @@ public class DisplayedTransactionsTest {
@Test
public void testUpdateWhenRepositoryIsEmpty() {
BtcWalletService walletService = mock(BtcWalletService.class);
XmrWalletService walletService = mock(XmrWalletService.class);
when(walletService.getTransactions(false))
.thenReturn(Collections.singleton(mock(Transaction.class)));
.thenReturn(Collections.singletonList(mock(MoneroTxWallet.class)));
TradableRepository tradableRepository = mock(TradableRepository.class);
when(tradableRepository.getAll()).thenReturn(FXCollections.emptyObservableSet());

View file

@ -22,13 +22,15 @@ import bisq.core.support.dispute.arbitration.ArbitrationManager;
import bisq.core.trade.Tradable;
import bisq.core.trade.Trade;
import org.bitcoinj.core.Transaction;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
import monero.wallet.model.MoneroTxWallet;
public class TransactionAwareTradableFactoryTest {
@Test
public void testCreateWhenNotOpenOfferOrTrade() {
@ -43,6 +45,6 @@ public class TransactionAwareTradableFactoryTest {
TransactionAwareTradable tradable = factory.create(delegate);
assertFalse(tradable.isRelatedToTransaction(mock(Transaction.class)));
assertFalse(tradable.isRelatedToTransaction(mock(MoneroTxWallet.class)));
}
}

View file

@ -17,14 +17,13 @@
package bisq.desktop.main.funds.transactions;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.XmrWalletService;
import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.arbitration.ArbitrationManager;
import bisq.core.support.dispute.refund.RefundManager;
import bisq.core.trade.Trade;
import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Transaction;
import javafx.collections.FXCollections;
@ -38,26 +37,30 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import monero.wallet.model.MoneroTxWallet;
public class TransactionAwareTradeTest {
private static final Sha256Hash XID = Sha256Hash.wrap("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef");
private Transaction transaction;
private MoneroTxWallet transaction;
private ArbitrationManager arbitrationManager;
private Trade delegate;
private TransactionAwareTradable trade;
private RefundManager refundManager;
private BtcWalletService btcWalletService;
private XmrWalletService xmrWalletService;
@Before
public void setUp() {
this.transaction = mock(Transaction.class);
when(transaction.getTxId()).thenReturn(XID);
this.transaction = mock(MoneroTxWallet.class);
when(transaction.getHash()).thenReturn(XID.toString());
delegate = mock(Trade.class, RETURNS_DEEP_STUBS);
arbitrationManager = mock(ArbitrationManager.class, RETURNS_DEEP_STUBS);
refundManager = mock(RefundManager.class, RETURNS_DEEP_STUBS);
btcWalletService = mock(BtcWalletService.class, RETURNS_DEEP_STUBS);
trade = new TransactionAwareTrade(delegate, arbitrationManager, refundManager, btcWalletService, null);
xmrWalletService = mock(XmrWalletService.class, RETURNS_DEEP_STUBS);
trade = new TransactionAwareTrade(delegate, arbitrationManager, refundManager, xmrWalletService, null);
}
@Test
@ -68,13 +71,19 @@ public class TransactionAwareTradeTest {
@Test
public void testIsRelatedToTransactionWhenPayoutTx() {
when(delegate.getPayoutTx().getTxId()).thenReturn(XID);
when(delegate.getPayoutTx().getHash()).thenReturn(XID.toString());
assertTrue(trade.isRelatedToTransaction(transaction));
}
@Test
public void testIsRelatedToTransactionWhenDepositTx() {
when(delegate.getDepositTx().getTxId()).thenReturn(XID);
public void testIsRelatedToTransactionWhenMakerDepositTx() {
when(delegate.getMakerDepositTx().getHash()).thenReturn(XID.toString());
assertTrue(trade.isRelatedToTransaction(transaction));
}
@Test
public void testIsRelatedToTransactionWhenTakerDepositTx() {
when(delegate.getTakerDepositTx().getHash()).thenReturn(XID.toString());
assertTrue(trade.isRelatedToTransaction(transaction));
}

View file

@ -137,7 +137,6 @@ public class TradesChartsViewModelTest {
now.getTime(),
null,
null,
null,
null));
set.add(new TradeStatistics3(offer.getCurrencyCode(),
Price.parse("EUR", "500").getValue(),
@ -146,7 +145,6 @@ public class TradesChartsViewModelTest {
now.getTime() + 100,
null,
null,
null,
null));
set.add(new TradeStatistics3(offer.getCurrencyCode(),
Price.parse("EUR", "600").getValue(),
@ -155,7 +153,6 @@ public class TradesChartsViewModelTest {
now.getTime() + 200,
null,
null,
null,
null));
set.add(new TradeStatistics3(offer.getCurrencyCode(),
Price.parse("EUR", "580").getValue(),
@ -164,7 +161,6 @@ public class TradesChartsViewModelTest {
now.getTime() + 300,
null,
null,
null,
null));
CandleData candleData = model.getCandleData(model.roundToTick(now, TradesChartsViewModel.TickUnit.DAY).getTime(), set, 0);
@ -227,7 +223,6 @@ public class TradesChartsViewModelTest {
t.date.getTime(),
null,
null,
null,
null))
);
ObservableSet<TradeStatistics3> tradeStats = FXCollections.observableSet(set);

View file

@ -1,7 +1,7 @@
package bisq.desktop.main.offer.createoffer;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.model.XmrAddressEntry;
import bisq.core.btc.wallet.XmrWalletService;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.GlobalSettings;
@ -47,8 +47,8 @@ public class CreateOfferDataModelTest {
GlobalSettings.setDefaultTradeCurrency(btc);
Res.setup();
AddressEntry addressEntry = mock(AddressEntry.class);
BtcWalletService btcWalletService = mock(BtcWalletService.class);
XmrAddressEntry addressEntry = mock(XmrAddressEntry.class);
XmrWalletService btcWalletService = mock(XmrWalletService.class);
PriceFeedService priceFeedService = mock(PriceFeedService.class);
FeeService feeService = mock(FeeService.class);
CreateOfferService createOfferService = mock(CreateOfferService.class);

View file

@ -23,14 +23,15 @@ import bisq.desktop.util.validation.FiatPriceValidator;
import bisq.desktop.util.validation.SecurityDepositValidator;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.model.XmrAddressEntry;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
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.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod;
@ -60,7 +61,6 @@ import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import static bisq.core.offer.OfferPayload.Direction;
import static bisq.desktop.maker.PreferenceMakers.empty;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@ -87,8 +87,8 @@ public class CreateOfferViewModelTest {
final FiatPriceValidator fiatPriceValidator = new FiatPriceValidator();
FeeService feeService = mock(FeeService.class);
AddressEntry addressEntry = mock(AddressEntry.class);
BtcWalletService btcWalletService = mock(BtcWalletService.class);
XmrAddressEntry addressEntry = mock(XmrAddressEntry.class);
XmrWalletService xmrWalletService = mock(XmrWalletService.class);
PriceFeedService priceFeedService = mock(PriceFeedService.class);
User user = mock(User.class);
PaymentAccount paymentAccount = mock(PaymentAccount.class);
@ -101,8 +101,8 @@ public class CreateOfferViewModelTest {
OfferUtil offerUtil = mock(OfferUtil.class);
var tradeStats = mock(TradeStatisticsManager.class);
when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
when(btcWalletService.getBalanceForAddress(any())).thenReturn(Coin.valueOf(1000L));
when(xmrWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
when(xmrWalletService.getBalanceForAccount(any(Integer.class))).thenReturn(Coin.valueOf(1000L));
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
when(priceFeedService.getMarketPrice(anyString())).thenReturn(
new MarketPrice("USD",
@ -122,20 +122,20 @@ public class CreateOfferViewModelTest {
when(tradeStats.getObservableTradeStatisticsSet()).thenReturn(FXCollections.observableSet());
CreateOfferDataModel dataModel = new CreateOfferDataModel(createOfferService,
null,
offerUtil,
btcWalletService,
bsqWalletService,
empty,
user,
null,
priceFeedService,
accountAgeWitnessService,
feeService,
coinFormatter,
tradeStats,
null);
dataModel.initWithData(Direction.BUY, new CryptoCurrency("BTC", "bitcoin"));
null,
offerUtil,
xmrWalletService,
bsqWalletService,
empty,
user,
null,
priceFeedService,
accountAgeWitnessService,
feeService,
coinFormatter,
tradeStats,
null);
dataModel.initWithData(OfferPayload.Direction.BUY, new CryptoCurrency("BTC", "bitcoin"));
dataModel.activate();
model = new CreateOfferViewModel(dataModel,

View file

@ -3,9 +3,9 @@ package bisq.desktop.main.portfolio.editoffer;
import bisq.desktop.util.validation.SecurityDepositValidator;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.model.XmrAddressEntry;
import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.XmrWalletService;
import bisq.core.locale.Country;
import bisq.core.locale.CryptoCurrency;
import bisq.core.locale.GlobalSettings;
@ -66,8 +66,8 @@ public class EditOfferDataModelTest {
Res.setup();
FeeService feeService = mock(FeeService.class);
AddressEntry addressEntry = mock(AddressEntry.class);
BtcWalletService btcWalletService = mock(BtcWalletService.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);
@ -79,8 +79,8 @@ public class EditOfferDataModelTest {
CreateOfferService createOfferService = mock(CreateOfferService.class);
OfferUtil offerUtil = mock(OfferUtil.class);
when(btcWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
when(btcWalletService.getBalanceForAddress(any())).thenReturn(Coin.valueOf(1000L));
when(xmrWalletService.getOrCreateAddressEntry(anyString(), any())).thenReturn(addressEntry);
when(xmrWalletService.getBalanceForAccount(any(Integer.class))).thenReturn(Coin.valueOf(1000L));
when(priceFeedService.updateCounterProperty()).thenReturn(new SimpleIntegerProperty());
when(priceFeedService.getMarketPrice(anyString())).thenReturn(
new MarketPrice("USD",
@ -98,20 +98,20 @@ public class EditOfferDataModelTest {
when(createOfferService.getRandomOfferId()).thenReturn(UUID.randomUUID().toString());
model = new EditOfferDataModel(createOfferService,
null,
offerUtil,
btcWalletService,
bsqWalletService,
empty,
user,
null,
priceFeedService,
accountAgeWitnessService,
feeService,
null,
null,
mock(TradeStatisticsManager.class),
null);
null,
offerUtil,
xmrWalletService,
bsqWalletService,
empty,
user,
null,
priceFeedService,
accountAgeWitnessService,
feeService,
null,
null,
mock(TradeStatisticsManager.class),
null);
}
@Test

View file

@ -18,8 +18,8 @@
package bisq.desktop.util;
import bisq.core.locale.Res;
import bisq.core.util.coin.ImmutableCoinFormatter;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.coin.ImmutableCoinFormatter;
import bisq.common.config.Config;
@ -36,8 +36,6 @@ import static com.natpryce.makeiteasy.MakeItEasy.with;
import static org.bitcoinj.core.CoinMaker.oneBitcoin;
import static org.bitcoinj.core.CoinMaker.satoshis;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
public class ImmutableCoinFormatterTest {