mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-10 09:20:04 +01: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
2 changed files with 20 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2013 Google Inc.
|
* Copyright 2013 Google Inc.
|
||||||
|
* Copyright 2014 Andreas Schildbach
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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>
|
* tx itself later if needed.</p>
|
||||||
*
|
*
|
||||||
* @author Kevin Greene
|
* @author Kevin Greene
|
||||||
|
* @author Andreas Schildbach
|
||||||
* @see <a href="https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki">BIP 0070</a>
|
* @see <a href="https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki">BIP 0070</a>
|
||||||
*/
|
*/
|
||||||
public class PaymentSession {
|
public class PaymentSession {
|
||||||
|
@ -597,8 +599,6 @@ public class PaymentSession {
|
||||||
try {
|
try {
|
||||||
if (request == null)
|
if (request == null)
|
||||||
throw new PaymentRequestException("request cannot be null");
|
throw new PaymentRequestException("request cannot be null");
|
||||||
if (!request.hasPaymentDetailsVersion())
|
|
||||||
throw new PaymentRequestException.InvalidVersion("No version");
|
|
||||||
if (request.getPaymentDetailsVersion() != 1)
|
if (request.getPaymentDetailsVersion() != 1)
|
||||||
throw new PaymentRequestException.InvalidVersion("Version 1 required. Received version " + request.getPaymentDetailsVersion());
|
throw new PaymentRequestException.InvalidVersion("Version 1 required. Received version " + request.getPaymentDetailsVersion());
|
||||||
paymentRequest = request;
|
paymentRequest = request;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2013 Google Inc.
|
* Copyright 2013 Google Inc.
|
||||||
|
* Copyright 2014 Andreas Schildbach
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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()));
|
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
|
@Test
|
||||||
public void testExpiredPaymentRequest() throws Exception {
|
public void testExpiredPaymentRequest() throws Exception {
|
||||||
MockPaymentSession paymentSession = new MockPaymentSession(newExpiredPaymentRequest());
|
MockPaymentSession paymentSession = new MockPaymentSession(newExpiredPaymentRequest());
|
||||||
|
|
Loading…
Add table
Reference in a new issue