From 1b37cef82222ee5128fcd90264cf0ba51fe942ff Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Thu, 5 Apr 2018 17:18:27 +0100 Subject: [PATCH] Minor: use of ByteArray.inputStream() and introduced PublicKey.hash (#2931) --- .../net/corda/core/internal/InternalUtils.kt | 5 +++- .../net/corda/core/utilities/EncodingUtils.kt | 4 +-- .../net/corda/core/flows/AttachmentTests.kt | 5 ++-- .../kotlin/net/corda/kryohook/KryoHook.kt | 5 +--- .../quasarhook/QuasarInstrumentationHook.kt | 5 ++-- .../internal/AttachmentsClassLoader.kt | 7 ++--- .../amqp/custom/InputStreamSerializer.kt | 2 +- .../internal/serialization/kryo/Kryo.kt | 3 +- .../serialization/kryo/KryoStreams.kt | 2 +- .../internal/AttachmentsClassLoaderTests.kt | 29 ++++++++++--------- .../amqp/SerializationOutputTests.kt | 5 ++-- .../internal/serialization/kryo/KryoTests.kt | 7 +++-- .../identity/PersistentIdentityService.kt | 3 +- .../node/messaging/TwoPartyTradeFlowTests.kt | 13 +++++---- 14 files changed, 48 insertions(+), 47 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt b/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt index 7f53da869f..a7aa8624c4 100644 --- a/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt +++ b/core/src/main/kotlin/net/corda/core/internal/InternalUtils.kt @@ -42,6 +42,7 @@ import java.nio.file.attribute.FileAttribute import java.nio.file.attribute.FileTime import java.security.KeyPair import java.security.PrivateKey +import java.security.PublicKey import java.security.cert.X509Certificate import java.time.Duration import java.time.temporal.Temporal @@ -230,7 +231,7 @@ fun logElapsedTime(label: String, logger: Logger? = null, body: () -> T): T /** Convert a [ByteArrayOutputStream] to [InputStreamAndHash]. */ fun ByteArrayOutputStream.toInputStreamAndHash(): InputStreamAndHash { val bytes = toByteArray() - return InputStreamAndHash(ByteArrayInputStream(bytes), bytes.sha256()) + return InputStreamAndHash(bytes.inputStream(), bytes.sha256()) } data class InputStreamAndHash(val inputStream: InputStream, val sha256: SecureHash.SHA256) { @@ -442,3 +443,5 @@ fun NotarisationRequest.generateSignature(serviceHub: ServiceHub): NotarisationR } return NotarisationRequestSignature(signature, serviceHub.myInfo.platformVersion) } + +val PublicKey.hash: SecureHash get() = encoded.sha256() diff --git a/core/src/main/kotlin/net/corda/core/utilities/EncodingUtils.kt b/core/src/main/kotlin/net/corda/core/utilities/EncodingUtils.kt index f4fdca5196..c7d5d75810 100644 --- a/core/src/main/kotlin/net/corda/core/utilities/EncodingUtils.kt +++ b/core/src/main/kotlin/net/corda/core/utilities/EncodingUtils.kt @@ -4,7 +4,7 @@ package net.corda.core.utilities import net.corda.core.crypto.Base58 import net.corda.core.crypto.Crypto -import net.corda.core.crypto.sha256 +import net.corda.core.internal.hash import java.nio.charset.Charset import java.security.PublicKey import java.util.* @@ -85,4 +85,4 @@ fun parsePublicKeyBase58(base58String: String): PublicKey = Crypto.decodePublicK fun PublicKey.toBase58String(): String = this.encoded.toBase58() /** Return the bytes of the SHA-256 output for this public key. */ -fun PublicKey.toSHA256Bytes(): ByteArray = this.encoded.sha256().bytes +fun PublicKey.toSHA256Bytes(): ByteArray = this.hash.bytes diff --git a/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt b/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt index 5047a18655..74414e47b1 100644 --- a/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt +++ b/core/src/test/kotlin/net/corda/core/flows/AttachmentTests.kt @@ -20,7 +20,6 @@ import net.corda.testing.node.internal.startFlow import org.junit.After import org.junit.Before import org.junit.Test -import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.util.jar.JarOutputStream import java.util.zip.ZipEntry @@ -59,7 +58,7 @@ class AttachmentTests { bobNode.registerInitiatedFlow(FetchAttachmentsResponse::class.java) // Insert an attachment into node zero's store directly. val id = aliceNode.database.transaction { - aliceNode.attachments.importAttachment(ByteArrayInputStream(fakeAttachment())) + aliceNode.attachments.importAttachment(fakeAttachment().inputStream()) } // Get node one to run a flow to fetch it and insert it. @@ -112,7 +111,7 @@ class AttachmentTests { val attachment = fakeAttachment() // Insert an attachment into node zero's store directly. val id = aliceNode.database.transaction { - aliceNode.attachments.importAttachment(ByteArrayInputStream(attachment)) + aliceNode.attachments.importAttachment(attachment.inputStream()) } // Corrupt its store. diff --git a/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt b/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt index 5afbd0e4ff..f08bdd52e9 100644 --- a/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt +++ b/experimental/kryo-hook/src/main/kotlin/net/corda/kryohook/KryoHook.kt @@ -5,13 +5,10 @@ import com.esotericsoftware.kryo.Kryo import com.esotericsoftware.kryo.io.Output import javassist.ClassPool import javassist.CtClass -import java.io.ByteArrayInputStream -import java.lang.StringBuilder import java.lang.instrument.ClassFileTransformer import java.lang.instrument.Instrumentation import java.security.ProtectionDomain import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.atomic.AtomicInteger class KryoHookAgent { companion object { @@ -69,7 +66,7 @@ object KryoHook : ClassFileTransformer { return null } return try { - val clazz = classPool.makeClass(ByteArrayInputStream(classfileBuffer)) + val clazz = classPool.makeClass(classfileBuffer.inputStream()) instrumentClass(clazz)?.toBytecode() } catch (throwable: Throwable) { println("SOMETHING WENT WRONG") diff --git a/experimental/quasar-hook/src/main/kotlin/net/corda/quasarhook/QuasarInstrumentationHook.kt b/experimental/quasar-hook/src/main/kotlin/net/corda/quasarhook/QuasarInstrumentationHook.kt index acd586fa31..1cc522206e 100644 --- a/experimental/quasar-hook/src/main/kotlin/net/corda/quasarhook/QuasarInstrumentationHook.kt +++ b/experimental/quasar-hook/src/main/kotlin/net/corda/quasarhook/QuasarInstrumentationHook.kt @@ -2,7 +2,6 @@ package net.corda.quasarhook import javassist.ClassPool import javassist.CtClass -import java.io.ByteArrayInputStream import java.lang.instrument.ClassFileTransformer import java.lang.instrument.Instrumentation import java.security.ProtectionDomain @@ -183,9 +182,9 @@ object QuasarInstrumentationHook : ClassFileTransformer { classfileBuffer: ByteArray ): ByteArray { return try { - val instrument = instrumentMap.get(className) + val instrument = instrumentMap[className] return instrument?.let { - val clazz = classPool.makeClass(ByteArrayInputStream(classfileBuffer)) + val clazz = classPool.makeClass(classfileBuffer.inputStream()) it(clazz) clazz.toBytecode() } ?: classfileBuffer diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoader.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoader.kt index 6117670407..5b53279f9f 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoader.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoader.kt @@ -5,7 +5,6 @@ import net.corda.core.contracts.ContractAttachment import net.corda.core.crypto.SecureHash import net.corda.core.internal.isUploaderTrusted import net.corda.core.serialization.CordaSerializable -import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.FileNotFoundException import java.io.InputStream @@ -101,12 +100,12 @@ class AttachmentsClassLoader(attachments: List, parent: ClassLoader if (url.protocol != "attachment") return null val attachment = idsToAttachments[SecureHash.parse(url.host)] ?: return null val path = url.path?.substring(1) ?: return null // Chop off the leading slash. - try { + return try { val stream = ByteArrayOutputStream() attachment.extractFile(path, stream) - return ByteArrayInputStream(stream.toByteArray()) + stream.toByteArray().inputStream() } catch (e: FileNotFoundException) { - return null + null } } } diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/custom/InputStreamSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/custom/InputStreamSerializer.kt index 47c5f0b539..ff2439bab9 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/custom/InputStreamSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/custom/InputStreamSerializer.kt @@ -36,6 +36,6 @@ object InputStreamSerializer : CustomSerializer.Implements(InputStr override fun readObject(obj: Any, schemas: SerializationSchemas, input: DeserializationInput): InputStream { val bits = input.readObject(obj, schemas, ByteArray::class.java) as ByteArray - return ByteArrayInputStream(bits) + return bits.inputStream() } } \ No newline at end of file diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/Kryo.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/Kryo.kt index e161768f65..86316cc006 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/Kryo.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/Kryo.kt @@ -28,7 +28,6 @@ import net.corda.nodeapi.internal.serialization.serializationContextKey import org.slf4j.Logger import org.slf4j.LoggerFactory import rx.Observable -import java.io.ByteArrayInputStream import java.io.InputStream import java.lang.reflect.InvocationTargetException import java.security.PrivateKey @@ -208,7 +207,7 @@ object InputStreamSerializer : Serializer() { System.arraycopy(chunk, 0, flattened, offset, chunk.size) offset += chunk.size } - return ByteArrayInputStream(flattened) + return flattened.inputStream() } } diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoStreams.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoStreams.kt index b1274223cc..1d26ba2703 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoStreams.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoStreams.kt @@ -66,5 +66,5 @@ internal fun Output.substitute(transform: (OutputStream) -> OutputStream) { } internal fun Input.substitute(transform: (InputStream) -> InputStream) { - inputStream = transform(SequenceInputStream(ByteArrayInputStream(buffer.copyOfRange(position(), limit())), inputStream)) + inputStream = transform(SequenceInputStream(buffer.copyOfRange(position(), limit()).inputStream(), inputStream)) } diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt index eeafa28630..7ac2ca9d4b 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/AttachmentsClassLoaderTests.kt @@ -2,7 +2,8 @@ package net.corda.nodeapi.internal import com.nhaarman.mockito_kotlin.doReturn import com.nhaarman.mockito_kotlin.whenever -import net.corda.core.contracts.* +import net.corda.core.contracts.Attachment +import net.corda.core.contracts.Contract import net.corda.core.crypto.SecureHash import net.corda.core.identity.CordaX500Name import net.corda.core.internal.declaredField @@ -22,9 +23,9 @@ import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.core.DUMMY_NOTARY_NAME import net.corda.testing.core.SerializationEnvironmentRule import net.corda.testing.core.TestIdentity +import net.corda.testing.internal.MockCordappConfigProvider import net.corda.testing.internal.kryoSpecific import net.corda.testing.internal.rigorousMock -import net.corda.testing.internal.MockCordappConfigProvider import net.corda.testing.services.MockAttachmentStorage import org.apache.commons.io.IOUtils import org.junit.Assert.* @@ -127,8 +128,8 @@ class AttachmentsClassLoaderTests { fun `test overlapping file exception`() { val storage = attachments val att0 = attachmentId - val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file.txt", "some data"))) - val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file.txt", "some other data"))) + val att1 = storage.importAttachment(fakeAttachment("file.txt", "some data").inputStream()) + val att2 = storage.importAttachment(fakeAttachment("file.txt", "some other data").inputStream()) assertFailsWith(AttachmentsClassLoader.OverlappingAttachments::class) { AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! }) @@ -139,8 +140,8 @@ class AttachmentsClassLoaderTests { fun `basic`() { val storage = attachments val att0 = attachmentId - val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file1.txt", "some data"))) - val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data"))) + val att1 = storage.importAttachment(fakeAttachment("file1.txt", "some data").inputStream()) + val att2 = storage.importAttachment(fakeAttachment("file2.txt", "some other data").inputStream()) val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! }) val txt = IOUtils.toString(cl.getResourceAsStream("file1.txt"), Charsets.UTF_8.name()) @@ -151,8 +152,8 @@ class AttachmentsClassLoaderTests { fun `Check platform independent path handling in attachment jars`() { val storage = MockAttachmentStorage() - val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("/folder1/foldera/file1.txt", "some data"))) - val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("\\folder1\\folderb\\file2.txt", "some other data"))) + val att1 = storage.importAttachment(fakeAttachment("/folder1/foldera/file1.txt", "some data").inputStream()) + val att2 = storage.importAttachment(fakeAttachment("\\folder1\\folderb\\file2.txt", "some other data").inputStream()) val data1a = readAttachment(storage.openAttachment(att1)!!, "/folder1/foldera/file1.txt") assertArrayEquals("some data".toByteArray(), data1a) @@ -171,8 +172,8 @@ class AttachmentsClassLoaderTests { fun `loading class AnotherDummyContract`() { val storage = attachments val att0 = attachmentId - val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file1.txt", "some data"))) - val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data"))) + val att1 = storage.importAttachment(fakeAttachment("file1.txt", "some data").inputStream()) + val att2 = storage.importAttachment(fakeAttachment("file2.txt", "some other data").inputStream()) val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! }, FilteringClassLoader) val contractClass = Class.forName(ISOLATED_CONTRACT_CLASS_NAME, true, cl) @@ -195,8 +196,8 @@ class AttachmentsClassLoaderTests { val bytes = contract.serialize() val storage = attachments val att0 = attachmentId - val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file1.txt", "some data"))) - val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data"))) + val att1 = storage.importAttachment(fakeAttachment("file1.txt", "some data").inputStream()) + val att2 = storage.importAttachment(fakeAttachment("file2.txt", "some other data").inputStream()) val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! }, FilteringClassLoader) @@ -221,8 +222,8 @@ class AttachmentsClassLoaderTests { val bytes = data.serialize(context = context2) val storage = attachments val att0 = attachmentId - val att1 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file1.txt", "some data"))) - val att2 = storage.importAttachment(ByteArrayInputStream(fakeAttachment("file2.txt", "some other data"))) + val att1 = storage.importAttachment(fakeAttachment("file1.txt", "some data").inputStream()) + val att2 = storage.importAttachment(fakeAttachment("file2.txt", "some other data").inputStream()) val cl = AttachmentsClassLoader(arrayOf(att0, att1, att2).map { storage.openAttachment(it)!! }, FilteringClassLoader) diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt index 822bf86396..a41f5b33c0 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/amqp/SerializationOutputTests.kt @@ -43,7 +43,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameters -import java.io.ByteArrayInputStream import java.io.IOException import java.io.NotSerializableException import java.math.BigDecimal @@ -1083,9 +1082,9 @@ class SerializationOutputTests(private val compression: CordaSerializationEncodi val factory2 = SerializerFactory(AllWhitelist, ClassLoader.getSystemClassLoader()) factory2.register(net.corda.nodeapi.internal.serialization.amqp.custom.InputStreamSerializer) val bytes = ByteArray(10) { it.toByte() } - val obj = ByteArrayInputStream(bytes) + val obj = bytes.inputStream() val obj2 = serdes(obj, factory, factory2, expectedEqual = false, expectDeserializedEqual = false) - val obj3 = ByteArrayInputStream(bytes) // Can't use original since the stream pointer has moved. + val obj3 = bytes.inputStream() // Can't use original since the stream pointer has moved. assertEquals(obj3.available(), obj2.available()) assertEquals(obj3.read(), obj2.read()) } diff --git a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoTests.kt b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoTests.kt index da045ce633..d7acb47e7f 100644 --- a/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoTests.kt +++ b/node-api/src/test/kotlin/net/corda/nodeapi/internal/serialization/kryo/KryoTests.kt @@ -29,7 +29,6 @@ import org.junit.runner.RunWith import org.junit.runners.Parameterized import org.junit.runners.Parameterized.Parameters import org.slf4j.LoggerFactory -import java.io.ByteArrayInputStream import java.io.InputStream import java.time.Instant import java.util.* @@ -190,7 +189,11 @@ class KryoTests(private val compression: CordaSerializationEncoding?) { @Test fun `HashCheckingStream (de)serialize`() { val rubbish = ByteArray(12345, { (it * it * 0.12345).toByte() }) - val readRubbishStream: InputStream = NodeAttachmentService.HashCheckingStream(SecureHash.sha256(rubbish), rubbish.size, ByteArrayInputStream(rubbish)).serialize(factory, context).deserialize(factory, context) + val readRubbishStream: InputStream = NodeAttachmentService.HashCheckingStream( + SecureHash.sha256(rubbish), + rubbish.size, + rubbish.inputStream() + ).serialize(factory, context).deserialize(factory, context) for (i in 0..12344) { assertEquals(rubbish[i], readRubbishStream.read().toByte()) } diff --git a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt index c5784c0bd0..a8ff0525e0 100644 --- a/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt +++ b/node/src/main/kotlin/net/corda/node/services/identity/PersistentIdentityService.kt @@ -5,6 +5,7 @@ import net.corda.core.crypto.SecureHash import net.corda.core.crypto.toStringShort import net.corda.core.identity.* import net.corda.core.internal.CertRole +import net.corda.core.internal.hash import net.corda.core.node.services.UnknownAnonymousPartyException import net.corda.core.serialization.SingletonSerializeAsToken import net.corda.core.utilities.MAX_HASH_HEX_SIZE @@ -62,7 +63,7 @@ class PersistentIdentityService(override val trustRoot: X509Certificate, ) } - private fun mapToKey(owningKey: PublicKey) = SecureHash.sha256(owningKey.encoded) + private fun mapToKey(owningKey: PublicKey) = owningKey.hash private fun mapToKey(party: PartyAndCertificate) = mapToKey(party.owningKey) } diff --git a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt index 4bd1dddbc0..604eca0f7a 100644 --- a/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt +++ b/node/src/test/kotlin/net/corda/node/messaging/TwoPartyTradeFlowTests.kt @@ -35,24 +35,26 @@ import net.corda.finance.contracts.asset.Cash import net.corda.finance.flows.TwoPartyTradeFlow.Buyer import net.corda.finance.flows.TwoPartyTradeFlow.Seller import net.corda.node.internal.StartedNode -import net.corda.node.services.api.WritableTransactionStorage import net.corda.node.services.api.IdentityServiceInternal +import net.corda.node.services.api.WritableTransactionStorage import net.corda.node.services.persistence.DBTransactionStorage import net.corda.node.services.persistence.checkpoints import net.corda.nodeapi.internal.persistence.CordaPersistence import net.corda.testing.core.* -import net.corda.testing.internal.LogHelper import net.corda.testing.dsl.LedgerDSL import net.corda.testing.dsl.TestLedgerDSLInterpreter import net.corda.testing.dsl.TestTransactionDSLInterpreter +import net.corda.testing.internal.LogHelper import net.corda.testing.internal.TEST_TX_TIME import net.corda.testing.internal.rigorousMock import net.corda.testing.internal.vault.VaultFiller -import net.corda.testing.node.* +import net.corda.testing.node.InMemoryMessagingNetwork +import net.corda.testing.node.MockServices import net.corda.testing.node.internal.InternalMockNetwork import net.corda.testing.node.internal.InternalMockNodeParameters import net.corda.testing.node.internal.pumpReceive import net.corda.testing.node.internal.startFlow +import net.corda.testing.node.ledger import org.assertj.core.api.Assertions.assertThat import org.junit.After import org.junit.Before @@ -60,7 +62,6 @@ import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.Parameterized import rx.Observable -import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.util.* import java.util.jar.JarOutputStream @@ -347,7 +348,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { it.closeEntry() } val attachmentID = aliceNode.database.transaction { - attachment(ByteArrayInputStream(stream.toByteArray())) + attachment(stream.toByteArray().inputStream()) } val bobsFakeCash = bobNode.database.transaction { @@ -451,7 +452,7 @@ class TwoPartyTradeFlowTests(private val anonymous: Boolean) { it.closeEntry() } val attachmentID = aliceNode.database.transaction { - attachment(ByteArrayInputStream(stream.toByteArray())) + attachment(stream.toByteArray().inputStream()) } val bobsKey = bobNode.services.keyManagementService.keys.single()