mirror of
https://github.com/corda/corda.git
synced 2025-02-20 01:16:42 +00:00
Added an openAttachment endpoint to the RPC interface and tests for the open, upload and exists attachment RPC interfaces.
This commit is contained in:
parent
cc45121bea
commit
539943d790
@ -16,6 +16,7 @@ import net.corda.core.node.services.Vault
|
||||
import net.corda.core.transactions.SignedTransaction
|
||||
import rx.Observable
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.time.Instant
|
||||
|
||||
data class StateMachineInfo(
|
||||
@ -99,6 +100,11 @@ interface CordaRPCOps : RPCOps {
|
||||
*/
|
||||
fun attachmentExists(id: SecureHash): Boolean
|
||||
|
||||
/**
|
||||
* Download an attachment JAR by ID
|
||||
*/
|
||||
fun openAttachment(id: SecureHash): InputStream
|
||||
|
||||
/**
|
||||
* Uploads a jar to the node, returns it's hash.
|
||||
*/
|
||||
|
@ -102,6 +102,7 @@ class CordaRPCOpsImpl(
|
||||
}
|
||||
|
||||
override fun attachmentExists(id: SecureHash) = services.storageService.attachments.openAttachment(id) != null
|
||||
override fun openAttachment(id: SecureHash) = services.storageService.attachments.openAttachment(id)!!.open()
|
||||
override fun uploadAttachment(jar: InputStream) = services.storageService.attachments.importAttachment(jar)
|
||||
override fun authoriseContractUpgrade(state: StateAndRef<*>, upgradedContractClass: Class<out UpgradedContract<*, *>>) = services.vaultService.authoriseContractUpgrade(state, upgradedContractClass)
|
||||
override fun deauthoriseContractUpgrade(state: StateAndRef<*>) = services.vaultService.deauthoriseContractUpgrade(state)
|
||||
|
@ -25,15 +25,22 @@ import net.corda.testing.expectEvents
|
||||
import net.corda.testing.node.MockNetwork
|
||||
import net.corda.testing.node.MockNetwork.MockNode
|
||||
import net.corda.testing.sequence
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import rx.Observable
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
|
||||
class CordaRPCOpsImplTest {
|
||||
|
||||
private companion object {
|
||||
val testJar = "net/corda/node/testing/test.jar"
|
||||
}
|
||||
|
||||
lateinit var network: MockNetwork
|
||||
lateinit var aliceNode: MockNode
|
||||
lateinit var notaryNode: MockNode
|
||||
@ -199,4 +206,24 @@ class CordaRPCOpsImplTest {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can upload an attachment`() {
|
||||
val inputJar = Thread.currentThread().contextClassLoader.getResourceAsStream(testJar)
|
||||
val secureHash = rpc.uploadAttachment(inputJar)
|
||||
assert(rpc.attachmentExists(secureHash))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `can download an uploaded attachment`() {
|
||||
val inputJar = Thread.currentThread().contextClassLoader.getResourceAsStream(testJar)
|
||||
val secureHash = rpc.uploadAttachment(inputJar)
|
||||
val bufferFile = ByteArrayOutputStream()
|
||||
val bufferRpc = ByteArrayOutputStream()
|
||||
|
||||
IOUtils.copy(Thread.currentThread().contextClassLoader.getResourceAsStream(testJar), bufferFile)
|
||||
IOUtils.copy(rpc.openAttachment(secureHash), bufferRpc)
|
||||
|
||||
assert(Arrays.equals(bufferFile.toByteArray(), bufferRpc.toByteArray()))
|
||||
}
|
||||
}
|
||||
|
BIN
node/src/test/resources/net/corda/node/testing/test.jar
Normal file
BIN
node/src/test/resources/net/corda/node/testing/test.jar
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user