Corda 在集成测试期间解析匿名参与方失败
我开发了一个简单的状态“item”,表示卖家将向一群匿名买家出售的物品。我写了流量测试,一切似乎都很顺利。我还想实施集成测试,以确认我的逻辑工作正常。我的流程失败,因为启动的卖方节点无法从其公钥解析买方。我能够在没有自己代码的情况下复制代码。我觉得我错过了注册步骤或其他什么,但是卖家节点可以使用X500名称解析买家节点。我有点困惑,为什么我在通过其公钥解决买方节点时遇到问题 要复制、克隆cordapps kotlin模板并用以下代码替换DriverBasedTest.kt的内容,请运行Corda 在集成测试期间解析匿名参与方失败,corda,Corda,我开发了一个简单的状态“item”,表示卖家将向一群匿名买家出售的物品。我写了流量测试,一切似乎都很顺利。我还想实施集成测试,以确认我的逻辑工作正常。我的流程失败,因为启动的卖方节点无法从其公钥解析买方。我能够在没有自己代码的情况下复制代码。我觉得我错过了注册步骤或其他什么,但是卖家节点可以使用X500名称解析买家节点。我有点困惑,为什么我在通过其公钥解决买方节点时遇到问题 要复制、克隆cordapps kotlin模板并用以下代码替换DriverBasedTest.kt的内容,请运行gradl
gradlew integrationTest
import net.corda.core.identity.AbstractParty
import net.corda.core.identity.CordaX500Name
import net.corda.core.utilities.getOrThrow
import net.corda.testing.core.TestIdentity
import net.corda.testing.driver.DriverDSL
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.NodeHandle
import net.corda.testing.driver.driver
import net.corda.testing.node.User
import org.junit.Test
import kotlin.test.assertEquals
class AnonymousTest {
private val seller = TestIdentity(CordaX500Name("Seller", "", "GB"))
private val buyer = TestIdentity(CordaX500Name("Buyer", "", "US"))
@Test
fun `anonymous resolution test`() = withDriver {
val sellerUser = User("sellerUser", "testPassword1", permissions = setOf("ALL"))
val buyerUser = User("buyerUser", "testPassword1", permissions = setOf("ALL"))
val sellerHandle = startNode(providedName = seller.name, rpcUsers = listOf(sellerUser)).getOrThrow()
startNode(providedName = buyer.name, rpcUsers = listOf(buyerUser)).getOrThrow()
val resolvedNameBuyerA = sellerHandle.resolveName(buyer.name)
assertEquals(buyer.name, resolvedNameBuyerA)
val resolveFromAnonymous = sellerHandle.resolveFromAnonymous(buyer.party.anonymise())
assertEquals(buyer.name, resolveFromAnonymous)
}
// Runs a test inside the Driver DSL, which provides useful functions for starting nodes, etc.
private fun withDriver(test: DriverDSL.() -> Unit) = driver(
DriverParameters(isDebug = true, startNodesInProcess = true)
) { test() }
// Makes an RPC call to retrieve another node's name from the network map.
private fun NodeHandle.resolveName(name: CordaX500Name) = rpc.wellKnownPartyFromX500Name(name)!!.name
private fun NodeHandle.resolveFromAnonymous(name: AbstractParty) = rpc.wellKnownPartyFromAnonymous(name)!!.name
}
试验结果如下:
kotlin.KotlinNullPointerException
at com.template.AnonymousTest.resolveFromAnonymous(DriverBasedTest.kt:40)
at com.template.AnonymousTest.access$resolveFromAnonymous(DriverBasedTest.kt:15)
at com.template.AnonymousTest$anonymous resolution test$1.invoke(DriverBasedTest.kt:28)
at com.template.AnonymousTest$anonymous resolution test$1.invoke(DriverBasedTest.kt:15)
at com.template.AnonymousTest$withDriver$1.invoke(DriverBasedTest.kt:35)
at com.template.AnonymousTest$withDriver$1.invoke(DriverBasedTest.kt:15)
at net.corda.testing.node.internal.DriverDSLImplKt.genericDriver(DriverDSLImpl.kt:1289)
at net.corda.testing.driver.Driver.driver(Driver.kt:197)
at com.template.AnonymousTest.withDriver(DriverBasedTest.kt:33)
at com.template.AnonymousTest.anonymous resolution test(DriverBasedTest.kt:20)
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.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:412)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)
请注意,Corda
TestIdentity
可能会产生误导,因为它们是新的、语义上独立的身份,即使您提供相同的名称
很高兴听到你们都准备好了,穆斯塔法。好运
TestIdentity
使用与节点中同名公钥不匹配的公钥创建标识。这个故事的寓意是TestIdentity不应该用于集成测试。是的,模板代码具有极大的误导性,因为helper函数startnodes
将TestIdentity
作为输入,让我认为输入超过了节点标识。我花了几个小时才明白事实并非如此。