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

Add api method 'getpaymentacctform' #4819

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 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
ec38152
Add api method 'getpaymentmethods'
ghubstan Nov 18, 2020
a465261
Avoid codacy issue over use of fully qualified name
ghubstan Nov 18, 2020
0046b08
Revert "Avoid codacy issue over use of fully qualified name"
ghubstan Nov 18, 2020
7a7d5ba
Print the payment method id (only)
ghubstan Nov 18, 2020
0e0af20
Avoid codacy issue over use of fully qualified name
ghubstan Nov 18, 2020
7d0648a
Make codacy happy again
ghubstan Nov 18, 2020
32ed7ac
Add ReflectionUtils to common.util pkg
ghubstan Nov 18, 2020
c25deba
Add new (gson) PaymentAccountTypeAdapter to core.api.model
ghubstan Nov 18, 2020
1f84ad0
Add isCountryBasedPaymentAccount to abstract PaymentAccount
ghubstan Nov 18, 2020
32dd727
Add new PaymentAccountForm to core.api.model
ghubstan Nov 18, 2020
8996fa1
Add boilerplate for new 'getpaymentacctform' api method
ghubstan Nov 18, 2020
dc227ec
Add new api method 'getpaymentacctform' to CLI
ghubstan Nov 18, 2020
fdb89a2
Test new api method 'getpaymentacctform'
ghubstan Nov 18, 2020
35c1c4e
Ensure EXPECTED_FORM.clear() is never skipped
ghubstan Nov 18, 2020
74fb5c0
Resolve BsqSendView file conflict
ghubstan Nov 26, 2020
4e9bb08
Merge branch 'master' into 14-getpaymentacctform
ghubstan Nov 26, 2020
ac2a0ee
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

This file was deleted.

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

This file was deleted.

95 changes: 88 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,29 +17,48 @@

package bisq.apitest.method;

import bisq.core.api.model.PaymentAccountForm;

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.GetPaymentAccountFormRequest;
import bisq.proto.grpc.GetPaymentAccountsRequest;
import bisq.proto.grpc.GetPaymentMethodsRequest;
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;
import bisq.proto.grpc.UnlockWalletRequest;
import bisq.proto.grpc.WithdrawFundsRequest;

import protobuf.PaymentAccount;
import protobuf.PaymentMethod;

import java.nio.charset.StandardCharsets;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import java.util.List;
import java.util.stream.Collectors;

import static bisq.apitest.config.BisqAppConfig.alicedaemon;
Expand Down Expand Up @@ -102,9 +121,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 +149,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 +173,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 +209,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 long getBalance(BisqAppConfig bisqAppConfig) {
return grpcStubs(bisqAppConfig).walletsService.getBalance(createBalanceRequest()).getBalance();
protected final BsqBalanceInfo getBsqBalances(BisqAppConfig bisqAppConfig) {
return getBalances(bisqAppConfig, "bsq").getBsq();
}

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

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 +236,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 All @@ -199,6 +256,30 @@ protected final String getUnusedBtcAddress(BisqAppConfig bisqAppConfig) {
.getAddress();
}

protected final List<PaymentMethod> getPaymentMethods(BisqAppConfig bisqAppConfig) {
var req = GetPaymentMethodsRequest.newBuilder().build();
return grpcStubs(bisqAppConfig).paymentAccountsService.getPaymentMethods(req).getPaymentMethodsList();
}

protected final File getPaymentAccountForm(BisqAppConfig bisqAppConfig, String paymentMethodId) {
// We take seemingly unnecessary steps to get a File object, but the point is to
// test the API, and we do not directly ask bisq.core.api.model.PaymentAccountForm
// for an empty json form (file).
var req = GetPaymentAccountFormRequest.newBuilder()
.setPaymentMethodId(paymentMethodId)
.build();
String jsonString = grpcStubs(bisqAppConfig).paymentAccountsService.getPaymentAccountForm(req)
.getPaymentAccountFormJson();
// Write the json string to a file here in the test case.
File jsonFile = PaymentAccountForm.getTmpJsonFile(paymentMethodId);
try (PrintWriter out = new PrintWriter(jsonFile, StandardCharsets.UTF_8)) {
out.println(jsonString);
} catch (IOException ex) {
fail("Could not create tmp payment account form.", ex);
}
return jsonFile;
}

protected final CreatePaymentAccountRequest createCreatePerfectMoneyPaymentAccountRequest(
String accountName,
String accountNumber,
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
Loading