Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API bug-fix for incorrect BsqSwap's OfferInfo.isActivated value [No. 3] #6094

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import bisq.proto.grpc.BalancesInfo;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand Down Expand Up @@ -190,6 +193,15 @@ protected static String encodeToHex(String s) {
return Utilities.bytesAsHexString(s.getBytes(UTF_8));
}

protected static Status.Code getStatusRuntimeExceptionStatusCode(Exception grpcException) {
if (grpcException instanceof StatusRuntimeException)
return ((StatusRuntimeException) grpcException).getStatus().getCode();
else
throw new IllegalArgumentException(
format("Expected a io.grpc.StatusRuntimeException argument, but got a %s",
grpcException.getClass().getName()));
}

protected void verifyNoLoggedNodeExceptions() {
var loggedExceptions = getNodeExceptionMessages();
if (loggedExceptions != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void setUp() {
public void testRegisterArbitratorShouldThrowException() {
Throwable exception = assertThrows(StatusRuntimeException.class, () ->
arbClient.registerDisputeAgent(ARBITRATOR, DEV_PRIVILEGE_PRIV_KEY));
assertEquals("INVALID_ARGUMENT: arbitrators must be registered in a Bisq UI",
assertEquals("UNIMPLEMENTED: arbitrators must be registered in a Bisq UI",
exception.getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

import static bisq.apitest.config.ApiTestConfig.BSQ;
import static bisq.apitest.config.ApiTestConfig.BTC;
import static io.grpc.Status.Code.NOT_FOUND;
import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static protobuf.OfferDirection.BUY;

Expand All @@ -44,7 +46,7 @@ public class BsqSwapOfferTest extends AbstractOfferTest {

@BeforeAll
public static void setUp() {
AbstractOfferTest.setUp();
AbstractOfferTest.setUp(false);
}

@BeforeEach
Expand Down Expand Up @@ -136,10 +138,13 @@ private void testGetMyBsqSwapOffer(OfferInfo bsqSwapOffer) {
numFetchAttempts++;
var fetchedBsqSwapOffer = aliceClient.getOffer(bsqSwapOffer.getId());
assertEquals(bsqSwapOffer.getId(), fetchedBsqSwapOffer.getId());
assertTrue(fetchedBsqSwapOffer.getIsActivated());
log.debug("Alice found her (my) new bsq swap offer on attempt # {}.", numFetchAttempts);
break;
} catch (Exception ex) {
log.warn(ex.getMessage());
var statusCode = getStatusRuntimeExceptionStatusCode(ex);
assertEquals(NOT_FOUND, statusCode, "Expected a NOT_FOUND status code from server");

if (numFetchAttempts >= 9)
fail(format("Alice giving up on fetching her (my) bsq swap offer after %d attempts.", numFetchAttempts), ex);
Expand All @@ -156,10 +161,13 @@ private void testGetBsqSwapOffer(OfferInfo bsqSwapOffer) {
numFetchAttempts++;
var fetchedBsqSwapOffer = bobClient.getOffer(bsqSwapOffer.getId());
assertEquals(bsqSwapOffer.getId(), fetchedBsqSwapOffer.getId());
assertTrue(fetchedBsqSwapOffer.getIsActivated());
log.debug("Bob found new available bsq swap offer on attempt # {}.", numFetchAttempts);
break;
} catch (Exception ex) {
log.warn(ex.getMessage());
var statusCode = getStatusRuntimeExceptionStatusCode(ex);
assertEquals(NOT_FOUND, statusCode, "Expected a NOT_FOUND status code from server");

if (numFetchAttempts > 9)
fail(format("Bob gave up on fetching available bsq swap offer after %d attempts.", numFetchAttempts), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void testCreateBuy1BTCFor20KBSQOffer() {
log.debug("Sell BSQ (Buy BTC) Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -89,6 +90,7 @@ public void testCreateBuy1BTCFor20KBSQOffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -119,6 +121,7 @@ public void testCreateSell1BTCFor20KBSQOffer() {
log.debug("SELL 20K BSQ Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -140,6 +143,7 @@ public void testCreateSell1BTCFor20KBSQOffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -170,6 +174,7 @@ public void testCreateBuyBTCWith1To2KBSQOffer() {
log.debug("BUY 1-2K BSQ Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -191,6 +196,7 @@ public void testCreateBuyBTCWith1To2KBSQOffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -221,6 +227,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
log.debug("SELL 5-10K BSQ Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -242,6 +249,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand All @@ -260,7 +268,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
@Test
@Order(5)
public void testGetAllMyBsqOffers() {
List<OfferInfo> offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(BSQ);
List<OfferInfo> offers = aliceClient.getMyOffersSortedByDate(BSQ);
log.debug("All Alice's BSQ Offers:\n{}", toOffersTable.apply(offers));
assertEquals(4, offers.size());
log.debug("ALICE'S BALANCES\n{}", formatBalancesTbls(aliceClient.getBalances()));
Expand All @@ -269,7 +277,7 @@ public void testGetAllMyBsqOffers() {
@Test
@Order(6)
public void testGetAvailableBsqOffers() {
List<OfferInfo> offers = bobClient.getCryptoCurrencyOffersSortedByDate(BSQ);
List<OfferInfo> offers = bobClient.getOffersSortedByDate(BSQ);
log.debug("All Bob's Available BSQ Offers:\n{}", toOffersTable.apply(offers));
assertEquals(4, offers.size());
log.debug("BOB'S BALANCES\n{}", formatBalancesTbls(bobClient.getBalances()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -79,6 +80,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -109,6 +111,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -128,6 +131,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -158,6 +162,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -177,6 +182,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -94,6 +95,7 @@ public void testCreateUSDBTCBuyOffer5PctPriceMargin() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -126,6 +128,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -143,6 +146,7 @@ public void testCreateNZDBTCBuyOfferMinus2PctPriceMargin() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -175,6 +179,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -192,6 +197,7 @@ public void testCreateGBPBTCSellOfferMinus1Point5PctPriceMargin() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -224,6 +230,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
log.debug("Offer #4:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -241,6 +248,7 @@ public void testCreateBRLBTCSellOffer6Point55PctPriceMargin() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -273,12 +281,14 @@ public void testCreateUSDBTCBuyOfferWithTriggerPrice() {
triggerPrice);
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

genBtcBlocksThenWait(1, 4000); // give time to add to offer book
newOffer = aliceClient.getOffer(newOffer.getId());
log.debug("Offer #5:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(triggerPrice, newOffer.getTriggerPrice());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() {
log.debug("Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -90,6 +91,7 @@ public void testCreateFixedPriceBuy1BTCFor200KXMROffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -118,6 +120,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() {
log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -137,6 +140,7 @@ public void testCreateFixedPriceSell1BTCFor200KXMROffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -168,6 +172,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
log.debug("Pending Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -191,6 +196,7 @@ public void testCreatePriceMarginBasedBuy1BTCOfferWithTriggerPrice() {
log.debug("Available Sell XMR (Buy BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
Expand Down Expand Up @@ -224,6 +230,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() {
log.debug("Buy XMR (Sell BTC) offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());
assertFalse(newOffer.getIsActivated());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
Expand All @@ -242,6 +249,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() {
newOffer = aliceClient.getOffer(newOfferId);
assertTrue(newOffer.getIsMyOffer());
assertFalse(newOffer.getIsMyPendingOffer());
assertTrue(newOffer.getIsActivated());
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertTrue(newOffer.getUseMarketBasedPrice());
Expand All @@ -257,7 +265,7 @@ public void testCreatePriceMarginBasedSell1BTCOffer() {
@Test
@Order(5)
public void testGetAllMyXMROffers() {
List<OfferInfo> offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(XMR);
List<OfferInfo> offers = aliceClient.getMyOffersSortedByDate(XMR);
log.debug("All of Alice's XMR offers:\n{}", toOffersTable.apply(offers));
assertEquals(4, offers.size());
log.debug("Alice's balances\n{}", formatBalancesTbls(aliceClient.getBalances()));
Expand All @@ -266,7 +274,7 @@ public void testGetAllMyXMROffers() {
@Test
@Order(6)
public void testGetAvailableXMROffers() {
List<OfferInfo> offers = bobClient.getCryptoCurrencyOffersSortedByDate(XMR);
List<OfferInfo> offers = bobClient.getOffersSortedByDate(XMR);
log.debug("All of Bob's available XMR offers:\n{}", toOffersTable.apply(offers));
assertEquals(4, offers.size());
log.debug("Bob's balances\n{}", formatBalancesTbls(bobClient.getBalances()));
Expand Down
Loading