我的问题是如何在流量测试中上传附件以使此测试成功。
这是我在trader-demo flowtest中做的测试
private fun issue_commercial_paper( amount: Amount<Currency>,
issueRef: OpaqueBytes,
recipient: Party,
notary: Party,
progressTracker: ProgressTracker): SignedTransaction {
val p = CommercialPaperIssueFlow(amount,issueRef,recipient,notary,progressTracker)
val future = BankCorpNode.services.startFlow(p)
mockNet.runNetwork()
return future.resultFuture.getOrThrow()
}
@Test
fun `trade issuance`(){
issue_commercial_paper(1000.DOLLARS,OpaqueBytes.of(42.toByte()),ACorp,notary,CommercialPaperIssueFlow.tracker())
val pass = SellerFlow(BCorp ,500.DOLLARS, SellerFlow.tracker() )
val future = ACorpNode.services.startFlow(pass)
mockNet.runNetwork()
val results = future.resultFuture.getOrThrow()
assertNotNull(results)
}
这是错误
kotlin.KotlinNullPointerException
at net.corda.traderdemo.flow.CommercialPaperIssueFlow.call(CommercialPaperIssueFlow.kt:54)
at net.corda.traderdemo.flow.CommercialPaperIssueFlow.call(CommercialPaperIssueFlow.kt:25)
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96)
at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44)
at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092)
at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788)
at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100)
at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:63)
你可以参考这个样本,看看你是否可以提前帮助我们 https://github.com/corda/corda/tree/c4ceca378762fe1959f075a1c8b1c301e411b6b8/samples/trader-demo
答案 0 :(得分:0)
假设您的附件位于main/resources/my-attachment.jar
下。在Java流测试中,您将此附件上载到节点,如下所示:
nodeA.transaction(() -> {
InputStream attachmentStream = getClass().getClassLoader().getResourceAsStream("my-attachment.jar");
try {
nodeA.getServices().getAttachments().importAttachment(attachmentStream, "joel", "myAttachment");
} catch (IOException e) {
e.printStackTrace();
}
// The attachment is now uploaded to the node.
// TODO: Remainder of the test.
return null;
});
或者在Kotlin:
nodeA.transaction {
val attachmentStream = javaClass.classLoader.getResourceAsStream("my-attachment.jar")
nodeA.services.attachments.importAttachment(attachmentStream, "joel", "myAttachment")
// The attachment is now uploaded to the node.
// TODO: Remainder of the test.
}