diff --git a/core/src/main/java/bisq/core/payment/ReceiptValidator.java b/core/src/main/java/bisq/core/payment/ReceiptValidator.java index e4997c92cd..e2175b6650 100644 --- a/core/src/main/java/bisq/core/payment/ReceiptValidator.java +++ b/core/src/main/java/bisq/core/payment/ReceiptValidator.java @@ -66,10 +66,15 @@ class ReceiptValidator { 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; } } diff --git a/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java b/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java index 178d1ba1a6..4be13530a6 100644 --- a/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java +++ b/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java @@ -174,6 +174,57 @@ public class ReceiptValidatorTest { assertTrue(new ReceiptValidator(offer, account, predicates).isValid()); } + @Test + // 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()); + + verify(predicates, never()).isOfferRequireSameOrSpecificBank(offer, account); + verify(predicates, never()).isMatchingBankId(offer, account); + } + + @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);