From 57509890f202fe69b26daaadaafa17096fa873f8 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:16:14 -0300 Subject: [PATCH 1/8] Throw client-friendly EX for payment sent/rcvd msgs Don't depend on silent, UI purposed task runner errors if confirmpaymentstarted or confirmpaymentreceived msgs are sent outside the proper context. Throw a FailedPreconditionException instead, and it will be translated into the proper gPRC StatusRuntimeException before being sent to client. For BTC buyers and sellers, block the messaging attempt if the taker deposit tx has not been confirmed. For BTC sellers, block an attempt to send a confirmpaymentreceived message until after receiving a confirmpaymentstarted message has been sent from the buyer. --- .../java/bisq/core/api/CoreTradesService.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/api/CoreTradesService.java b/core/src/main/java/bisq/core/api/CoreTradesService.java index 0899a02d892..c010e845b3e 100644 --- a/core/src/main/java/bisq/core/api/CoreTradesService.java +++ b/core/src/main/java/bisq/core/api/CoreTradesService.java @@ -17,6 +17,7 @@ package bisq.core.api; +import bisq.core.api.exception.FailedPreconditionException; import bisq.core.api.exception.NotAvailableException; import bisq.core.api.exception.NotFoundException; import bisq.core.btc.model.AddressEntry; @@ -177,6 +178,13 @@ void takeOffer(Offer offer, void confirmPaymentStarted(String tradeId) { var trade = getTrade(tradeId); if (isFollowingBuyerProtocol(trade)) { + if (!trade.isDepositConfirmed()) { + throw new FailedPreconditionException( + format("cannot send a payment started message for trade '%s'%n" + + "until trade deposit tx '%s' is confirmed", + trade.getId(), + trade.getDepositTxId())); + } var tradeProtocol = tradeManager.getTradeProtocol(trade); ((BuyerProtocol) tradeProtocol).onPaymentStarted( () -> { @@ -186,15 +194,29 @@ void confirmPaymentStarted(String tradeId) { } ); } else { - throw new IllegalStateException("you are the seller and not sending payment"); + throw new FailedPreconditionException("you are the seller, and not sending payment"); } } void confirmPaymentReceived(String tradeId) { var trade = getTrade(tradeId); if (isFollowingBuyerProtocol(trade)) { - throw new IllegalStateException("you are the buyer, and not receiving payment"); + throw new FailedPreconditionException("you are the buyer, and not receiving payment"); } else { + if (!trade.isDepositConfirmed()) { + throw new FailedPreconditionException( + format("cannot send a payment received message for trade '%s'%n" + + "until trade deposit tx '%s' is confirmed", + trade.getId(), + trade.getDepositTxId())); + } + + if (!trade.isFiatSent()) { + throw new FailedPreconditionException( + format("cannot send a payment received confirmation message for trade '%s'%n" + + "until after a trade payment started message has been sent", + trade.getId())); + } var tradeProtocol = tradeManager.getTradeProtocol(trade); ((SellerProtocol) tradeProtocol).onPaymentReceived( () -> { From 4be80404036c0ce37cb37fb46cbd59e3863ee04d Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:22:07 -0300 Subject: [PATCH 2/8] Disable BSQ v1 protocol trade tests in TradeTest suite Replaced by BSQ Swaps, and will be deprecated. --- apitest/src/test/java/bisq/apitest/scenario/TradeTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java b/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java index 3631e6f6cec..26e1325bb0d 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java @@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j; 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; @@ -70,6 +71,7 @@ public void testTakeSellBTCOffer(final TestInfo testInfo) { test.testBobsBtcWithdrawalToExternalAddress(testInfo); } + @Disabled @Test @Order(3) public void testTakeBuyBSQOffer(final TestInfo testInfo) { @@ -91,6 +93,7 @@ public void testTakeBuyBTCOfferWithNationalBankAcct(final TestInfo testInfo) { test.testCloseTrade(testInfo); } + @Disabled @Test @Order(5) public void testTakeSellBSQOffer(final TestInfo testInfo) { From 4bad8152f00279dfb51dd02886a783fae71e4a00 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:25:13 -0300 Subject: [PATCH 3/8] Add payment msg precondition checks to AbstractTradeTest - verifyPaymentSentMsgIsFromBtcBuyerPrecondition - verifyPaymentReceivedMsgIsFromBtcSellerPrecondition - verifyPaymentSentMsgDepositTxConfirmedPrecondition - verifyPaymentReceivedMsgDepositTxConfirmedPrecondition - verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition Changed a couple of related method names. --- .../method/trade/AbstractTradeTest.java | 89 ++++++++++++++++++- 1 file changed, 87 insertions(+), 2 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java b/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java index 52ed72056f2..408dc343d89 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java @@ -2,6 +2,8 @@ import bisq.proto.grpc.TradeInfo; +import io.grpc.StatusRuntimeException; + import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; @@ -32,6 +34,7 @@ import bisq.cli.GrpcClient; import bisq.cli.table.builder.TableBuilder; +@SuppressWarnings({"ConstantConditions", "unused"}) public class AbstractTradeTest extends AbstractOfferTest { public static final ExpectedProtocolStatus EXPECTED_PROTOCOL_STATUS = new ExpectedProtocolStatus(); @@ -117,6 +120,15 @@ protected final void waitForDepositConfirmation(Logger log, } } + protected final void verifyTakerDepositNotConfirmed(TradeInfo trade) { + if (trade.getIsDepositConfirmed()) { + fail(format("INVALID_PHASE for trade %s in STATE=%s PHASE=%s, deposit tx should NOT be confirmed yet.", + trade.getShortId(), + trade.getState(), + trade.getPhase())); + } + } + protected final void verifyTakerDepositConfirmed(TradeInfo trade) { if (!trade.getIsDepositConfirmed()) { fail(format("INVALID_PHASE for trade %s in STATE=%s PHASE=%s, deposit tx never confirmed.", @@ -126,7 +138,80 @@ protected final void verifyTakerDepositConfirmed(TradeInfo trade) { } } - protected final void waitForBuyerSeesPaymentInitiatedMessage(Logger log, + protected final void verifyPaymentSentMsgIsFromBtcBuyerPrecondition(Logger log, GrpcClient sellerClient) { + String userName = toUserName.apply(sellerClient); + log.debug("BTC seller {} incorrectly sends a confirmpaymentstarted message, for trade {}", userName, tradeId); + Throwable exception = assertThrows(StatusRuntimeException.class, () -> sellerClient.confirmPaymentStarted(tradeId)); + String expectedExceptionMessage = "FAILED_PRECONDITION: you are the seller, and not sending payment"; + assertEquals(expectedExceptionMessage, exception.getMessage()); + } + + protected final void verifyPaymentReceivedMsgIsFromBtcSellerPrecondition(Logger log, GrpcClient buyerClient) { + String userName = toUserName.apply(buyerClient); + log.debug("BTC buyer {} incorrectly sends a confirmpaymentreceived message, for trade {}", userName, tradeId); + Throwable exception = assertThrows(StatusRuntimeException.class, () -> buyerClient.confirmPaymentReceived(tradeId)); + String expectedExceptionMessage = "FAILED_PRECONDITION: you are the buyer, and not receiving payment"; + assertEquals(expectedExceptionMessage, exception.getMessage()); + } + + protected final void verifyPaymentSentMsgDepositTxConfirmedPrecondition(Logger log, GrpcClient buyerClient) { + var trade = buyerClient.getTrade(tradeId); + verifyTakerDepositNotConfirmed(trade); + + String userName = toUserName.apply(buyerClient); + log.debug("BTC buyer {} sends a confirmpaymentstarted message before deposit tx is confirmed, for trade {}", + userName, + tradeId); + Throwable exception = assertThrows(StatusRuntimeException.class, () -> buyerClient.confirmPaymentStarted(tradeId)); + String expectedExceptionMessage = + format("FAILED_PRECONDITION: cannot send a payment started message for trade '%s'", tradeId); + String failureReason = format("Expected exception message to start with '%s'%n, but got '%s'", + expectedExceptionMessage, + exception.getMessage()); + assertTrue(exception.getMessage().startsWith(expectedExceptionMessage), failureReason); + expectedExceptionMessage = format("until trade deposit tx '%s' is confirmed", trade.getDepositTxId()); + assertTrue(exception.getMessage().contains(expectedExceptionMessage)); + } + + protected final void verifyPaymentReceivedMsgDepositTxConfirmedPrecondition(Logger log, GrpcClient sellerClient) { + var trade = sellerClient.getTrade(tradeId); + verifyTakerDepositNotConfirmed(trade); + + String userName = toUserName.apply(sellerClient); + log.debug("BTC seller {} sends a confirmpaymentreceived message before deposit tx is confirmed, for trade {}", + userName, + tradeId); + Throwable exception = assertThrows(StatusRuntimeException.class, () -> sellerClient.confirmPaymentReceived(tradeId)); + String expectedExceptionMessage = + format("FAILED_PRECONDITION: cannot send a payment received message for trade '%s'", tradeId); + String failureReason = format("Expected exception message to start with '%s'%n, but got '%s'", + expectedExceptionMessage, + exception.getMessage()); + assertTrue(exception.getMessage().startsWith(expectedExceptionMessage), failureReason); + expectedExceptionMessage = format("until trade deposit tx '%s' is confirmed", trade.getDepositTxId()); + assertTrue(exception.getMessage().contains(expectedExceptionMessage)); + } + + protected final void verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(Logger log, GrpcClient sellerClient) { + var trade = sellerClient.getTrade(tradeId); + verifyTakerDepositConfirmed(trade); + + String userName = toUserName.apply(sellerClient); + log.debug("BTC seller {} sends a confirmpaymentreceived message before a payment started message has been sent, for trade {}", + userName, + tradeId); + Throwable exception = assertThrows(StatusRuntimeException.class, () -> sellerClient.confirmPaymentReceived(tradeId)); + String expectedExceptionMessage = + format("FAILED_PRECONDITION: cannot send a payment received confirmation message for trade '%s'", tradeId); + String failureReason = format("Expected exception message to start with '%s'%n, but got '%s'", + expectedExceptionMessage, + exception.getMessage()); + assertTrue(exception.getMessage().startsWith(expectedExceptionMessage), failureReason); + expectedExceptionMessage = "until after a trade payment started message has been sent"; + assertTrue(exception.getMessage().contains(expectedExceptionMessage)); + } + + protected final void waitUntilBuyerSeesPaymentStartedMessage(Logger log, TestInfo testInfo, GrpcClient grpcClient, String tradeId) { @@ -153,7 +238,7 @@ protected final void waitForBuyerSeesPaymentInitiatedMessage(Logger log, } } - protected final void waitForSellerSeesPaymentInitiatedMessage(Logger log, + protected final void waitUntilSellerSeesPaymentStartedMessage(Logger log, TestInfo testInfo, GrpcClient grpcClient, String tradeId) { From 421cdcaa0f121e63b3323dadba17ad359fb0c902 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:28:54 -0300 Subject: [PATCH 4/8] Deprecate BSQ v1 protocol trade tests --- .../java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java | 5 +++-- .../java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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 1425e7182cd..c9df07de75e 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java @@ -46,6 +46,7 @@ // https://github.com/ghubstan/bisq/blob/master/cli/src/main/java/bisq/cli/TradeFormat.java +@Deprecated // Bisq v1 protocol BSQ trades have been replaced by BSQ Swaps. @Disabled @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @@ -122,7 +123,7 @@ public void testBobsConfirmPaymentStarted(final TestInfo testInfo) { genBtcBlocksThenWait(1, 2_500); bobClient.confirmPaymentStarted(trade.getTradeId()); sleep(6000); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); logTrade(log, testInfo, "Alice's Maker/Buyer View (Payment Sent)", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Seller View (Payment Sent)", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -134,7 +135,7 @@ public void testBobsConfirmPaymentStarted(final TestInfo testInfo) { @Order(3) public void testAlicesConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); sleep(2_000); var trade = aliceClient.getTrade(tradeId); verifyBsqPaymentHasBeenReceived(log, aliceClient, trade); 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 f7cf59cc899..9d710f717de 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java @@ -46,6 +46,7 @@ import bisq.apitest.method.offer.AbstractOfferTest; import bisq.cli.table.builder.TableBuilder; +@Deprecated // Bisq v1 protocol BSQ trades have been replaced by BSQ Swaps. @Disabled @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) @@ -114,7 +115,7 @@ public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { genBtcBlocksThenWait(1, 2_500); aliceClient.confirmPaymentStarted(trade.getTradeId()); sleep(6_000); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); logTrade(log, testInfo, "Alice's Maker/Seller View (Payment Sent)", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Buyer View (Payment Sent)", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -126,7 +127,7 @@ public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { @Order(3) public void testBobsConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); sleep(2_000); var trade = bobClient.getTrade(tradeId); From 3ce68d6b0c53bc9ace15c48a653ec9dcc8837545 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:29:30 -0300 Subject: [PATCH 5/8] Adjust to method renaming in superclass --- .../method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 186a6e5cbbe..ad5c5e84ffc 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java @@ -185,7 +185,7 @@ public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { waitForDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); aliceClient.confirmPaymentStarted(trade.getTradeId()); sleep(6_000); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); trade = aliceClient.getTrade(tradeId); assertEquals(OFFER_FEE_PAID.name(), trade.getOffer().getState()); logTrade(log, testInfo, "Alice's Maker/Buyer View (Payment Sent)", aliceClient.getTrade(tradeId)); @@ -199,7 +199,7 @@ public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { @Order(4) public void testBobsConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); var trade = bobClient.getTrade(tradeId); bobClient.confirmPaymentReceived(trade.getTradeId()); sleep(3_000); From 757067199437fcc6c5cea01c4e761e4637be668e Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Mon, 13 Jun 2022 21:30:36 -0300 Subject: [PATCH 6/8] Add payment msg precondition checks to v1 protocol tests - verifyPaymentSentMsgIsFromBtcBuyerPrecondition - verifyPaymentReceivedMsgIsFromBtcSellerPrecondition - verifyPaymentSentMsgDepositTxConfirmedPrecondition - verifyPaymentReceivedMsgDepositTxConfirmedPrecondition - verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition --- .../method/trade/TakeBuyBTCOfferTest.java | 37 ++++++++++++--- .../method/trade/TakeBuyXMROfferTest.java | 45 ++++++++++++++----- .../method/trade/TakeSellBTCOfferTest.java | 38 +++++++++++++--- .../method/trade/TakeSellXMROfferTest.java | 39 ++++++++++++---- 4 files changed, 125 insertions(+), 34 deletions(-) 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 e2c653f4ad2..6f339dfcb0f 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java @@ -42,6 +42,7 @@ import static protobuf.OpenOffer.State.AVAILABLE; @Disabled +@SuppressWarnings("ConstantConditions") @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class TakeBuyBTCOfferTest extends AbstractTradeTest { @@ -82,11 +83,9 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { sleep(2_500); // Allow available offer to be removed from offer book. alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD); assertEquals(0, alicesUsdOffers.size()); - genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); trade = bobClient.getTrade(tradeId); - verifyTakerDepositConfirmed(trade); + verifyTakerDepositNotConfirmed(trade); logTrade(log, testInfo, "Alice's Maker/Buyer View", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Seller View", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -96,23 +95,47 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { @Test @Order(2) + public void testPaymentMessagingPreconditions(final TestInfo testInfo) { + try { + // Alice is maker / btc buyer, Bob is taker / btc seller. + // Verify payment sent and rcvd msgs are sent by the right peers: buyer and seller. + verifyPaymentSentMsgIsFromBtcBuyerPrecondition(log, bobClient); + verifyPaymentReceivedMsgIsFromBtcSellerPrecondition(log, aliceClient); + + // Verify fiat payment sent and rcvd msgs cannot be sent before trade deposit tx is confirmed. + verifyPaymentSentMsgDepositTxConfirmedPrecondition(log, aliceClient); + verifyPaymentReceivedMsgDepositTxConfirmedPrecondition(log, bobClient); + + // Now generate the BTC block to confirm the taker deposit tx. + genBtcBlocksThenWait(1, 2_500); + waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + + // Verify the seller can only send a payment rcvd msg after the payment started msg. + verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, bobClient); + } catch (StatusRuntimeException e) { + fail(e); + } + } + + @Test + @Order(3) public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = aliceClient.getTrade(tradeId); waitForDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); aliceClient.confirmPaymentStarted(trade.getTradeId()); sleep(6_000); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); } catch (StatusRuntimeException e) { fail(e); } } @Test - @Order(3) + @Order(4) public void testBobsConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); var trade = bobClient.getTrade(tradeId); bobClient.confirmPaymentReceived(trade.getTradeId()); sleep(3_000); @@ -131,7 +154,7 @@ public void testBobsConfirmPaymentReceived(final TestInfo testInfo) { } @Test - @Order(4) + @Order(5) public void testCloseTrade(final TestInfo testInfo) { try { genBtcBlocksThenWait(1, 1_000); 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 da7d448c773..3577593048f 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java @@ -47,6 +47,7 @@ import bisq.cli.table.builder.TableBuilder; @Disabled +@SuppressWarnings("ConstantConditions") @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class TakeBuyXMROfferTest extends AbstractTradeTest { @@ -89,11 +90,9 @@ public void testTakeAlicesSellBTCForXMROffer(final TestInfo testInfo) { var trade = takeAlicesOffer(offerId, bobsXmrAcct.getId(), TRADE_FEE_CURRENCY_CODE); alicesXmrOffers = aliceClient.getMyOffersSortedByDate(XMR); assertEquals(0, alicesXmrOffers.size()); - genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); trade = bobClient.getTrade(tradeId); - verifyTakerDepositConfirmed(trade); + verifyTakerDepositNotConfirmed(trade); logTrade(log, testInfo, "Alice's Maker/Buyer View", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Seller View", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -103,15 +102,39 @@ public void testTakeAlicesSellBTCForXMROffer(final TestInfo testInfo) { @Test @Order(2) + public void testPaymentMessagingPreconditions(final TestInfo testInfo) { + try { + // Alice is maker / xmr buyer (btc seller), Bob is taker / xmr seller (btc buyer). + // Verify payment sent and rcvd msgs are sent by the right peers: buyer and seller. + verifyPaymentSentMsgIsFromBtcBuyerPrecondition(log, aliceClient); + verifyPaymentReceivedMsgIsFromBtcSellerPrecondition(log, bobClient); + + // Verify xmr payment sent and rcvd msgs cannot be sent before trade deposit tx is confirmed. + verifyPaymentSentMsgDepositTxConfirmedPrecondition(log, bobClient); + verifyPaymentReceivedMsgDepositTxConfirmedPrecondition(log, aliceClient); + + // Now generate the BTC block to confirm the taker deposit tx. + genBtcBlocksThenWait(1, 2_500); + waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + + // Verify the seller can only send a payment rcvd msg after the payment started msg. + verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, aliceClient); + } catch (StatusRuntimeException e) { + fail(e); + } + } + + @Test + @Order(3) public void testBobsConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = bobClient.getTrade(tradeId); verifyTakerDepositConfirmed(trade); - log.debug("Bob sends XMR payment to Alice for trade {}", trade.getTradeId()); - bobClient.confirmPaymentStarted(trade.getTradeId()); + log.debug("Bob sends XMR payment to Alice for trade {}", tradeId); + bobClient.confirmPaymentStarted(tradeId); sleep(3500); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); logTrade(log, testInfo, "Alice's Maker/Buyer View (Payment Sent)", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Seller View (Payment Sent)", bobClient.getTrade(tradeId)); @@ -121,18 +144,18 @@ public void testBobsConfirmPaymentStarted(final TestInfo testInfo) { } @Test - @Order(3) + @Order(4) public void testAlicesConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); sleep(2_000); var trade = aliceClient.getTrade(tradeId); // If we were trading BSQ, Alice would verify payment has been sent to her // Bisq / BSQ wallet, but we can do no such checks for XMR payments. // All XMR transfers are done outside Bisq. - log.debug("Alice verifies XMR payment was received from Bob, for trade {}", trade.getTradeId()); - aliceClient.confirmPaymentReceived(trade.getTradeId()); + log.debug("Alice verifies XMR payment was received from Bob, for trade {}", tradeId); + aliceClient.confirmPaymentReceived(tradeId); sleep(3_000); trade = aliceClient.getTrade(tradeId); @@ -150,7 +173,7 @@ public void testAlicesConfirmPaymentReceived(final TestInfo testInfo) { } @Test - @Order(4) + @Order(5) public void testCloseTrade(final TestInfo testInfo) { try { genBtcBlocksThenWait(1, 1_000); 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 ff9e70d7583..5cc5dc7da46 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java @@ -43,6 +43,7 @@ import static protobuf.OfferDirection.SELL; @Disabled +@SuppressWarnings("ConstantConditions") @Slf4j @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class TakeSellBTCOfferTest extends AbstractTradeTest { @@ -86,10 +87,9 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) { sleep(2_500); // Allow available offer to be removed from offer book. var takeableUsdOffers = bobClient.getOffersSortedByDate(SELL.name(), USD); assertEquals(0, takeableUsdOffers.size()); - genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); + trade = bobClient.getTrade(tradeId); - verifyTakerDepositConfirmed(trade); + verifyTakerDepositNotConfirmed(trade); logTrade(log, testInfo, "Alice's Maker/Buyer View", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Seller View", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -99,23 +99,47 @@ public void testTakeAlicesSellOffer(final TestInfo testInfo) { @Test @Order(2) + public void testPaymentMessagingPreconditions(final TestInfo testInfo) { + try { + // Alice is maker / btc seller, Bob is taker / btc buyer. + // Verify payment sent and rcvd msgs are sent by the right peers: buyer and seller. + verifyPaymentSentMsgIsFromBtcBuyerPrecondition(log, aliceClient); + verifyPaymentReceivedMsgIsFromBtcSellerPrecondition(log, bobClient); + + // Verify fiat payment sent and rcvd msgs cannot be sent before trade deposit tx is confirmed. + verifyPaymentSentMsgDepositTxConfirmedPrecondition(log, bobClient); + verifyPaymentReceivedMsgDepositTxConfirmedPrecondition(log, aliceClient); + + // Now generate the BTC block to confirm the taker deposit tx. + genBtcBlocksThenWait(1, 2_500); + waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + + // Verify the seller can only send a payment rcvd msg after the payment started msg. + verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, aliceClient); + } catch (StatusRuntimeException e) { + fail(e); + } + } + + @Test + @Order(3) public void testBobsConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = bobClient.getTrade(tradeId); verifyTakerDepositConfirmed(trade); bobClient.confirmPaymentStarted(tradeId); sleep(6_000); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); } catch (StatusRuntimeException e) { fail(e); } } @Test - @Order(3) + @Order(4) public void testAlicesConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); var trade = aliceClient.getTrade(tradeId); aliceClient.confirmPaymentReceived(trade.getTradeId()); @@ -134,7 +158,7 @@ public void testAlicesConfirmPaymentReceived(final TestInfo testInfo) { } @Test - @Order(4) + @Order(5) public void testBobsBtcWithdrawalToExternalAddress(final TestInfo testInfo) { try { genBtcBlocksThenWait(1, 1_000); 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 6b884f5bff4..71eafa38a11 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java @@ -60,7 +60,7 @@ public class TakeSellXMROfferTest extends AbstractTradeTest { @BeforeAll public static void setUp() { - AbstractOfferTest.setUp(); + AbstractOfferTest.setUp(false); createXmrPaymentAccounts(); EXPECTED_PROTOCOL_STATUS.init(); } @@ -93,12 +93,9 @@ public void testTakeAlicesBuyBTCForXMROffer(final TestInfo testInfo) { var trade = takeAlicesOffer(offerId, bobsXmrAcct.getId(), TRADE_FEE_CURRENCY_CODE); alicesXmrOffers = aliceClient.getMyOffersSortedByDate(XMR); assertEquals(0, alicesXmrOffers.size()); - genBtcBlocksThenWait(1, 2_500); - - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); trade = bobClient.getTrade(tradeId); - verifyTakerDepositConfirmed(trade); + verifyTakerDepositNotConfirmed(trade); logTrade(log, testInfo, "Alice's Maker/Seller View", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Buyer View", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -108,6 +105,30 @@ public void testTakeAlicesBuyBTCForXMROffer(final TestInfo testInfo) { @Test @Order(2) + public void testPaymentMessagingPreconditions(final TestInfo testInfo) { + try { + // Alice is maker / xmr seller (btc buyer), Bob is taker / xmr buyer (btc seller). + // Verify payment sent and rcvd msgs are sent by the right peers: buyer and seller. + verifyPaymentSentMsgIsFromBtcBuyerPrecondition(log, bobClient); + verifyPaymentReceivedMsgIsFromBtcSellerPrecondition(log, aliceClient); + + // Verify xmr payment sent and rcvd msgs cannot be sent before trade deposit tx is confirmed. + verifyPaymentSentMsgDepositTxConfirmedPrecondition(log, aliceClient); + verifyPaymentReceivedMsgDepositTxConfirmedPrecondition(log, bobClient); + + // Now generate the BTC block to confirm the taker deposit tx. + genBtcBlocksThenWait(1, 2_500); + waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + + // Verify the seller can only send a payment rcvd msg after the payment started msg. + verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, bobClient); + } catch (StatusRuntimeException e) { + fail(e); + } + } + + @Test + @Order(3) public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = aliceClient.getTrade(tradeId); @@ -116,7 +137,7 @@ public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { aliceClient.confirmPaymentStarted(trade.getTradeId()); sleep(3500); - waitForBuyerSeesPaymentInitiatedMessage(log, testInfo, aliceClient, tradeId); + waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); logTrade(log, testInfo, "Alice's Maker/Seller View (Payment Sent)", aliceClient.getTrade(tradeId)); logTrade(log, testInfo, "Bob's Taker/Buyer View (Payment Sent)", bobClient.getTrade(tradeId)); } catch (StatusRuntimeException e) { @@ -125,10 +146,10 @@ public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { } @Test - @Order(3) + @Order(4) public void testBobsConfirmPaymentReceived(final TestInfo testInfo) { try { - waitForSellerSeesPaymentInitiatedMessage(log, testInfo, bobClient, tradeId); + waitUntilSellerSeesPaymentStartedMessage(log, testInfo, bobClient, tradeId); var trade = bobClient.getTrade(tradeId); sleep(2_000); @@ -154,7 +175,7 @@ public void testBobsConfirmPaymentReceived(final TestInfo testInfo) { } @Test - @Order(4) + @Order(5) public void testAlicesBtcWithdrawalToExternalAddress(final TestInfo testInfo) { try { genBtcBlocksThenWait(1, 1_000); From 87cce9053fbaec7e536a05a0e9ebafeda6276696 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 14 Jun 2022 08:49:45 -0300 Subject: [PATCH 7/8] Minor formatting, rename a method --- .../method/trade/AbstractTradeTest.java | 22 ++++++++++++------- .../method/trade/TakeBuyBSQOfferTest.java | 2 +- .../method/trade/TakeBuyBTCOfferTest.java | 4 ++-- ...keBuyBTCOfferWithNationalBankAcctTest.java | 4 ++-- .../method/trade/TakeBuyXMROfferTest.java | 2 +- .../method/trade/TakeSellBSQOfferTest.java | 6 ++--- .../method/trade/TakeSellBTCOfferTest.java | 2 +- .../method/trade/TakeSellXMROfferTest.java | 6 ++--- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java b/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java index 408dc343d89..b389b6d6fb8 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/AbstractTradeTest.java @@ -43,10 +43,16 @@ public class AbstractTradeTest extends AbstractOfferTest { @Getter protected static String tradeId; - protected final Supplier maxTradeStateAndPhaseChecks = () -> isLongRunningTest ? 10 : 2; + protected final Supplier maxTradeStateAndPhaseChecks = () -> + isLongRunningTest + ? 10 + : 2; protected final Function toTradeDetailTable = (trade) -> new TableBuilder(TRADE_DETAIL_TBL, trade).build().toString(); - protected final Function toUserName = (client) -> client.equals(aliceClient) ? "Alice" : "Bob"; + protected final Function toUserName = (client) -> + client.equals(aliceClient) + ? "Alice" + : "Bob"; @BeforeAll public static void initStaticFixtures() { @@ -87,17 +93,17 @@ protected final TradeInfo takeAlicesOffer(String offerId, return trade; } - protected final void waitForDepositConfirmation(Logger log, - TestInfo testInfo, - GrpcClient grpcClient, - String tradeId) { + protected final void waitForTakerDepositConfirmation(Logger log, + TestInfo testInfo, + GrpcClient takerClient, + String tradeId) { Predicate isTradeInDepositConfirmedStateAndPhase = (t) -> t.getState().equals(DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN.name()) && t.getPhase().equals(DEPOSIT_CONFIRMED.name()); - String userName = toUserName.apply(grpcClient); + String userName = toUserName.apply(takerClient); for (int i = 1; i <= maxTradeStateAndPhaseChecks.get(); i++) { - TradeInfo trade = grpcClient.getTrade(tradeId); + TradeInfo trade = takerClient.getTrade(tradeId); if (!isTradeInDepositConfirmedStateAndPhase.test(trade)) { log.warn("{} still waiting on trade {} tx {}: DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN, attempt # {}", userName, 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 c9df07de75e..923a243b28a 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBSQOfferTest.java @@ -101,7 +101,7 @@ public void testTakeAlicesSellBTCForBSQOffer(final TestInfo testInfo) { alicesBsqOffers = aliceClient.getMyOffersSortedByDate(BSQ); assertEquals(0, alicesBsqOffers.size()); - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); genBtcBlocksThenWait(1, 2_500); trade = bobClient.getTrade(tradeId); 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 6f339dfcb0f..54d20acc23f 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java @@ -108,7 +108,7 @@ public void testPaymentMessagingPreconditions(final TestInfo testInfo) { // Now generate the BTC block to confirm the taker deposit tx. genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + waitForTakerDepositConfirmation(log, testInfo, bobClient, tradeId); // Verify the seller can only send a payment rcvd msg after the payment started msg. verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, bobClient); @@ -122,7 +122,7 @@ public void testPaymentMessagingPreconditions(final TestInfo testInfo) { public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = aliceClient.getTrade(tradeId); - waitForDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); aliceClient.confirmPaymentStarted(trade.getTradeId()); sleep(6_000); waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); 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 ad5c5e84ffc..d1b7efd3492 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java @@ -145,7 +145,7 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { alicesOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), BRL); assertEquals(0, alicesOffers.size()); genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); trade = bobClient.getTrade(tradeId); verifyTakerDepositConfirmed(trade); @@ -182,7 +182,7 @@ public void testBankAcctDetailsIncludedInContracts(final TestInfo testInfo) { public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = aliceClient.getTrade(tradeId); - waitForDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); aliceClient.confirmPaymentStarted(trade.getTradeId()); sleep(6_000); waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); 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 3577593048f..5e85a866e99 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyXMROfferTest.java @@ -115,7 +115,7 @@ public void testPaymentMessagingPreconditions(final TestInfo testInfo) { // Now generate the BTC block to confirm the taker deposit tx. genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + waitForTakerDepositConfirmation(log, testInfo, bobClient, tradeId); // Verify the seller can only send a payment rcvd msg after the payment started msg. verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, aliceClient); 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 9d710f717de..efd0a6c77af 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBSQOfferTest.java @@ -82,7 +82,7 @@ public void testTakeAlicesBuyBTCForBSQOffer(final TestInfo testInfo) { alicesLegacyBsqAcct.getId(), TRADE_FEE_CURRENCY_CODE); log.debug("Alice's SELL BSQ (BUY BTC) Offer:\n{}", new TableBuilder(OFFER_TBL, alicesOffer).build()); - genBtcBlocksThenWait(1, 4_000); + genBtcBlocksThenWait(1, 2_500); var offerId = alicesOffer.getId(); assertTrue(alicesOffer.getIsCurrencyForMakerFeeBtc()); var alicesBsqOffers = aliceClient.getMyOffers(btcTradeDirection, BSQ); @@ -95,7 +95,7 @@ public void testTakeAlicesBuyBTCForBSQOffer(final TestInfo testInfo) { alicesBsqOffers = aliceClient.getMyOffersSortedByDate(BSQ); assertEquals(0, alicesBsqOffers.size()); genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, bobClient, trade.getTradeId()); trade = bobClient.getTrade(tradeId); verifyTakerDepositConfirmed(trade); logTrade(log, testInfo, "Alice's Maker/Seller View", aliceClient.getTrade(tradeId)); @@ -110,7 +110,7 @@ public void testTakeAlicesBuyBTCForBSQOffer(final TestInfo testInfo) { public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = aliceClient.getTrade(tradeId); - waitForDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); sendBsqPayment(log, aliceClient, trade); genBtcBlocksThenWait(1, 2_500); aliceClient.confirmPaymentStarted(trade.getTradeId()); 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 5cc5dc7da46..6d9f2e450a8 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellBTCOfferTest.java @@ -112,7 +112,7 @@ public void testPaymentMessagingPreconditions(final TestInfo testInfo) { // Now generate the BTC block to confirm the taker deposit tx. genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + waitForTakerDepositConfirmation(log, testInfo, bobClient, tradeId); // Verify the seller can only send a payment rcvd msg after the payment started msg. verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, aliceClient); 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 71eafa38a11..90c8fe1007e 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java @@ -118,7 +118,7 @@ public void testPaymentMessagingPreconditions(final TestInfo testInfo) { // Now generate the BTC block to confirm the taker deposit tx. genBtcBlocksThenWait(1, 2_500); - waitForDepositConfirmation(log, testInfo, bobClient, tradeId); + waitForTakerDepositConfirmation(log, testInfo, bobClient, tradeId); // Verify the seller can only send a payment rcvd msg after the payment started msg. verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition(log, bobClient); @@ -132,10 +132,10 @@ public void testPaymentMessagingPreconditions(final TestInfo testInfo) { public void testAlicesConfirmPaymentStarted(final TestInfo testInfo) { try { var trade = aliceClient.getTrade(tradeId); - waitForDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); + waitForTakerDepositConfirmation(log, testInfo, aliceClient, trade.getTradeId()); log.debug("Alice sends XMR payment to Bob for trade {}", trade.getTradeId()); aliceClient.confirmPaymentStarted(trade.getTradeId()); - sleep(3500); + sleep(3_500); waitUntilBuyerSeesPaymentStartedMessage(log, testInfo, aliceClient, tradeId); logTrade(log, testInfo, "Alice's Maker/Seller View (Payment Sent)", aliceClient.getTrade(tradeId)); From 2db1e4cb3d1ef8249f93d23cb0e1249c916c6555 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 14 Jun 2022 08:50:24 -0300 Subject: [PATCH 8/8] Add new msg precondition unit test to Trade test suites --- .../java/bisq/apitest/scenario/LongRunningTradesTest.java | 1 + apitest/src/test/java/bisq/apitest/scenario/TradeTest.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/apitest/src/test/java/bisq/apitest/scenario/LongRunningTradesTest.java b/apitest/src/test/java/bisq/apitest/scenario/LongRunningTradesTest.java index 4322a11bbd3..b041b4dde01 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/LongRunningTradesTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/LongRunningTradesTest.java @@ -78,6 +78,7 @@ public void testTakeSellBTCOffer(final TestInfo testInfo) { TakeSellBTCOfferTest test = new TakeSellBTCOfferTest(); setLongRunningTest(true); test.testTakeAlicesSellOffer(testInfo); + test.testPaymentMessagingPreconditions(testInfo); test.testBobsConfirmPaymentStarted(testInfo); test.testAlicesConfirmPaymentReceived(testInfo); test.testBobsBtcWithdrawalToExternalAddress(testInfo); diff --git a/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java b/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java index 26e1325bb0d..3c2252d402f 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/TradeTest.java @@ -56,6 +56,7 @@ public void init() { public void testTakeBuyBTCOffer(final TestInfo testInfo) { TakeBuyBTCOfferTest test = new TakeBuyBTCOfferTest(); test.testTakeAlicesBuyOffer(testInfo); + test.testPaymentMessagingPreconditions(testInfo); test.testAlicesConfirmPaymentStarted(testInfo); test.testBobsConfirmPaymentReceived(testInfo); test.testCloseTrade(testInfo); @@ -66,6 +67,7 @@ public void testTakeBuyBTCOffer(final TestInfo testInfo) { public void testTakeSellBTCOffer(final TestInfo testInfo) { TakeSellBTCOfferTest test = new TakeSellBTCOfferTest(); test.testTakeAlicesSellOffer(testInfo); + test.testPaymentMessagingPreconditions(testInfo); test.testBobsConfirmPaymentStarted(testInfo); test.testAlicesConfirmPaymentReceived(testInfo); test.testBobsBtcWithdrawalToExternalAddress(testInfo); @@ -110,6 +112,7 @@ public void testTakeBuyXMROffer(final TestInfo testInfo) { TakeBuyXMROfferTest test = new TakeBuyXMROfferTest(); TakeBuyXMROfferTest.createXmrPaymentAccounts(); test.testTakeAlicesSellBTCForXMROffer(testInfo); + test.testPaymentMessagingPreconditions(testInfo); test.testBobsConfirmPaymentStarted(testInfo); test.testAlicesConfirmPaymentReceived(testInfo); test.testCloseTrade(testInfo); @@ -121,6 +124,7 @@ public void testTakeSellXMROffer(final TestInfo testInfo) { TakeSellXMROfferTest test = new TakeSellXMROfferTest(); TakeBuyXMROfferTest.createXmrPaymentAccounts(); test.testTakeAlicesBuyBTCForXMROffer(testInfo); + test.testPaymentMessagingPreconditions(testInfo); test.testAlicesConfirmPaymentStarted(testInfo); test.testBobsConfirmPaymentReceived(testInfo); test.testAlicesBtcWithdrawalToExternalAddress(testInfo);