Test new api method 'getpaymentacctform'

This commit is contained in:
ghubstan 2020-11-18 16:18:57 -03:00
parent dc227ec8cc
commit fdb89a26d0
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
4 changed files with 393 additions and 14 deletions

View File

@ -17,6 +17,8 @@
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;
@ -29,6 +31,7 @@ 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;
@ -49,6 +52,12 @@ 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;
@ -252,6 +261,25 @@ public class MethodTest extends ApiTestCase {
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,

View File

@ -0,0 +1,126 @@
package bisq.apitest.method.payment;
import bisq.core.api.model.PaymentAccountForm;
import bisq.core.locale.Res;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonWriter;
import java.nio.file.Paths;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import static java.lang.String.format;
import static java.lang.System.getProperty;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import bisq.apitest.method.MethodTest;
@Slf4j
public class AbstractPaymentAccountTest extends MethodTest {
static final String PROPERTY_NAME_COMMENT = "_COMMENT_";
static final String PROPERTY_VALUE_COMMENT = "Please do not edit the paymentMethodId field.";
static final String PROPERTY_NAME_PAYMENT_METHOD_ID = "paymentMethodId";
static final String PROPERTY_NAME_ACCOUNT_NAME = "accountName";
static final String PROPERTY_NAME_ACCOUNT_NR = "accountNr";
static final String PROPERTY_NAME_ACCOUNT_TYPE = "accountType";
static final String PROPERTY_NAME_BANK_ACCOUNT_NAME = "bankAccountName";
static final String PROPERTY_NAME_BANK_ACCOUNT_NUMBER = "bankAccountNumber";
static final String PROPERTY_NAME_BANK_ACCOUNT_TYPE = "bankAccountType";
static final String PROPERTY_NAME_BANK_BRANCH_CODE = "bankBranchCode";
static final String PROPERTY_NAME_BANK_BRANCH_NAME = "bankBranchName";
static final String PROPERTY_NAME_BANK_CODE = "bankCode";
@SuppressWarnings("unused")
static final String PROPERTY_NAME_BANK_ID = "bankId";
static final String PROPERTY_NAME_BANK_NAME = "bankName";
static final String PROPERTY_NAME_BRANCH_ID = "branchId";
static final String PROPERTY_NAME_BIC = "bic";
static final String PROPERTY_NAME_COUNTRY = "country";
static final String PROPERTY_NAME_CITY = "city";
static final String PROPERTY_NAME_CONTACT = "contact";
static final String PROPERTY_NAME_EMAIL = "email";
static final String PROPERTY_NAME_EMAIL_OR_MOBILE_NR = "emailOrMobileNr";
static final String PROPERTY_NAME_EXTRA_INFO = "extraInfo";
static final String PROPERTY_NAME_HOLDER_NAME = "holderName";
static final String PROPERTY_NAME_HOLDER_TAX_ID = "holderTaxId";
static final String PROPERTY_NAME_IBAN = "iban";
static final String PROPERTY_NAME_MOBILE_NR = "mobileNr";
static final String PROPERTY_NAME_NATIONAL_ACCOUNT_ID = "nationalAccountId";
static final String PROPERTY_NAME_PAY_ID = "payid";
static final String PROPERTY_NAME_POSTAL_ADDRESS = "postalAddress";
static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.serializeNulls()
.create();
static final Map<String, Object> EXPECTED_FORM = new HashMap<>();
// A payment account serializer / deserializer.
static final PaymentAccountForm PAYMENT_ACCOUNT_FORM = new PaymentAccountForm();
@BeforeEach
public void setup() {
Res.setup();
EXPECTED_FORM.clear();
}
protected final void verifyEmptyForm(File jsonForm, String paymentMethodId, String... fields) {
@SuppressWarnings("unchecked")
Map<String, Object> emptyForm = (Map<String, Object>) GSON.fromJson(
PAYMENT_ACCOUNT_FORM.toJsonString(jsonForm),
Object.class);
assertNotNull(emptyForm);
assertEquals(PROPERTY_VALUE_COMMENT, emptyForm.get(PROPERTY_NAME_COMMENT));
assertEquals(paymentMethodId, emptyForm.get(PROPERTY_NAME_PAYMENT_METHOD_ID));
assertEquals("Your accountname", emptyForm.get(PROPERTY_NAME_ACCOUNT_NAME));
for (String field : fields) {
assertEquals("Your " + field.toLowerCase(), emptyForm.get(field));
}
}
protected final File fillPaymentAccountForm() {
File tmpJsonForm = null;
try {
tmpJsonForm = File.createTempFile("temp_acct_form_",
".json",
Paths.get(getProperty("java.io.tmpdir")).toFile());
tmpJsonForm.deleteOnExit();
JsonWriter writer = new JsonWriter(new OutputStreamWriter(new FileOutputStream(tmpJsonForm), UTF_8));
writer.beginObject();
writer.name(PROPERTY_NAME_COMMENT);
writer.value(PROPERTY_VALUE_COMMENT);
for (Map.Entry<String, Object> entry : EXPECTED_FORM.entrySet()) {
String k = entry.getKey();
Object v = entry.getValue();
writer.name(k);
writer.value(v.toString());
}
writer.endObject();
writer.close();
} catch (IOException ex) {
log.error("", ex);
fail(format("Could not write json file from form entries %s", EXPECTED_FORM));
}
return tmpJsonForm;
}
}

View File

@ -22,6 +22,8 @@ import bisq.proto.grpc.GetPaymentAccountsRequest;
import protobuf.PaymentAccount;
import protobuf.PerfectMoneyAccountPayload;
import java.io.File;
import java.util.List;
import java.util.stream.Collectors;
@ -32,26 +34,24 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestMethodOrder;
import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.core.payment.payload.PaymentMethod.*;
import static java.util.Comparator.comparing;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import bisq.apitest.method.MethodTest;
@Disabled
@Slf4j
@TestMethodOrder(OrderAnnotation.class)
public class CreatePaymentAccountTest extends MethodTest {
public class CreatePaymentAccountTest extends AbstractPaymentAccountTest {
static final String PERFECT_MONEY_ACCT_NAME = "Perfect Money USD";
static final String PERFECT_MONEY_ACCT_NUMBER = "0123456789";
// TODO Test PaymentAccountForm's PaymentAccount toPaymentAccount(File jsonForm)
// after replacement api method 'createpaymentacct' is implemented.
@BeforeAll
public static void setUp() {
@ -64,7 +64,221 @@ public class CreatePaymentAccountTest extends MethodTest {
@Test
@Order(1)
public void testCreatePerfectMoneyUSDPaymentAccount() {
public void testCreateAustraliaPayidAccount(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, AUSTRALIA_PAYID_ID);
verifyEmptyForm(emptyForm,
AUSTRALIA_PAYID_ID,
PROPERTY_NAME_BANK_ACCOUNT_NAME);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, AUSTRALIA_PAYID_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Australia Pay ID Account");
EXPECTED_FORM.put(PROPERTY_NAME_PAY_ID, "123 456 789");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_ACCOUNT_NAME, "Credit Union Australia");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testBrazilNationalBankAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, NATIONAL_BANK_ID);
verifyEmptyForm(emptyForm,
NATIONAL_BANK_ID,
PROPERTY_NAME_ACCOUNT_NR,
PROPERTY_NAME_ACCOUNT_TYPE,
PROPERTY_NAME_BANK_NAME,
PROPERTY_NAME_BRANCH_ID,
PROPERTY_NAME_COUNTRY,
PROPERTY_NAME_HOLDER_NAME,
PROPERTY_NAME_HOLDER_TAX_ID,
PROPERTY_NAME_NATIONAL_ACCOUNT_ID);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, NATIONAL_BANK_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Banco do Brasil");
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NR, "456789-87");
// No BankId is required for BR.
EXPECTED_FORM.put(PROPERTY_NAME_BANK_NAME, "Banco do Brasil");
EXPECTED_FORM.put(PROPERTY_NAME_BRANCH_ID, "456789-10");
EXPECTED_FORM.put(PROPERTY_NAME_COUNTRY, "BR");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_NAME, "Joao da Silva");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_TAX_ID, "123456789");
EXPECTED_FORM.put(PROPERTY_NAME_NATIONAL_ACCOUNT_ID, "123456789");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testChaseQuickPayAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, CHASE_QUICK_PAY_ID);
verifyEmptyForm(emptyForm,
CHASE_QUICK_PAY_ID,
PROPERTY_NAME_EMAIL,
PROPERTY_NAME_HOLDER_NAME);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, CHASE_QUICK_PAY_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Quick Pay Acct");
EXPECTED_FORM.put(PROPERTY_NAME_EMAIL, "johndoe@quickpay.com");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_NAME, "John Doe");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testClearXChangeAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, CLEAR_X_CHANGE_ID);
verifyEmptyForm(emptyForm,
CLEAR_X_CHANGE_ID,
PROPERTY_NAME_EMAIL_OR_MOBILE_NR,
PROPERTY_NAME_HOLDER_NAME);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, CLEAR_X_CHANGE_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "USD Zelle Account");
EXPECTED_FORM.put(PROPERTY_NAME_EMAIL_OR_MOBILE_NR, "jane@doe.com");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_NAME, "Jane Doe");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testF2FAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, F2F_ID);
verifyEmptyForm(emptyForm,
F2F_ID,
PROPERTY_NAME_COUNTRY,
PROPERTY_NAME_CITY,
PROPERTY_NAME_CONTACT,
PROPERTY_NAME_EXTRA_INFO);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, F2F_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Conta Cara a Cara");
EXPECTED_FORM.put(PROPERTY_NAME_COUNTRY, "BR");
EXPECTED_FORM.put(PROPERTY_NAME_CITY, "Rio de Janeiro");
EXPECTED_FORM.put(PROPERTY_NAME_CONTACT, "Freddy Beira Mar");
EXPECTED_FORM.put(PROPERTY_NAME_EXTRA_INFO, "So fim de semana");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testHalCashAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, HAL_CASH_ID);
verifyEmptyForm(emptyForm,
HAL_CASH_ID,
PROPERTY_NAME_MOBILE_NR);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, HAL_CASH_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Hal Cash Acct");
EXPECTED_FORM.put(PROPERTY_NAME_MOBILE_NR, "798 123 456");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testJapanBankAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, JAPAN_BANK_ID);
verifyEmptyForm(emptyForm,
JAPAN_BANK_ID,
PROPERTY_NAME_BANK_NAME,
PROPERTY_NAME_BANK_CODE,
PROPERTY_NAME_BANK_BRANCH_CODE,
PROPERTY_NAME_BANK_BRANCH_NAME,
PROPERTY_NAME_BANK_ACCOUNT_NAME,
PROPERTY_NAME_BANK_ACCOUNT_TYPE,
PROPERTY_NAME_BANK_ACCOUNT_NUMBER);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, JAPAN_BANK_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Fukuoka Account");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_NAME, "Bank of Kyoto");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_CODE, "FKBKJPJT");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_BRANCH_CODE, "8100-8727");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_BRANCH_NAME, "Fukuoka Branch");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_ACCOUNT_NAME, "Fukuoka Account");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_ACCOUNT_TYPE, "Yen Account");
EXPECTED_FORM.put(PROPERTY_NAME_BANK_ACCOUNT_NUMBER, "8100-8727-0000");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testSepaAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, SEPA_ID);
verifyEmptyForm(emptyForm,
SEPA_ID,
PROPERTY_NAME_COUNTRY,
PROPERTY_NAME_HOLDER_NAME,
PROPERTY_NAME_IBAN,
PROPERTY_NAME_BIC);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, SEPA_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Conta Sepa");
EXPECTED_FORM.put(PROPERTY_NAME_COUNTRY, "PT");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_NAME, "Jose da Silva");
EXPECTED_FORM.put(PROPERTY_NAME_IBAN, "909-909");
EXPECTED_FORM.put(PROPERTY_NAME_BIC, "909");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testSwishAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, SWISH_ID);
verifyEmptyForm(emptyForm,
SWISH_ID,
PROPERTY_NAME_MOBILE_NR,
PROPERTY_NAME_HOLDER_NAME);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, SWISH_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Swish Account");
EXPECTED_FORM.put(PROPERTY_NAME_MOBILE_NR, "+46 7 6060 0101");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_NAME, "Swish Account Holder");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
@Test
public void testUSPostalMoneyOrderAccountForm(TestInfo testInfo) {
File emptyForm = getEmptyForm(testInfo, US_POSTAL_MONEY_ORDER_ID);
verifyEmptyForm(emptyForm,
US_POSTAL_MONEY_ORDER_ID,
PROPERTY_NAME_HOLDER_NAME,
PROPERTY_NAME_POSTAL_ADDRESS);
EXPECTED_FORM.put(PROPERTY_NAME_PAYMENT_METHOD_ID, US_POSTAL_MONEY_ORDER_ID);
EXPECTED_FORM.put(PROPERTY_NAME_ACCOUNT_NAME, "Bubba's Acct");
EXPECTED_FORM.put(PROPERTY_NAME_HOLDER_NAME, "Bubba");
EXPECTED_FORM.put(PROPERTY_NAME_POSTAL_ADDRESS, "000 Westwood Terrace Austin, TX 78700");
File completedForm = fillPaymentAccountForm();
log.info("Completed form: {}", PAYMENT_ACCOUNT_FORM.toJsonString(completedForm));
}
private File getEmptyForm(TestInfo testInfo, String paymentMethodId) {
File emptyForm = getPaymentAccountForm(alicedaemon, paymentMethodId);
// A short cut over the API:
// File emptyForm = PAYMENT_ACCOUNT_FORM.getPaymentAccountForm(paymentMethodId);
emptyForm.deleteOnExit();
log.info("{} Empty form saved to {}", testName(testInfo), PAYMENT_ACCOUNT_FORM.getClickableURI(emptyForm));
return emptyForm;
}
@Test
@Order(2)
public void testDeprecatedCreatePerfectMoneyUSDPaymentAccount() {
String PERFECT_MONEY_ACCT_NAME = "Perfect Money USD";
String PERFECT_MONEY_ACCT_NUMBER = "0123456789";
var perfectMoneyPaymentAccountRequest = createCreatePerfectMoneyPaymentAccountRequest(
PERFECT_MONEY_ACCT_NAME,
PERFECT_MONEY_ACCT_NUMBER,

View File

@ -7,12 +7,10 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.TestMethodOrder;
import static bisq.apitest.Scaffold.BitcoinCoreApp.bitcoind;
import static bisq.apitest.config.BisqAppConfig.alicedaemon;
import static bisq.apitest.config.BisqAppConfig.arbdaemon;
import static bisq.apitest.config.BisqAppConfig.seednode;
import static org.junit.jupiter.api.Assertions.fail;
@ -28,7 +26,8 @@ public class PaymentAccountTest extends MethodTest {
@BeforeAll
public static void setUp() {
try {
setUpScaffold(bitcoind, seednode, arbdaemon, alicedaemon);
// setUpScaffold(bitcoind, seednode, arbdaemon, alicedaemon);
setUpScaffold(alicedaemon);
} catch (Exception ex) {
fail(ex);
}
@ -43,9 +42,21 @@ public class PaymentAccountTest extends MethodTest {
@Test
@Order(2)
public void testCreatePaymentAccount() {
public void testCreatePaymentAccount(TestInfo testInfo) {
CreatePaymentAccountTest test = new CreatePaymentAccountTest();
test.testCreatePerfectMoneyUSDPaymentAccount();
test.testCreateAustraliaPayidAccount(testInfo);
test.testBrazilNationalBankAccountForm(testInfo);
test.testChaseQuickPayAccountForm(testInfo);
test.testClearXChangeAccountForm(testInfo);
test.testF2FAccountForm(testInfo);
test.testHalCashAccountForm(testInfo);
test.testJapanBankAccountForm(testInfo);
test.testSepaAccountForm(testInfo);
test.testSwishAccountForm(testInfo);
test.testUSPostalMoneyOrderAccountForm(testInfo);
test.testDeprecatedCreatePerfectMoneyUSDPaymentAccount();
}
@AfterAll