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

Change API OfferInfo volume/minVolume proto fields to string [#4] #6060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6f1057a
Include unmerged API NPE fix to FeeService class (see PR #6052)
ghubstan Feb 17, 2022
4596960
Prepare API Offers .proto defs for significant changes
ghubstan Feb 17, 2022
ddd3ec3
Fix comment about changing "all" number fields to string
ghubstan Feb 17, 2022
135a42b
Delete deprecated CLI console output formatting classes
ghubstan Feb 17, 2022
461edff
Change OfferInfo proto's 'price' field type to string
ghubstan Feb 17, 2022
3405dbf
Adjust cli module to OfferInfo.price field change to string type
ghubstan Feb 17, 2022
89267e5
Fix typo in comment
ghubstan Feb 17, 2022
1d70b1b
Adjust apitest cases to OfferInfo.price proto field type to string
ghubstan Feb 17, 2022
18888f4
Fix 'unnecessary use of fully qualified name'.
ghubstan Feb 17, 2022
62a0a14
Change existing `uint64 triggerPrice` field type in grpc.proto to `st…
ghubstan Feb 18, 2022
fafe416
Adjust to `string triggerPrice` change in API core classes.
ghubstan Feb 18, 2022
68450c4
Adjust to `string triggerPrice` change in API cli classes
ghubstan Feb 18, 2022
2af3ac2
Adjust to `string triggerPrice` change in API test cases
ghubstan Feb 18, 2022
d42c580
Change OfferInfo proto's volume fields' type to string
ghubstan Feb 18, 2022
2056e26
Adjust cli module to grpc.proto::volume field type change (string)
ghubstan Feb 18, 2022
31c8fbb
Remove some dead code
ghubstan Feb 18, 2022
15f75ee
Add some asserts on volume/min-volume strings from server
ghubstan Feb 18, 2022
1a3622b
Merge branch 'master' into 4-change-grpc-proto-volume-to-string
ghubstan Feb 18, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import protobuf.PaymentAccount;

import java.math.BigDecimal;
import java.math.MathContext;

import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

import lombok.Setter;
Expand Down Expand Up @@ -62,7 +62,7 @@ public abstract class AbstractOfferTest extends MethodTest {

protected static final int ACTIVATE_OFFER = 1;
protected static final int DEACTIVATE_OFFER = 0;
protected static final long NO_TRIGGER_PRICE = 0;
protected static final String NO_TRIGGER_PRICE = "0";

@Setter
protected static boolean isLongRunningTest;
Expand Down Expand Up @@ -94,41 +94,20 @@ public static void setUp() {
protected final Function<Double, Double> scaledDownMktPriceMargin = (mktPriceMargin) ->
exactMultiply(mktPriceMargin, 0.01);

// Price value of fiat offer returned from server will be scaled up by 10^4.
protected final Function<BigDecimal, Long> scaledUpFiatOfferPrice = (price) -> {
BigDecimal factor = new BigDecimal(10).pow(4);
return price.multiply(factor).longValue();
};

// Price value of altcoin offer returned from server will be scaled up by 10^8.
protected final Function<String, Long> scaledUpAltcoinOfferPrice = (altcoinPriceAsString) -> {
BigDecimal factor = new BigDecimal(10).pow(8);
BigDecimal priceAsBigDecimal = new BigDecimal(altcoinPriceAsString);
return priceAsBigDecimal.multiply(factor).longValue();
};

protected final BiFunction<Double, Double, Long> calcFiatTriggerPriceAsLong = (base, delta) -> {
var priceAsDouble = new BigDecimal(base).add(new BigDecimal(delta)).doubleValue();
return Double.valueOf(exactMultiply(priceAsDouble, 10_000)).longValue();
};

protected final BiFunction<Double, Double, Long> calcAltcoinTriggerPriceAsLong = (base, delta) -> {
var priceAsDouble = new BigDecimal(base).add(new BigDecimal(delta)).doubleValue();
return Double.valueOf(exactMultiply(priceAsDouble, 100_000_000)).longValue();
};

protected final BiFunction<Double, Double, String> calcPriceAsString = (base, delta) -> {
var priceAsBigDecimal = new BigDecimal(Double.toString(base))
.add(new BigDecimal(Double.toString(delta)));
return priceAsBigDecimal.toPlainString();
};

protected final Function<OfferInfo, String> toOfferTable = (offer) ->
new TableBuilder(OFFER_TBL, offer).build().toString();

protected final Function<List<OfferInfo>, String> toOffersTable = (offers) ->
new TableBuilder(OFFER_TBL, offers).build().toString();

protected 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))
.round(mathContext);
return format("%." + precision + "f", priceAsBigDecimal.doubleValue());
}

protected OfferInfo getAvailableBsqSwapOffer(GrpcClient client,
OfferDirection direction,
boolean checkForLoggedExceptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void createBsqSwapOffer() {
var newOfferId = bsqSwapOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(BUY.name(), bsqSwapOffer.getDirection());
assertEquals(5_000, bsqSwapOffer.getPrice());
assertEquals("0.00005000", bsqSwapOffer.getPrice());
assertEquals(1_000_000L, bsqSwapOffer.getAmount());
assertEquals(1_000_000L, bsqSwapOffer.getMinAmount());
assertEquals(BSQ, bsqSwapOffer.getBaseCurrencyCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ public void testCreateBuy1BTCFor20KBSQOffer() {
getDefaultBuyerSecurityDepositAsPercent(),
alicesLegacyBsqAcct.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("Sell BSQ (Buy BTC) OFFER:\n{}", toOfferTable.apply(newOffer));
log.debug("Sell BSQ (Buy BTC) Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(100_000_000L, newOffer.getMinAmount());
assertEquals("20000.00", newOffer.getVolume());
assertEquals("20000.00", newOffer.getMinVolume());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -91,9 +93,11 @@ public void testCreateBuy1BTCFor20KBSQOffer() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(100_000_000L, newOffer.getMinAmount());
assertEquals("20000.00", newOffer.getVolume());
assertEquals("20000.00", newOffer.getMinVolume());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -113,17 +117,19 @@ public void testCreateSell1BTCFor20KBSQOffer() {
getDefaultBuyerSecurityDepositAsPercent(),
alicesLegacyBsqAcct.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("SELL 20K BSQ OFFER:\n{}", toOfferTable.apply(newOffer));
log.debug("SELL 20K BSQ Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(100_000_000L, newOffer.getMinAmount());
assertEquals("20000.00", newOffer.getVolume());
assertEquals("20000.00", newOffer.getMinVolume());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -138,9 +144,11 @@ public void testCreateSell1BTCFor20KBSQOffer() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(100_000_000L, newOffer.getAmount());
assertEquals(100_000_000L, newOffer.getMinAmount());
assertEquals("20000.00", newOffer.getVolume());
assertEquals("20000.00", newOffer.getMinVolume());
assertEquals(15_000_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -160,17 +168,19 @@ public void testCreateBuyBTCWith1To2KBSQOffer() {
getDefaultBuyerSecurityDepositAsPercent(),
alicesLegacyBsqAcct.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("BUY 1-2K BSQ OFFER:\n{}", toOfferTable.apply(newOffer));
log.debug("BUY 1-2K BSQ Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(10_000_000L, newOffer.getAmount());
assertEquals(5_000_000L, newOffer.getMinAmount());
assertEquals("2000.00", newOffer.getVolume());
assertEquals("1000.00", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -185,9 +195,11 @@ public void testCreateBuyBTCWith1To2KBSQOffer() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(10_000_000L, newOffer.getAmount());
assertEquals(5_000_000L, newOffer.getMinAmount());
assertEquals("2000.00", newOffer.getVolume());
assertEquals("1000.00", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -207,17 +219,19 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
getDefaultBuyerSecurityDepositAsPercent(),
alicesLegacyBsqAcct.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("SELL 5-10K BSQ OFFER:\n{}", toOfferTable.apply(newOffer));
log.debug("SELL 5-10K BSQ Offer:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(50_000_000L, newOffer.getAmount());
assertEquals(25_000_000L, newOffer.getMinAmount());
assertEquals("10000.00", newOffer.getVolume());
assertEquals("5000.00", newOffer.getMinVolume());
assertEquals(7_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -232,9 +246,11 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(5_000, newOffer.getPrice());
assertEquals("0.00005000", newOffer.getPrice());
assertEquals(50_000_000L, newOffer.getAmount());
assertEquals(25_000_000L, newOffer.getMinAmount());
assertEquals("10000.00", newOffer.getVolume());
assertEquals("5000.00", newOffer.getMinVolume());
assertEquals(7_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(alicesLegacyBsqAcct.getId(), newOffer.getPaymentAccountId());
assertEquals(BSQ, newOffer.getBaseCurrencyCode());
Expand All @@ -246,7 +262,7 @@ public void testCreateSellBTCFor5To10KBSQOffer() {
@Order(5)
public void testGetAllMyBsqOffers() {
List<OfferInfo> offers = aliceClient.getMyCryptoCurrencyOffersSortedByDate(BSQ);
log.debug("ALL ALICE'S BSQ OFFERS:\n{}", toOffersTable.apply(offers));
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 @@ -255,7 +271,7 @@ public void testGetAllMyBsqOffers() {
@Order(6)
public void testGetAvailableBsqOffers() {
List<OfferInfo> offers = bobClient.getCryptoCurrencyOffersSortedByDate(BSQ);
log.debug("ALL BOB'S AVAILABLE BSQ OFFERS:\n{}", toOffersTable.apply(offers));
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 @@ -58,17 +58,19 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
getDefaultBuyerSecurityDepositAsPercent(),
audAccount.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("OFFER #1:\n{}", toOfferTable.apply(newOffer));
log.debug("Offer #1:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(360_000_000, newOffer.getPrice());
assertEquals("36000.0000", newOffer.getPrice());
assertEquals(10_000_000, newOffer.getAmount());
assertEquals(10_000_000, newOffer.getMinAmount());
assertEquals("3600", newOffer.getVolume());
assertEquals("3600", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(audAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(BTC, newOffer.getBaseCurrencyCode());
Expand All @@ -81,9 +83,11 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(360_000_000, newOffer.getPrice());
assertEquals("36000.0000", newOffer.getPrice());
assertEquals(10_000_000, newOffer.getAmount());
assertEquals(10_000_000, newOffer.getMinAmount());
assertEquals("3600", newOffer.getVolume());
assertEquals("3600", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(audAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(BTC, newOffer.getBaseCurrencyCode());
Expand All @@ -103,17 +107,19 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
getDefaultBuyerSecurityDepositAsPercent(),
usdAccount.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("OFFER #2:\n{}", toOfferTable.apply(newOffer));
log.debug("Offer #2:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(300_001_234, newOffer.getPrice());
assertEquals("30000.1234", newOffer.getPrice());
assertEquals(10_000_000, newOffer.getAmount());
assertEquals(10_000_000, newOffer.getMinAmount());
assertEquals("3000", newOffer.getVolume());
assertEquals("3000", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(usdAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(BTC, newOffer.getBaseCurrencyCode());
Expand All @@ -126,9 +132,11 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(BUY.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(300_001_234, newOffer.getPrice());
assertEquals("30000.1234", newOffer.getPrice());
assertEquals(10_000_000, newOffer.getAmount());
assertEquals(10_000_000, newOffer.getMinAmount());
assertEquals("3000", newOffer.getVolume());
assertEquals("3000", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(usdAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(BTC, newOffer.getBaseCurrencyCode());
Expand All @@ -148,17 +156,19 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
getDefaultBuyerSecurityDepositAsPercent(),
eurAccount.getId(),
MAKER_FEE_CURRENCY_CODE);
log.debug("OFFER #3:\n{}", toOfferTable.apply(newOffer));
log.debug("Offer #3:\n{}", toOfferTable.apply(newOffer));
assertTrue(newOffer.getIsMyOffer());
assertTrue(newOffer.getIsMyPendingOffer());

String newOfferId = newOffer.getId();
assertNotEquals("", newOfferId);
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(295_001_234, newOffer.getPrice());
assertEquals("29500.1234", newOffer.getPrice());
assertEquals(10_000_000, newOffer.getAmount());
assertEquals(5_000_000, newOffer.getMinAmount());
assertEquals("2950", newOffer.getVolume());
assertEquals("1475", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(eurAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(BTC, newOffer.getBaseCurrencyCode());
Expand All @@ -171,9 +181,11 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
assertEquals(newOfferId, newOffer.getId());
assertEquals(SELL.name(), newOffer.getDirection());
assertFalse(newOffer.getUseMarketBasedPrice());
assertEquals(295_001_234, newOffer.getPrice());
assertEquals("29500.1234", newOffer.getPrice());
assertEquals(10_000_000, newOffer.getAmount());
assertEquals(5_000_000, newOffer.getMinAmount());
assertEquals("2950", newOffer.getVolume());
assertEquals("1475", newOffer.getMinVolume());
assertEquals(1_500_000, newOffer.getBuyerSecurityDeposit());
assertEquals(eurAccount.getId(), newOffer.getPaymentAccountId());
assertEquals(BTC, newOffer.getBaseCurrencyCode());
Expand Down
Loading