Add editoffer test case, suppress annoying warnings

This commit is contained in:
ghubstan 2021-06-15 11:39:06 -03:00
parent 4da64b9bd0
commit 063b52eb70
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
3 changed files with 46 additions and 9 deletions

View File

@ -39,10 +39,7 @@ import org.junit.jupiter.api.TestMethodOrder;
import static bisq.apitest.config.ApiTestConfig.BSQ; import static bisq.apitest.config.ApiTestConfig.BSQ;
import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent; import static bisq.core.btc.wallet.Restrictions.getDefaultBuyerSecurityDepositAsPercent;
import static bisq.proto.grpc.EditOfferRequest.EditType.FIXED_PRICE_AND_ACTIVATION_STATE; import static bisq.proto.grpc.EditOfferRequest.EditType.*;
import static bisq.proto.grpc.EditOfferRequest.EditType.MKT_PRICE_MARGIN_AND_TRIGGER_PRICE;
import static bisq.proto.grpc.EditOfferRequest.EditType.MKT_PRICE_MARGIN_AND_TRIGGER_PRICE_AND_ACTIVATION_STATE;
import static bisq.proto.grpc.EditOfferRequest.EditType.MKT_PRICE_MARGIN_ONLY;
import static java.lang.String.format; import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
@ -51,6 +48,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static protobuf.OfferPayload.Direction.BUY; import static protobuf.OfferPayload.Direction.BUY;
import static protobuf.OfferPayload.Direction.SELL; import static protobuf.OfferPayload.Direction.SELL;
@SuppressWarnings("ALL")
@Disabled @Disabled
@Slf4j @Slf4j
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@ -175,6 +173,7 @@ public class EditOfferTest extends AbstractOfferTest {
OfferInfo editedOffer = aliceClient.getMyOffer(originalOffer.getId()); OfferInfo editedOffer = aliceClient.getMyOffer(originalOffer.getId());
var expectedNewFixedPrice = scaledUpFiatPrice.apply(new BigDecimal(editedFixedPriceAsString)); var expectedNewFixedPrice = scaledUpFiatPrice.apply(new BigDecimal(editedFixedPriceAsString));
assertEquals(expectedNewFixedPrice, editedOffer.getPrice()); assertEquals(expectedNewFixedPrice, editedOffer.getPrice());
assertFalse(editedOffer.getUseMarketBasedPrice());
doSanityCheck(originalOffer, editedOffer); doSanityCheck(originalOffer, editedOffer);
} }
@ -211,6 +210,40 @@ public class EditOfferTest extends AbstractOfferTest {
@Test @Test
@Order(7) @Order(7)
public void testEditMktPriceMarginAndDeactivation() {
PaymentAccount paymentAcct = getOrCreatePaymentAccount("US");
var originalMktPriceMargin = new BigDecimal("0.0").doubleValue();
OfferInfo originalOffer = createMktPricedOfferForEdit(SELL.name(),
DOLLAR,
paymentAcct.getId(),
originalMktPriceMargin,
0);
genBtcBlocksThenWait(1, 2500); // Wait for offer book entry.
originalOffer = aliceClient.getMyOffer(originalOffer.getId());
assertEquals(scaledDownMktPriceMargin.apply(originalMktPriceMargin), originalOffer.getMarketPriceMargin());
// Edit the offer's price margin and trigger price, and deactivate it.
var newMktPriceMargin = new BigDecimal("1.50").doubleValue();
aliceClient.editOffer(originalOffer.getId(),
"0.00",
originalOffer.getUseMarketBasedPrice(),
newMktPriceMargin,
0,
DEACTIVATE_OFFER,
MKT_PRICE_MARGIN_AND_ACTIVATION_STATE);
// Wait for edited offer to be removed from offer-book, edited, and re-published.
genBtcBlocksThenWait(1, 2500);
OfferInfo editedOffer = aliceClient.getMyOffer(originalOffer.getId());
assertEquals(scaledDownMktPriceMargin.apply(newMktPriceMargin), editedOffer.getMarketPriceMargin());
assertEquals(0, editedOffer.getTriggerPrice());
assertFalse(editedOffer.getIsActivated());
doSanityCheck(originalOffer, editedOffer);
}
@Test
@Order(8)
public void testEditMktPriceMarginAndTriggerPriceAndDeactivation() { public void testEditMktPriceMarginAndTriggerPriceAndDeactivation() {
PaymentAccount paymentAcct = getOrCreatePaymentAccount("US"); PaymentAccount paymentAcct = getOrCreatePaymentAccount("US");
@ -249,7 +282,7 @@ public class EditOfferTest extends AbstractOfferTest {
} }
@Test @Test
@Order(8) @Order(9)
public void testEditingFixedPriceInMktPriceMarginBasedOfferShouldThrowException() { public void testEditingFixedPriceInMktPriceMarginBasedOfferShouldThrowException() {
PaymentAccount paymentAcct = getOrCreatePaymentAccount("US"); PaymentAccount paymentAcct = getOrCreatePaymentAccount("US");
var originalMktPriceMargin = new BigDecimal("0.0").doubleValue(); var originalMktPriceMargin = new BigDecimal("0.0").doubleValue();
@ -279,7 +312,7 @@ public class EditOfferTest extends AbstractOfferTest {
} }
@Test @Test
@Order(9) @Order(10)
public void testEditingTriggerPriceInFixedPriceOfferShouldThrowException() { public void testEditingTriggerPriceInFixedPriceOfferShouldThrowException() {
PaymentAccount paymentAcct = getOrCreatePaymentAccount("RU"); PaymentAccount paymentAcct = getOrCreatePaymentAccount("RU");
double mktPriceAsDouble = aliceClient.getBtcPrice(RUBLE); double mktPriceAsDouble = aliceClient.getBtcPrice(RUBLE);
@ -301,7 +334,7 @@ public class EditOfferTest extends AbstractOfferTest {
} }
@Test @Test
@Order(10) @Order(11)
public void testChangeFixedPriceOfferToPriceMarginBasedOfferWithTriggerPrice() { public void testChangeFixedPriceOfferToPriceMarginBasedOfferWithTriggerPrice() {
PaymentAccount paymentAcct = getOrCreatePaymentAccount("MX"); PaymentAccount paymentAcct = getOrCreatePaymentAccount("MX");
double mktPriceAsDouble = aliceClient.getBtcPrice("MXN"); double mktPriceAsDouble = aliceClient.getBtcPrice("MXN");
@ -335,7 +368,7 @@ public class EditOfferTest extends AbstractOfferTest {
} }
@Test @Test
@Order(11) @Order(12)
public void testChangePriceMarginBasedOfferToFixedPriceOfferAndDeactivateIt() { public void testChangePriceMarginBasedOfferToFixedPriceOfferAndDeactivateIt() {
PaymentAccount paymentAcct = getOrCreatePaymentAccount("GB"); PaymentAccount paymentAcct = getOrCreatePaymentAccount("GB");
double mktPriceAsDouble = aliceClient.getBtcPrice("GBP"); double mktPriceAsDouble = aliceClient.getBtcPrice("GBP");
@ -360,10 +393,10 @@ public class EditOfferTest extends AbstractOfferTest {
// Wait for edited offer to be removed from offer-book, edited, and re-published. // Wait for edited offer to be removed from offer-book, edited, and re-published.
genBtcBlocksThenWait(1, 2500); genBtcBlocksThenWait(1, 2500);
OfferInfo editedOffer = aliceClient.getMyOffer(originalOffer.getId()); OfferInfo editedOffer = aliceClient.getMyOffer(originalOffer.getId());
assertEquals(scaledUpFiatPrice.apply(new BigDecimal(fixedPriceAsString)), editedOffer.getPrice());
assertFalse(editedOffer.getUseMarketBasedPrice()); assertFalse(editedOffer.getUseMarketBasedPrice());
assertEquals(0.00, editedOffer.getMarketPriceMargin()); assertEquals(0.00, editedOffer.getMarketPriceMargin());
assertEquals(0, editedOffer.getTriggerPrice()); assertEquals(0, editedOffer.getTriggerPrice());
assertEquals(scaledUpFiatPrice.apply(new BigDecimal(fixedPriceAsString)), editedOffer.getPrice());
assertFalse(editedOffer.getIsActivated()); assertFalse(editedOffer.getIsActivated());
} }

View File

@ -98,6 +98,7 @@ public class OfferTest extends AbstractOfferTest {
test.testEditMktPriceMargin(); test.testEditMktPriceMargin();
test.testEditFixedPrice(); test.testEditFixedPrice();
test.testEditFixedPriceAndDeactivation(); test.testEditFixedPriceAndDeactivation();
test.testEditMktPriceMarginAndDeactivation();
test.testEditMktPriceMarginAndTriggerPriceAndDeactivation(); test.testEditMktPriceMarginAndTriggerPriceAndDeactivation();
test.testEditingFixedPriceInMktPriceMarginBasedOfferShouldThrowException(); test.testEditingFixedPriceInMktPriceMarginBasedOfferShouldThrowException();
test.testEditingTriggerPriceInFixedPriceOfferShouldThrowException(); test.testEditingTriggerPriceInFixedPriceOfferShouldThrowException();

View File

@ -126,6 +126,7 @@ public class OffersServiceRequest {
// TODO Make sure this is not duplicated anywhere on CLI side. // TODO Make sure this is not duplicated anywhere on CLI side.
private final Function<Long, String> scaledPriceStringFormat = (price) -> { private final Function<Long, String> scaledPriceStringFormat = (price) -> {
BigDecimal factor = new BigDecimal(10).pow(4); BigDecimal factor = new BigDecimal(10).pow(4);
//noinspection BigDecimalMethodWithoutRoundingCalled
return new BigDecimal(price).divide(factor).toPlainString(); return new BigDecimal(price).divide(factor).toPlainString();
}; };
@ -195,6 +196,7 @@ public class OffersServiceRequest {
.setEnable(enable) .setEnable(enable)
.setEditType(editType) .setEditType(editType)
.build(); .build();
//noinspection ResultOfMethodCallIgnored
grpcStubs.offersService.editOffer(request); grpcStubs.offersService.editOffer(request);
} }
@ -202,6 +204,7 @@ public class OffersServiceRequest {
var request = CancelOfferRequest.newBuilder() var request = CancelOfferRequest.newBuilder()
.setId(offerId) .setId(offerId)
.build(); .build();
//noinspection ResultOfMethodCallIgnored
grpcStubs.offersService.cancelOffer(request); grpcStubs.offersService.cancelOffer(request);
} }