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

Refactor getbalance api #4808

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fc8af8c
Define new grpc bsq/btc balances protos
ghubstan Nov 13, 2020
faf45ec
Add proto wrappers for serving bsq, btc or all balances
ghubstan Nov 13, 2020
4c03b46
Define proto for api method 'getunusedbsqaddress'
ghubstan Nov 13, 2020
3e98910
Define proto fapi method 'sendbsq'
ghubstan Nov 13, 2020
9f033ee
Add proto fields to support trade fee currency choice
ghubstan Nov 13, 2020
c1c099c
Implement and test api method 'getunusedbsqaddress'
ghubstan Nov 13, 2020
7c2068e
Add teardown to test case
ghubstan Nov 13, 2020
8dc1a74
Remove trailing spaces in blank line
ghubstan Nov 13, 2020
208a37b
Implement and test new getbalance(s) api methods
ghubstan Nov 13, 2020
7f0f949
Resolve unnecessary use of fully qualified name for codacy
ghubstan Nov 13, 2020
0d3b3a6
Stub out api method 'sendbsq' in core
ghubstan Nov 13, 2020
dc3274f
Re comment sendbsq tests so travis ci does not fail
ghubstan Nov 13, 2020
446bd32
Refactor desktop's BsqSendView, share with api
ghubstan Nov 13, 2020
4a90b40
Resolve 'Avoid creating BigDecimal with a decimal' issue for codacy
ghubstan Nov 13, 2020
722460e
Support paying trade fees in bsq or btc (api)
ghubstan Nov 13, 2020
8157f8f
Delete deprecated api test, adjust api build/run doc
ghubstan Nov 13, 2020
7e9ab22
Refactor api getbalance methods.
ghubstan Nov 14, 2020
187a85f
Fix typo
ghubstan Nov 14, 2020
34efc04
Remove unnecessary fully qualified name
ghubstan Nov 14, 2020
530a9f9
Remove unused imports
ghubstan Nov 14, 2020
33bd215
Resolve BsqSendView file conflict
ghubstan Nov 26, 2020
3cc9419
Merge branch 'master' into 12-refactor-balances-api
ghubstan Nov 26, 2020
fc7aef6
Adjust to changed CoinUtil
ghubstan Nov 26, 2020
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
2 changes: 1 addition & 1 deletion apitest/docs/build-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ To run all test cases in a package:

To run a single test case:

$ ./gradlew :apitest:test --tests "bisq.apitest.method.GetBalanceTest" -DrunApiTests=true
$ ./gradlew :apitest:test --tests "bisq.apitest.scenario.WalletTest" -DrunApiTests=true

To run test cases from Intellij, add two JVM arguments to your JUnit launchers:

Expand Down
73 changes: 0 additions & 73 deletions apitest/src/test/java/bisq/apitest/method/GetBalanceTest.java

This file was deleted.

59 changes: 52 additions & 7 deletions apitest/src/test/java/bisq/apitest/method/MethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@

package bisq.apitest.method;

import bisq.proto.grpc.AddressBalanceInfo;
import bisq.proto.grpc.BalancesInfo;
import bisq.proto.grpc.BsqBalanceInfo;
import bisq.proto.grpc.BtcBalanceInfo;
import bisq.proto.grpc.CancelOfferRequest;
import bisq.proto.grpc.ConfirmPaymentReceivedRequest;
import bisq.proto.grpc.ConfirmPaymentStartedRequest;
import bisq.proto.grpc.CreatePaymentAccountRequest;
import bisq.proto.grpc.GetBalanceRequest;
import bisq.proto.grpc.GetAddressBalanceRequest;
import bisq.proto.grpc.GetBalancesRequest;
import bisq.proto.grpc.GetFundingAddressesRequest;
import bisq.proto.grpc.GetOfferRequest;
import bisq.proto.grpc.GetPaymentAccountsRequest;
import bisq.proto.grpc.GetTradeRequest;
import bisq.proto.grpc.GetUnusedBsqAddressRequest;
import bisq.proto.grpc.KeepFundsRequest;
import bisq.proto.grpc.LockWalletRequest;
import bisq.proto.grpc.MarketPriceRequest;
import bisq.proto.grpc.OfferInfo;
import bisq.proto.grpc.RegisterDisputeAgentRequest;
import bisq.proto.grpc.RemoveWalletPasswordRequest;
import bisq.proto.grpc.SendBsqRequest;
import bisq.proto.grpc.SetWalletPasswordRequest;
import bisq.proto.grpc.TakeOfferRequest;
import bisq.proto.grpc.TradeInfo;
Expand Down Expand Up @@ -102,9 +109,12 @@ public static void startSupportingApps(boolean registerDisputeAgents,
}

