Corda V1单元测试代码问题

时间:2017-10-17 08:16:18

标签: corda

请任何建议,但我同意git核心项目。大多数junit测试都有编译错误,有些无法正常运行。我在下面的代码中使用Junit测试V14版本的代码就可以了。但在CordaV1版本中。像爆炸一样弹出错误:

net.corda.core.transactions.MissingContractAttachments: Cannot find contract attachments for [com.legalcontract.contract.LegalContractCode]
    at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core_main(TransactionBuilder.kt:96) ~[corda-core-1.0.0.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core_main$default(TransactionBuilder.kt:87) ~[corda-core-1.0.0.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toWireTransaction(TransactionBuilder.kt:85) ~[corda-core-1.0.0.jar:?]
    at net.corda.core.transactions.TransactionBuilder.toLedgerTransaction(TransactionBuilder.kt:107) ~[corda-core-1.0.0.jar:?]
    at net.corda.core.transactions.TransactionBuilder.verify(TransactionBuilder.kt:113) ~[corda-core-1.0.0.jar:?]
    at com.legalcontract.flow.LegalContractFlow$Initiator.call(LegalContractFlow.kt:247) ~[main/:?]
    at com.legalcontract.flow.LegalContractFlow$Initiator.call(LegalContractFlow.kt:47) ~[main/:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:112) [corda-node-1.0.0.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:40) [corda-node-1.0.0.jar:?]
    at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_131]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_131]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_131]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]

代码:

@After
fun tearDown() {
    net.stopNodes()
}
@Before
fun setup() {
    net = MockNetwork(false, true)
}

class WrapperStream(input: InputStream) : FilterInputStream(input)

@Test
fun `flow a new status valid Legal Contract`() {

        val notaryNode = net.createNotaryNode()
        val a = net.createPartyNode(notaryNode.network.myAddress, CordaX500Name("a","London","GB"))
        val b = net.createPartyNode(notaryNode.network.myAddress, CordaX500Name("b","New York","US"))

        a.internals.registerInitiatedFlow(LegalContractFlow.Acceptor::class.java)
        b.internals.registerInitiatedFlow(LegalContractFlow.Acceptor::class.java)

        val attachment = gInputStreamAndHash()
        println(attachment)

        val id = a.database.transaction {
         a.attachments.importAttachment(attachment.inputStream)
        }


        assertEquals(attachment.sha256, id, "Attachment has correct SHA256 hash")
        LegalContractFlowTests.attachList.add(id.toString())

        var fileName: String = "test1"

        var legalContract: LegalContract = LegalContract(a.info.legalIdentities.first().name.toString(),LegalContractFlowTests.attachList.get(0))
//

        System.out.print(legalContract)
        var state: LegalContractState = LegalContractState(
                legalContract,
                a.info.legalIdentities.first(),
                b.info.legalIdentities.first())

        val flow = LegalContractFlow.Initiator(state,  b.info.chooseIdentity(), false)
        val future = a.services.startFlow(flow).resultFuture


        var signedTx = future.getOrThrow()


        for (node in listOf(a, b)) {
            assertEquals(signedTx, node.services.validatedTransactions.getTransaction(signedTx.id))
        }

    }

1 个答案:

答案 0 :(得分:0)

在Corda V1中,您需要告诉您的测试在查找合同附件时要扫描哪些包 - 请参阅https://docs.corda.net/key-concepts-contract-constraints.html#testing

这只是一块临时样板,预计将来会被删除。实际节点也不需要它,仅用于模拟节点。