From bb400364532000a10e7e3402aefb40c4cae4703e Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Sat, 5 Jul 2014 17:27:22 +0200 Subject: [PATCH] Fix a payment protocol unit test that had a forgotten @Test annotation and thus didn't actually work. --- .../protocols/payments/PaymentProtocol.java | 11 +++++ .../payments/PaymentProtocolTest.java | 45 +++++++++---------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/protocols/payments/PaymentProtocol.java b/core/src/main/java/com/google/bitcoin/protocols/payments/PaymentProtocol.java index 5d69088b..9a682858 100644 --- a/core/src/main/java/com/google/bitcoin/protocols/payments/PaymentProtocol.java +++ b/core/src/main/java/com/google/bitcoin/protocols/payments/PaymentProtocol.java @@ -23,6 +23,7 @@ import com.google.bitcoin.core.NetworkParameters; import com.google.bitcoin.core.Transaction; import com.google.bitcoin.crypto.X509Utils; import com.google.bitcoin.script.ScriptBuilder; +import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import com.google.protobuf.ByteString; @@ -269,6 +270,16 @@ public class PaymentProtocol { throw new PaymentProtocolException.PkiVerificationException(x); } } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("displayName", displayName) + .add("rootAuthorityName", rootAuthorityName) + .add("merchantSigningKey", merchantSigningKey) + .add("rootAuthority", rootAuthority) + .toString(); + } } /** diff --git a/core/src/test/java/com/google/bitcoin/protocols/payments/PaymentProtocolTest.java b/core/src/test/java/com/google/bitcoin/protocols/payments/PaymentProtocolTest.java index c1d21ae4..64c21495 100644 --- a/core/src/test/java/com/google/bitcoin/protocols/payments/PaymentProtocolTest.java +++ b/core/src/test/java/com/google/bitcoin/protocols/payments/PaymentProtocolTest.java @@ -16,16 +16,15 @@ package com.google.bitcoin.protocols.payments; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.security.KeyStore; -import java.security.PrivateKey; -import java.security.cert.X509Certificate; -import java.util.LinkedList; -import java.util.List; - +import com.google.bitcoin.core.*; +import com.google.bitcoin.crypto.X509Utils; +import com.google.bitcoin.params.TestNet3Params; +import com.google.bitcoin.params.UnitTestParams; +import com.google.bitcoin.protocols.payments.PaymentProtocol.Output; +import com.google.bitcoin.protocols.payments.PaymentProtocol.PkiVerificationData; +import com.google.bitcoin.protocols.payments.PaymentProtocolException.PkiVerificationException; +import com.google.bitcoin.script.ScriptBuilder; +import com.google.bitcoin.testing.FakeTxBuilder; import org.bitcoin.protocols.payments.Protos; import org.bitcoin.protocols.payments.Protos.Payment; import org.bitcoin.protocols.payments.Protos.PaymentACK; @@ -33,18 +32,13 @@ import org.bitcoin.protocols.payments.Protos.PaymentRequest; import org.junit.Before; import org.junit.Test; -import com.google.bitcoin.core.Address; -import com.google.bitcoin.core.Coin; -import com.google.bitcoin.core.ECKey; -import com.google.bitcoin.core.NetworkParameters; -import com.google.bitcoin.core.Transaction; -import com.google.bitcoin.crypto.X509Utils; -import com.google.bitcoin.params.UnitTestParams; -import com.google.bitcoin.protocols.payments.PaymentProtocol.Output; -import com.google.bitcoin.protocols.payments.PaymentProtocol.PkiVerificationData; -import com.google.bitcoin.protocols.payments.PaymentProtocolException.PkiVerificationException; -import com.google.bitcoin.script.ScriptBuilder; -import com.google.bitcoin.testing.FakeTxBuilder; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.cert.X509Certificate; +import java.util.LinkedList; +import java.util.List; + +import static org.junit.Assert.*; public class PaymentProtocolTest { @@ -105,9 +99,10 @@ public class PaymentProtocolTest { return paymentRequest.build(); } + @Test public void testPaymentRequest() throws Exception { // Create - PaymentRequest paymentRequest = PaymentProtocol.createPaymentRequest(NETWORK_PARAMS, AMOUNT, TO_ADDRESS, MEMO, + PaymentRequest paymentRequest = PaymentProtocol.createPaymentRequest(TestNet3Params.get(), AMOUNT, TO_ADDRESS, MEMO, PAYMENT_URL, MERCHANT_DATA).build(); byte[] paymentRequestBytes = paymentRequest.toByteArray(); @@ -117,10 +112,10 @@ public class PaymentProtocolTest { final List parsedOutputs = parsedPaymentRequest.getOutputs(); assertEquals(1, parsedOutputs.size()); assertEquals(AMOUNT, parsedOutputs.get(0).amount); - assertEquals(ScriptBuilder.createOutputScript(TO_ADDRESS).getProgram(), parsedOutputs.get(0).scriptData); + assertArrayEquals(ScriptBuilder.createOutputScript(TO_ADDRESS).getProgram(), parsedOutputs.get(0).scriptData); assertEquals(MEMO, parsedPaymentRequest.getMemo()); assertEquals(PAYMENT_URL, parsedPaymentRequest.getPaymentUrl()); - assertEquals(MERCHANT_DATA, parsedPaymentRequest.getMerchantData()); + assertArrayEquals(MERCHANT_DATA, parsedPaymentRequest.getMerchantData()); } @Test