// Convenience methods for building gRPC request objects
protected final GetBalancesRequest createGetBalancesRequest(String currencyCode) {
return GetBalancesRequest.newBuilder().setCurrencyCode(currencyCode).build();
}

protected final GetBalanceRequest createBalanceRequest() {
return GetBalanceRequest.newBuilder().build();
protected final GetAddressBalanceRequest createGetAddressBalanceRequest(String address) {
return GetAddressBalanceRequest.newBuilder().setAddress(address).build();
}

protected final SetWalletPasswordRequest createSetWalletPasswordRequest(String password) {
Expand All @@ -127,6 +137,14 @@ protected final LockWalletRequest createLockWalletRequest() {
return LockWalletRequest.newBuilder().build();
}

protected final GetUnusedBsqAddressRequest createGetUnusedBsqAddressRequest() {
return GetUnusedBsqAddressRequest.newBuilder().build();
}

protected final SendBsqRequest createSendBsqRequest(String address, double amount) {
return SendBsqRequest.newBuilder().setAddress(address).setAmount(amount).build();
}

protected final GetFundingAddressesRequest createGetFundingAddressesRequest() {
return GetFundingAddressesRequest.newBuilder().build();
}
Expand All @@ -143,8 +161,14 @@ protected final CancelOfferRequest createCancelOfferRequest(String offerId) {
return CancelOfferRequest.newBuilder().setId(offerId).build();
}

protected final TakeOfferRequest createTakeOfferRequest(String offerId, String paymentAccountId) {
return TakeOfferRequest.newBuilder().setOfferId(offerId).setPaymentAccountId(paymentAccountId).build();
protected final TakeOfferRequest createTakeOfferRequest(String offerId,
String paymentAccountId,
String takerFeeCurrencyCode) {
return TakeOfferRequest.newBuilder()
.setOfferId(offerId)
.setPaymentAccountId(paymentAccountId)
.setTakerFeeCurrencyCode(takerFeeCurrencyCode)
.build();
}

protected final GetTradeRequest createGetTradeRequest(String tradeId) {
Expand Down Expand Up @@ -173,9 +197,21 @@ protected final WithdrawFundsRequest createWithdrawFundsRequest(String tradeId,
}

// Convenience methods for calling frequently used & thoroughly tested gRPC services.
protected final BalancesInfo getBalances(BisqAppConfig bisqAppConfig, String currencyCode) {
return grpcStubs(bisqAppConfig).walletsService.getBalances(
createGetBalancesRequest(currencyCode)).getBalances();
}

protected final BsqBalanceInfo getBsqBalances(BisqAppConfig bisqAppConfig) {
return getBalances(bisqAppConfig, "bsq").getBsq();
}

protected final BtcBalanceInfo getBtcBalances(BisqAppConfig bisqAppConfig) {
return getBalances(bisqAppConfig, "btc").getBtc();
}

protected final long getBalance(BisqAppConfig bisqAppConfig) {
return grpcStubs(bisqAppConfig).walletsService.getBalance(createBalanceRequest()).getBalance();
protected final AddressBalanceInfo getAddressBalance(BisqAppConfig bisqAppConfig, String address) {
return grpcStubs(bisqAppConfig).walletsService.getAddressBalance(createGetAddressBalanceRequest(address)).getAddressBalanceInfo();
}

protected final void unlockWallet(BisqAppConfig bisqAppConfig, String password, long timeout) {
Expand All @@ -188,6 +224,15 @@ protected final void lockWallet(BisqAppConfig bisqAppConfig) {
grpcStubs(bisqAppConfig).walletsService.lockWallet(createLockWalletRequest());
}

protected final String getUnusedBsqAddress(BisqAppConfig bisqAppConfig) {
return grpcStubs(bisqAppConfig).walletsService.getUnusedBsqAddress(createGetUnusedBsqAddressRequest()).getAddress();
}

protected final void sendBsq(BisqAppConfig bisqAppConfig, String address, double amount) {
//noinspection ResultOfMethodCallIgnored
grpcStubs(bisqAppConfig).walletsService.sendBsq(createSendBsqRequest(address, amount));
}

protected final String getUnusedBtcAddress(BisqAppConfig bisqAppConfig) {
//noinspection OptionalGetWithoutIsPresent
return grpcStubs(bisqAppConfig).walletsService.getFundingAddresses(createGetFundingAddressesRequest())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,35 @@ public static void setUp() {
protected final OfferInfo createAliceOffer(PaymentAccount paymentAccount,
String direction,
String currencyCode,
long amount) {
return createMarketBasedPricedOffer(aliceStubs, paymentAccount, direction, currencyCode, amount);
long amount,
String makerFeeCurrencyCode) {
return createMarketBasedPricedOffer(aliceStubs,
paymentAccount,
direction,
currencyCode,
amount,
makerFeeCurrencyCode);
}

protected final OfferInfo createBobOffer(PaymentAccount paymentAccount,
String direction,
String currencyCode,
long amount) {
return createMarketBasedPricedOffer(bobStubs, paymentAccount, direction, currencyCode, amount);
long amount,
String makerFeeCurrencyCode) {
return createMarketBasedPricedOffer(bobStubs,
paymentAccount,
direction,
currencyCode,
amount,
makerFeeCurrencyCode);
}

protected final OfferInfo createMarketBasedPricedOffer(GrpcStubs grpcStubs,
PaymentAccount paymentAccount,
String direction,
String currencyCode,
long amount) {
long amount,
String makerFeeCurrencyCode) {
var req = CreateOfferRequest.newBuilder()
.setPaymentAccountId(paymentAccount.getId())
.setDirection(direction)
Expand All @@ -99,6 +112,7 @@ protected final OfferInfo createMarketBasedPricedOffer(GrpcStubs grpcStubs,
.setMarketPriceMargin(0.00)
.setPrice("0")
.setBuyerSecurityDeposit(getDefaultBuyerSecurityDepositAsPercent())
.setMakerFeeCurrencyCode(makerFeeCurrencyCode)
.build();
return grpcStubs.offersService.createOffer(req).getOffer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void testCancelOffer() {
.setMarketPriceMargin(0.00)
.setPrice("0")
.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent())
.setMakerFeeCurrencyCode("bsq")
.build();

// Create some offers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class CreateOfferUsingFixedPriceTest extends AbstractOfferTest {

private static final String MAKER_FEE_CURRENCY_CODE = "bsq";

@Test
@Order(1)
public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
Expand All @@ -51,6 +53,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
.setMarketPriceMargin(0.00)
.setPrice("16000")
.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent())
.setMakerFeeCurrencyCode(MAKER_FEE_CURRENCY_CODE)
.build();
var newOffer = aliceStubs.offersService.createOffer(req).getOffer();
String newOfferId = newOffer.getId();
Expand All @@ -64,6 +67,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("AUD", newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());

newOffer = getOffer(newOfferId);
assertEquals(newOfferId, newOffer.getId());
Expand All @@ -76,6 +80,7 @@ public void testCreateAUDBTCBuyOfferUsingFixedPrice16000() {
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("AUD", newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());
}

@Test
Expand All @@ -91,6 +96,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
.setMarketPriceMargin(0.00)
.setPrice("10000.1234")
.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent())
.setMakerFeeCurrencyCode(MAKER_FEE_CURRENCY_CODE)
.build();
var newOffer = aliceStubs.offersService.createOffer(req).getOffer();
String newOfferId = newOffer.getId();
Expand All @@ -104,6 +110,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("USD", newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());

newOffer = getOffer(newOfferId);
assertEquals(newOfferId, newOffer.getId());
Expand All @@ -116,6 +123,7 @@ public void testCreateUSDBTCBuyOfferUsingFixedPrice100001234() {
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("USD", newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());
}

@Test
Expand All @@ -131,6 +139,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
.setMarketPriceMargin(0.00)
.setPrice("9500.1234")
.setBuyerSecurityDeposit(Restrictions.getDefaultBuyerSecurityDepositAsPercent())
.setMakerFeeCurrencyCode(MAKER_FEE_CURRENCY_CODE)
.build();
var newOffer = aliceStubs.offersService.createOffer(req).getOffer();
String newOfferId = newOffer.getId();
Expand All @@ -144,6 +153,7 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("EUR", newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());

newOffer = getOffer(newOfferId);
assertEquals(newOfferId, newOffer.getId());
Expand All @@ -156,5 +166,6 @@ public void testCreateEURBTCSellOfferUsingFixedPrice95001234() {
assertEquals(alicesDummyAcct.getId(), newOffer.getPaymentAccountId());
assertEquals("BTC", newOffer.getBaseCurrencyCode());
assertEquals("EUR", newOffer.getCounterCurrencyCode());
assertFalse(newOffer.getIsCurrencyForMakerFeeBtc());
}
}
Loading