gpt4 book ai didi

gradle - java.lang.IllegalArgumentException带Kotlin的Corda转换存储库

转载 作者:行者123 更新时间:2023-12-03 05:35:06 25 4
gpt4 key购买 nike

我尝试在带有TDD的Kotlin Corda转换存储库中编写契约(Contract)。所有IOUIssueTests均失败。

我有jdk 1.8.0_211。 Gradle 5.5。并安装了kotlin插件。借条状态也得到执行。

这是我的5 IOUIssueTest的IOUContract:

 package net.corda.training.contract

import net.corda.core.contracts.*
import net.corda.core.transactions.LedgerTransaction
import net.corda.training.state.IOUState
/**
* This is where you'll add the contract code which defines how the [IOUState] behaves. Look at the unit tests in
* [IOUContractTests] for instructions on how to complete the [IOUContract] class.
*/
@LegalProseReference(uri = "<prose_contract_uri>")
class IOUContract : Contract {
companion object {
@JvmStatic
val IOU_CONTRACT_ID = "net.corda.training.contract.IOUContract"

}


/**
* Add any commands required for this contract as classes within this interface.
* It is useful to encapsulate your commands inside an interface, so you can use the [requireSingleCommand]
* function to check for a number of commands which implement this interface.
*/
interface Commands : CommandData {

class Issue : TypeOnlyCommandData(), Commands
}

/**
* The contract code for the [IOUContract].
* The constraints are self documenting so don't require any additional explanation.
*/
override fun verify(tx: LedgerTransaction) {
val command = tx.commands.requireSingleCommand<Commands>()

when (command.value) {

is Commands.Issue -> {
requireThat {
"No inputs should be consumed when issuing an IOU." using (tx.inputs.isEmpty())
"Only one output state should be created when issuing an IOU." using (tx.outputs.size == 1)
val iou = tx.outputStates.single() as IOUState
"A newly issued IOU must have a positive amount." using (iou.amount.quantity > 0)
"The lender and borrower cannot have the same identity." using (iou.lender !== iou.borrower)
"Both lender and borrower together only may sign IOU issue transaction." using(iou.participants.toSet() == iou.participants.map { it.owningKey}.toSet())

}
}

}

}
}

但是,当我运行IOUIsuueTest.kt时,出现以下错误:
java.lang.IllegalArgumentException: Attempted to find dependent attachment for class net/corda/core/contracts/TypeOnlyCommandData, but could not find a suitable candidate.

at net.corda.core.transactions.TransactionBuilder.addMissingDependency(TransactionBuilder.kt:179)
at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core(TransactionBuilder.kt:160)
at net.corda.core.transactions.TransactionBuilder.toWireTransactionWithContext$core$default(TransactionBuilder.kt:128)
at net.corda.core.transactions.TransactionBuilder.toWireTransaction(TransactionBuilder.kt:125)
at net.corda.testing.dsl.TestTransactionDSLInterpreter.toWireTransaction$test_utils(TestDSL.kt:95)
at net.corda.testing.dsl.TestLedgerDSLInterpreter.recordTransactionWithTransactionMap(TestDSL.kt:257)
at net.corda.testing.dsl.TestLedgerDSLInterpreter._transaction(TestDSL.kt:289)
at net.corda.testing.dsl.LedgerDSL._transaction(LedgerDSLInterpreter.kt)
at net.corda.testing.dsl.LedgerDSL.transaction(LedgerDSLInterpreter.kt:141)
at net.corda.testing.dsl.LedgerDSL.transaction$default(LedgerDSLInterpreter.kt:139)
at net.corda.training.contract.IOUIssueTests$mustIncludeIssueCommand$1.invoke(IOUIssueTests.kt:57)
at net.corda.training.contract.IOUIssueTests$mustIncludeIssueCommand$1.invoke(IOUIssueTests.kt:21)
at net.corda.testing.node.NodeTestUtils$ledger$2.invoke(NodeTestUtils.kt:39)
at net.corda.testing.node.NodeTestUtils$ledger$2.invoke(NodeTestUtils.kt)
at net.corda.testing.internal.InternalTestUtilsKt$withTestSerializationEnvIfNotSet$1.invoke(InternalTestUtils.kt:214)
at net.corda.testing.internal.InternalTestUtilsKt$withTestSerializationEnvIfNotSet$1.invoke(InternalTestUtils.kt)
at net.corda.testing.common.internal.CommonSerializationTestHelpersKt.asContextEnv(CommonSerializationTestHelpers.kt:11)
at net.corda.testing.internal.InternalSerializationTestHelpersKt.asTestContextEnv(InternalSerializationTestHelpers.kt:33)
at net.corda.testing.internal.InternalSerializationTestHelpersKt.asTestContextEnv$default(InternalSerializationTestHelpers.kt:31)
at net.corda.testing.internal.InternalTestUtilsKt.withTestSerializationEnvIfNotSet(InternalTestUtils.kt:214)
at net.corda.testing.node.NodeTestUtils.ledger(NodeTestUtils.kt:36)
at net.corda.testing.node.NodeTestUtils.ledger$default(NodeTestUtils.kt:23)
at net.corda.training.contract.IOUIssueTests.mustIncludeIssueCommand(IOUIssueTests.kt:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.

Java:66)

最佳答案

错误已修复。我已经使用过Kotlin单元测试。 Kotlin Unit Test

关于gradle - java.lang.IllegalArgumentException带Kotlin的Corda转换存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56853334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com