|
| 1 | +import bisq.core.btc.wallet.BisqRegtestNetworkParams; |
| 2 | +import bisq.core.btc.wallet.BsqCoinSelector; |
| 3 | +import bisq.core.btc.wallet.BsqWalletV2; |
| 4 | +import bisq.core.btc.wallet.BtcWalletV2; |
| 5 | + |
| 6 | +import org.bitcoinj.core.Address; |
| 7 | +import org.bitcoinj.core.Coin; |
| 8 | +import org.bitcoinj.core.PeerGroup; |
| 9 | +import org.bitcoinj.wallet.Wallet; |
| 10 | + |
| 11 | +import java.util.stream.Stream; |
| 12 | + |
| 13 | +import org.junit.jupiter.params.ParameterizedTest; |
| 14 | +import org.junit.jupiter.params.provider.MethodSource; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 18 | +import static org.mockito.Mockito.mock; |
| 19 | + |
| 20 | +public class BsqWalletV2Test { |
| 21 | + |
| 22 | + @ParameterizedTest |
| 23 | + @MethodSource("invalidCoinsProvider") |
| 24 | + void sendBsqDustAndInvalidAmount(Coin amountToSend) { |
| 25 | + var networkParams = new BisqRegtestNetworkParams(); |
| 26 | + var bsqWalletV2 = new BsqWalletV2(networkParams, |
| 27 | + mock(PeerGroup.class), |
| 28 | + mock(BtcWalletV2.class), |
| 29 | + mock(Wallet.class), |
| 30 | + mock(BsqCoinSelector.class)); |
| 31 | + |
| 32 | + var exception = assertThrows(IllegalArgumentException.class, () -> { |
| 33 | + Address receiverAddress = mock(Address.class); |
| 34 | + bsqWalletV2.sendBsq(receiverAddress, amountToSend, Coin.ofSat(10)); |
| 35 | + }); |
| 36 | + |
| 37 | + assertTrue(exception.getMessage().contains("dust limit"), |
| 38 | + "BSQ wallet send dust amount. This shouldn't happen!"); |
| 39 | + } |
| 40 | + |
| 41 | + static Stream<Coin> invalidCoinsProvider() { |
| 42 | + var networkParams = new BisqRegtestNetworkParams(); |
| 43 | + Coin dustAmount = networkParams.getMinNonDustOutput() |
| 44 | + .minus(Coin.valueOf(1)); |
| 45 | + return Stream.of(dustAmount, Coin.ofSat(0), Coin.ofSat(-1)); |
| 46 | + } |
| 47 | +} |
0 commit comments