mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
Fix handling of defaults when parsing the payment message. Bitpay is leaving out the payment details version which was handled incorrectly. Adds a testcase for the defaults.
This commit is contained in:
parent
4409891da1
commit
295e8a154d
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2013 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -72,6 +73,7 @@ import java.util.concurrent.Callable;
|
||||
* tx itself later if needed.</p>
|
||||
*
|
||||
* @author Kevin Greene
|
||||
* @author Andreas Schildbach
|
||||
* @see <a href="https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki">BIP 0070</a>
|
||||
*/
|
||||
public class PaymentSession {
|
||||
@ -597,8 +599,6 @@ public class PaymentSession {
|
||||
try {
|
||||
if (request == null)
|
||||
throw new PaymentRequestException("request cannot be null");
|
||||
if (!request.hasPaymentDetailsVersion())
|
||||
throw new PaymentRequestException.InvalidVersion("No version");
|
||||
if (request.getPaymentDetailsVersion() != 1)
|
||||
throw new PaymentRequestException.InvalidVersion("Version 1 required. Received version " + request.getPaymentDetailsVersion());
|
||||
paymentRequest = request;
|
||||
|
@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Copyright 2013 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -82,6 +83,23 @@ public class PaymentSessionTest {
|
||||
assertTrue(refundScript.equals(payment.getRefundTo(0).getScript()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaults() throws Exception {
|
||||
Protos.Output.Builder outputBuilder = Protos.Output.newBuilder()
|
||||
.setScript(ByteString.copyFrom(outputToMe.getScriptBytes()));
|
||||
Protos.PaymentDetails paymentDetails = Protos.PaymentDetails.newBuilder()
|
||||
.setTime(time)
|
||||
.addOutputs(outputBuilder)
|
||||
.build();
|
||||
Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.newBuilder()
|
||||
.setSerializedPaymentDetails(paymentDetails.toByteString())
|
||||
.build();
|
||||
MockPaymentSession paymentSession = new MockPaymentSession(paymentRequest);
|
||||
assertEquals(BigInteger.ZERO, paymentSession.getValue());
|
||||
assertNull(paymentSession.getPaymentUrl());
|
||||
assertNull(paymentSession.getMemo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpiredPaymentRequest() throws Exception {
|
||||
MockPaymentSession paymentSession = new MockPaymentSession(newExpiredPaymentRequest());
|
||||
|
Loading…
x
Reference in New Issue
Block a user