Skip to content

Commit

Permalink
Add payment msg precondition checks to v1 protocol tests
Browse files Browse the repository at this point in the history
- verifyPaymentSentMsgIsFromBtcBuyerPrecondition
- verifyPaymentReceivedMsgIsFromBtcSellerPrecondition
- verifyPaymentSentMsgDepositTxConfirmedPrecondition
- verifyPaymentReceivedMsgDepositTxConfirmedPrecondition
- verifyPaymentReceivedMsgAfterPaymentSentMsgPrecondition
  • Loading branch information
ghubstan committed Jun 14, 2022
1 parent 3ce68d6 commit 7570671
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import static protobuf.OpenOffer.State.AVAILABLE;

@Disabled
@SuppressWarnings("ConstantConditions")
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TakeBuyBTCOfferTest extends AbstractTradeTest {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import bisq.cli.table.builder.TableBuilder;

@Disabled
@SuppressWarnings("ConstantConditions")
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TakeBuyXMROfferTest extends AbstractTradeTest {
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import static protobuf.OfferDirection.SELL;

@Disabled
@SuppressWarnings("ConstantConditions")
@Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TakeSellBTCOfferTest extends AbstractTradeTest {
Expand Down Expand Up @@ -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) {
Expand All @@ -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());
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TakeSellXMROfferTest extends AbstractTradeTest {

@BeforeAll
public static void setUp() {
AbstractOfferTest.setUp();
AbstractOfferTest.setUp(false);
createXmrPaymentAccounts();
EXPECTED_PROTOCOL_STATUS.init();
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 7570671

Please sign in to comment.