Skip to content

Commit

Permalink
Unit test payment method accounts
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
namloan committed Aug 2, 2023
1 parent 10c085a commit 538f8d3
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 7 deletions.
2 changes: 2 additions & 0 deletions account/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ dependencies {

implementation 'network:network'
implementation libs.google.guava

testImplementation libs.assertj.core
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static List<TradeCurrency> toTradeCurrencies(List<String> 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<String> getWiseCountries() {
List<String> list = new ArrayList<>(List.of("AR", "AU", "BD", "BR", "BG", "CA", "CL", "CN", "CO", "CR", "CZ", "DK", "EG",
Expand All @@ -106,7 +106,6 @@ static List<String> getWiseCurrencies() {
"GBP",
"GEL",
"HKD",
"HRK",
"HUF",
"IDR",
"ILS",
Expand Down Expand Up @@ -137,7 +136,7 @@ static List<String> 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<String> 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",
Expand All @@ -157,7 +156,6 @@ static List<String> getRevolutCurrencies() {
"EUR",
"GBP",
"HKD",
"HRK",
"HUF",
"ILS",
"ISK",
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
75 changes: 75 additions & 0 deletions account/src/test/java/bisq/account/accounts/F2FAccountTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
77 changes: 77 additions & 0 deletions account/src/test/java/bisq/account/accounts/SepaAccountTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading

0 comments on commit 538f8d3

Please sign in to comment.