diff --git a/src/main/java/bisq/core/payment/ReceiptPredicates.java b/src/main/java/bisq/core/payment/ReceiptPredicates.java index 6179213a..e103335c 100644 --- a/src/main/java/bisq/core/payment/ReceiptPredicates.java +++ b/src/main/java/bisq/core/payment/ReceiptPredicates.java @@ -100,11 +100,13 @@ boolean isMatchingCurrency(Offer offer, PaymentAccount account) { return codes.contains(offer.getCurrencyCode()); } - boolean isSepaRelated(Offer offer, PaymentAccount account) { - PaymentMethod offerPaymentMethod = offer.getPaymentMethod(); - return (account instanceof SepaAccount - || account instanceof SepaInstantAccount) - && (offerPaymentMethod.equals(PaymentMethod.SEPA) - || offerPaymentMethod.equals(PaymentMethod.SEPA_INSTANT)); + boolean isMatchingSepaOffer(Offer offer, PaymentAccount account) { + boolean isSepa = account instanceof SepaAccount; + boolean isSepaInstant = account instanceof SepaInstantAccount; + return offer.getPaymentMethod().equals(PaymentMethod.SEPA) && (isSepa || isSepaInstant); + } + + boolean isMatchingSepaInstant(Offer offer, PaymentAccount account) { + return offer.getPaymentMethod().equals(PaymentMethod.SEPA_INSTANT) && account instanceof SepaInstantAccount; } } diff --git a/src/main/java/bisq/core/payment/ReceiptValidator.java b/src/main/java/bisq/core/payment/ReceiptValidator.java index bd7ca8ba..e4997c92 100644 --- a/src/main/java/bisq/core/payment/ReceiptValidator.java +++ b/src/main/java/bisq/core/payment/ReceiptValidator.java @@ -56,13 +56,20 @@ boolean isValid() { } // We have same country - if (predicates.isSepaRelated(offer, account)) { - // Sepa or Sepa Instant + if (predicates.isMatchingSepaOffer(offer, account)) { + // Sepa offer and taker account is Sepa or Sepa Instant return true; - } else if (predicates.isOfferRequireSameOrSpecificBank(offer, account)) { + } + + if (predicates.isMatchingSepaInstant(offer, account)) { + // Sepa Instant offer and taker account + return true; + } + + if (predicates.isOfferRequireSameOrSpecificBank(offer, account)) { return predicates.isMatchingBankId(offer, account); - } else { - return isEqualPaymentMethods; } + + return isEqualPaymentMethods; } } diff --git a/src/main/java/bisq/core/trade/Contract.java b/src/main/java/bisq/core/trade/Contract.java index 4d60465a..2ec150d2 100644 --- a/src/main/java/bisq/core/trade/Contract.java +++ b/src/main/java/bisq/core/trade/Contract.java @@ -20,6 +20,7 @@ import bisq.core.monetary.Price; import bisq.core.offer.OfferPayload; import bisq.core.payment.payload.PaymentAccountPayload; +import bisq.core.payment.payload.PaymentMethod; import bisq.core.proto.CoreProtoResolver; import bisq.network.p2p.NodeAddress; @@ -110,12 +111,15 @@ public Contract(OfferPayload offerPayload, this.makerMultiSigPubKey = makerMultiSigPubKey; this.takerMultiSigPubKey = takerMultiSigPubKey; - // PaymentMethod need to be the same - checkArgument(makerPaymentAccountPayload.getPaymentMethodId() - .equals(takerPaymentAccountPayload.getPaymentMethodId()), - "payment methods of maker and taker must be the same.\n" + - "makerPaymentMethodId=" + makerPaymentAccountPayload.getPaymentMethodId() + "\n" + - "takerPaymentMethodId=" + takerPaymentAccountPayload.getPaymentMethodId()); + String makerPaymentMethodId = makerPaymentAccountPayload.getPaymentMethodId(); + String takerPaymentMethodId = takerPaymentAccountPayload.getPaymentMethodId(); + // For SEPA offers we accept also SEPA_INSTANT takers + // Otherwise both ids need to be the same + boolean result = (makerPaymentMethodId.equals(PaymentMethod.SEPA_ID) && takerPaymentMethodId.equals(PaymentMethod.SEPA_INSTANT_ID)) || + makerPaymentMethodId.equals(takerPaymentMethodId); + checkArgument(result, "payment methods of maker and taker must be the same.\n" + + "makerPaymentMethodId=" + makerPaymentMethodId + "\n" + + "takerPaymentMethodId=" + takerPaymentMethodId); } diff --git a/src/test/java/bisq/core/payment/ReceiptPredicatesTest.java b/src/test/java/bisq/core/payment/ReceiptPredicatesTest.java index d6a27602..e6de2beb 100644 --- a/src/test/java/bisq/core/payment/ReceiptPredicatesTest.java +++ b/src/test/java/bisq/core/payment/ReceiptPredicatesTest.java @@ -53,19 +53,23 @@ public void testIsMatchingCurrency() { } @Test - public void testIsSepaRelated() { + public void testIsMatchingSepaOffer() { Offer offer = mock(Offer.class); PaymentMethod.SEPA = mock(PaymentMethod.class); when(offer.getPaymentMethod()).thenReturn(PaymentMethod.SEPA); - assertTrue(predicates.isSepaRelated(offer, mock(SepaInstantAccount.class))); - assertTrue(predicates.isSepaRelated(offer, mock(SepaAccount.class))); + assertTrue(predicates.isMatchingSepaOffer(offer, mock(SepaInstantAccount.class))); + assertTrue(predicates.isMatchingSepaOffer(offer, mock(SepaAccount.class))); + } + @Test + public void testIsMatchingSepaInstant() { + Offer offer = mock(Offer.class); PaymentMethod.SEPA_INSTANT = mock(PaymentMethod.class); when(offer.getPaymentMethod()).thenReturn(PaymentMethod.SEPA_INSTANT); - assertTrue(predicates.isSepaRelated(offer, mock(SepaInstantAccount.class))); - assertTrue(predicates.isSepaRelated(offer, mock(SepaAccount.class))); + assertTrue(predicates.isMatchingSepaInstant(offer, mock(SepaInstantAccount.class))); + assertFalse(predicates.isMatchingSepaInstant(offer, mock(SepaAccount.class))); } @Test diff --git a/src/test/java/bisq/core/payment/ReceiptValidatorTest.java b/src/test/java/bisq/core/payment/ReceiptValidatorTest.java index 6ed342cb..93a74e4f 100644 --- a/src/test/java/bisq/core/payment/ReceiptValidatorTest.java +++ b/src/test/java/bisq/core/payment/ReceiptValidatorTest.java @@ -79,14 +79,25 @@ public void testIsValidWhenNotMatchingCodes() { } @Test - public void testIsValidWhenSepaRelated() { + public void testIsValidWhenSepaOffer() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(false); - when(predicates.isSepaRelated(offer, account)).thenReturn(true); + when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(true); assertTrue(validator.isValid()); - verify(predicates).isSepaRelated(offer, account); + verify(predicates).isMatchingSepaOffer(offer, account); + } + + @Test + public void testIsValidWhenSepaInstant() { + when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); + when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); + when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(true); + + assertTrue(validator.isValid()); + verify(predicates).isMatchingSepaOffer(offer, account); } @Test @@ -96,7 +107,8 @@ public void testIsValidWhenSpecificBankAccountAndOfferRequireSpecificBank() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false); when(predicates.isOfferRequireSameOrSpecificBank(offer, account)).thenReturn(true); when(predicates.isMatchingBankId(offer, account)).thenReturn(false); @@ -110,7 +122,8 @@ public void testIsValidWhenSameBankAccountAndOfferRequireSpecificBank() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false); when(predicates.isOfferRequireSameOrSpecificBank(offer, account)).thenReturn(true); when(predicates.isMatchingBankId(offer, account)).thenReturn(false); @@ -124,7 +137,8 @@ public void testIsValidWhenSpecificBankAccount() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false); when(predicates.isOfferRequireSameOrSpecificBank(offer, account)).thenReturn(true); when(predicates.isMatchingBankId(offer, account)).thenReturn(true); @@ -138,7 +152,8 @@ public void testIsValidWhenSameBankAccount() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaOffer(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaInstant(offer, account)).thenReturn(false); when(predicates.isOfferRequireSameOrSpecificBank(offer, account)).thenReturn(true); when(predicates.isMatchingBankId(offer, account)).thenReturn(true); @@ -152,7 +167,9 @@ public void testIsValidWhenNationalBankAccount() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(offer, account)).thenReturn(false); + when(predicates.isMatchingSepaOffer(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()); @@ -169,7 +186,8 @@ public void testIsValidWhenWesternUnionAccount() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(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()); @@ -180,7 +198,8 @@ public void testIsValidWhenWesternIrregularAccount() { when(predicates.isMatchingCurrency(offer, account)).thenReturn(true); when(predicates.isEqualPaymentMethods(offer, account)).thenReturn(true); when(predicates.isMatchingCountryCodes(offer, account)).thenReturn(true); - when(predicates.isSepaRelated(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(validator.isValid());