From 2febe6b3270e1141a2535150c827fded93c6fd70 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sun, 20 Feb 2022 15:22:40 -0300 Subject: [PATCH] Adjust apitest cases to new .proto *Pct field names --- .../java/bisq/apitest/method/MethodTest.java | 15 +++ .../method/offer/AbstractOfferTest.java | 18 ++- .../apitest/method/offer/CancelOfferTest.java | 3 +- .../method/offer/CreateBSQOffersTest.java | 11 +- .../offer/CreateOfferUsingFixedPriceTest.java | 7 +- ...CreateOfferUsingMarketPriceMarginTest.java | 23 ++-- .../method/offer/CreateXMROffersTest.java | 9 +- .../apitest/method/offer/EditOfferTest.java | 108 +++++++++--------- .../method/offer/ValidateCreateOfferTest.java | 7 +- .../method/trade/BsqSwapBuyBtcTradeTest.java | 3 +- .../method/trade/TakeBuyBSQOfferTest.java | 3 +- .../method/trade/TakeBuyBTCOfferTest.java | 3 +- ...keBuyBTCOfferWithNationalBankAcctTest.java | 3 +- .../method/trade/TakeBuyXMROfferTest.java | 3 +- .../method/trade/TakeSellBSQOfferTest.java | 3 +- .../method/trade/TakeSellBTCOfferTest.java | 3 +- .../method/trade/TakeSellXMROfferTest.java | 3 +- .../LongRunningOfferDeactivationTest.java | 5 +- .../java/bisq/apitest/scenario/OfferTest.java | 8 +- .../apitest/scenario/bot/RandomOffer.java | 6 +- 20 files changed, 128 insertions(+), 116 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/MethodTest.java b/apitest/src/test/java/bisq/apitest/method/MethodTest.java index f01c4ecbf53..5ca04409449 100644 --- a/apitest/src/test/java/bisq/apitest/method/MethodTest.java +++ b/apitest/src/test/java/bisq/apitest/method/MethodTest.java @@ -30,7 +30,10 @@ import java.io.IOException; import java.io.PrintWriter; +import java.math.BigDecimal; + import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import org.slf4j.Logger; @@ -42,6 +45,7 @@ import static bisq.apitest.config.ApiTestRateMeterInterceptorConfig.getTestRateMeterInterceptorConfig; import static bisq.cli.table.builder.TableType.BSQ_BALANCE_TBL; import static bisq.cli.table.builder.TableType.BTC_BALANCE_TBL; +import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Arrays.stream; @@ -162,6 +166,17 @@ protected final bisq.core.payment.PaymentAccount createPaymentAccount(GrpcClient return bisq.core.payment.PaymentAccount.fromProto(paymentAccount, CORE_PROTO_RESOLVER); } + public static final Supplier defaultBuyerSecurityDepositPct = () -> { + var defaultPct = BigDecimal.valueOf(getDefaultBuyerSecurityDepositAsPercent()); + if (defaultPct.precision() != 2) + throw new IllegalStateException(format( + "Unexpected decimal precision, expected 2 but actual is %d%n." + + "Check for changes to Restrictions.getDefaultBuyerSecurityDepositAsPercent()", + defaultPct.precision())); + + return defaultPct.movePointRight(2).doubleValue(); + }; + public static String formatBalancesTbls(BalancesInfo allBalances) { StringBuilder balances = new StringBuilder(BTC).append("\n"); balances.append(new TableBuilder(BTC_BALANCE_TBL, allBalances.getBtc()).build()); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java index 627afff6c52..627c1befe3b 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java @@ -44,7 +44,6 @@ import static bisq.apitest.config.BisqAppConfig.bobdaemon; import static bisq.apitest.config.BisqAppConfig.seednode; import static bisq.cli.table.builder.TableType.OFFER_TBL; -import static bisq.common.util.MathUtils.exactMultiply; import static java.lang.String.format; import static java.lang.System.out; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -78,29 +77,28 @@ public abstract class AbstractOfferTest extends MethodTest { @BeforeAll public static void setUp() { + setUp(false); + } + + public static void setUp(boolean startSupportingAppsInDebugMode) { startSupportingApps(true, - false, + startSupportingAppsInDebugMode, bitcoind, seednode, arbdaemon, alicedaemon, bobdaemon); - initSwapPaymentAccounts(); createLegacyBsqPaymentAccounts(); } - // Mkt Price Margin value of offer returned from server is scaled down by 10^-2. - protected final Function scaledDownMktPriceMargin = (mktPriceMargin) -> - exactMultiply(mktPriceMargin, 0.01); - - protected final Function toOfferTable = (offer) -> + protected static final Function toOfferTable = (offer) -> new TableBuilder(OFFER_TBL, offer).build().toString(); - protected final Function, String> toOffersTable = (offers) -> + protected static final Function, String> toOffersTable = (offers) -> new TableBuilder(OFFER_TBL, offers).build().toString(); - protected String calcPriceAsString(double base, double delta, int precision) { + protected static String calcPriceAsString(double base, double delta, int precision) { var mathContext = new MathContext(precision); var priceAsBigDecimal = new BigDecimal(Double.toString(base), mathContext) .add(new BigDecimal(Double.toString(delta), mathContext)) diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CancelOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CancelOfferTest.java index d0ec6d86f1b..119427c0cf1 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CancelOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CancelOfferTest.java @@ -33,7 +33,6 @@ import org.junit.jupiter.api.TestMethodOrder; import static bisq.apitest.config.ApiTestConfig.BSQ; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static org.junit.jupiter.api.Assertions.assertEquals; import static protobuf.OfferDirection.BUY; @@ -52,7 +51,7 @@ public class CancelOfferTest extends AbstractOfferTest { 10000000L, 10000000L, 0.00, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), paymentAccountId, BSQ, NO_TRIGGER_PRICE); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java index 2b878c1803d..1807d1000b5 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateBSQOffersTest.java @@ -32,7 +32,6 @@ import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.BTC; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -63,7 +62,7 @@ public void testCreateBuy1BTCFor20KBSQOffer() { 100_000_000L, 100_000_000L, "0.00005", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("Sell BSQ (Buy BTC) Offer:\n{}", toOfferTable.apply(newOffer)); @@ -114,7 +113,7 @@ public void testCreateSell1BTCFor20KBSQOffer() { 100_000_000L, 100_000_000L, "0.00005", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("SELL 20K BSQ Offer:\n{}", toOfferTable.apply(newOffer)); @@ -165,7 +164,7 @@ public void testCreateBuyBTCWith1To2KBSQOffer() { 10_000_000L, 5_000_000L, "0.00005", // FIXED PRICE IN BTC sats FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("BUY 1-2K BSQ Offer:\n{}", toOfferTable.apply(newOffer)); @@ -216,7 +215,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() { 50_000_000L, 25_000_000L, "0.00005", // FIXED PRICE IN BTC sats FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("SELL 5-10K BSQ Offer:\n{}", toOfferTable.apply(newOffer)); @@ -280,6 +279,6 @@ private void genBtcBlockAndWaitForOfferPreparation() { // Extra time is needed for the OfferUtils#isBsqForMakerFeeAvailable, which // can sometimes return an incorrect false value if the BsqWallet's // available confirmed balance is temporarily = zero during BSQ offer prep. - genBtcBlocksThenWait(1, 5000); + genBtcBlocksThenWait(1, 5_000); } } diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java index 794fb1310a8..7691a5e26d4 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingFixedPriceTest.java @@ -31,7 +31,6 @@ import static bisq.apitest.config.ApiTestConfig.BTC; import static bisq.apitest.config.ApiTestConfig.EUR; import static bisq.apitest.config.ApiTestConfig.USD; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -55,7 +54,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() { 10_000_000L, 10_000_000L, "36000", - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), audAccount.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer)); @@ -104,7 +103,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() { 10_000_000L, 10_000_000L, "30000.1234", - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), usdAccount.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer)); @@ -153,7 +152,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() { 10_000_000L, 5_000_000L, "29500.1234", - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), eurAccount.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer)); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java index 64c3cf20cc8..fc61b5699dc 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateOfferUsingMarketPriceMarginTest.java @@ -38,7 +38,6 @@ import static bisq.common.util.MathUtils.roundDouble; import static bisq.common.util.MathUtils.scaleDownByPowerOf10; import static bisq.common.util.MathUtils.scaleUpByPowerOf10; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static java.lang.Math.abs; import static java.lang.String.format; import static java.math.RoundingMode.HALF_UP; @@ -65,13 +64,13 @@ public class CreateOfferUsingMarketPriceMarginTest extends AbstractOfferTest { @Order(1) public void testCreateUSDBTCBuyOffer5PctPriceMargin() { PaymentAccount usdAccount = createDummyF2FAccount(aliceClient, "US"); - double priceMarginPctInput = 5.00; + double priceMarginPctInput = 5.00d; var newOffer = aliceClient.createMarketBasedPricedOffer(BUY.name(), "usd", 10_000_000L, 10_000_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), usdAccount.getId(), MAKER_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); @@ -83,6 +82,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() { assertNotEquals("", newOfferId); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(10_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -97,6 +97,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() { assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(10_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -112,13 +113,13 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() { @Order(2) public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() { PaymentAccount nzdAccount = createDummyF2FAccount(aliceClient, "NZ"); - double priceMarginPctInput = -2.00; + double priceMarginPctInput = -2.00d; // -2% var newOffer = aliceClient.createMarketBasedPricedOffer(BUY.name(), "nzd", 10_000_000L, 10_000_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), nzdAccount.getId(), MAKER_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); @@ -130,6 +131,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() { assertNotEquals("", newOfferId); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(10_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -144,6 +146,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() { assertEquals(newOfferId, newOffer.getId()); assertEquals(BUY.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(10_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -165,7 +168,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() { 10_000_000L, 5_000_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), gbpAccount.getId(), MAKER_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); @@ -177,6 +180,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() { assertNotEquals("", newOfferId); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(5_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -191,6 +195,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() { assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(5_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -212,7 +217,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() { 10_000_000L, 5_000_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), brlAccount.getId(), MAKER_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); @@ -224,6 +229,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() { assertNotEquals("", newOfferId); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(5_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -238,6 +244,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() { assertEquals(newOfferId, newOffer.getId()); assertEquals(SELL.name(), newOffer.getDirection()); assertTrue(newOffer.getUseMarketBasedPrice()); + assertEquals(priceMarginPctInput, newOffer.getMarketPriceMarginPct()); assertEquals(10_000_000, newOffer.getAmount()); assertEquals(5_000_000, newOffer.getMinAmount()); assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit()); @@ -260,7 +267,7 @@ public void testCreateUSDBTCBuyOfferWithTriggerPrice() { 10_000_000L, 5_000_000L, 0.0, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), usdAccount.getId(), MAKER_FEE_CURRENCY_CODE, triggerPrice); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java index 33fad708d85..64d46e279f9 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/CreateXMROffersTest.java @@ -33,7 +33,6 @@ import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.BTC; import static bisq.apitest.config.ApiTestConfig.XMR; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; @@ -66,7 +65,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() { 100_000_000L, 75_000_000L, "0.005", // FIXED PRICE IN BTC (satoshis) FOR 1 XMR - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer)); @@ -113,7 +112,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() { 100_000_000L, 50_000_000L, "0.005", // FIXED PRICE IN BTC (satoshis) FOR 1 XMR - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), MAKER_FEE_CURRENCY_CODE); log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer)); @@ -162,7 +161,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() { 100_000_000L, 75_000_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), MAKER_FEE_CURRENCY_CODE, triggerPrice); @@ -218,7 +217,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() { 100_000_000L, 50_000_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), MAKER_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); diff --git a/apitest/src/test/java/bisq/apitest/method/offer/EditOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/EditOfferTest.java index cf6fb51acf4..4e839924019 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/EditOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/EditOfferTest.java @@ -38,7 +38,6 @@ import org.junit.jupiter.api.TestMethodOrder; import static bisq.apitest.config.ApiTestConfig.*; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.proto.grpc.EditOfferRequest.EditType.*; import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.*; @@ -141,21 +140,21 @@ public void testSetTriggerPriceToNegativeValueShouldThrowException() { @Order(4) public void testEditMktPriceMargin() { PaymentAccount paymentAcct = getOrCreatePaymentAccount("US"); - var originalMktPriceMargin = new BigDecimal("0.1").doubleValue(); + var originalMktPriceMarginPct = 0.1d; // 0.1% var originalOffer = createMktPricedOfferForEdit(SELL.name(), USD, paymentAcct.getId(), - originalMktPriceMargin, + originalMktPriceMarginPct, NO_TRIGGER_PRICE); log.debug("Original USD offer:\n{}", toOfferTable.apply(originalOffer)); genBtcBlocksThenWait(1, 2_500); // Wait for entry into offer book. - assertEquals(scaledDownMktPriceMargin.apply(originalMktPriceMargin), originalOffer.getMarketPriceMargin()); + assertEquals(originalMktPriceMarginPct, originalOffer.getMarketPriceMarginPct()); // Edit the offer's price margin, nothing else. - var newMktPriceMargin = new BigDecimal("0.5").doubleValue(); + var newMktPriceMargin = 0.5d; // 0.5% aliceClient.editOfferPriceMargin(originalOffer.getId(), newMktPriceMargin); OfferInfo editedOffer = aliceClient.getOffer(originalOffer.getId()); log.debug("Edited USD offer:\n{}", toOfferTable.apply(editedOffer)); - assertEquals(scaledDownMktPriceMargin.apply(newMktPriceMargin), editedOffer.getMarketPriceMargin()); + assertEquals(newMktPriceMargin, editedOffer.getMarketPriceMarginPct()); assertTrue(editedOffer.getUseMarketBasedPrice()); doSanityCheck(originalOffer, editedOffer); @@ -222,24 +221,23 @@ public void testEditFixedPriceAndDeactivation() { @Order(7) public void testEditMktPriceMarginAndDeactivation() { PaymentAccount paymentAcct = getOrCreatePaymentAccount("US"); - - var originalMktPriceMargin = new BigDecimal("0.0").doubleValue(); + var originalMktPriceMarginPct = 0.00d; OfferInfo originalOffer = createMktPricedOfferForEdit(SELL.name(), USD, paymentAcct.getId(), - originalMktPriceMargin, + originalMktPriceMarginPct, NO_TRIGGER_PRICE); log.debug("Original USD offer:\n{}", toOfferTable.apply(originalOffer)); genBtcBlocksThenWait(1, 2_500); // Wait for entry into offer book. originalOffer = aliceClient.getOffer(originalOffer.getId()); - assertEquals(scaledDownMktPriceMargin.apply(originalMktPriceMargin), originalOffer.getMarketPriceMargin()); + assertEquals(originalMktPriceMarginPct, originalOffer.getMarketPriceMarginPct()); // Edit the offer's price margin and trigger price, and deactivate it. - var newMktPriceMargin = new BigDecimal("1.50").doubleValue(); + var newMktPriceMarginPct = 1.50d; // 1.5% aliceClient.editOffer(originalOffer.getId(), "0.00", originalOffer.getUseMarketBasedPrice(), - newMktPriceMargin, + newMktPriceMarginPct, NO_TRIGGER_PRICE, DEACTIVATE_OFFER, MKT_PRICE_MARGIN_AND_ACTIVATION_STATE); @@ -247,7 +245,7 @@ public void testEditMktPriceMarginAndDeactivation() { genBtcBlocksThenWait(1, 2_500); OfferInfo editedOffer = aliceClient.getOffer(originalOffer.getId()); log.debug("Edited USD offer:\n{}", toOfferTable.apply(editedOffer)); - assertEquals(scaledDownMktPriceMargin.apply(newMktPriceMargin), editedOffer.getMarketPriceMargin()); + assertEquals(newMktPriceMarginPct, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); assertFalse(editedOffer.getIsActivated()); assertTrue(editedOffer.getUseMarketBasedPrice()); @@ -259,27 +257,27 @@ public void testEditMktPriceMarginAndDeactivation() { @Order(8) public void testEditMktPriceMarginAndTriggerPriceAndDeactivation() { PaymentAccount paymentAcct = getOrCreatePaymentAccount("US"); - var originalMktPriceMargin = new BigDecimal("0.0").doubleValue(); + var originalMktPriceMarginPct = 0.00d; var mktPriceAsDouble = aliceClient.getBtcPrice(USD); var originalTriggerPrice = calcPriceAsString(mktPriceAsDouble, -5_000.0000, 4); OfferInfo originalOffer = createMktPricedOfferForEdit(SELL.name(), USD, paymentAcct.getId(), - originalMktPriceMargin, + originalMktPriceMarginPct, originalTriggerPrice); log.debug("Original USD offer:\n{}", toOfferTable.apply(originalOffer)); genBtcBlocksThenWait(1, 2_500); // Wait for entry into offer book. originalOffer = aliceClient.getOffer(originalOffer.getId()); - assertEquals(scaledDownMktPriceMargin.apply(originalMktPriceMargin), originalOffer.getMarketPriceMargin()); + assertEquals(originalMktPriceMarginPct, originalOffer.getMarketPriceMarginPct()); assertEquals(originalTriggerPrice, originalOffer.getTriggerPrice()); // Edit the offer's price margin and trigger price, and deactivate it. - var newMktPriceMargin = new BigDecimal("0.1").doubleValue(); + var newMktPriceMarginPct = 0.10d; // 0.1% var newTriggerPrice = calcPriceAsString(mktPriceAsDouble, -2_000.0000, 4); aliceClient.editOffer(originalOffer.getId(), "0.00", originalOffer.getUseMarketBasedPrice(), - newMktPriceMargin, + newMktPriceMarginPct, newTriggerPrice, DEACTIVATE_OFFER, MKT_PRICE_MARGIN_AND_TRIGGER_PRICE_AND_ACTIVATION_STATE); @@ -287,7 +285,7 @@ public void testEditMktPriceMarginAndTriggerPriceAndDeactivation() { genBtcBlocksThenWait(1, 2_500); OfferInfo editedOffer = aliceClient.getOffer(originalOffer.getId()); log.debug("Edited USD offer:\n{}", toOfferTable.apply(editedOffer)); - assertEquals(scaledDownMktPriceMargin.apply(newMktPriceMargin), editedOffer.getMarketPriceMargin()); + assertEquals(newMktPriceMarginPct, editedOffer.getMarketPriceMarginPct()); assertEquals(newTriggerPrice, editedOffer.getTriggerPrice()); assertFalse(editedOffer.getIsActivated()); @@ -298,22 +296,22 @@ public void testEditMktPriceMarginAndTriggerPriceAndDeactivation() { @Order(9) public void testEditingFixedPriceInMktPriceMarginBasedOfferShouldThrowException() { PaymentAccount paymentAcct = getOrCreatePaymentAccount("US"); - var originalMktPriceMargin = new BigDecimal("0.0").doubleValue(); + var originalMktPriceMarginPct = 0.00d; var originalOffer = createMktPricedOfferForEdit(SELL.name(), USD, paymentAcct.getId(), - originalMktPriceMargin, + originalMktPriceMarginPct, NO_TRIGGER_PRICE); log.debug("Original USD offer:\n{}", toOfferTable.apply(originalOffer)); genBtcBlocksThenWait(1, 2_500); // Wait for entry into offer book. // Try to edit both the fixed price and mkt price margin. - var newMktPriceMargin = new BigDecimal("0.25").doubleValue(); + var newMktPriceMarginPct = 0.25d; // 0.25% var newFixedPrice = "50000.0000"; Throwable exception = assertThrows(StatusRuntimeException.class, () -> aliceClient.editOffer(originalOffer.getId(), newFixedPrice, originalOffer.getUseMarketBasedPrice(), - newMktPriceMargin, + newMktPriceMarginPct, NO_TRIGGER_PRICE, ACTIVATE_OFFER, MKT_PRICE_MARGIN_ONLY)); @@ -361,13 +359,13 @@ public void testChangeFixedPriceOfferToPriceMarginBasedOfferWithTriggerPrice() { genBtcBlocksThenWait(1, 2_500); // Wait for entry into offer book. // Change the offer to mkt price based and set a trigger price. - var newMktPriceMargin = new BigDecimal("0.05").doubleValue(); + var newMktPriceMarginPct = 0.05d; // 0.05% var delta = 200_000.0000; // trigger price on buy offer is 200K above mkt price var newTriggerPrice = calcPriceAsString(mktPriceAsDouble, delta, 4); aliceClient.editOffer(originalOffer.getId(), "0.00", true, - newMktPriceMargin, + newMktPriceMarginPct, newTriggerPrice, ACTIVATE_OFFER, MKT_PRICE_MARGIN_AND_TRIGGER_PRICE); @@ -376,7 +374,7 @@ public void testChangeFixedPriceOfferToPriceMarginBasedOfferWithTriggerPrice() { OfferInfo editedOffer = aliceClient.getOffer(originalOffer.getId()); log.debug("Edited MXN offer:\n{}", toOfferTable.apply(editedOffer)); assertTrue(editedOffer.getUseMarketBasedPrice()); - assertEquals(scaledDownMktPriceMargin.apply(newMktPriceMargin), editedOffer.getMarketPriceMargin()); + assertEquals(newMktPriceMarginPct, editedOffer.getMarketPriceMarginPct()); assertEquals(newTriggerPrice, editedOffer.getTriggerPrice()); assertTrue(editedOffer.getIsActivated()); @@ -388,13 +386,13 @@ public void testChangeFixedPriceOfferToPriceMarginBasedOfferWithTriggerPrice() { public void testChangePriceMarginBasedOfferToFixedPriceOfferAndDeactivateIt() { PaymentAccount paymentAcct = getOrCreatePaymentAccount("GB"); double mktPriceAsDouble = aliceClient.getBtcPrice("GBP"); - var originalMktPriceMargin = new BigDecimal("0.25").doubleValue(); + var originalMktPriceMarginPct = new BigDecimal("0.25").doubleValue(); var delta = 1_000.0000; // trigger price on sell offer is 1K below mkt price var originalTriggerPriceAsLong = calcPriceAsString(mktPriceAsDouble, delta, 4); var originalOffer = createMktPricedOfferForEdit(SELL.name(), "GBP", paymentAcct.getId(), - originalMktPriceMargin, + originalMktPriceMarginPct, originalTriggerPriceAsLong); log.debug("Original GBP offer:\n{}", toOfferTable.apply(originalOffer)); genBtcBlocksThenWait(1, 2_500); // Wait for entry into offer book. @@ -413,7 +411,7 @@ public void testChangePriceMarginBasedOfferToFixedPriceOfferAndDeactivateIt() { log.debug("Edited GBP offer:\n{}", toOfferTable.apply(editedOffer)); assertEquals(fixedPriceAsString, editedOffer.getPrice()); assertFalse(editedOffer.getUseMarketBasedPrice()); - assertEquals(0.00, editedOffer.getMarketPriceMargin()); + assertEquals(0.00, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); assertFalse(editedOffer.getIsActivated()); } @@ -426,7 +424,7 @@ public void testChangeFixedPricedBsqOfferToPriceMarginBasedOfferShouldThrowExcep 100_000_000L, 100_000_000L, "0.00005", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), BSQ); log.debug("Original BSQ offer:\n{}", toOfferTable.apply(originalOffer)); @@ -453,7 +451,7 @@ public void testEditTriggerPriceOnFixedPriceBsqOfferShouldThrowException() { 100_000_000L, 100_000_000L, "0.00005", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), BSQ); log.debug("Original BSQ offer:\n{}", toOfferTable.apply(originalOffer)); @@ -482,7 +480,7 @@ public void testEditFixedPriceOnBsqOffer() { 100_000_000L, 100_000_000L, fixedPriceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), BSQ); log.debug("Original BSQ offer:\n{}", toOfferTable.apply(originalOffer)); @@ -502,7 +500,7 @@ public void testEditFixedPriceOnBsqOffer() { assertEquals(newFixedPriceAsString, editedOffer.getPrice()); assertTrue(editedOffer.getIsActivated()); assertFalse(editedOffer.getUseMarketBasedPrice()); - assertEquals(0.00, editedOffer.getMarketPriceMargin()); + assertEquals(0.00, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); } @@ -515,7 +513,7 @@ public void testDisableBsqOffer() { 100_000_000L, 100_000_000L, fixedPriceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), BSQ); log.debug("Original BSQ offer:\n{}", toOfferTable.apply(originalOffer)); @@ -534,7 +532,7 @@ public void testDisableBsqOffer() { assertFalse(editedOffer.getIsActivated()); assertEquals(fixedPriceAsString, editedOffer.getPrice()); assertFalse(editedOffer.getUseMarketBasedPrice()); - assertEquals(0.00, editedOffer.getMarketPriceMargin()); + assertEquals(0.00, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); } @@ -547,7 +545,7 @@ public void testEditFixedPriceAndDisableBsqOffer() { 100_000_000L, 100_000_000L, fixedPriceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), BSQ); log.debug("Original BSQ offer:\n{}", toOfferTable.apply(originalOffer)); @@ -567,7 +565,7 @@ public void testEditFixedPriceAndDisableBsqOffer() { assertFalse(editedOffer.getIsActivated()); assertEquals(newFixedPriceAsString, editedOffer.getPrice()); assertFalse(editedOffer.getUseMarketBasedPrice()); - assertEquals(0.00, editedOffer.getMarketPriceMargin()); + assertEquals(0.00, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); } @@ -604,7 +602,7 @@ public void testChangePriceMarginBasedXmrOfferWithTriggerPriceToFixedPricedAndDe log.debug("Edited XMR offer:\n{}", toOfferTable.apply(editedOffer)); assertEquals(newFixedPriceAsString, editedOffer.getPrice()); assertFalse(editedOffer.getUseMarketBasedPrice()); - assertEquals(0.00, editedOffer.getMarketPriceMargin()); + assertEquals(0.00, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); assertFalse(editedOffer.getIsActivated()); @@ -615,11 +613,11 @@ public void testChangePriceMarginBasedXmrOfferWithTriggerPriceToFixedPricedAndDe @Order(19) public void testEditTriggerPriceOnPriceMarginBasedXmrOffer() { createXmrPaymentAccounts(); - double mktPriceMargin = -0.075d; + double mktPriceMarginPct = -0.075d; OfferInfo originalOffer = createMktPricedOfferForEdit(SELL.name(), XMR, alicesXmrAcct.getId(), - mktPriceMargin, + mktPriceMarginPct, NO_TRIGGER_PRICE); log.debug("Pending XMR offer:\n{}", toOfferTable.apply(originalOffer)); genBtcBlocksThenWait(1, 2500); // Wait for entry into offer book. @@ -632,7 +630,7 @@ public void testEditTriggerPriceOnPriceMarginBasedXmrOffer() { aliceClient.editOffer(originalOffer.getId(), "0", true, - mktPriceMargin, + mktPriceMarginPct, triggerPrice, ACTIVATE_OFFER, TRIGGER_PRICE_ONLY); @@ -641,7 +639,7 @@ public void testEditTriggerPriceOnPriceMarginBasedXmrOffer() { OfferInfo editedOffer = aliceClient.getOffer(originalOffer.getId()); log.info("Edited XMR offer:\n{}", toOfferTable.apply(editedOffer)); assertTrue(editedOffer.getUseMarketBasedPrice()); - assertEquals(scaledDownMktPriceMargin.apply(mktPriceMargin), editedOffer.getMarketPriceMargin()); + assertEquals(mktPriceMarginPct, editedOffer.getMarketPriceMarginPct()); assertEquals(triggerPrice, editedOffer.getTriggerPrice()); assertTrue(editedOffer.getIsActivated()); @@ -659,7 +657,7 @@ public void testChangeFixedPricedXmrOfferToPriceMarginBasedOfferWithTriggerPrice 100_000_000L, 50_000_000L, fixedPriceAsString, // FIXED PRICE IN BTC (satoshis) FOR 1 XMR - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), BSQ); log.debug("Pending XMR offer:\n{}", toOfferTable.apply(originalOffer)); @@ -669,13 +667,13 @@ public void testChangeFixedPricedXmrOfferToPriceMarginBasedOfferWithTriggerPrice log.debug("Original XMR offer:\n{}", toOfferTable.apply(originalOffer)); // Change the offer to mkt price based and set a trigger price. - var newMktPriceMargin = new BigDecimal("0.05").doubleValue(); + var newMktPriceMarginPct = 0.05d; // 0.05% var delta = -0.00100000; var newTriggerPrice = calcPriceAsString(mktPriceAsDouble, delta, 8); aliceClient.editOffer(originalOffer.getId(), "0.00", true, - newMktPriceMargin, + newMktPriceMarginPct, newTriggerPrice, ACTIVATE_OFFER, MKT_PRICE_MARGIN_AND_TRIGGER_PRICE); @@ -684,7 +682,7 @@ public void testChangeFixedPricedXmrOfferToPriceMarginBasedOfferWithTriggerPrice OfferInfo editedOffer = aliceClient.getOffer(originalOffer.getId()); log.debug("Edited XMR offer:\n{}", toOfferTable.apply(editedOffer)); assertTrue(editedOffer.getUseMarketBasedPrice()); - assertEquals(scaledDownMktPriceMargin.apply(newMktPriceMargin), editedOffer.getMarketPriceMargin()); + assertEquals(newMktPriceMarginPct, editedOffer.getMarketPriceMarginPct()); assertEquals(newTriggerPrice, editedOffer.getTriggerPrice()); assertTrue(editedOffer.getIsActivated()); @@ -700,7 +698,7 @@ public void testEditTriggerPriceOnFixedPriceXmrOfferShouldThrowException() { 100_000_000L, 25_000_000L, "0.007", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), BSQ); log.debug("Original XMR offer:\n{}", toOfferTable.apply(originalOffer)); @@ -731,7 +729,7 @@ public void testEditFixedPriceOnXmrOffer() { 100_000_000L, 100_000_000L, fixedPriceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), BSQ); log.debug("Original BSQ offer:\n{}", toOfferTable.apply(originalOffer)); @@ -765,7 +763,7 @@ public void testDisableXmrOffer() { 100_000_000L, 50_000_000L, fixedPriceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), BSQ); log.debug("Original XMR offer:\n{}", toOfferTable.apply(originalOffer)); @@ -798,7 +796,7 @@ public void testEditFixedPriceAndDisableXmrOffer() { 100_000_000L, 100_000_000L, fixedPriceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), BSQ); log.debug("Original XMR offer:\n{}", toOfferTable.apply(originalOffer)); @@ -860,14 +858,14 @@ public void testEditBsqSwapOfferShouldThrowException() { private OfferInfo createMktPricedOfferForEdit(String direction, String currencyCode, String paymentAccountId, - double marketPriceMargin, + double marketPriceMarginPct, String triggerPrice) { return aliceClient.createMarketBasedPricedOffer(direction, currencyCode, AMOUNT, AMOUNT, - marketPriceMargin, - getDefaultBuyerSecurityDepositAsPercent(), + marketPriceMarginPct, + defaultBuyerSecurityDepositPct.get(), paymentAccountId, BSQ, triggerPrice); @@ -882,7 +880,7 @@ private OfferInfo createFixedPricedOfferForEdit(String direction, AMOUNT, AMOUNT, priceAsString, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), paymentAccountId, BSQ); } @@ -904,7 +902,7 @@ private void doSanityCheck(OfferInfo originalOffer, OfferInfo editedOffer) { private void assertMarketBasedPriceFieldsAreIgnored(OfferInfo editedOffer) { assertFalse(editedOffer.getUseMarketBasedPrice()); - assertEquals(0.00, editedOffer.getMarketPriceMargin()); + assertEquals(0.00, editedOffer.getMarketPriceMarginPct()); assertEquals(NO_TRIGGER_PRICE, editedOffer.getTriggerPrice()); } diff --git a/apitest/src/test/java/bisq/apitest/method/offer/ValidateCreateOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/ValidateCreateOfferTest.java index cc8a02f33d9..48a8ccbbbb5 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/ValidateCreateOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/ValidateCreateOfferTest.java @@ -31,7 +31,6 @@ import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.BTC; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static java.lang.String.format; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -53,7 +52,7 @@ public void testAmtTooLargeShouldThrowException() { 100000000000L, // exceeds amount limit 100000000000L, "10000.0000", - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), usdAccount.getId(), BSQ)); assertEquals("UNKNOWN: An error occurred at task: ValidateOffer", exception.getMessage()); @@ -70,7 +69,7 @@ public void testNoMatchingEURPaymentAccountShouldThrowException() { 10000000L, 10000000L, "40000.0000", - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), chfAccount.getId(), BTC)); String expectedError = format("UNKNOWN: cannot create EUR offer with payment account %s", chfAccount.getId()); @@ -88,7 +87,7 @@ public void testNoMatchingCADPaymentAccountShouldThrowException() { 10000000L, 10000000L, "63000.0000", - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), audAccount.getId(), BTC)); String expectedError = format("UNKNOWN: cannot create CAD offer with payment account %s", audAccount.getId()); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/BsqSwapBuyBtcTradeTest.java b/apitest/src/test/java/bisq/apitest/method/trade/BsqSwapBuyBtcTradeTest.java index 9b4a687ea8f..8dc20b54170 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/BsqSwapBuyBtcTradeTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/BsqSwapBuyBtcTradeTest.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -48,7 +49,7 @@ import bisq.apitest.method.offer.AbstractOfferTest; import bisq.cli.GrpcClient; -// @Disabled +@Disabled @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class BsqSwapBuyBtcTradeTest extends AbstractTradeTest { diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java index 50bde49e244..503e5f41e30 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java @@ -30,7 +30,6 @@ import org.junit.jupiter.api.TestMethodOrder; import static bisq.apitest.config.ApiTestConfig.BSQ; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -76,7 +75,7 @@ public void testTakeAlicesSellBTCForBSQOffer(final TestInfo testInfo) { 15_000_000L, 7_500_000L, "0.000035", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), TRADE_FEE_CURRENCY_CODE); log.debug("Alice's BUY BSQ (SELL BTC) Offer:\n{}", toOfferTable.apply(alicesOffer)); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java index 55487f740bd..9ec651b0813 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java @@ -32,7 +32,6 @@ import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.USD; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -62,7 +61,7 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { 12_500_000L, 12_500_000L, // min-amount = amount 0.00, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesUsdAccount.getId(), TRADE_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java index e0e2ee746bd..0049cb54911 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java @@ -49,7 +49,6 @@ import org.junit.jupiter.api.TestMethodOrder; import static bisq.apitest.config.ApiTestConfig.BSQ; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -94,7 +93,7 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { 1_000_000L, 1_000_000L, // min-amount = amount 0.00, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesPaymentAccount.getId(), TRADE_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java index bb572976026..7ed209da5c1 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java @@ -32,7 +32,6 @@ import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.XMR; import static bisq.cli.table.builder.TableType.OFFER_TBL; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.State.BUYER_RECEIVED_PAYOUT_TX_PUBLISHED_MSG; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -77,7 +76,7 @@ public void testTakeAlicesSellBTCForXMROffer(final TestInfo testInfo) { 15_000_000L, 7_500_000L, "0.00455500", // FIXED PRICE IN BTC (satoshis) FOR 1 XMR - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), TRADE_FEE_CURRENCY_CODE); log.debug("Alice's BUY XMR (SELL BTC) Offer:\n{}", new TableBuilder(OFFER_TBL, alicesOffer).build()); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java index ac1f0569153..fcb79cee8ed 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java @@ -32,7 +32,6 @@ import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.BTC; import static bisq.cli.table.builder.TableType.OFFER_TBL; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.Phase.WITHDRAWN; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -78,7 +77,7 @@ public void testTakeAlicesBuyBTCForBSQOffer(final TestInfo testInfo) { 15_000_000L, 7_500_000L, "0.000035", // FIXED PRICE IN BTC (satoshis) FOR 1 BSQ - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesLegacyBsqAcct.getId(), TRADE_FEE_CURRENCY_CODE); log.debug("Alice's SELL BSQ (BUY BTC) Offer:\n{}", new TableBuilder(OFFER_TBL, alicesOffer).build()); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java index 9e205f5ef37..89735ef2c0e 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java @@ -32,7 +32,6 @@ import static bisq.apitest.config.ApiTestConfig.BTC; import static bisq.apitest.config.ApiTestConfig.USD; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.Phase.WITHDRAWN; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -65,7 +64,7 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) { 12_500_000L, 12_500_000L, // min-amount = amount 0.00, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesUsdAccount.getId(), TRADE_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java index 769d6dac8a0..6ecc572c3d9 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java @@ -32,7 +32,6 @@ import static bisq.apitest.config.ApiTestConfig.BTC; import static bisq.apitest.config.ApiTestConfig.XMR; import static bisq.cli.table.builder.TableType.OFFER_TBL; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.trade.model.bisq_v1.Trade.Phase.PAYOUT_PUBLISHED; import static bisq.core.trade.model.bisq_v1.Trade.Phase.WITHDRAWN; import static bisq.core.trade.model.bisq_v1.Trade.State.SELLER_SAW_ARRIVED_PAYOUT_TX_PUBLISHED_MSG; @@ -80,7 +79,7 @@ public void testTakeAlicesBuyBTCForXMROffer(final TestInfo testInfo) { 20_000_000L, 10_500_000L, priceMarginPctInput, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), alicesXmrAcct.getId(), TRADE_FEE_CURRENCY_CODE, NO_TRIGGER_PRICE); diff --git a/apitest/src/test/java/bisq/apitest/scenario/LongRunningOfferDeactivationTest.java b/apitest/src/test/java/bisq/apitest/scenario/LongRunningOfferDeactivationTest.java index a27fa8174d4..00293fd5f93 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/LongRunningOfferDeactivationTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/LongRunningOfferDeactivationTest.java @@ -31,7 +31,6 @@ import org.junit.jupiter.api.condition.EnabledIf; import static bisq.apitest.config.ApiTestConfig.BTC; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static java.lang.System.getenv; import static org.junit.jupiter.api.Assertions.fail; import static protobuf.OfferDirection.BUY; @@ -65,7 +64,7 @@ public void testSellOfferAutoDisable(final TestInfo testInfo) { 1_000_000, 1_000_000, 0.00, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), paymentAcct.getId(), BTC, triggerPrice); @@ -112,7 +111,7 @@ public void testBuyOfferAutoDisable(final TestInfo testInfo) { 1_000_000, 1_000_000, 0.00, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), paymentAcct.getId(), BTC, triggerPrice); diff --git a/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java b/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java index 2d6eef8cbe9..f9a0b4c7188 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -41,9 +42,14 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class OfferTest extends AbstractOfferTest { + @BeforeAll + public static void setUp() { + setUp(false); // Use setUp(true) for running API daemons in remote debug mode. + } + @Test @Order(1) - public void testAmtTooLargeShouldThrowException() { + public void testCreateOfferValidation() { ValidateCreateOfferTest test = new ValidateCreateOfferTest(); test.testAmtTooLargeShouldThrowException(); test.testNoMatchingEURPaymentAccountShouldThrowException(); diff --git a/apitest/src/test/java/bisq/apitest/scenario/bot/RandomOffer.java b/apitest/src/test/java/bisq/apitest/scenario/bot/RandomOffer.java index 5f6cf143d43..40afcadab95 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/bot/RandomOffer.java +++ b/apitest/src/test/java/bisq/apitest/scenario/bot/RandomOffer.java @@ -33,10 +33,10 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import static bisq.apitest.method.offer.AbstractOfferTest.defaultBuyerSecurityDepositPct; import static bisq.cli.CurrencyFormat.formatInternalFiatPrice; import static bisq.cli.CurrencyFormat.formatSatoshis; import static bisq.common.util.MathUtils.scaleDownByPowerOf10; -import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.payment.payload.PaymentMethod.F2F_ID; import static java.lang.String.format; import static java.math.RoundingMode.HALF_UP; @@ -127,7 +127,7 @@ public RandomOffer create() throws InvalidRandomOfferException { amount, minAmount, priceMargin, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), feeCurrency, "0" /*no trigger price*/); } else { @@ -137,7 +137,7 @@ public RandomOffer create() throws InvalidRandomOfferException { amount, minAmount, fixedOfferPrice, - getDefaultBuyerSecurityDepositAsPercent(), + defaultBuyerSecurityDepositPct.get(), feeCurrency); } this.id = offer.getId();