Skip to content

Commit 1aa4a3d

Browse files
committed
BsqWalletV2Test: Add invalid and dust send tests
The tests try to send 0 BSQ and the current dust amount in BSQ.
1 parent 05fd5f6 commit 1aa4a3d

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

core/src/integrationTest/java/bisq/core/BitcoinjBsqTests.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import bisq.core.btc.exceptions.BsqChangeBelowDustException;
44
import bisq.core.btc.wallet.BisqDefaultCoinSelector;
5+
import bisq.core.btc.wallet.BisqRegtestNetworkParams;
56
import bisq.core.btc.wallet.BsqCoinSelector;
67
import bisq.core.btc.wallet.BsqWalletV2;
78
import bisq.core.btc.wallet.BtcWalletV2;
@@ -15,7 +16,6 @@
1516
import org.bitcoinj.core.InsufficientMoneyException;
1617
import org.bitcoinj.core.TransactionOutput;
1718
import org.bitcoinj.kits.WalletAppKit;
18-
import org.bitcoinj.params.RegTestParams;
1919
import org.bitcoinj.wallet.Wallet;
2020

2121
import java.nio.file.Path;
@@ -45,12 +45,6 @@
4545
@Slf4j
4646
public class BitcoinjBsqTests {
4747

48-
private static class BisqRegtestNetworkParams extends RegTestParams {
49-
public void setPort(int port) {
50-
this.port = port;
51-
}
52-
}
53-
5448
private final BitcoindRegtestSetup regtestSetup;
5549
private final BisqRegtestNetworkParams networkParams;
5650

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package bisq.core.btc.wallet;
2+
3+
import org.bitcoinj.params.RegTestParams;
4+
5+
public class BisqRegtestNetworkParams extends RegTestParams {
6+
public void setPort(int port) {
7+
this.port = port;
8+
}
9+
}
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)