From 538f8d3941d14a677e984d1784582e8ac8456c20 Mon Sep 17 00:00:00 2001 From: namloan Date: Thu, 3 Aug 2023 00:32:28 +0200 Subject: [PATCH] Unit test payment method accounts Discovered and fixed some issues along the way. The most important is the removal of HRK as supported currency in Revolut and Wise. HRK was replaced by the Euro in 2023. The presence of HRK was preventing the Revolut and Wise FiatPaymentRails enums from being properly initialized (they were throwing NullPointerException). --- account/build.gradle | 2 + .../bisq/account/accounts/RevolutAccount.java | 3 +- .../payment_method/FiatPaymentRailUtil.java | 6 +- .../accounts/AchTransferAccountTest.java | 74 ++++++++++++++++++ .../bisq/account/accounts/F2FAccountTest.java | 75 ++++++++++++++++++ .../account/accounts/RevolutAccountTest.java | 60 +++++++++++++++ .../account/accounts/SepaAccountTest.java | 77 +++++++++++++++++++ .../accounts/UserDefinedFiatAccountTest.java | 60 +++++++++++++++ .../main/java/bisq/common/locale/Country.java | 2 +- .../main/java/bisq/common/locale/Region.java | 2 +- 10 files changed, 354 insertions(+), 7 deletions(-) create mode 100644 account/src/test/java/bisq/account/accounts/AchTransferAccountTest.java create mode 100644 account/src/test/java/bisq/account/accounts/F2FAccountTest.java create mode 100644 account/src/test/java/bisq/account/accounts/RevolutAccountTest.java create mode 100644 account/src/test/java/bisq/account/accounts/SepaAccountTest.java create mode 100644 account/src/test/java/bisq/account/accounts/UserDefinedFiatAccountTest.java diff --git a/account/build.gradle b/account/build.gradle index f08400bd79..58b587313c 100644 --- a/account/build.gradle +++ b/account/build.gradle @@ -11,4 +11,6 @@ dependencies { implementation 'network:network' implementation libs.google.guava + + testImplementation libs.assertj.core } diff --git a/account/src/main/java/bisq/account/accounts/RevolutAccount.java b/account/src/main/java/bisq/account/accounts/RevolutAccount.java index b9fb17a867..1fd36a43c1 100644 --- a/account/src/main/java/bisq/account/accounts/RevolutAccount.java +++ b/account/src/main/java/bisq/account/accounts/RevolutAccount.java @@ -42,7 +42,8 @@ private RevolutAccount(String accountName, RevolutAccountPayload revolutAccountP @Override public bisq.account.protobuf.Account toProto() { - return getAccountBuilder().setRevolutAccount(bisq.account.protobuf.RevolutAccount.newBuilder()).build(); + return getAccountBuilder() + .setRevolutAccount(bisq.account.protobuf.RevolutAccount.newBuilder()).build(); } public static RevolutAccount fromProto(bisq.account.protobuf.Account proto) { diff --git a/account/src/main/java/bisq/account/payment_method/FiatPaymentRailUtil.java b/account/src/main/java/bisq/account/payment_method/FiatPaymentRailUtil.java index 9d2f339062..035b26f652 100644 --- a/account/src/main/java/bisq/account/payment_method/FiatPaymentRailUtil.java +++ b/account/src/main/java/bisq/account/payment_method/FiatPaymentRailUtil.java @@ -79,7 +79,7 @@ static List toTradeCurrencies(List currencyCodes) { .collect(Collectors.toList()); } - // https://wise.com/help/articles/2571942/what-countriesregions-can-i-send-to + // https://wise.com/help/articles/2571907/what-currencies-can-i-send-to-and-from?origin=related-article-2571942 // https://github.com/bisq-network/proposals/issues/243 static List getWiseCountries() { List list = new ArrayList<>(List.of("AR", "AU", "BD", "BR", "BG", "CA", "CL", "CN", "CO", "CR", "CZ", "DK", "EG", @@ -106,7 +106,6 @@ static List getWiseCurrencies() { "GBP", "GEL", "HKD", - "HRK", "HUF", "IDR", "ILS", @@ -137,7 +136,7 @@ static List getWiseCurrencies() { ); } - // https://www.revolut.com/help/getting-started/exchanging-currencies/what-fiat-currencies-are-supported-for-holding-and-exchange + // https://help.revolut.com/help/wealth/exchanging-money/what-currencies-are-available/what-currencies-are-supported-for-holding-and-exchange/ static List getRevolutCountries() { return List.of("AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "GR", "HU", "IS", "IE", "IT", "LV", "LI", "LT", "LU", "MT", "NL", @@ -157,7 +156,6 @@ static List getRevolutCurrencies() { "EUR", "GBP", "HKD", - "HRK", "HUF", "ILS", "ISK", diff --git a/account/src/test/java/bisq/account/accounts/AchTransferAccountTest.java b/account/src/test/java/bisq/account/accounts/AchTransferAccountTest.java new file mode 100644 index 0000000000..c0846dd02d --- /dev/null +++ b/account/src/test/java/bisq/account/accounts/AchTransferAccountTest.java @@ -0,0 +1,74 @@ +package bisq.account.accounts; + +import bisq.account.protobuf.Account; +import bisq.account.protobuf.AccountPayload; +import bisq.account.protobuf.BankAccount; +import bisq.account.protobuf.BankAccountPayload; +import bisq.account.protobuf.CountryBasedAccount; +import bisq.account.protobuf.CountryBasedAccountPayload; +import bisq.account.protobuf.FiatPaymentMethod; +import bisq.account.protobuf.PaymentMethod; +import bisq.common.protobuf.Country; +import bisq.common.protobuf.Region; +import org.junit.jupiter.api.Test; + +import static java.lang.System.currentTimeMillis; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Offset.offset; + +class AchTransferAccountTest { + + private static final Account PROTO = Account.newBuilder() + .setAccountName("accountName") + .setCreationDate(123) + .setPaymentMethod(PaymentMethod.newBuilder() + .setName("ACH_TRANSFER") + .setFiatPaymentMethod(FiatPaymentMethod.newBuilder())) + .setAccountPayload(AccountPayload.newBuilder() + .setId("id") + .setPaymentMethodName("ACH_TRANSFER") + .setCountryBasedAccountPayload(CountryBasedAccountPayload.newBuilder() + .setCountryCode("countryCode") + .setBankAccountPayload(BankAccountPayload.newBuilder() + .setBankName("bankName") + .setAchTransferAccountPayload( + bisq.account.protobuf.AchTransferAccountPayload.newBuilder()))) + ) + .setCountryBasedAccount(CountryBasedAccount.newBuilder() + .setCountry(Country.newBuilder() + .setCode("countryCode") + .setName("countryName") + .setRegion(Region.newBuilder() + .setCode("regionCode") + .setName("regionName"))) + .setBankAccount(BankAccount.newBuilder() + .setAchTransferAccount(bisq.account.protobuf.AchTransferAccount.newBuilder()))) + .build(); + + private static final AchTransferAccount ACCOUNT = new AchTransferAccount( + "accountName", + new AchTransferAccountPayload("id", "ACH_TRANSFER", "countryCode", null, "bankName", null, null, null, null), + new bisq.common.locale.Country( + "countryCode", + "countryName", + new bisq.common.locale.Region("regionCode", "regionName"))); + + @Test + void toProto() { + var result = ACCOUNT.toProto(); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate_", "memoizedHashCode") + .isEqualTo(PROTO); + } + + @Test + void fromProto() { + var result = AchTransferAccount.fromProto(PROTO); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate") + .isEqualTo(ACCOUNT); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + } +} diff --git a/account/src/test/java/bisq/account/accounts/F2FAccountTest.java b/account/src/test/java/bisq/account/accounts/F2FAccountTest.java new file mode 100644 index 0000000000..18207cfc0a --- /dev/null +++ b/account/src/test/java/bisq/account/accounts/F2FAccountTest.java @@ -0,0 +1,75 @@ +package bisq.account.accounts; + +import bisq.account.protobuf.Account; +import bisq.account.protobuf.AccountPayload; +import bisq.account.protobuf.CountryBasedAccount; +import bisq.account.protobuf.CountryBasedAccountPayload; +import bisq.account.protobuf.F2FAccount; +import bisq.account.protobuf.F2FAccountPayload; +import bisq.account.protobuf.FiatPaymentMethod; +import bisq.account.protobuf.PaymentMethod; +import bisq.common.protobuf.Country; +import bisq.common.protobuf.Region; +import org.junit.jupiter.api.Test; + +import static java.lang.System.currentTimeMillis; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Offset.offset; + +class F2FAccountTest { + + private static final Account PROTO = Account.newBuilder() + .setAccountName("accountName") + .setCreationDate(123) + .setPaymentMethod(PaymentMethod.newBuilder() + .setName("F2F") + .setFiatPaymentMethod(FiatPaymentMethod.newBuilder().build()) + .build()) + .setAccountPayload(AccountPayload.newBuilder() + .setId("id") + .setPaymentMethodName("F2F") + .setCountryBasedAccountPayload(CountryBasedAccountPayload.newBuilder() + .setCountryCode("countryCode") + .setF2FAccountPayload(F2FAccountPayload.newBuilder() + .setCity("city") + .setContact("contact") + .setExtraInfo("extraInfo"))) + ) + .setCountryBasedAccount(CountryBasedAccount.newBuilder() + .setCountry(Country.newBuilder() + .setCode("countryCode") + .setName("countryName") + .setRegion(Region.newBuilder() + .setCode("regionCode") + .setName("regionName"))) + .setF2FAccount(F2FAccount.newBuilder()) + ) + .build(); + + private static final bisq.account.accounts.F2FAccount ACCOUNT = new bisq.account.accounts.F2FAccount( + "accountName", + new bisq.account.accounts.F2FAccountPayload("id", "F2F", "countryCode", "city", "contact", "extraInfo"), + new bisq.common.locale.Country( + "countryCode", + "countryName", + new bisq.common.locale.Region("regionCode", "regionName"))); + + @Test + void toProto() { + var result = ACCOUNT.toProto(); + assertThat(result).usingRecursiveComparison() + .ignoringFields("accountPayload_.memoizedHashCode", "memoizedHashCode", "creationDate_") + .isEqualTo(PROTO); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + } + + @Test + void fromProto() { + var result = bisq.account.accounts.F2FAccount.fromProto(PROTO); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate") + .isEqualTo(ACCOUNT); + assertThat(result.getCreationDate()).isCloseTo(System.currentTimeMillis(), offset(1000L)); + } +} diff --git a/account/src/test/java/bisq/account/accounts/RevolutAccountTest.java b/account/src/test/java/bisq/account/accounts/RevolutAccountTest.java new file mode 100644 index 0000000000..302fd8bbb7 --- /dev/null +++ b/account/src/test/java/bisq/account/accounts/RevolutAccountTest.java @@ -0,0 +1,60 @@ +package bisq.account.accounts; + +import bisq.account.protobuf.Account; +import bisq.account.protobuf.AccountPayload; +import bisq.account.protobuf.FiatPaymentMethod; +import bisq.account.protobuf.PaymentMethod; +import bisq.account.protobuf.RevolutAccount; +import bisq.account.protobuf.RevolutAccountPayload; +import org.junit.jupiter.api.Test; + +import static java.lang.System.currentTimeMillis; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Offset.offset; + +class RevolutAccountTest { + + private static final Account PROTO = Account.newBuilder() + .setAccountName("accountName") + .setCreationDate(123) + .setPaymentMethod( + PaymentMethod.newBuilder() + .setName("REVOLUT") + .setFiatPaymentMethod( + FiatPaymentMethod.newBuilder().build()) + .build()) + .setRevolutAccount(RevolutAccount.newBuilder()) + .setAccountPayload(AccountPayload.newBuilder() + .setId("id") + .setPaymentMethodName("REVOLUT") + .setRevolutAccountPayload(RevolutAccountPayload.newBuilder() + .setEmail("email") + .build()) + .build()) + .build(); + + private static final bisq.account.accounts.RevolutAccount ACCOUNT = new bisq.account.accounts.RevolutAccount( + "accountName", "email"); + + @Test + void toProto() { + var result = ACCOUNT.toProto(); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("accountPayload_.id_", "accountPayload_.memoizedHashCode", "creationDate_", "memoizedHashCode") + .isEqualTo(PROTO); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + assertThat(result.getAccountPayload().getId()).isNotEmpty(); + } + + @Test + void fromProto() { + var result = bisq.account.accounts.RevolutAccount.fromProto(PROTO); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate", "accountPayload.id") + .isEqualTo(ACCOUNT); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + assertThat(result.getAccountPayload().getId()).isNotEmpty(); + } +} \ No newline at end of file diff --git a/account/src/test/java/bisq/account/accounts/SepaAccountTest.java b/account/src/test/java/bisq/account/accounts/SepaAccountTest.java new file mode 100644 index 0000000000..a0814fdc96 --- /dev/null +++ b/account/src/test/java/bisq/account/accounts/SepaAccountTest.java @@ -0,0 +1,77 @@ +package bisq.account.accounts; + +import bisq.account.protobuf.AccountPayload; +import bisq.account.protobuf.CountryBasedAccount; +import bisq.account.protobuf.CountryBasedAccountPayload; +import bisq.account.protobuf.FiatPaymentMethod; +import bisq.account.protobuf.PaymentMethod; +import bisq.account.protobuf.SepaAccount; +import bisq.account.protobuf.SepaAccountPayload; +import bisq.common.protobuf.Country; +import bisq.common.protobuf.Region; +import org.junit.jupiter.api.Test; + +import static java.lang.System.currentTimeMillis; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Offset.offset; + +class SepaAccountTest { + + private static final bisq.account.protobuf.Account PROTO = bisq.account.protobuf.Account.newBuilder() + .setAccountName("accountName") + .setCreationDate(123) + .setPaymentMethod(PaymentMethod.newBuilder() + .setName("SEPA") + .setFiatPaymentMethod(FiatPaymentMethod.newBuilder())) + .setAccountPayload(AccountPayload.newBuilder() + .setId("id") + .setPaymentMethodName("SEPA") + .setCountryBasedAccountPayload(CountryBasedAccountPayload.newBuilder() + .setCountryCode("countryCode") + .setSepaAccountPayload(SepaAccountPayload.newBuilder() + .setHolderName("holderName") + .setIban("iban") + .setBic("bic") + ))) + .setCountryBasedAccount(CountryBasedAccount.newBuilder() + .setCountry(Country.newBuilder() + .setCode("countryCode") + .setName("countryName") + .setRegion(Region.newBuilder() + .setCode("regionCode") + .setName("regionName"))) + .setSepaAccount(SepaAccount.newBuilder())) + .build(); + + private static final bisq.account.accounts.SepaAccount ACCOUNT = new bisq.account.accounts.SepaAccount( + "accountName", + "holderName", + "iban", + "bic", + new bisq.common.locale.Country( + "countryCode", + "countryName", + new bisq.common.locale.Region("regionCode", "regionName"))); + + @Test + void toProto() { + var result = ACCOUNT.toProto(); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate_", "accountPayload_.id_", "memoizedHashCode", "accountPayload_.memoizedHashCode") + .isEqualTo(PROTO); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + assertThat(result.getAccountPayload().getId()).isNotEmpty(); + } + + @Test + void fromProto() { + var result = bisq.account.accounts.SepaAccount.fromProto(PROTO); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate", "accountPayload.id") + .isEqualTo(ACCOUNT); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + assertThat(result.getAccountPayload().getId()).isNotEmpty(); + } +} diff --git a/account/src/test/java/bisq/account/accounts/UserDefinedFiatAccountTest.java b/account/src/test/java/bisq/account/accounts/UserDefinedFiatAccountTest.java new file mode 100644 index 0000000000..7822e88e64 --- /dev/null +++ b/account/src/test/java/bisq/account/accounts/UserDefinedFiatAccountTest.java @@ -0,0 +1,60 @@ +package bisq.account.accounts; + +import bisq.account.protobuf.Account; +import bisq.account.protobuf.AccountPayload; +import bisq.account.protobuf.FiatPaymentMethod; +import bisq.account.protobuf.PaymentMethod; +import bisq.account.protobuf.UserDefinedFiatAccount; +import bisq.account.protobuf.UserDefinedFiatAccountPayload; +import org.junit.jupiter.api.Test; + +import static java.lang.System.currentTimeMillis; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Offset.offset; + +class UserDefinedFiatAccountTest { + + private static final bisq.account.protobuf.Account PROTO = Account.newBuilder() + .setAccountName("accountName") + .setCreationDate(123) + .setPaymentMethod( + PaymentMethod.newBuilder() + .setName("accountName") + .setFiatPaymentMethod( + FiatPaymentMethod.newBuilder().build()) + .build()) + .setAccountPayload(AccountPayload.newBuilder() + .setId("id") + .setPaymentMethodName("accountName") + .setUserDefinedFiatAccountPayload(UserDefinedFiatAccountPayload.newBuilder() + .setAccountData("customData") + .build()) + .build()) + .setUserDefinedFiatAccount(UserDefinedFiatAccount.newBuilder().build()) + .build(); + + private static final bisq.account.accounts.UserDefinedFiatAccount ACCOUNT = new bisq.account.accounts.UserDefinedFiatAccount( + "accountName", "customData"); + + @Test + void toProto() { + var result = ACCOUNT.toProto(); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("accountPayload_.id_", "accountPayload_.memoizedHashCode", "creationDate_", "memoizedHashCode") + .isEqualTo(PROTO); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + assertThat(result.getAccountPayload().getId()).isNotEmpty(); + } + + @Test + void fromProto() { + var result = bisq.account.accounts.UserDefinedFiatAccount.fromProto(PROTO); + assertThat(result) + .usingRecursiveComparison() + .ignoringFields("creationDate", "accountPayload.id") + .isEqualTo(ACCOUNT); + assertThat(result.getCreationDate()).isCloseTo(currentTimeMillis(), offset(1000L)); + assertThat(result.getAccountPayload().getId()).isNotEmpty(); + } +} \ No newline at end of file diff --git a/common/src/main/java/bisq/common/locale/Country.java b/common/src/main/java/bisq/common/locale/Country.java index 62667f95af..94b3be5930 100644 --- a/common/src/main/java/bisq/common/locale/Country.java +++ b/common/src/main/java/bisq/common/locale/Country.java @@ -44,7 +44,7 @@ public Country(String code, String name, Region region) { public bisq.common.protobuf.Country toProto() { return bisq.common.protobuf.Country.newBuilder() .setCode(code) - .setCode(name) + .setName(name) .setRegion(region.toProto()) .build(); } diff --git a/common/src/main/java/bisq/common/locale/Region.java b/common/src/main/java/bisq/common/locale/Region.java index 385be9277b..e3c09c1721 100644 --- a/common/src/main/java/bisq/common/locale/Region.java +++ b/common/src/main/java/bisq/common/locale/Region.java @@ -37,7 +37,7 @@ public Region(String code, String name) { public bisq.common.protobuf.Region toProto() { return bisq.common.protobuf.Region.newBuilder() .setCode(code) - .setCode(name) + .setName(name) .build(); }