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

Prevent taking of offers with unequal bank account types (excl. SEPA) #3673

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion core/src/main/java/bisq/core/payment/ReceiptValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ boolean isValid() {
return true;
}

// Aside from Sepa or Sepa Instant, payment methods need to match
if (!isEqualPaymentMethods) {
return false;
}

if (predicates.isOfferRequireSameOrSpecificBank(offer, account)) {
return predicates.isMatchingBankId(offer, account);
}

return isEqualPaymentMethods;
return true;
}
}
82 changes: 66 additions & 16 deletions core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
package bisq.core.payment;

import bisq.core.offer.Offer;
import bisq.core.payment.payload.PaymentMethod;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;

@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class ReceiptValidatorTest {
private ReceiptValidator validator;
private PaymentAccount account;
Expand All @@ -43,6 +44,11 @@ public void setUp() {
this.validator = new ReceiptValidator(offer, account, predicates);
}

@After
public void tearDown() {
verifyZeroInteractions(offer);
}

@Test
public void testIsValidWhenCurrencyDoesNotMatch() {
when(predicates.isMatchingCurrency(offer, account)).thenReturn(false);
Expand Down Expand Up @@ -169,12 +175,59 @@ public void testIsValidWhenNationalBankAccount() {
}

@Test
public void testIsValidWhenWesternUnionAccount() {
account = mock(WesternUnionAccount.class);
// Same or Specific Bank offers can't be taken by National Bank accounts. TODO: Consider partially relaxing to allow Specific Banks.
public void testIsValidWhenNationalBankAccountAndOfferIsNot() {
account = mock(NationalBankAccount.class);

when(predicates.isMatchingCurrency(offer, account)).thenReturn(true);
when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(false);
when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true);
when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false);
when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false);

assertFalse(new ReceiptValidator(offer, account, predicates).isValid());

verify(predicates, never()).isOfferRequireSameOrSpecificBank(offer, account);
verify(predicates, never()).isMatchingBankId(offer, account);
}

@Test
// National or Same Bank offers can't be taken by Specific Banks accounts. TODO: Consider partially relaxing to allow National Bank.
public void testIsValidWhenSpecificBanksAccountAndOfferIsNot() {
account = mock(SpecificBanksAccount.class);

when(predicates.isMatchingCurrency(offer, account)).thenReturn(true);
when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(false);
when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true);
when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false);
when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false);

assertFalse(new ReceiptValidator(offer, account, predicates).isValid());

PaymentMethod.WESTERN_UNION = mock(PaymentMethod.class);
verify(predicates, never()).isOfferRequireSameOrSpecificBank(offer, account);
verify(predicates, never()).isMatchingBankId(offer, account);
}

when(offer.getPaymentMethod()).thenReturn(PaymentMethod.WESTERN_UNION);
@Test
// National or Specific Bank offers can't be taken by Same Bank accounts.
public void testIsValidWhenSameBankAccountAndOfferIsNot() {
account = mock(SameBankAccount.class);

when(predicates.isMatchingCurrency(offer, account)).thenReturn(true);
when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(false);
when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true);
when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false);
when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false);

assertFalse(new ReceiptValidator(offer, account, predicates).isValid());

verify(predicates, never()).isOfferRequireSameOrSpecificBank(offer, account);
verify(predicates, never()).isMatchingBankId(offer, account);
}

@Test
public void testIsValidWhenWesternUnionAccount() {
account = mock(WesternUnionAccount.class);

when(predicates.isMatchingCurrency(offer, account)).thenReturn(true);
when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true);
Expand Down Expand Up @@ -202,17 +255,14 @@ public void testIsValidWhenWesternIrregularAccount() {
public void testIsValidWhenMoneyGramAccount() {
account = mock(MoneyGramAccount.class);

PaymentMethod.MONEY_GRAM = mock(PaymentMethod.class);

when(offer.getPaymentMethod()).thenReturn(PaymentMethod.MONEY_GRAM);

when(predicates.isMatchingCurrency(offer, account)).thenReturn(true);
when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true);
when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(false);
when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false);
when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false);
when(predicates.isOfferRequireSameOrSpecificBank(offer, account)).thenReturn(false);

assertTrue(new ReceiptValidator(offer, account, predicates).isValid());

verify(predicates, never()).isMatchingCountryCodes(offer, account);
verify(predicates, never()).isMatchingSepaOffer(offer, account);
verify(predicates, never()).isMatchingSepaInstant(offer, account);
verify(predicates, never()).isOfferRequireSameOrSpecificBank(offer, account);
}
}