diff --git a/core/src/main/java/bisq/core/payment/ReceiptValidator.java b/core/src/main/java/bisq/core/payment/ReceiptValidator.java index e4997c92cdc..e2175b66506 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 @@ 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; } } diff --git a/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java b/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java index 19c16d2f34a..4be13530a6c 100644 --- a/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java +++ b/core/src/test/java/bisq/core/payment/ReceiptValidatorTest.java @@ -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; @@ -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); @@ -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); @@ -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); } }