mirror of
https://github.com/corda/corda.git
synced 2024-12-27 08:22:35 +00:00
Trying to fix EnclaveletTest.kt
Trying to fix EnclaveletTest.kt Trying to fix EnclaveletTest.kt Trying to fix EnclaveletTest.kt EnclaveletTest passes. Restored incorrectly removed function in TransactionDSLInterpreter. Fixed NativeSgxApiTest
This commit is contained in:
parent
9284e731c0
commit
85bc0a38a2
@ -21,30 +21,35 @@ class NativeSgxApiTest {
|
||||
val enclavePath = "../sgx-jvm/jvm-enclave/enclave/build/cordaenclave.signed.so"
|
||||
}
|
||||
|
||||
private val stubbedCashContractBytes = Cash.PROGRAM_ID.toByteArray()
|
||||
|
||||
@Ignore("The SGX code is not part of the standard build yet")
|
||||
@Test
|
||||
fun `verification of valid transaction works`() {
|
||||
ledger {
|
||||
// Issue a couple of cash states and spend them.
|
||||
val wtx1 = transaction {
|
||||
output("c1", Cash.State(1000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "c1", Cash.State(1000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, Cash.Commands.Issue())
|
||||
verifies()
|
||||
}
|
||||
val wtx2 = transaction {
|
||||
output("c2", Cash.State(2000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "c2", Cash.State(2000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, Cash.Commands.Issue())
|
||||
verifies()
|
||||
}
|
||||
val wtx3 = transaction {
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
input("c1")
|
||||
input("c2")
|
||||
output(Cash.State(3000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MINI_CORP_PUBKEY)))
|
||||
output(Cash.PROGRAM_ID, "c3", Cash.State(3000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MINI_CORP_PUBKEY)))
|
||||
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
|
||||
val req = TransactionVerificationRequest(wtx3.serialize(), arrayOf(wtx1.serialize(), wtx2.serialize()), emptyArray())
|
||||
val req = TransactionVerificationRequest(wtx3.serialize(), arrayOf(wtx1.serialize(), wtx2.serialize()), arrayOf(stubbedCashContractBytes))
|
||||
val serialized = req.serialize()
|
||||
assertNull(NativeSgxApi.verify(enclavePath, serialized.bytes))
|
||||
}
|
||||
|
@ -3,15 +3,17 @@
|
||||
package com.r3.enclaves.txverify
|
||||
|
||||
import com.esotericsoftware.minlog.Log
|
||||
import net.corda.core.contracts.HashAttachmentConstraint
|
||||
import net.corda.core.crypto.sha256
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.transactions.WireTransaction
|
||||
import net.corda.nodeapi.internal.serialization.GeneratedAttachment
|
||||
import java.io.File
|
||||
|
||||
// This file implements the functionality of the SGX transaction verification enclave.
|
||||
|
||||
|
||||
/** This is just used to simplify marshalling across the enclave boundary (EDL is a bit awkward) */
|
||||
@CordaSerializable
|
||||
class TransactionVerificationRequest(val wtxToVerify: SerializedBytes<WireTransaction>,
|
||||
@ -35,9 +37,9 @@ fun verifyInEnclave(reqBytes: ByteArray) {
|
||||
val dependencies = req.dependencies.map { it.deserialize() }.associateBy { it.id }
|
||||
val ltx = wtxToVerify.toLedgerTransaction(
|
||||
resolveIdentity = { null },
|
||||
resolveAttachment = { null },
|
||||
resolveAttachment = { secureHash -> req.attachments.filter { it.sha256() == secureHash }.map { GeneratedAttachment(it) }.singleOrNull() },
|
||||
resolveStateRef = { dependencies[it.txhash]?.outputs?.get(it.index) },
|
||||
resolveContractAttachment = { null }
|
||||
resolveContractAttachment = { (it.constraint as HashAttachmentConstraint).attachmentId }
|
||||
)
|
||||
ltx.verify()
|
||||
}
|
||||
|
@ -18,31 +18,33 @@ import kotlin.test.assertTrue
|
||||
|
||||
class EnclaveletTest {
|
||||
|
||||
private val stubbedCashContractBytes = Cash.PROGRAM_ID.toByteArray()
|
||||
|
||||
@Test
|
||||
fun success() {
|
||||
ledger {
|
||||
// Issue a couple of cash states and spend them.
|
||||
val wtx1 = transaction {
|
||||
attachment(Cash.PROGRAM_ID)
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "c1", Cash.State(1000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, Cash.Commands.Issue())
|
||||
verifies()
|
||||
}
|
||||
val wtx2 = transaction {
|
||||
attachment(Cash.PROGRAM_ID)
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "c2", Cash.State(2000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, Cash.Commands.Issue())
|
||||
verifies()
|
||||
}
|
||||
val wtx3 = transaction {
|
||||
attachment(Cash.PROGRAM_ID)
|
||||
input(Cash.PROGRAM_ID, "c1")
|
||||
input(Cash.PROGRAM_ID, "c2")
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
input("c1")
|
||||
input("c2")
|
||||
output(Cash.PROGRAM_ID, "c3", Cash.State(3000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MINI_CORP_PUBKEY)))
|
||||
command(MEGA_CORP_PUBKEY, Cash.Commands.Move())
|
||||
verifies()
|
||||
}
|
||||
val req = TransactionVerificationRequest(wtx3.serialize(), arrayOf(wtx1.serialize(), wtx2.serialize()), emptyArray())
|
||||
val req = TransactionVerificationRequest(wtx3.serialize(), arrayOf(wtx1.serialize(), wtx2.serialize()), arrayOf(stubbedCashContractBytes))
|
||||
val serialized = req.serialize()
|
||||
Files.write(Paths.get("/tmp/req"), serialized.bytes)
|
||||
verifyInEnclave(serialized.bytes)
|
||||
@ -54,26 +56,27 @@ class EnclaveletTest {
|
||||
ledger {
|
||||
// Issue a couple of cash states and spend them.
|
||||
val wtx1 = transaction {
|
||||
attachment(Cash.PROGRAM_ID)
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "c1", Cash.State(1000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, Cash.Commands.Issue())
|
||||
verifies()
|
||||
}
|
||||
val wtx2 = transaction {
|
||||
attachment(Cash.PROGRAM_ID)
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
output(Cash.PROGRAM_ID, "c2", Cash.State(2000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MEGA_CORP_PUBKEY)))
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, Cash.Commands.Issue())
|
||||
verifies()
|
||||
}
|
||||
val wtx3 = transaction {
|
||||
attachment(Cash.PROGRAM_ID)
|
||||
input(Cash.PROGRAM_ID, "c1")
|
||||
input(Cash.PROGRAM_ID, "c2")
|
||||
attachments(Cash.PROGRAM_ID)
|
||||
input("c1")
|
||||
input("c2")
|
||||
command(DUMMY_CASH_ISSUER.party.owningKey, DummyCommandData)
|
||||
output(Cash.PROGRAM_ID, "c3", Cash.State(3000.POUNDS `issued by` DUMMY_CASH_ISSUER, AnonymousParty(MINI_CORP_PUBKEY)))
|
||||
failsWith("Required ${Cash.Commands.Move::class.java.canonicalName} command")
|
||||
}
|
||||
val req = TransactionVerificationRequest(wtx3.serialize(), arrayOf(wtx1.serialize(), wtx2.serialize()), emptyArray())
|
||||
// TODO need to add the CashContract Attachment Bytes
|
||||
val req = TransactionVerificationRequest(wtx3.serialize(), arrayOf(wtx1.serialize(), wtx2.serialize()), arrayOf(stubbedCashContractBytes))
|
||||
val e = assertFailsWith<Exception> { verifyInEnclave(req.serialize().bytes) }
|
||||
assertTrue(e.message!!.contains("Required ${Cash.Commands.Move::class.java.canonicalName} command"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user